diff options
author | Linux Build Service Account <lnxbuild@localhost> | 2023-06-29 02:58:38 -0700 |
---|---|---|
committer | Linux Build Service Account <lnxbuild@localhost> | 2023-06-29 02:58:38 -0700 |
commit | dfbcb0b15a5c12351b1a5b7f2895468e896cff14 (patch) | |
tree | 1a7e8d444c006ea7602279985906ed81c8266158 | |
parent | 4c96265e9d0ce51bdec804aad4f2433836430d10 (diff) | |
parent | 1e185fd7142a8c7907d64cbac9df5e29ddaeafa8 (diff) |
Merge 1e185fd7142a8c7907d64cbac9df5e29ddaeafa8 on remote branch
Change-Id: Ia6fc931ebb5792c7427b61df18fdc7797fe277a9
-rw-r--r-- | android/util.go | 9 | ||||
-rw-r--r-- | android/util_test.go | 8 | ||||
-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/afdo.go | 2 | ||||
-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/config/global.go | 4 | ||||
-rw-r--r-- | cc/library.go | 29 | ||||
-rw-r--r-- | etc/prebuilt_etc.go | 4 |
12 files changed, 296 insertions, 23 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/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/afdo.go b/cc/afdo.go index 49f69873c..137ea97fe 100644 --- a/cc/afdo.go +++ b/cc/afdo.go @@ -34,7 +34,7 @@ var ( var afdoProfileProjectsConfigKey = android.NewOnceKey("AfdoProfileProjects") -const afdoCFlagsFormat = "-fprofile-sample-accurate -fprofile-sample-use=%s" +const afdoCFlagsFormat = "-fprofile-sample-use=%s" func recordMissingAfdoProfileFile(ctx android.BaseModuleContext, missing string) { getNamedMapForConfig(ctx.Config(), modulesMissingProfileFileKey).Store(missing, true) 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) @@ -1974,6 +1974,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. // @@ -1993,13 +2004,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 485120f9d..fe384feb3 100644 --- a/cc/cc_test.go +++ b/cc/cc_test.go @@ -3716,6 +3716,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/config/global.go b/cc/config/global.go index 44891d492..1ba4426db 100644 --- a/cc/config/global.go +++ b/cc/config/global.go @@ -383,8 +383,8 @@ var ( // prebuilts/clang default settings. ClangDefaultBase = "prebuilts/clang/host" // TODO(b/243545528) Match upstream version - ClangDefaultVersion = "clang-r475365b" - ClangDefaultShortVersion = "16.0.2" + ClangDefaultVersion = "clang-r487747c" + ClangDefaultShortVersion = "17" // Directories with warnings from Android.bp files. WarningAllowedProjects = []string{ diff --git a/cc/library.go b/cc/library.go index 3f0bd0bc4..da4f20b25 100644 --- a/cc/library.go +++ b/cc/library.go @@ -933,9 +933,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 { @@ -964,6 +972,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) { @@ -1802,6 +1813,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 @@ -1816,12 +1833,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 { @@ -2415,7 +2429,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 } @@ -2680,7 +2697,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 |