]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: don't substitute '$WORK' for work directory in -x heredocs
authorMichael Matloob <matloob@golang.org>
Fri, 28 Oct 2022 00:51:04 +0000 (17:51 -0700)
committerMichael Matloob <matloob@golang.org>
Fri, 28 Oct 2022 17:33:10 +0000 (17:33 +0000)
When writing the set of commands excuted for go build -x, $WORK is
substituted for the work directory in all the commnands. But this
includes the cat <<EOF commands used to create a file with the given
contents. While we can expect the shell to substitute $WORK properly,
commands that read input files, such as importcfgs won't do that
substitution.

This is necessary to fix the build_dash_x script test for CL 432535
because it removes .a files from the traditional stdlib install
locations. The test can pass even with importcfg packagefiles in $WORK
because all transitive imports are in the stdlib, and the compiler can
fall back to finding stdlib .a files in their traditional places, but
once they're gone the packagefile paths in $WORK will have paths that
contain the string $WORK, and os.Open will fail to open them for
reading. And since the fallback is gone the test will fail.

For #47257

Change-Id: I5db0066de6ed3ccf97927a78ce0939e3eb14aebe
Reviewed-on: https://go-review.googlesource.com/c/go/+/446116
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
src/cmd/go/internal/work/exec.go

index 79d5615f894fc7f304298e187a693ae6ba7acf1f..11f6c7a498d179c89ce8e36cf4f4852c2a14e2f8 100644 (file)
@@ -2061,7 +2061,7 @@ func (b *Builder) fmtcmd(dir string, format string, args ...any) string {
                        cmd = "cd " + dir + "\n" + cmd
                }
        }
-       if b.WorkDir != "" {
+       if b.WorkDir != "" && !strings.HasPrefix(cmd, "cat ") {
                cmd = strings.ReplaceAll(cmd, b.WorkDir, "$WORK")
                escaped := strconv.Quote(b.WorkDir)
                escaped = escaped[1 : len(escaped)-1] // strip quote characters