]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/script: remove special-case escaping logic for $WORK
authorBryan C. Mills <bcmills@google.com>
Thu, 18 Aug 2022 17:54:43 +0000 (13:54 -0400)
committerGopher Robot <gobot@golang.org>
Mon, 24 Oct 2022 21:18:16 +0000 (21:18 +0000)
Previously, the script engine implicitly escaped the path in the
$WORK environment variable to be the literal string '$WORK', which
produces somewhat better error messages in case of failure.

However, for a general-purpose script engine that implicit behavior is
surprising, and it isn't really necessary.

For #27494.

Change-Id: Ic1d5b8801bbd068157315685539e7cc2795b3aa5
Reviewed-on: https://go-review.googlesource.com/c/go/+/426854
Reviewed-by: Russ Cox <rsc@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>

src/cmd/go/internal/script/cmds.go
src/cmd/go/internal/script/state.go
src/cmd/go/script_test.go
src/cmd/go/testdata/script/build_n_cgo.txt
src/cmd/go/testdata/script/build_relative_tmpdir.txt
src/cmd/go/testdata/script/cache_unix.txt
src/cmd/go/testdata/script/mod_empty_err.txt
src/cmd/go/testdata/script/mod_gobuild_import.txt
src/cmd/go/testdata/script/modfile_flag.txt

index 1e98db1e2ca6c478c6164a185ed7d89830efad05..c0bd31ed657a684c03fa44e5b1fe940483e2e775 100644 (file)
@@ -707,9 +707,6 @@ func match(s *State, args []string, text, name string) error {
                text = string(data)
        }
 
