]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: fix PGO script flag matching
authorMichael Pratt <mpratt@google.com>
Wed, 24 May 2023 16:43:09 +0000 (12:43 -0400)
committerGopher Robot <gobot@golang.org>
Wed, 24 May 2023 17:13:42 +0000 (17:13 +0000)
build_pgo.txt hard-coded a check for / rather than using ${/}, causing a
failure on Windows

The failure in build_pgo_auto_multi.txt is more interesting. If the
first argument to stdout starts with `-` the script engine expects it to
be a flag to grep, and thus doesn't regexp-escape `\` in the expansion
of `${/}`.

The script engine doesn't _require_ that these are flags to grep, so it
is still possible to use them for matching, but this ideally will change
in the future, so change all patterns to avoid starting with `-`.

Fixes #60408.

Change-Id: Ie4041a730d22ce40a4436abae7713f211dcb42e4
Reviewed-on: https://go-review.googlesource.com/c/go/+/497881
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Michael Pratt <mpratt@google.com>
Auto-Submit: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/go/testdata/script/build_pgo.txt
src/cmd/go/testdata/script/build_pgo_auto.txt
src/cmd/go/testdata/script/build_pgo_auto_multi.txt

index 2e3354a1ca8c435012bceaf3bb834737b1fb738f..3b0804badd6f5db100d71608ef58e97f08fc45c8 100644 (file)
@@ -12,8 +12,10 @@ go build -x -pgo=prof -o triv.exe triv.go
 stderr 'compile.*-pgoprofile=.*prof.*triv.go'
 
 # check that PGO appears in build info
+# N.B. we can't start the stdout check with -pgo because the script assumes that
+# if the first arg starts with - it is a grep flag.
 go version -m triv.exe
-stdout '-pgo=.*/prof'
+stdout 'build\s+-pgo=.*'${/}'prof'
 
 # store the build ID
 go list -export -json=BuildID -pgo=prof triv.go
@@ -44,7 +46,7 @@ go build -x -pgo=prof -trimpath -o triv.exe triv.go
 
 # check that path is trimmed
 go version -m triv.exe
-stdout '-pgo=prof'
+stdout 'build\s+-pgo=prof'
 
 -- prof --
 -- triv.go --
index 117f0c01cbceec007750240c0c4e0ad9f7bc26a1..bb5b0e48287f090cd26163e6df03dba2925ef412 100644 (file)
@@ -10,8 +10,10 @@ stderr 'compile.*-pgoprofile=.*default\.pgo.*a1.go'
 stderr 'compile.*-p test/dep.*-pgoprofile=.*default\.pgo'
 
 # check that pgo appears in build info
+# N.B. we can't start the stdout check with -pgo because the script assumes that
+# if the first arg starts with - it is a grep flag.
 go version -m a1.exe
-stdout '-pgo=.*default\.pgo'
+stdout 'build\s+-pgo=.*default\.pgo'
 
 # use default.pgo for ... with a single main package
 go build -a -x -pgo=auto ./a/...
@@ -19,16 +21,16 @@ stderr 'compile.*-pgoprofile=.*default\.pgo.*a1.go'
 
 # check that pgo appears in build info
 go version -m a1$GOEXE
-stdout '-pgo=.*default\.pgo'
+stdout 'build\s+-pgo=.*default\.pgo'
 
 # build succeeds without PGO when default.pgo file is absent
 go build -a -x -pgo=auto -o nopgo.exe ./nopgo
 stderr 'compile.*nopgo.go'
-! stderr '-pgoprofile'
+! stderr 'compile.*-pgoprofile'
 
 # check that pgo doesn't appear in build info
 go version -m nopgo.exe
-! stdout -pgo=
+! stdout 'build\s+-pgo='
 
 # other build-related commands
 go install -a -n -pgo=auto ./a/a1
@@ -56,24 +58,24 @@ stderr 'compile.*-p test/dep.*-pgoprofile=.*default\.pgo'
 
 # check that pgo appears in build info
 go version -m a1.exe
-stdout '-pgo=.*default\.pgo'
+stdout 'build\s+-pgo=.*default\.pgo'
 
 go build -a -x -o nopgo.exe ./nopgo
 stderr 'compile.*nopgo.go'
-! stderr '-pgoprofile'
+! stderr 'compile.*-pgoprofile'
 
 # check that pgo doesn't appear in build info
 go version -m nopgo.exe
-! stdout -pgo=
+! stdout 'build\s+-pgo='
 
 # -pgo=off should turn off PGO.
 go build -a -x -pgo=off -o a1.exe ./a/a1
 stderr 'compile.*a1.go'
-! stderr '-pgoprofile'
+! stderr 'compile.*-pgoprofile'
 
 # check that pgo doesn't appear in build info
 go version -m a1.exe
-! stdout -pgo=
+! stdout 'build\s+-pgo='
 
 -- go.mod --
 module test
index 331a83e4c75f8404d2861c9a1bb971f23cfac848..66dc9128dccc740cfdcc8df6667bf36b344fc3ed 100644 (file)
@@ -36,14 +36,16 @@ stderr -count=3 'compile.*dep3(/|\\\\)dep3.go'
 stderr -count=2 'compile.*-pgoprofile=.*dep3(/|\\\\)dep3\.go'
 
 # check that pgo appears or not in build info as expected
+# N.B. we can't start the stdout check with -pgo because the script assumes that
+# if the first arg starts with - it is a grep flag.
 go version -m $GOBIN/a$GOEXE
-stdout '-pgo=.*a'${/}'default\.pgo'
+stdout 'build\s+-pgo=.*a'${/}'default\.pgo'
 
 go version -m $GOBIN/b$GOEXE
-stdout '-pgo=.*b'${/}'default\.pgo'
+stdout 'build\s+-pgo=.*b'${/}'default\.pgo'
 
 go version -m $GOBIN/nopgo$GOEXE
-! stdout -pgo=
+! stdout 'build\s+-pgo='
 
 # go test works the same way
 go test -a -n -pgo=auto ./a ./b ./nopgo