From 7738709f7ad88164a914d0afe99b6c7f2c8f686e Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Wed, 24 Jun 2015 19:57:08 +0200 Subject: [PATCH] Support build tags for `build.go` --- build.go | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/build.go b/build.go index 701321e59..765432f0c 100644 --- a/build.go +++ b/build.go @@ -198,12 +198,24 @@ func gitVersion() string { } func main() { - for _, arg := range os.Args[1:] { + buildTags := []string{} + + skipNext := false + params := os.Args[1:] + for i, arg := range params { + if skipNext { + skipNext = false + continue + } + switch arg { case "-v", "--verbose": verbose = true case "-k", "--keep-gopath": keepGopath = true + case "-t", "-tags", "--tags": + skipNext = true + buildTags = strings.Split(params[i+1], " ") case "-h": showUsage(os.Stdout) default: @@ -213,6 +225,17 @@ func main() { } } + if len(buildTags) == 0 { + verbosePrintf("adding build-tag release\n") + buildTags = []string{"release"} + } + + for i := range buildTags { + buildTags[i] = strings.TrimSpace(buildTags[i]) + } + + verbosePrintf("build tags: %s\n", buildTags) + root, err := os.Getwd() if err != nil { die("Getwd(): %v\n", err) @@ -236,7 +259,7 @@ func main() { version := getVersion() compileTime := time.Now().Format(timeFormat) args := []string{ - "-tags", "release", + "-tags", strings.Join(buildTags, " "), "-ldflags", fmt.Sprintf(`-s -X main.version %q -X main.compiledAt %q`, version, compileTime), "-o", "restic", "github.com/restic/restic/cmd/restic", }