Skip to content

Commit d23727e

Browse files
Eric Stroczynskihasbro17
Eric Stroczynski
andauthored
cmd/operator-sdk/build: expand env in go build (#1535) (#1710)
* cmd/operator-sdk/build: expand env in go build * internal/util/projutil: always append os.Environ() to go cmds * CHANGELOG.md: add bug fix for env expansion in operator-sdk build Co-Authored-By: Haseeb Tariq <hasbro17@gmail.com>
1 parent 1f42f85 commit d23727e

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
- Fixes header file content validation when the content contains empty lines or centered text. ([#1544](https://github.com/operator-framework/operator-sdk/pull/1544))
1414
- Generated CSV's that include a deployment install strategy will be checked for a reference to `metadata.annotations['olm.targetNamespaces']`, and if one is not found a reference will be added to the `WATCH_NAMESPACE` env var for all containers in the deployment. This is a bug because any other value that references the CSV's namespace is incorrect. ([#1396](https://github.com/operator-framework/operator-sdk/pull/1396))
15+
- Build `-trimpath` was not being respected. `$GOPATH` was not expanding because `exec.Cmd{}` is not executed in a shell environment. ([#1535](https://github.com/operator-framework/operator-sdk/pull/1535))
1516

1617
## v0.8.1
1718

cmd/operator-sdk/build/cmd.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ func buildFunc(cmd *cobra.Command, args []string) error {
9292
goBuildEnv = append(goBuildEnv, "CGO_ENABLED=0")
9393
}
9494

95-
goTrimFlags := []string{"-gcflags", "all=-trimpath=${GOPATH}", "-asmflags", "all=-trimpath=${GOPATH}"}
95+
trimPath := os.ExpandEnv("all=-trimpath=${GOPATH}")
96+
goTrimFlags := []string{"-gcflags", trimPath, "-asmflags", trimPath}
9697
absProjectPath := projutil.MustGetwd()
9798
projectName := filepath.Base(absProjectPath)
9899

internal/util/projutil/exec.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@ func getGeneralArgs(cmd string, opts GoCmdOptions) ([]string, error) {
113113
}
114114

115115
func setCommandFields(c *exec.Cmd, opts GoCmdOptions) {
116+
c.Env = append(c.Env, os.Environ()...)
116117
if len(opts.Env) != 0 {
117-
c.Env = append(os.Environ(), opts.Env...)
118+
c.Env = append(c.Env, opts.Env...)
118119
}
119120
if opts.Dir != "" {
120121
c.Dir = opts.Dir

0 commit comments

Comments
 (0)