From 10b96ec705d2e2015c43de7c6e6b061a291db329 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Mon, 9 Apr 2018 12:20:09 +0200 Subject: [PATCH] Added option for reproducible build --- build.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/build.go b/build.go index f719eb5..d560e51 100644 --- a/build.go +++ b/build.go @@ -3,23 +3,37 @@ package main import ( + "flag" "os" "os/exec" "strings" ) +var reproducible = flag.Bool("r", false, "If set, the build will remove local directories from the debug infos.") + func main() { + flag.Parse() + env := os.Environ() wd, err := os.Getwd() if err != nil { panic(err) } - env = append(env, "GOPATH="+wd) - args := []string{"build"} + env = append(env, "GOPATH="+wd, "CGO_ENABLED=0") - if len(os.Args) == 2 { - target := os.Args[1] + args := []string{"build", "-ldflags=-s -w"} + + if *reproducible { + args = append(args, + "-asmflags=all=-trimpath="+wd, + "-gcflags=all=-trimpath="+wd, + "-a", + ) + } + + if len(flag.Args()) == 1 { + target := flag.Arg(0) targetParts := strings.Split(target, "/") if len(targetParts) != 2 { println("Invalid target specification. Example: windows/386")