}
}
- if *listTest {
+ if *listTest || (cfg.BuildPGO == "auto" && len(cmdline) > 1) {
all := pkgs
if !*listDeps {
all = loadPackageList(pkgs)
}
// Update import paths to distinguish the real package p
- // from p recompiled for q.test.
+ // from p recompiled for q.test, or to distinguish between
+ // p compiled with different PGO profiles.
// This must happen only once the build code is done
// looking at import paths, because it will get very confused
// if it sees these.
old := make(map[string]string)
for _, p := range all {
- if p.ForTest != "" {
+ if p.ForTest != "" || p.Internal.ForMain != "" {
new := p.Desc()
old[new] = p.ImportPath
p.ImportPath = new
m := make(map[string]string)
for _, p := range all {
for _, p1 := range p.Internal.Imports {
- if p1.ForTest != "" {
+ if p1.ForTest != "" || p1.Internal.ForMain != "" {
m[old[p1.ImportPath]] = p1.ImportPath
}
}
if p.ForTest != "" {
return p.ImportPath + " [" + p.ForTest + ".test]"
}
+ if p.Internal.ForMain != "" {
+ return p.ImportPath + " [" + p.Internal.ForMain + "]"
+ }
return p.ImportPath
}
Embed map[string][]string // //go:embed comment mapping
OrigImportPath string // original import path before adding '_test' suffix
PGOProfile string // path to PGO profile
+ ForMain string // the main package if this package is built specifically for it
Asmflags []string // -asmflags for this package
Gcflags []string // -gcflags for this package
p1.Internal.Imports = slices.Clone(p.Internal.Imports)
copied[p] = p1
p = p1
+ p.Internal.ForMain = pmain.ImportPath
}
p.Internal.PGOProfile = file
// Recurse to dependencies.
stderr 'compile.*-pgoprofile=.*b(/|\\\\)default\.pgo.*dep(/|\\\\)dep\.go'
! stderr 'compile.*-pgoprofile=.*nopgo(/|\\\\)nopgo_test\.go'
+# go list -deps prints packages built multiple times.
+go list -pgo=auto -deps ./a ./b ./nopgo
+stdout 'test/dep \[test/a\]'
+stdout 'test/dep \[test/b\]'
+stdout 'test/dep$'
+
# Here we have 3 main packages, a, b, and nopgo, where a and b each has
# its own default.pgo profile, and nopgo has none.
# All 3 main packages import dep and dep2, both of which then import dep3