build runs "go build args..." with GOPATH set to gopath.
(cwd string, env map[string]string, args ...string)
| 124 | |
| 125 | // build runs "go build args..." with GOPATH set to gopath. |
| 126 | func build(cwd string, env map[string]string, args ...string) error { |
| 127 | // -trimpath removes all absolute paths from the binary. |
| 128 | a := []string{"build", "-trimpath"} |
| 129 | |
| 130 | if enablePIE { |
| 131 | a = append(a, "-buildmode=pie") |
| 132 | } |
| 133 | |
| 134 | a = append(a, args...) |
| 135 | cmd := exec.Command("go", a...) |
| 136 | cmd.Env = os.Environ() |
| 137 | for k, v := range env { |
| 138 | cmd.Env = append(cmd.Env, k+"="+v) |
| 139 | } |
| 140 | if !enableCGO { |
| 141 | cmd.Env = append(cmd.Env, "CGO_ENABLED=0") |
| 142 | } |
| 143 | |
| 144 | printEnv(cmd.Env) |
| 145 | |
| 146 | cmd.Dir = cwd |
| 147 | cmd.Stdout = os.Stdout |
| 148 | cmd.Stderr = os.Stderr |
| 149 | |
| 150 | verbosePrintf("chdir %q\n", cwd) |
| 151 | verbosePrintf("go %q\n", a) |
| 152 | |
| 153 | return cmd.Run() |
| 154 | } |
| 155 | |
| 156 | // test runs "go test args..." with GOPATH set to gopath. |
| 157 | func test(cwd string, env map[string]string, args ...string) error { |
no test coverage detected