From: Michael Pratt Date: Wed, 24 May 2023 16:43:09 +0000 (-0400) Subject: cmd/go: fix PGO script flag matching X-Git-Tag: go1.21rc1~286 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=067dd573b2deba45a02383139bd2885321b2f71d;p=gostls13.git cmd/go: fix PGO script flag matching 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 Run-TryBot: Michael Pratt Auto-Submit: Michael Pratt TryBot-Result: Gopher Robot --- diff --git a/src/cmd/go/testdata/script/build_pgo.txt b/src/cmd/go/testdata/script/build_pgo.txt index 2e3354a1ca..3b0804badd 100644 --- a/src/cmd/go/testdata/script/build_pgo.txt +++ b/src/cmd/go/testdata/script/build_pgo.txt @@ -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 -- diff --git a/src/cmd/go/testdata/script/build_pgo_auto.txt b/src/cmd/go/testdata/script/build_pgo_auto.txt index 117f0c01cb..bb5b0e4828 100644 --- a/src/cmd/go/testdata/script/build_pgo_auto.txt +++ b/src/cmd/go/testdata/script/build_pgo_auto.txt @@ -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 diff --git a/src/cmd/go/testdata/script/build_pgo_auto_multi.txt b/src/cmd/go/testdata/script/build_pgo_auto_multi.txt index 331a83e4c7..66dc9128dc 100644 --- a/src/cmd/go/testdata/script/build_pgo_auto_multi.txt +++ b/src/cmd/go/testdata/script/build_pgo_auto_multi.txt @@ -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