BuildO string // -o flag
BuildP = runtime.GOMAXPROCS(0) // -p flag
BuildPGO string // -pgo flag
- BuildPGOFile string // profile selected by -pgo flag, an absolute path (if not empty)
BuildPkgdir string // -pkgdir flag
BuildRace bool // -race flag
BuildToolexec []string // -toolexec flag
TestmainGo *[]byte // content for _testmain.go
Embed map[string][]string // //go:embed comment mapping
OrigImportPath string // original import path before adding '_test' suffix
+ PGOProfile string // path to PGO profile
Asmflags []string // -asmflags for this package
Gcflags []string // -gcflags for this package
appendSetting("-ldflags", ldflags)
}
}
- if cfg.BuildPGOFile != "" {
+ if p.Internal.PGOProfile != "" {
if cfg.BuildTrimpath {
- appendSetting("-pgo", filepath.Base(cfg.BuildPGOFile))
+ appendSetting("-pgo", filepath.Base(p.Internal.PGOProfile))
} else {
- appendSetting("-pgo", cfg.BuildPGOFile)
+ appendSetting("-pgo", p.Internal.PGOProfile)
}
}
if cfg.BuildMSan {
return pkgs
}
-// setPGOProfilePath sets cfg.BuildPGOFile to the PGO profile path.
+// setPGOProfilePath sets the PGO profile path for pkgs.
// In -pgo=auto mode, it finds the default PGO profile.
func setPGOProfilePath(pkgs []*Package) {
switch cfg.BuildPGO {
}
file := filepath.Join(mainpkg.Dir, "default.pgo")
if fi, err := os.Stat(file); err == nil && !fi.IsDir() {
- cfg.BuildPGOFile = file
+ for _, p := range PackageList(pkgs) {
+ p.Internal.PGOProfile = file
+ }
}
default:
// Profile specified from the command line.
// Make it absolute path, as the compiler runs on various directories.
- if p, err := filepath.Abs(cfg.BuildPGO); err != nil {
+ file, err := filepath.Abs(cfg.BuildPGO)
+ if err != nil {
base.Fatalf("fail to get absolute path of PGO file %s: %v", cfg.BuildPGO, err)
- } else {
- cfg.BuildPGOFile = p
+ }
+
+ for _, p := range PackageList(pkgs) {
+ p.Internal.PGOProfile = file
}
}
}
ptest.Internal.Embed = testEmbed
ptest.EmbedFiles = str.StringList(p.EmbedFiles, p.TestEmbedFiles)
ptest.Internal.OrigImportPath = p.Internal.OrigImportPath
+ ptest.Internal.PGOProfile = p.Internal.PGOProfile
ptest.Internal.Build.Directives = append(slices.Clip(p.Internal.Build.Directives), p.Internal.Build.TestDirectives...)
ptest.collectDeps()
} else {
Gccgoflags: p.Internal.Gccgoflags,
Embed: xtestEmbed,
OrigImportPath: p.Internal.OrigImportPath,
+ PGOProfile: p.Internal.PGOProfile,
},
}
if pxtestNeedsPtest {
Ldflags: p.Internal.Ldflags,
Gccgoflags: p.Internal.Gccgoflags,
OrigImportPath: p.Internal.OrigImportPath,
+ PGOProfile: p.Internal.PGOProfile,
},
}
for _, file := range inputFiles {
fmt.Fprintf(h, "file %s %s\n", file, b.fileHash(filepath.Join(p.Dir, file)))
}
- if cfg.BuildPGOFile != "" {
- fmt.Fprintf(h, "pgofile %s\n", b.fileHash(cfg.BuildPGOFile))
+ if p.Internal.PGOProfile != "" {
+ fmt.Fprintf(h, "pgofile %s\n", b.fileHash(p.Internal.PGOProfile))
}
for _, a1 := range a.Deps {
p1 := a1.Package
if p.Internal.CoverageCfg != "" {
defaultGcFlags = append(defaultGcFlags, "-coveragecfg="+p.Internal.CoverageCfg)
}
- if cfg.BuildPGOFile != "" {
- defaultGcFlags = append(defaultGcFlags, "-pgoprofile="+cfg.BuildPGOFile)
+ if p.Internal.PGOProfile != "" {
+ defaultGcFlags = append(defaultGcFlags, "-pgoprofile="+p.Internal.PGOProfile)
}
if symabis != "" {
defaultGcFlags = append(defaultGcFlags, "-symabis", symabis)