]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: keep BuildInfo list sorted even with -pgo
authorRuss Cox <rsc@golang.org>
Tue, 20 Jun 2023 17:14:11 +0000 (13:14 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 10 Aug 2023 15:55:10 +0000 (15:55 +0000)
The -pgo build setting is added late, so sort it into place.
Noticed while working on CL 504536.

Change-Id: I080d2389dc0b3176fb72c9e2434e5f3ae70e294e
Reviewed-on: https://go-review.googlesource.com/c/go/+/504537
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/go/internal/load/pkg.go
src/cmd/go/testdata/script/build_pgo_auto.txt

index 4ea1ebaa25da5a7454e4a7c414635ac50db496b7..0abc09186dee5b585ff2089f248479a265bd4a72 100644 (file)
@@ -2387,10 +2387,10 @@ func (p *Package) setBuildInfo(ctx context.Context, autoVCS bool) {
                        appendSetting("-ldflags", ldflags)
                }
        }
-       // N.B. -pgo added later by setPGOProfilePath.
        if cfg.BuildMSan {
                appendSetting("-msan", "true")
        }
+       // N.B. -pgo added later by setPGOProfilePath.
        if cfg.BuildRace {
                appendSetting("-race", "true")
        }
@@ -2928,6 +2928,10 @@ func setPGOProfilePath(pkgs []*Package) {
                } else {
                        appendBuildSetting(p.Internal.BuildInfo, "-pgo", file)
                }
+               // Adding -pgo breaks the sort order in BuildInfo.Settings. Restore it.
+               slices.SortFunc(p.Internal.BuildInfo.Settings, func(x, y debug.BuildSetting) int {
+                       return strings.Compare(x.Key, y.Key)
+               })
        }
 
        switch cfg.BuildPGO {
index 5dd799a77f20f8e8c55819268bf774aa34eca846..509be0d5c601f72c12a33aa5b57d25c4b0db1748 100644 (file)
@@ -14,6 +14,9 @@ stderr 'compile.*-p test/dep.*-pgoprofile=.*default\.pgo'
 # if the first arg starts with - it is a grep flag.
 stderr 'build\\t-pgo=.*default\.pgo'
 
+# check also that -pgo appears with the other flags, before non-flag settings
+! stderr 'build\\t[A-Za-z].*build\\t-pgo'
+
 # use default.pgo for ... with a single main package
 go build -n -pgo=auto ./a/...
 stderr 'compile.*-pgoprofile=.*default\.pgo.*a1.go'