2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-22 19:08:55 +00:00

Allow building without git

This commit is contained in:
Florian Weingarten 2015-08-19 00:31:14 -04:00
parent cd4cc1daec
commit 38f1a8d0a9

View File

@ -190,7 +190,8 @@ func gitVersion() string {
"--long", "--tags", "--dirty", "--always") "--long", "--tags", "--dirty", "--always")
out, err := cmd.Output() out, err := cmd.Output()
if err != nil { 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)) version := strings.TrimSpace(string(out))
@ -257,16 +258,19 @@ func main() {
die("copying files from %v to %v failed: %v\n", root, gopath, err) die("copying files from %v to %v failed: %v\n", root, gopath, err)
} }
version := getVersion()
compileTime := time.Now().Format(timeFormat)
output := "restic" output := "restic"
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
output = "restic.exe" 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{ args := []string{
"-tags", strings.Join(buildTags, " "), "-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", "-o", output, "github.com/restic/restic/cmd/restic",
} }