Add bp2build conversion to reference to fdo_profile targets
The fdo_profile targets are handcrafted in ag/20469925. Bp2build creates fdo_profile attribute on cc_library_shared and references to the fdo_profile target if the profile exists. This works under assumption that all afdo profiles have an associated Bazel fdo_profile target declared in the same folder/package. As noted in b/253540178, this won't work when we check in the BUILD files (which is likely 6+ months away) because some profiles might only exist internally but not in AOSP. We will implement a long-term solution once we figure out all the requirements we need to support afdo both in Soong and Bazel. Bug: 253540178 Test: go tests Change-Id: Iebd5dd7a76583b4b2bf0d9ee56d58f247d313a54 Merged-In: Iebd5dd7a76583b4b2bf0d9ee56d58f247d313a54
This commit is contained in:
@@ -3603,6 +3603,70 @@ cc_library_static {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCcLibraryWithAfdoEnabled(t *testing.T) {
|
||||||
|
bp := `
|
||||||
|
cc_library {
|
||||||
|
name: "foo",
|
||||||
|
afdo: true,
|
||||||
|
include_build_directory: false,
|
||||||
|
}`
|
||||||
|
|
||||||
|
// TODO(b/260714900): Add test case for arch-specific afdo profile
|
||||||
|
testCases := []struct {
|
||||||
|
description string
|
||||||
|
filesystem map[string]string
|
||||||
|
expectedBazelTargets []string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
description: "cc_library with afdo enabled and existing profile",
|
||||||
|
filesystem: map[string]string{"vendor/google_data/pgo_profile/sampling/foo.afdo": ""},
|
||||||
|
expectedBazelTargets: []string{
|
||||||
|
MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{}),
|
||||||
|
MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
|
||||||
|
"fdo_profile": `"//vendor/google_data/pgo_profile/sampling:foo"`,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
description: "cc_library with afdo enabled and existing profile in AOSP",
|
||||||
|
filesystem: map[string]string{"toolchain/pgo-profiles/sampling/foo.afdo": ""},
|
||||||
|
expectedBazelTargets: []string{
|
||||||
|
MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{}),
|
||||||
|
MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
|
||||||
|
"fdo_profile": `"//toolchain/pgo-profiles/sampling:foo"`,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
description: "cc_library with afdo enabled but profile filename doesn't match with module name",
|
||||||
|
filesystem: map[string]string{"toolchain/pgo-profiles/sampling/bar.afdo": ""},
|
||||||
|
expectedBazelTargets: []string{
|
||||||
|
MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{}),
|
||||||
|
MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
description: "cc_library with afdo enabled but profile doesn't exist",
|
||||||
|
expectedBazelTargets: []string{
|
||||||
|
MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{}),
|
||||||
|
MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
t.Run(testCase.description, func(t *testing.T) {
|
||||||
|
runCcLibraryTestCase(t, Bp2buildTestCase{
|
||||||
|
ExpectedBazelTargets: testCase.expectedBazelTargets,
|
||||||
|
ModuleTypeUnderTest: "cc_library",
|
||||||
|
ModuleTypeUnderTestFactory: cc.LibraryFactory,
|
||||||
|
Description: testCase.description,
|
||||||
|
Blueprint: binaryReplacer.Replace(bp),
|
||||||
|
Filesystem: testCase.filesystem,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestCcLibraryHeaderAbiChecker(t *testing.T) {
|
func TestCcLibraryHeaderAbiChecker(t *testing.T) {
|
||||||
runCcLibraryTestCase(t, Bp2buildTestCase{
|
runCcLibraryTestCase(t, Bp2buildTestCase{
|
||||||
Description: "cc_library with header abi checker",
|
Description: "cc_library with header abi checker",
|
||||||
|
@@ -393,6 +393,8 @@ type compilerAttributes struct {
|
|||||||
features bazel.StringListAttribute
|
features bazel.StringListAttribute
|
||||||
|
|
||||||
suffix bazel.StringAttribute
|
suffix bazel.StringAttribute
|
||||||
|
|
||||||
|
fdoProfile bazel.LabelAttribute
|
||||||
}
|
}
|
||||||
|
|
||||||
type filterOutFn func(string) bool
|
type filterOutFn func(string) bool
|
||||||
@@ -777,6 +779,13 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module)
|
|||||||
(&compilerAttrs).srcs.Add(&convertedLSrcs.srcName)
|
(&compilerAttrs).srcs.Add(&convertedLSrcs.srcName)
|
||||||
(&compilerAttrs).cSrcs.Add(&convertedLSrcs.cSrcName)
|
(&compilerAttrs).cSrcs.Add(&convertedLSrcs.cSrcName)
|
||||||
|
|
||||||
|
if module.afdo != nil && module.afdo.Properties.Afdo {
|
||||||
|
fdoProfileDep := bp2buildFdoProfile(ctx, module)
|
||||||
|
if fdoProfileDep != nil {
|
||||||
|
(&compilerAttrs).fdoProfile.SetValue(*fdoProfileDep)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if !compilerAttrs.syspropSrcs.IsEmpty() {
|
if !compilerAttrs.syspropSrcs.IsEmpty() {
|
||||||
(&linkerAttrs).wholeArchiveDeps.Add(bp2buildCcSysprop(ctx, module.Name(), module.Properties.Min_sdk_version, compilerAttrs.syspropSrcs))
|
(&linkerAttrs).wholeArchiveDeps.Add(bp2buildCcSysprop(ctx, module.Name(), module.Properties.Min_sdk_version, compilerAttrs.syspropSrcs))
|
||||||
}
|
}
|
||||||
@@ -793,6 +802,37 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type fdoProfileAttributes struct {
|
||||||
|
Absolute_path_profile string
|
||||||
|
}
|
||||||
|
|
||||||
|
func bp2buildFdoProfile(
|
||||||
|
ctx android.Bp2buildMutatorContext,
|
||||||
|
m *Module,
|
||||||
|
) *bazel.Label {
|
||||||
|
for _, project := range globalAfdoProfileProjects {
|
||||||
|
// We handcraft a BUILD file with fdo_profile targets that use the existing profiles in the project
|
||||||
|
// This implementation is assuming that every afdo profile in globalAfdoProfileProjects already has
|
||||||
|
// an associated fdo_profile target declared in the same package.
|
||||||
|
// TODO(b/260714900): Handle arch-specific afdo profiles (e.g. `<module-name>-arm<64>.afdo`)
|
||||||
|
path := android.ExistentPathForSource(ctx, project, m.Name()+".afdo")
|
||||||
|
if path.Valid() {
|
||||||
|
// FIXME: Some profiles only exist internally and are not released to AOSP.
|
||||||
|
// When generated BUILD files are checked in, we'll run into merge conflict.
|
||||||
|
// The cc_library_shared target in AOSP won't have reference to an fdo_profile target because
|
||||||
|
// the profile doesn't exist. Internally, the same cc_library_shared target will
|
||||||
|
// have reference to the fdo_profile.
|
||||||
|
// For more context, see b/258682955#comment2
|
||||||
|
fdoProfileLabel := "//" + strings.TrimSuffix(project, "/") + ":" + m.Name()
|
||||||
|
return &bazel.Label{
|
||||||
|
Label: fdoProfileLabel,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func bp2buildCcAidlLibrary(
|
func bp2buildCcAidlLibrary(
|
||||||
ctx android.Bp2buildMutatorContext,
|
ctx android.Bp2buildMutatorContext,
|
||||||
m *Module,
|
m *Module,
|
||||||
|
@@ -417,6 +417,8 @@ func libraryBp2Build(ctx android.TopDownMutatorContext, m *Module) {
|
|||||||
Strip: stripAttrsFromLinkerAttrs(&linkerAttrs),
|
Strip: stripAttrsFromLinkerAttrs(&linkerAttrs),
|
||||||
Features: baseAttributes.features,
|
Features: baseAttributes.features,
|
||||||
bazelCcHeaderAbiCheckerAttributes: bp2buildParseAbiCheckerProps(ctx, m),
|
bazelCcHeaderAbiCheckerAttributes: bp2buildParseAbiCheckerProps(ctx, m),
|
||||||
|
|
||||||
|
Fdo_profile: compilerAttrs.fdoProfile,
|
||||||
}
|
}
|
||||||
|
|
||||||
if compilerAttrs.stubsSymbolFile != nil && len(compilerAttrs.stubsVersions.Value) > 0 {
|
if compilerAttrs.stubsSymbolFile != nil && len(compilerAttrs.stubsVersions.Value) > 0 {
|
||||||
@@ -2930,6 +2932,8 @@ func sharedOrStaticLibraryBp2Build(ctx android.TopDownMutatorContext, module *Mo
|
|||||||
Suffix: compilerAttrs.suffix,
|
Suffix: compilerAttrs.suffix,
|
||||||
|
|
||||||
bazelCcHeaderAbiCheckerAttributes: bp2buildParseAbiCheckerProps(ctx, module),
|
bazelCcHeaderAbiCheckerAttributes: bp2buildParseAbiCheckerProps(ctx, module),
|
||||||
|
|
||||||
|
Fdo_profile: compilerAttrs.fdoProfile,
|
||||||
}
|
}
|
||||||
if compilerAttrs.stubsSymbolFile != nil && len(compilerAttrs.stubsVersions.Value) > 0 {
|
if compilerAttrs.stubsSymbolFile != nil && len(compilerAttrs.stubsVersions.Value) > 0 {
|
||||||
hasStubs := true
|
hasStubs := true
|
||||||
@@ -3020,6 +3024,8 @@ type bazelCcLibrarySharedAttributes struct {
|
|||||||
Suffix bazel.StringAttribute
|
Suffix bazel.StringAttribute
|
||||||
|
|
||||||
bazelCcHeaderAbiCheckerAttributes
|
bazelCcHeaderAbiCheckerAttributes
|
||||||
|
|
||||||
|
Fdo_profile bazel.LabelAttribute
|
||||||
}
|
}
|
||||||
|
|
||||||
type bazelCcStubSuiteAttributes struct {
|
type bazelCcStubSuiteAttributes struct {
|
||||||
|
Reference in New Issue
Block a user