summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--addRepo.go2
-rw-r--r--args.go15
-rw-r--r--buildPackage.go19
-rw-r--r--main.go8
4 files changed, 29 insertions, 15 deletions
diff --git a/addRepo.go b/addRepo.go
index 1722d41..9b6d0eb 100644
--- a/addRepo.go
+++ b/addRepo.go
@@ -76,7 +76,7 @@ func (c *controlBox) addRepo(path string) {
}
lasttag := c.status.GetLastTagVersion()
- if args.Release {
+ if argv.Release {
debversion = c.status.DebianReleaseVersion()
c.dirtyL.SetText("false")
}
diff --git a/args.go b/args.go
index 70c34fd..f01e98b 100644
--- a/args.go
+++ b/args.go
@@ -12,15 +12,18 @@ import (
"go.wit.com/log"
)
-var args struct {
- NoGui bool `arg:"--no-gui" help:"don't open the gui, just make the .deb"`
- Repo string `arg:"--repo" help:"go get path to the repo"`
- PkgDir string `arg:"--pkg-dir" help:"set default directory (~/incoming/)"`
- Release bool `arg:"--release" help:"build a release from the last git tag"`
+var argv args
+
+type args struct {
+ NoGui bool `arg:"--no-gui" help:"don't open the gui, just make the .deb"`
+ Ldflags []string `arg:"--ldflags" help:"flags to pass to go build"`
+ Repo string `arg:"--repo" help:"go get path to the repo"`
+ PkgDir string `arg:"--pkg-dir" help:"set default directory (~/incoming/)"`
+ Release bool `arg:"--release" help:"build a release from the last git tag"`
}
func init() {
- arg.MustParse(&args)
+ arg.MustParse(&argv)
if debugger.ArgDebug() {
log.Info("cmd line --debugger == true")
diff --git a/buildPackage.go b/buildPackage.go
index 2fcfd32..95c76bb 100644
--- a/buildPackage.go
+++ b/buildPackage.go
@@ -47,7 +47,7 @@ func (c *controlBox) buildPackage() (bool, error) {
}
var fullfilename string
- if args.Release {
+ if argv.Release {
fullfilename = filepath.Join(homeDir, "go/bin", filename)
} else {
fullfilename = filename
@@ -59,7 +59,7 @@ func (c *controlBox) buildPackage() (bool, error) {
return false, errors.New("binary existed before build")
}
- if args.Release {
+ if argv.Release {
os.Unsetenv("GO111MODULE")
path := c.pathL.String() + "@latest"
cmd := []string{"go", "install", "-v", "-x", path}
@@ -71,9 +71,20 @@ func (c *controlBox) buildPackage() (bool, error) {
} else {
// set the GO111 build var to true. pass the versions to the compiler manually
os.Setenv("GO111MODULE", "off")
+ cmd := []string{"go", "build", "-v", "-x"}
+
+ // add some standard golang flags
vldflag := "-X main.VERSION=" + version
gldflag := "-X main.GUIVERSION=" + version // todo: git this from the filesystem
- if shell.Run([]string{"go", "build", "-v", "-x", "-ldflags", vldflag, "-ldflags", gldflag}) {
+ cmd = append(cmd, "-ldflags", vldflag)
+ cmd = append(cmd, "-ldflags", gldflag)
+
+ // add any flags from the command line
+ for _, flag := range argv.Ldflags {
+ cmd = append(cmd, "-ldflags", "-X " + flag)
+ }
+
+ if shell.Run(cmd) {
log.Warn("go build worked")
} else {
return false, errors.New("go build")
@@ -144,7 +155,7 @@ func (c *controlBox) buildPackage() (bool, error) {
// if the git repo has a "./build" script run it before packaging
// this way the user can put custom files in the .deb package
if c.status.Exists("build") {
- if args.Release {
+ if argv.Release {
os.Unsetenv("GO111MODULE")
} else {
os.Setenv("GO111MODULE", "off")
diff --git a/main.go b/main.go
index 4259608..4c239c0 100644
--- a/main.go
+++ b/main.go
@@ -21,7 +21,7 @@ var cBox *controlBox
var basicWindow *gadgets.BasicWindow
func main() {
- if args.Repo == "" {
+ if argv.Repo == "" {
log.Info("You need to tell me what repo you want to work on")
println("")
println("go-deb --repo go.wit.com/apps/helloworld")
@@ -32,11 +32,11 @@ func main() {
basicWindow = makebasicWindow()
- filepath := filepath.Join("/home/jcarr/go/src", args.Repo)
+ filepath := filepath.Join("/home/jcarr/go/src", argv.Repo)
os.Chdir(filepath)
// scan the repo
- cBox.addRepo(args.Repo)
+ cBox.addRepo(argv.Repo)
// look for a 'config' file in the repo
if cBox.readControlFile() == nil {
@@ -47,7 +47,7 @@ func main() {
cBox.computeControlValues()
// verify the values for the package
- if args.NoGui {
+ if argv.NoGui {
shell.TestTerminalColor()
if ok, err := cBox.buildPackage(); ok {
log.Info("build worked")