diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-05-25 02:40:31 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-05-25 02:40:31 +0000 |
commit | 58b7367ffe5fb5ab2773ba565458364cc1b6dad8 (patch) | |
tree | ce466f6d8ea069c0f2d3c822815fa0121c67d1b6 | |
parent | f0abaf401a5c86b54f2c85a84ea8bd3ad0230610 (diff) | |
parent | bebdce680d74df68d05718c46ee216ca6c430da9 (diff) | |
download | soong-58b7367ffe5fb5ab2773ba565458364cc1b6dad8.tar.gz |
Snap for 10196038 from bebdce680d74df68d05718c46ee216ca6c430da9 to udc-qpr1-release
Change-Id: I9003ad6d0f0fc4a1196d28d31285689f97f57dab
-rw-r--r-- | android/util.go | 9 | ||||
-rw-r--r-- | android/util_test.go | 8 | ||||
-rw-r--r-- | apex/apex.go | 14 | ||||
-rw-r--r-- | bazel/cquery/request_type.go | 3 | ||||
-rw-r--r-- | bp2build/cc_library_conversion_test.go | 40 | ||||
-rw-r--r-- | bp2build/cc_library_shared_conversion_test.go | 63 | ||||
-rw-r--r-- | cc/bp2build.go | 11 | ||||
-rw-r--r-- | cc/cc.go | 19 | ||||
-rw-r--r-- | cc/cc_test.go | 127 | ||||
-rw-r--r-- | cc/library.go | 29 | ||||
-rw-r--r-- | etc/prebuilt_etc.go | 4 | ||||
-rw-r--r-- | java/config/config.go | 2 |
12 files changed, 301 insertions, 28 deletions
diff --git a/android/util.go b/android/util.go index 38e0a4dbb..08a3521a5 100644 --- a/android/util.go +++ b/android/util.go @@ -26,7 +26,11 @@ import ( // CopyOf returns a new slice that has the same contents as s. func CopyOf(s []string) []string { - return append([]string(nil), s...) + // If the input is nil, return nil and not an empty list + if s == nil { + return s + } + return append([]string{}, s...) } // Concat returns a new slice concatenated from the two input slices. It does not change the input @@ -276,6 +280,8 @@ func RemoveFromList(s string, list []string) (bool, []string) { // FirstUniqueStrings returns all unique elements of a slice of strings, keeping the first copy of // each. It modifies the slice contents in place, and returns a subslice of the original slice. func FirstUniqueStrings(list []string) []string { + // Do not moodify the input in-place, operate on a copy instead. + list = CopyOf(list) // 128 was chosen based on BenchmarkFirstUniqueStrings results. if len(list) > 128 { return firstUniqueStringsMap(list) @@ -332,6 +338,7 @@ func LastUniqueStrings(list []string) []string { // SortedUniqueStrings returns what the name says func SortedUniqueStrings(list []string) []string { + // FirstUniqueStrings creates a copy of `list`, so the input remains untouched. unique := FirstUniqueStrings(list) sort.Strings(unique) return unique diff --git a/android/util_test.go b/android/util_test.go index 5584b38f7..a2ef58958 100644 --- a/android/util_test.go +++ b/android/util_test.go @@ -381,6 +381,14 @@ func TestRemoveFromList(t *testing.T) { } } +func TestCopyOfEmptyAndNil(t *testing.T) { + emptyList := []string{} + copyOfEmptyList := CopyOf(emptyList) + AssertBoolEquals(t, "Copy of an empty list should be an empty list and not nil", true, copyOfEmptyList != nil) + copyOfNilList := CopyOf(nil) + AssertBoolEquals(t, "Copy of a nil list should be a nil list and not an empty list", true, copyOfNilList == nil) +} + func ExampleCopyOf() { a := []string{"1", "2", "3"} b := CopyOf(a) diff --git a/apex/apex.go b/apex/apex.go index 7fb6f504e..c1c9e5c88 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -137,6 +137,10 @@ type apexBundleProperties struct { // List of filesystem images that are embedded inside this APEX bundle. Filesystems []string + // The minimum SDK version that this APEX must support at minimum. This is usually set to + // the SDK version that the APEX was first introduced. + Min_sdk_version *string + // Whether this APEX is considered updatable or not. When set to true, this will enforce // additional rules for making sure that the APEX is truly updatable. To be updatable, // min_sdk_version should be set as well. This will also disable the size optimizations like @@ -380,10 +384,6 @@ type overridableProperties struct { // Trim against a specific Dynamic Common Lib APEX Trim_against *string - - // The minimum SDK version that this APEX must support at minimum. This is usually set to - // the SDK version that the APEX was first introduced. - Min_sdk_version *string } type apexBundle struct { @@ -2924,7 +2924,7 @@ func (a *apexBundle) minSdkVersionValue(ctx android.EarlyModuleContext) string { // Only override the minSdkVersion value on Apexes which already specify // a min_sdk_version (it's optional for non-updatable apexes), and that its // min_sdk_version value is lower than the one to override with. - minApiLevel := minSdkVersionFromValue(ctx, proptools.String(a.overridableProperties.Min_sdk_version)) + minApiLevel := minSdkVersionFromValue(ctx, proptools.String(a.properties.Min_sdk_version)) if minApiLevel.IsNone() { return "" } @@ -3575,8 +3575,8 @@ func convertWithBp2build(a *apexBundle, ctx android.TopDownMutatorContext) (baze // TODO(b/219503907) this would need to be set to a.MinSdkVersionValue(ctx) but // given it's coming via config, we probably don't want to put it in here. var minSdkVersion bazel.StringAttribute - if a.overridableProperties.Min_sdk_version != nil { - minSdkVersion.SetValue(*a.overridableProperties.Min_sdk_version) + if a.properties.Min_sdk_version != nil { + minSdkVersion.SetValue(*a.properties.Min_sdk_version) } if props, ok := productVariableProps[minSdkVersionPropName]; ok { for c, p := range props { diff --git a/bazel/cquery/request_type.go b/bazel/cquery/request_type.go index bf3a6b5c6..6a3b3c82c 100644 --- a/bazel/cquery/request_type.go +++ b/bazel/cquery/request_type.go @@ -149,6 +149,7 @@ sharedLibraries = [] rootSharedLibraries = [] shared_info_tag = "//build/bazel/rules/cc:cc_library_shared.bzl%CcSharedLibraryOutputInfo" +stubs_tag = "//build/bazel/rules/cc:cc_stub_library.bzl%CcStubInfo" unstripped_tag = "//build/bazel/rules/cc:stripped_cc_common.bzl%CcUnstrippedInfo" unstripped = "" @@ -160,6 +161,8 @@ if shared_info_tag in p: unstripped = path if unstripped_tag in p: unstripped = p[unstripped_tag].unstripped.path +elif stubs_tag in p: + rootSharedLibraries.extend([f.path for f in target.files.to_list()]) else: for linker_input in linker_inputs: for library in linker_input.libraries: diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go index d2c463dbb..7165ac45b 100644 --- a/bp2build/cc_library_conversion_test.go +++ b/bp2build/cc_library_conversion_test.go @@ -4350,3 +4350,43 @@ cc_library { }, }) } + +func TestCcLibraryCppFlagsInProductVariables(t *testing.T) { + runCcLibraryTestCase(t, Bp2buildTestCase{ + Description: "cc_library cppflags in product variables", + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Blueprint: soongCcLibraryPreamble + `cc_library { + name: "a", + srcs: ["a.cpp"], + cppflags: [ + "-Wextra", + "-DDEBUG_ONLY_CODE=0", + ], + product_variables: { + eng: { + cppflags: [ + "-UDEBUG_ONLY_CODE", + "-DDEBUG_ONLY_CODE=1", + ], + }, + }, + include_build_directory: false, +} +`, + ExpectedBazelTargets: makeCcLibraryTargets("a", AttrNameToString{ + "cppflags": `[ + "-Wextra", + "-DDEBUG_ONLY_CODE=0", + ] + select({ + "//build/bazel/product_variables:eng": [ + "-UDEBUG_ONLY_CODE", + "-DDEBUG_ONLY_CODE=1", + ], + "//conditions:default": [], + })`, + "srcs": `["a.cpp"]`, + }), + }, + ) +} diff --git a/bp2build/cc_library_shared_conversion_test.go b/bp2build/cc_library_shared_conversion_test.go index cbea943e1..9ba933717 100644 --- a/bp2build/cc_library_shared_conversion_test.go +++ b/bp2build/cc_library_shared_conversion_test.go @@ -1250,3 +1250,66 @@ cc_library_shared { }, }) } + +func TestCcLibrarySharedStubsDessertVersionConversion(t *testing.T) { + runCcLibrarySharedTestCase(t, Bp2buildTestCase{ + Description: "cc_library_shared converts dessert codename versions to numerical versions", + Blueprint: ` +cc_library_shared { + name: "a", + include_build_directory: false, + stubs: { + symbol_file: "a.map.txt", + versions: [ + "Q", + "R", + "31", + ], + }, +} +cc_library_shared { + name: "b", + include_build_directory: false, + stubs: { + symbol_file: "b.map.txt", + versions: [ + "Q", + "R", + "31", + "current", + ], + }, +} +`, + ExpectedBazelTargets: []string{ + makeCcStubSuiteTargets("a", AttrNameToString{ + "soname": `"a.so"`, + "source_library_label": `"//:a"`, + "stubs_symbol_file": `"a.map.txt"`, + "stubs_versions": `[ + "29", + "30", + "31", + "current", + ]`, + }), + MakeBazelTarget("cc_library_shared", "a", AttrNameToString{ + "stubs_symbol_file": `"a.map.txt"`, + }), + makeCcStubSuiteTargets("b", AttrNameToString{ + "soname": `"b.so"`, + "source_library_label": `"//:b"`, + "stubs_symbol_file": `"b.map.txt"`, + "stubs_versions": `[ + "29", + "30", + "31", + "current", + ]`, + }), + MakeBazelTarget("cc_library_shared", "b", AttrNameToString{ + "stubs_symbol_file": `"b.map.txt"`, + }), + }, + }) +} diff --git a/cc/bp2build.go b/cc/bp2build.go index c8f516cdc..adf5a08ec 100644 --- a/cc/bp2build.go +++ b/cc/bp2build.go @@ -517,7 +517,7 @@ func (ca *compilerAttributes) convertProductVariables(ctx android.BazelConversio productVarPropNameToAttribute := map[string]*bazel.StringListAttribute{ "Cflags": &ca.copts, "Asflags": &ca.asFlags, - "CppFlags": &ca.cppFlags, + "Cppflags": &ca.cppFlags, } for propName, attr := range productVarPropNameToAttribute { if productConfigProps, exists := productVariableProps[propName]; exists { @@ -762,8 +762,13 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module) if libraryProps, ok := archVariantLibraryProperties[axis][cfg].(*LibraryProperties); ok { if axis == bazel.NoConfigAxis { - compilerAttrs.stubsSymbolFile = libraryProps.Stubs.Symbol_file - compilerAttrs.stubsVersions.SetSelectValue(axis, cfg, libraryProps.Stubs.Versions) + if libraryProps.Stubs.Symbol_file != nil { + compilerAttrs.stubsSymbolFile = libraryProps.Stubs.Symbol_file + versions := android.CopyOf(libraryProps.Stubs.Versions) + normalizeVersions(ctx, versions) + versions = addCurrentVersionIfNotPresent(versions) + compilerAttrs.stubsVersions.SetSelectValue(axis, cfg, versions) + } } if suffix := libraryProps.Suffix; suffix != nil { compilerAttrs.suffix.SetSelectValue(axis, cfg, suffix) @@ -1964,6 +1964,17 @@ func (c *Module) ProcessBazelQueryResponse(ctx android.ModuleContext) { c.maybeInstall(mctx, apexInfo) } +func moduleContextFromAndroidModuleContext(actx android.ModuleContext, c *Module) ModuleContext { + ctx := &moduleContext{ + ModuleContext: actx, + moduleContextImpl: moduleContextImpl{ + mod: c, + }, + } + ctx.ctx = ctx + return ctx +} + func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { // Handle the case of a test module split by `test_per_src` mutator. // @@ -1983,13 +1994,7 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { c.makeLinkType = GetMakeLinkType(actx, c) - ctx := &moduleContext{ - ModuleContext: actx, - moduleContextImpl: moduleContextImpl{ - mod: c, - }, - } - ctx.ctx = ctx + ctx := moduleContextFromAndroidModuleContext(actx, c) deps := c.depsToPaths(ctx) if ctx.Failed() { diff --git a/cc/cc_test.go b/cc/cc_test.go index b986511f0..3ae4b1561 100644 --- a/cc/cc_test.go +++ b/cc/cc_test.go @@ -3680,6 +3680,133 @@ func TestStubsForLibraryInMultipleApexes(t *testing.T) { } } +func TestMixedBuildUsesStubs(t *testing.T) { + // TODO(b/275313114): Test exposes non-determinism which should be corrected and the test + // reenabled. + t.Skip() + t.Parallel() + bp := ` + cc_library_shared { + name: "libFoo", + bazel_module: { label: "//:libFoo" }, + srcs: ["foo.c"], + stubs: { + symbol_file: "foo.map.txt", + versions: ["current"], + }, + apex_available: ["bar", "a1"], + } + + cc_library_shared { + name: "libBar", + srcs: ["bar.c"], + shared_libs: ["libFoo"], + apex_available: ["a1"], + } + + cc_library_shared { + name: "libA1", + srcs: ["a1.c"], + shared_libs: ["libFoo"], + apex_available: ["a1"], + } + + cc_library_shared { + name: "libBarA1", + srcs: ["bara1.c"], + shared_libs: ["libFoo"], + apex_available: ["bar", "a1"], + } + + cc_library_shared { + name: "libAnyApex", + srcs: ["anyApex.c"], + shared_libs: ["libFoo"], + apex_available: ["//apex_available:anyapex"], + } + + cc_library_shared { + name: "libBaz", + srcs: ["baz.c"], + shared_libs: ["libFoo"], + apex_available: ["baz"], + } + + cc_library_shared { + name: "libQux", + srcs: ["qux.c"], + shared_libs: ["libFoo"], + apex_available: ["qux", "bar"], + }` + + result := android.GroupFixturePreparers( + prepareForCcTest, + android.FixtureModifyConfig(func(config android.Config) { + config.BazelContext = android.MockBazelContext{ + OutputBaseDir: "out/bazel", + LabelToCcInfo: map[string]cquery.CcInfo{ + "//:libFoo": { + RootDynamicLibraries: []string{"libFoo.so"}, + }, + "//:libFoo_stub_libs-current": { + RootDynamicLibraries: []string{"libFoo_stub_libs-current.so"}, + }, + }, + } + }), + ).RunTestWithBp(t, bp) + ctx := result.TestContext + + variants := ctx.ModuleVariantsForTests("libFoo") + expectedVariants := []string{ + "android_arm64_armv8-a_shared", + "android_arm64_armv8-a_shared_current", + "android_arm_armv7-a-neon_shared", + "android_arm_armv7-a-neon_shared_current", + } + variantsMismatch := false + if len(variants) != len(expectedVariants) { + variantsMismatch = true + } else { + for _, v := range expectedVariants { + if !inList(v, variants) { + variantsMismatch = false + } + } + } + if variantsMismatch { + t.Errorf("variants of libFoo expected:\n") + for _, v := range expectedVariants { + t.Errorf("%q\n", v) + } + t.Errorf(", but got:\n") + for _, v := range variants { + t.Errorf("%q\n", v) + } + } + + linkAgainstFoo := []string{"libBarA1"} + linkAgainstFooStubs := []string{"libBar", "libA1", "libBaz", "libQux", "libAnyApex"} + + libFooPath := "out/bazel/execroot/__main__/libFoo.so" + for _, lib := range linkAgainstFoo { + libLinkRule := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld") + libFlags := libLinkRule.Args["libFlags"] + if !strings.Contains(libFlags, libFooPath) { + t.Errorf("%q: %q is not found in %q", lib, libFooPath, libFlags) + } + } + + libFooStubPath := "out/bazel/execroot/__main__/libFoo_stub_libs-current.so" + for _, lib := range linkAgainstFooStubs { + libLinkRule := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld") + libFlags := libLinkRule.Args["libFlags"] + if !strings.Contains(libFlags, libFooStubPath) { + t.Errorf("%q: %q is not found in %q", lib, libFooStubPath, libFlags) + } + } +} + func TestVersioningMacro(t *testing.T) { t.Parallel() for _, tc := range []struct{ moduleName, expected string }{ diff --git a/cc/library.go b/cc/library.go index 172ca6459..7051f723c 100644 --- a/cc/library.go +++ b/cc/library.go @@ -931,9 +931,17 @@ func (handler *ccLibraryBazelHandler) generateSharedBazelBuildActions(ctx androi func (handler *ccLibraryBazelHandler) QueueBazelCall(ctx android.BaseModuleContext, label string) { bazelCtx := ctx.Config().BazelContext bazelCtx.QueueBazelRequest(label, cquery.GetCcInfo, android.GetConfigKeyApexVariant(ctx, GetApexConfigKey(ctx))) + if v := handler.module.library.stubsVersion(); v != "" { + stubsLabel := label + "_stub_libs-" + v + bazelCtx.QueueBazelRequest(stubsLabel, cquery.GetCcInfo, android.GetConfigKeyApexVariant(ctx, GetApexConfigKey(ctx))) + } } func (handler *ccLibraryBazelHandler) ProcessBazelQueryResponse(ctx android.ModuleContext, label string) { + if v := handler.module.library.stubsVersion(); v != "" { + // if we are a stubs variant, just use the Bazel stubs target + label = label + "_stub_libs-" + v + } bazelCtx := ctx.Config().BazelContext ccInfo, err := bazelCtx.GetCcInfo(label, android.GetConfigKeyApexVariant(ctx, GetApexConfigKey(ctx))) if err != nil { @@ -962,6 +970,9 @@ func (handler *ccLibraryBazelHandler) ProcessBazelQueryResponse(ctx android.Modu } handler.module.setAndroidMkVariablesFromCquery(ccInfo.CcAndroidMkInfo) + + cctx := moduleContextFromAndroidModuleContext(ctx, handler.module) + addStubDependencyProviders(cctx) } func (library *libraryDecorator) setFlagExporterInfoFromCcInfo(ctx android.ModuleContext, ccInfo cquery.CcInfo) { @@ -1787,6 +1798,12 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext, Target: ctx.Target(), }) + addStubDependencyProviders(ctx) + + return unstrippedOutputFile +} + +func addStubDependencyProviders(ctx ModuleContext) { stubs := ctx.GetDirectDepsWithTag(stubImplDepTag) if len(stubs) > 0 { var stubsInfo []SharedStubLibrary @@ -1801,12 +1818,9 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext, } ctx.SetProvider(SharedLibraryStubsProvider, SharedLibraryStubsInfo{ SharedStubLibraries: stubsInfo, - - IsLLNDK: ctx.IsLlndk(), + IsLLNDK: ctx.IsLlndk(), }) } - - return unstrippedOutputFile } func (library *libraryDecorator) unstrippedOutputFilePath() android.Path { @@ -2392,7 +2406,10 @@ func (library *libraryDecorator) stubsVersions(ctx android.BaseMutatorContext) [ } // Future API level is implicitly added if there isn't - vers := library.Properties.Stubs.Versions + return addCurrentVersionIfNotPresent(library.Properties.Stubs.Versions) +} + +func addCurrentVersionIfNotPresent(vers []string) []string { if inList(android.FutureApiLevel.String(), vers) { return vers } @@ -2657,7 +2674,7 @@ func LinkageMutator(mctx android.BottomUpMutatorContext) { // normalizeVersions modifies `versions` in place, so that each raw version // string becomes its normalized canonical form. // Validates that the versions in `versions` are specified in least to greatest order. -func normalizeVersions(ctx android.BaseModuleContext, versions []string) { +func normalizeVersions(ctx android.BazelConversionPathContext, versions []string) { var previous android.ApiLevel for i, v := range versions { ver, err := android.ApiLevelFromUser(ctx, v) diff --git a/etc/prebuilt_etc.go b/etc/prebuilt_etc.go index 6817dcef0..3e1bbded6 100644 --- a/etc/prebuilt_etc.go +++ b/etc/prebuilt_etc.go @@ -652,9 +652,7 @@ func generatePrebuiltSnapshot(s snapshot.SnapshotSingleton, ctx android.Singleto prop := snapshot.SnapshotJsonFlags{} propOut := snapshotLibOut + ".json" prop.InitBaseSnapshotProps(m) - if m.subdirProperties.Relative_install_path != nil { - prop.RelativeInstallPath = *m.subdirProperties.Relative_install_path - } + prop.RelativeInstallPath = m.SubDir() if m.properties.Filename != nil { prop.Filename = *m.properties.Filename diff --git a/java/config/config.go b/java/config/config.go index b82a137e7..195dae16b 100644 --- a/java/config/config.go +++ b/java/config/config.go @@ -98,7 +98,7 @@ func init() { "-JDcom.android.tools.r8.emitRecordAnnotationsExInDex", }, dexerJavaVmFlagsList...)) exportedVars.ExportStringListStaticVariable("R8Flags", append([]string{ - "-JXmx2048M", + "-JXmx4096M", "-JDcom.android.tools.r8.emitRecordAnnotationsInDex", "-JDcom.android.tools.r8.emitPermittedSubclassesAnnotationsInDex", "-JDcom.android.tools.r8.emitRecordAnnotationsExInDex", |