build.go: Strip temporary path, allow reproducible builds

https://github.com/restic/restic/commit/de48a5ac9c9c814c5870d9a52c2ff55607a8b1fa
This commit is contained in:
Zlatko Čalušić
2017-06-02 08:56:08 +02:00
parent ba98452c5e
commit fbac61c6cb
+5 -2
View File
@@ -195,8 +195,11 @@ func cleanEnv() (env []string) {
// build runs "go build args..." with GOPATH set to gopath.
func build(cwd, goos, goarch, gopath string, args ...string) error {
args = append([]string{"build"}, args...)
cmd := exec.Command("go", args...)
a := []string{"build"}
a = append(a, "-asmflags", fmt.Sprintf("-trimpath=%s", gopath))
a = append(a, "-gcflags", fmt.Sprintf("-trimpath=%s", gopath))
a = append(a, args...)
cmd := exec.Command("go", a...)
cmd.Env = append(cleanEnv(), "GOPATH="+gopath, "GOARCH="+goarch, "GOOS="+goos)
if !enableCGO {
cmd.Env = append(cmd.Env, "CGO_ENABLED=0")