allow passing of -ldflags
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
d460d8a686
commit
051b470b90
|
@ -76,7 +76,7 @@ func (c *controlBox) addRepo(path string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
lasttag := c.status.GetLastTagVersion()
|
lasttag := c.status.GetLastTagVersion()
|
||||||
if args.Release {
|
if argv.Release {
|
||||||
debversion = c.status.DebianReleaseVersion()
|
debversion = c.status.DebianReleaseVersion()
|
||||||
c.dirtyL.SetText("false")
|
c.dirtyL.SetText("false")
|
||||||
}
|
}
|
||||||
|
|
15
args.go
15
args.go
|
@ -12,15 +12,18 @@ import (
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
var args struct {
|
var argv args
|
||||||
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"`
|
type args struct {
|
||||||
PkgDir string `arg:"--pkg-dir" help:"set default directory (~/incoming/)"`
|
NoGui bool `arg:"--no-gui" help:"don't open the gui, just make the .deb"`
|
||||||
Release bool `arg:"--release" help:"build a release from the last git tag"`
|
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() {
|
func init() {
|
||||||
arg.MustParse(&args)
|
arg.MustParse(&argv)
|
||||||
|
|
||||||
if debugger.ArgDebug() {
|
if debugger.ArgDebug() {
|
||||||
log.Info("cmd line --debugger == true")
|
log.Info("cmd line --debugger == true")
|
||||||
|
|
|
@ -47,7 +47,7 @@ func (c *controlBox) buildPackage() (bool, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var fullfilename string
|
var fullfilename string
|
||||||
if args.Release {
|
if argv.Release {
|
||||||
fullfilename = filepath.Join(homeDir, "go/bin", filename)
|
fullfilename = filepath.Join(homeDir, "go/bin", filename)
|
||||||
} else {
|
} else {
|
||||||
fullfilename = filename
|
fullfilename = filename
|
||||||
|
@ -59,7 +59,7 @@ func (c *controlBox) buildPackage() (bool, error) {
|
||||||
return false, errors.New("binary existed before build")
|
return false, errors.New("binary existed before build")
|
||||||
}
|
}
|
||||||
|
|
||||||
if args.Release {
|
if argv.Release {
|
||||||
os.Unsetenv("GO111MODULE")
|
os.Unsetenv("GO111MODULE")
|
||||||
path := c.pathL.String() + "@latest"
|
path := c.pathL.String() + "@latest"
|
||||||
cmd := []string{"go", "install", "-v", "-x", path}
|
cmd := []string{"go", "install", "-v", "-x", path}
|
||||||
|
@ -71,9 +71,20 @@ func (c *controlBox) buildPackage() (bool, error) {
|
||||||
} else {
|
} else {
|
||||||
// set the GO111 build var to true. pass the versions to the compiler manually
|
// set the GO111 build var to true. pass the versions to the compiler manually
|
||||||
os.Setenv("GO111MODULE", "off")
|
os.Setenv("GO111MODULE", "off")
|
||||||
|
cmd := []string{"go", "build", "-v", "-x"}
|
||||||
|
|
||||||
|
// add some standard golang flags
|
||||||
vldflag := "-X main.VERSION=" + version
|
vldflag := "-X main.VERSION=" + version
|
||||||
gldflag := "-X main.GUIVERSION=" + version // todo: git this from the filesystem
|
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")
|
log.Warn("go build worked")
|
||||||
} else {
|
} else {
|
||||||
return false, errors.New("go build")
|
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
|
// if the git repo has a "./build" script run it before packaging
|
||||||
// this way the user can put custom files in the .deb package
|
// this way the user can put custom files in the .deb package
|
||||||
if c.status.Exists("build") {
|
if c.status.Exists("build") {
|
||||||
if args.Release {
|
if argv.Release {
|
||||||
os.Unsetenv("GO111MODULE")
|
os.Unsetenv("GO111MODULE")
|
||||||
} else {
|
} else {
|
||||||
os.Setenv("GO111MODULE", "off")
|
os.Setenv("GO111MODULE", "off")
|
||||||
|
|
8
main.go
8
main.go
|
@ -21,7 +21,7 @@ var cBox *controlBox
|
||||||
var basicWindow *gadgets.BasicWindow
|
var basicWindow *gadgets.BasicWindow
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if args.Repo == "" {
|
if argv.Repo == "" {
|
||||||
log.Info("You need to tell me what repo you want to work on")
|
log.Info("You need to tell me what repo you want to work on")
|
||||||
println("")
|
println("")
|
||||||
println("go-deb --repo go.wit.com/apps/helloworld")
|
println("go-deb --repo go.wit.com/apps/helloworld")
|
||||||
|
@ -32,11 +32,11 @@ func main() {
|
||||||
|
|
||||||
basicWindow = makebasicWindow()
|
basicWindow = makebasicWindow()
|
||||||
|
|
||||||
filepath := filepath.Join("/home/jcarr/go/src", args.Repo)
|
filepath := filepath.Join("/home/jcarr/go/src", argv.Repo)
|
||||||
os.Chdir(filepath)
|
os.Chdir(filepath)
|
||||||
|
|
||||||
// scan the repo
|
// scan the repo
|
||||||
cBox.addRepo(args.Repo)
|
cBox.addRepo(argv.Repo)
|
||||||
|
|
||||||
// look for a 'config' file in the repo
|
// look for a 'config' file in the repo
|
||||||
if cBox.readControlFile() == nil {
|
if cBox.readControlFile() == nil {
|
||||||
|
@ -47,7 +47,7 @@ func main() {
|
||||||
cBox.computeControlValues()
|
cBox.computeControlValues()
|
||||||
// verify the values for the package
|
// verify the values for the package
|
||||||
|
|
||||||
if args.NoGui {
|
if argv.NoGui {
|
||||||
shell.TestTerminalColor()
|
shell.TestTerminalColor()
|
||||||
if ok, err := cBox.buildPackage(); ok {
|
if ok, err := cBox.buildPackage(); ok {
|
||||||
log.Info("build worked")
|
log.Info("build worked")
|
||||||
|
|
Loading…
Reference in New Issue