diff --git a/android/api_levels.go b/android/api_levels.go index 1fbbc1597..926d29794 100644 --- a/android/api_levels.go +++ b/android/api_levels.go @@ -344,7 +344,7 @@ func getFinalCodenamesMap(config Config) map[string]int { var apiLevelsMapKey = NewOnceKey("ApiLevelsMap") -func getApiLevelsMap(config Config) map[string]int { +func GetApiLevelsMap(config Config) map[string]int { return config.Once(apiLevelsMapKey, func() interface{} { apiLevelsMap := map[string]int{ "G": 9, @@ -374,7 +374,7 @@ func getApiLevelsMap(config Config) map[string]int { } func (a *apiLevelsSingleton) GenerateBuildActions(ctx SingletonContext) { - apiLevelsMap := getApiLevelsMap(ctx.Config()) + apiLevelsMap := GetApiLevelsMap(ctx.Config()) apiLevelsJson := GetApiLevelsJson(ctx) createApiLevelsJson(ctx, apiLevelsJson, apiLevelsMap) } diff --git a/android/bazel.go b/android/bazel.go index 99cc30c91..7971451c2 100644 --- a/android/bazel.go +++ b/android/bazel.go @@ -226,6 +226,7 @@ var ( "packages/apps/WallpaperPicker":/* recursive = */ false, "prebuilts/gcc":/* recursive = */ true, + "prebuilts/build-tools":/* recursive = */ false, "prebuilts/sdk":/* recursive = */ false, "prebuilts/sdk/current/extras/app-toolkit":/* recursive = */ false, "prebuilts/sdk/current/support":/* recursive = */ false, diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go index 59a238976..de4f437b6 100644 --- a/bp2build/cc_library_conversion_test.go +++ b/bp2build/cc_library_conversion_test.go @@ -1297,6 +1297,8 @@ func makeCcLibraryTargets(name string, attrs attrNameToString) []string { "additional_linker_inputs": true, "linkopts": true, "strip": true, + "stubs_symbol_file": true, + "stubs_versions": true, } sharedAttrs := attrNameToString{} staticAttrs := attrNameToString{} @@ -2390,3 +2392,32 @@ func TestCcLibraryStaticDisabledForSomeArch(t *testing.T) { }), }}) } + +func TestCcLibraryStubs(t *testing.T) { + runCcLibraryTestCase(t, bp2buildTestCase{ + description: "cc_library stubs", + moduleTypeUnderTest: "cc_library", + moduleTypeUnderTestFactory: cc.LibraryFactory, + dir: "foo/bar", + filesystem: map[string]string{ + "foo/bar/Android.bp": ` +cc_library { + name: "a", + stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] }, + bazel_module: { bp2build_available: true }, + include_build_directory: false, +} +`, + }, + blueprint: soongCcLibraryPreamble, + expectedBazelTargets: makeCcLibraryTargets("a", attrNameToString{ + "stubs_symbol_file": `"a.map.txt"`, + "stubs_versions": `[ + "28", + "29", + "current", + ]`, + }), + }, + ) +} diff --git a/bp2build/cc_library_shared_conversion_test.go b/bp2build/cc_library_shared_conversion_test.go index 97a600a99..0f6765320 100644 --- a/bp2build/cc_library_shared_conversion_test.go +++ b/bp2build/cc_library_shared_conversion_test.go @@ -464,3 +464,33 @@ func TestCcLibrarySharedUseVersionLib(t *testing.T) { }, }) } + +func TestCcLibrarySharedStubs(t *testing.T) { + runCcLibrarySharedTestCase(t, bp2buildTestCase{ + description: "cc_library_shared stubs", + moduleTypeUnderTest: "cc_library_shared", + moduleTypeUnderTestFactory: cc.LibrarySharedFactory, + dir: "foo/bar", + filesystem: map[string]string{ + "foo/bar/Android.bp": ` +cc_library_shared { + name: "a", + stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] }, + bazel_module: { bp2build_available: true }, + include_build_directory: false, +} +`, + }, + blueprint: soongCcLibraryPreamble, + expectedBazelTargets: []string{makeBazelTarget("cc_library_shared", "a", attrNameToString{ + "stubs_symbol_file": `"a.map.txt"`, + "stubs_versions": `[ + "28", + "29", + "current", + ]`, + }), + }, + }, + ) +} diff --git a/bp2build/conversion.go b/bp2build/conversion.go index 81a4b2624..96c12d3e1 100644 --- a/bp2build/conversion.go +++ b/bp2build/conversion.go @@ -1,6 +1,7 @@ package bp2build import ( + "encoding/json" "fmt" "reflect" "strings" @@ -27,6 +28,13 @@ func CreateSoongInjectionFiles(cfg android.Config, metrics CodegenMetrics) []Baz files = append(files, newFile("product_config", "soong_config_variables.bzl", cfg.Bp2buildSoongConfigDefinitions.String())) + apiLevelsContent, err := json.Marshal(android.GetApiLevelsMap(cfg)) + if err != nil { + panic(err) + } + files = append(files, newFile("api_levels", GeneratedBuildFileName, `exports_files(["api_levels.json"])`)) + files = append(files, newFile("api_levels", "api_levels.json", string(apiLevelsContent))) + return files } diff --git a/bp2build/conversion_test.go b/bp2build/conversion_test.go index 3e6d9e614..629ca9bba 100644 --- a/bp2build/conversion_test.go +++ b/bp2build/conversion_test.go @@ -102,6 +102,14 @@ func TestCreateBazelFiles_Bp2Build_CreatesDefaultFiles(t *testing.T) { dir: "product_config", basename: "soong_config_variables.bzl", }, + { + dir: "api_levels", + basename: GeneratedBuildFileName, + }, + { + dir: "api_levels", + basename: "api_levels.json", + }, } if len(files) != len(expectedFilePaths) { diff --git a/cc/bp2build.go b/cc/bp2build.go index cc2e60e57..c5eab0683 100644 --- a/cc/bp2build.go +++ b/cc/bp2build.go @@ -280,6 +280,9 @@ type compilerAttributes struct { includes BazelIncludes protoSrcs bazel.LabelListAttribute + + stubsSymbolFile *string + stubsVersions bazel.StringListAttribute } type filterOutFn func(string) bool @@ -464,10 +467,11 @@ func includesFromLabelList(labelList bazel.LabelList) (relative, absolute []stri return relative, absolute } -// bp2BuildParseCompilerProps returns copts, srcs and hdrs and other attributes. +// bp2BuildParseBaseProps returns all compiler, linker, library attributes of a cc module.. func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module) baseAttributes { archVariantCompilerProps := module.GetArchVariantProperties(ctx, &BaseCompilerProperties{}) archVariantLinkerProps := module.GetArchVariantProperties(ctx, &BaseLinkerProperties{}) + archVariantLibraryProperties := module.GetArchVariantProperties(ctx, &LibraryProperties{}) var implementationHdrs bazel.LabelListAttribute @@ -484,6 +488,7 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module) } allAxesAndConfigs(archVariantCompilerProps) allAxesAndConfigs(archVariantLinkerProps) + allAxesAndConfigs(archVariantLibraryProperties) compilerAttrs := compilerAttributes{} linkerAttrs := linkerAttributes{} @@ -519,6 +524,13 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module) currIncludes := compilerAttrs.localIncludes.SelectValue(axis, config) currIncludes = android.FirstUniqueStrings(append(currIncludes, includes...)) compilerAttrs.localIncludes.SetSelectValue(axis, config, currIncludes) + + if libraryProps, ok := archVariantLibraryProperties[axis][config].(*LibraryProperties); ok { + if axis == bazel.NoConfigAxis { + compilerAttrs.stubsSymbolFile = libraryProps.Stubs.Symbol_file + compilerAttrs.stubsVersions.SetSelectValue(axis, config, libraryProps.Stubs.Versions) + } + } } } diff --git a/cc/library.go b/cc/library.go index 1f9ff7c8d..cefbf6c44 100644 --- a/cc/library.go +++ b/cc/library.go @@ -381,6 +381,9 @@ func libraryBp2Build(ctx android.TopDownMutatorContext, m *Module) { None: linkerAttrs.stripNone, }, Features: linkerAttrs.features, + + Stubs_symbol_file: compilerAttrs.stubsSymbolFile, + Stubs_versions: compilerAttrs.stubsVersions, } staticProps := bazel.BazelTargetModuleProperties{ @@ -2518,6 +2521,9 @@ func sharedOrStaticLibraryBp2Build(ctx android.TopDownMutatorContext, module *Mo }, Features: linkerAttrs.features, + + Stubs_symbol_file: compilerAttrs.stubsSymbolFile, + Stubs_versions: compilerAttrs.stubsVersions, } } @@ -2591,4 +2597,7 @@ type bazelCcLibrarySharedAttributes struct { Asflags bazel.StringListAttribute Features bazel.StringListAttribute + + Stubs_symbol_file *string + Stubs_versions bazel.StringListAttribute }