From 93ac1605bd0faf88eb4fa7cc7600f850911ef884 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Mon, 13 Oct 2014 20:10:32 +0200 Subject: [PATCH] Set version on command line when building --- build.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/build.go b/build.go index 899aeed39..3d8cd61a3 100644 --- a/build.go +++ b/build.go @@ -42,6 +42,7 @@ var ( goarch string goos string noupgrade bool + version string ) const minGoVersion = 1.3 @@ -64,6 +65,7 @@ func main() { flag.StringVar(&goarch, "goarch", runtime.GOARCH, "GOARCH") flag.StringVar(&goos, "goos", runtime.GOOS, "GOOS") flag.BoolVar(&noupgrade, "no-upgrade", false, "Disable upgrade functionality") + flag.StringVar(&version, "version", getVersion(), "Set compiled in version string") flag.Parse() switch goarch { @@ -280,7 +282,7 @@ func clean() { func ldflags() string { var b bytes.Buffer b.WriteString("-w") - b.WriteString(fmt.Sprintf(" -X main.Version %s", version())) + b.WriteString(fmt.Sprintf(" -X main.Version %s", version)) b.WriteString(fmt.Sprintf(" -X main.BuildStamp %d", buildStamp())) b.WriteString(fmt.Sprintf(" -X main.BuildUser %s", buildUser())) b.WriteString(fmt.Sprintf(" -X main.BuildHost %s", buildHost())) @@ -298,7 +300,7 @@ func rmr(paths ...string) { } } -func version() string { +func getVersion() string { v := run("git", "describe", "--always", "--dirty") v = versionRe.ReplaceAllFunc(v, func(s []byte) []byte { s[0] = '+' @@ -345,7 +347,7 @@ func buildArch() string { } func archiveName() string { - return fmt.Sprintf("syncthing-%s-%s", buildArch(), version()) + return fmt.Sprintf("syncthing-%s-%s", buildArch(), version) } func run(cmd string, args ...string) []byte {