-       // Matching against workdir would be misleading.
-       text = strings.ReplaceAll(text, s.workdir, "$WORK")
-
        if n > 0 {
                count := len(re.FindAllString(text, -1))
                if count != n {
index fcbe90531ad1b80e79762834c0fc10f849eabdff..f40c4426da7966bafd169a8d3ad0d7a09146d9c4 100644 (file)
@@ -132,13 +132,6 @@ func (s *State) ExpandEnv(str string, inRegexp bool) string {
        return os.Expand(str, func(key string) string {
                e := s.envMap[key]
                if inRegexp {
-                       // Replace workdir with $WORK, since we have done the same substitution in
-                       // the text we're about to compare against.
-                       //
-                       // TODO(bcmills): This seems out-of-place in the script engine.
-                       // See if we can remove it.
-                       e = strings.ReplaceAll(e, s.workdir, "$WORK")
-
                        // Quote to literal strings: we want paths like C:\work\go1.4 to remain
                        // paths rather than regular expressions.
                        e = regexp.QuoteMeta(e)
index e362ec346646ce9010435ecf4f2f3972238ab6c8..f0fe6d04602fe51b8c5336a87de2d665b9e2dd26 100644 (file)
@@ -115,11 +115,9 @@ func TestScript(t *testing.T) {
                                t.Fatal(err)
                        }
 
-                       if *testWork {
-                               work, _ := s.LookupEnv("WORK")
-                               t.Logf("$WORK=%s", work)
-                       }
                        t.Log(time.Now().UTC().Format(time.RFC3339))
+                       work, _ := s.LookupEnv("WORK")
+                       t.Logf("$WORK=%s", work)
 
                        // With -testsum, if a go.mod file is present in the test's initial
                        // working directory, run 'go mod tidy'.
index 7aa77aea42ad3b8bbcd3046845ffcd37a021163e..fa01927720b0dc94220c3623bef0ff86ddc299b4 100644 (file)
@@ -4,6 +4,7 @@
 # See issue golang.org/issue/37012.
 go build -n
 ! stderr '[/\\]\$WORK'
+stderr '[ =]\$WORK'
 
 -- go.mod --
 module m
index 3e98a67b813e1174924678765f80336c1c1f0eea..ea7412e1168e5154ca5ea71062464eabd0c25e63 100644 (file)
@@ -5,14 +5,14 @@ cd $WORK
 mkdir tmp
 env GOTMPDIR=tmp
 go build -work a
-stderr 'WORK=\$WORK' # the test script itself converts the absolute directory back to $WORK
+stderr 'WORK='$WORK
 
 # Similarly if TMP/TMPDIR is relative.
 env GOTMPDIR=
 env TMP=tmp    # Windows
 env TMPDIR=tmp # Unix
 go build -work a
-stderr 'WORK=\$WORK'
+stderr 'WORK='$WORK
 
 -- a/a.go --
 package a
index 0e07ba63823e52b12502e2ffcf3a0969ee8b207b..975960fd39f7eaad05ac45cb5cbea2e294697a0b 100644 (file)
@@ -17,17 +17,17 @@ env HOME=$WORK/home
 
 # With all three set, we should prefer GOCACHE.
 go env GOCACHE
-stdout '\$WORK/gocache$'
+stdout $WORK'/gocache$'
 
 # Without GOCACHE, we should prefer XDG_CACHE_HOME over HOME.
 env GOCACHE=
 go env GOCACHE
-stdout '\$WORK/xdg/go-build$$'
+stdout $WORK'/xdg/go-build$$'
 
 # With only HOME set, we should use $HOME/.cache.
 env XDG_CACHE_HOME=
 go env GOCACHE
-stdout '\$WORK/home/.cache/go-build$'
+stdout $WORK'/home/.cache/go-build$'
 
 # With no guidance from the environment, we must disable the cache, but that
 # should not cause commands that do not write to the cache to fail.
index c4359bccccf49cffd05862ee3dc3b41b60c26222..4b4a0076e0f72c753476ed3f0dd260d7b4fe416a 100644 (file)
@@ -4,20 +4,20 @@ env GO111MODULE=on
 cd $WORK
 
 go list -e -f {{.Error}} .
-stdout 'no Go files in \$WORK'
+stdout 'no Go files in '$WORK
 
 go list -e -f {{.Error}} ./empty
-stdout 'no Go files in \$WORK[/\\]empty'
+stdout 'no Go files in '$WORK${/}'empty'
 
 go list -e -f {{.Error}} ./exclude
-stdout 'build constraints exclude all Go files in \$WORK[/\\]exclude'
+stdout 'build constraints exclude all Go files in '$WORK${/}'exclude'
 
 go list -e -f {{.Error}} ./missing
 stdout 'stat '$WORK'[/\\]missing: directory not found'
 
 # use 'go build -n' because 'go list' reports no error.
 ! go build -n ./testonly
-stderr 'example.com/m/testonly: no non-test Go files in \$WORK[/\\]testonly'
+stderr 'example.com/m/testonly: no non-test Go files in '$WORK${/}'testonly'
 
 -- $WORK/go.mod --
 module example.com/m
index c13ae844b56739d1a265d3cc60b1ee39b2d926ac..70af331595058a4f13ffd80b6d09709f3252596f 100644 (file)
@@ -55,13 +55,13 @@ stdout w1.go
 env GO111MODULE=on
 exec $WORK/testfindonly$GOEXE gobuild.example.com/x/y/z/i $WORK
 ! stdout 'build constraints'
-stdout '^dir=\$WORK.+i err=<nil>$'
+stdout '^dir='$WORK'.+i err=<nil>$'
 
 # Issue 37153: Import with empty srcDir should work.
 env GO111MODULE=on
 exec $WORK/testfindonly$GOEXE gobuild.example.com/x/y/z/i ''
 ! stdout 'build constraints'
-stdout '^dir=\$WORK.+i err=<nil>$'
+stdout '^dir='$WORK'.+i err=<nil>$'
 
 -- go.mod --
 module gobuild.example.com/x/y/z
index 398e523a9ceb65b5438bbc8cd04c9ae4a0c1387c..6d28759849c962bf710514a746e81157d8c3768a 100644 (file)
@@ -14,7 +14,7 @@ grep example.com/m go.alt.mod
 # 'go env GOMOD' should print the path to the real file.
 # 'go env' does not recognize the '-modfile' flag.
 go env GOMOD
-stdout '^\$WORK[/\\]gopath[/\\]src[/\\]go.mod$'
+stdout '^'$WORK${/}gopath${/}src${/}'go\.mod$'
 
 # 'go list -m' should print the effective go.mod file as GoMod though.
 go list -m -f '{{.GoMod}}'