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()
|
||||
if args.Release {
|
||||
if argv.Release {
|
||||
debversion = c.status.DebianReleaseVersion()
|
||||
c.dirtyL.SetText("false")
|
||||
}
|
||||
|
|
15
args.go
15
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")
|
||||
|
|
|
@ -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")
|
||||
|
|
8
main.go
8
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")
|
||||
|
|
Loading…
Reference in New Issue