diff --git a/cc/pgo.go b/cc/pgo.go index 02be16805..c5e4e86fd 100644 --- a/cc/pgo.go +++ b/cc/pgo.go @@ -94,6 +94,24 @@ func (props *PgoProperties) profileUseFlags(ctx ModuleContext, file string) []st return flags } +func (props *PgoProperties) addProfileUseFlags(ctx ModuleContext, flags Flags) Flags { + // If the PGO profiles project is found, and this module has PGO + // enabled, add flags to use the profile + if profilesDir := getPgoProfilesDir(ctx); props.PgoPresent && profilesDir.Valid() { + profileFile := android.PathForSource(ctx, profilesDir.String(), *props.Pgo.Profile_file) + profileUseFlags := props.profileUseFlags(ctx, profileFile.String()) + + flags.CFlags = append(flags.CFlags, profileUseFlags...) + flags.LdFlags = append(flags.LdFlags, profileUseFlags...) + + // Update CFlagsDeps and LdFlagsDeps so the module is rebuilt + // if profileFile gets updated + flags.CFlagsDeps = append(flags.CFlagsDeps, profileFile) + flags.LdFlagsDeps = append(flags.LdFlagsDeps, profileFile) + } + return flags +} + func (props *PgoProperties) isPGO(ctx BaseModuleContext) bool { isInstrumentation := props.isInstrumentation() isSampling := props.isSampling() @@ -191,19 +209,8 @@ func (pgo *pgo) flags(ctx ModuleContext, flags Flags) Flags { return props.addProfileGatherFlags(ctx, flags) } - // If the PGO profiles project is found, and this module has PGO - // enabled, add flags to use the profile - if profilesDir := getPgoProfilesDir(ctx); props.PgoPresent && profilesDir.Valid() { - profileFile := android.PathForSource(ctx, profilesDir.String(), *(props.Pgo.Profile_file)) - profileUseFlags := props.profileUseFlags(ctx, profileFile.String()) - - flags.CFlags = append(flags.CFlags, profileUseFlags...) - flags.LdFlags = append(flags.LdFlags, profileUseFlags...) - - // Update CFlagsDeps and LdFlagsDeps so the module is rebuilt - // if profileFile gets updated - flags.CFlagsDeps = append(flags.CFlagsDeps, profileFile) - flags.LdFlagsDeps = append(flags.LdFlagsDeps, profileFile) + if !ctx.AConfig().IsEnvTrue("ANDROID_PGO_NO_PROFILE_USE") { + return props.addProfileUseFlags(ctx, flags) } return flags