From 38f1a8d0a905ce17b544505598be60a6fdbc7726 Mon Sep 17 00:00:00 2001 From: Florian Weingarten Date: Wed, 19 Aug 2015 00:31:14 -0400 Subject: [PATCH] Allow building without git --- build.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/build.go b/build.go index c62cd8574..1e62384bc 100644 --- a/build.go +++ b/build.go @@ -190,7 +190,8 @@ func gitVersion() string { "--long", "--tags", "--dirty", "--always") out, err := cmd.Output() if err != nil { - die("git describe returned error: %v\n", err) + verbosePrintf("git describe returned error: %v\n", err) + return "" } version := strings.TrimSpace(string(out)) @@ -257,16 +258,19 @@ func main() { die("copying files from %v to %v failed: %v\n", root, gopath, err) } - version := getVersion() - compileTime := time.Now().Format(timeFormat) output := "restic" if runtime.GOOS == "windows" { output = "restic.exe" } - + version := getVersion() + compileTime := time.Now().Format(timeFormat) + ldflags := fmt.Sprintf("-s -X main.compiledAt %q", compileTime) + if version != "" { + ldflags = fmt.Sprintf("%s -X main.version %q", ldflags, version) + } args := []string{ "-tags", strings.Join(buildTags, " "), - "-ldflags", fmt.Sprintf(`-s -X main.version %q -X main.compiledAt %q`, version, compileTime), + "-ldflags", ldflags, "-o", output, "github.com/restic/restic/cmd/restic", }