diff options
| -rw-r--r-- | android/bazel.go | 3 | ||||
| -rw-r--r-- | android/module.go | 59 | ||||
| -rw-r--r-- | android/module_test.go | 50 | ||||
| -rw-r--r-- | android/paths.go | 9 | ||||
| -rw-r--r-- | android/paths_test.go | 87 | ||||
| -rw-r--r-- | bazel/properties.go | 13 | ||||
| -rw-r--r-- | bp2build/cc_library_conversion_test.go | 4 | ||||
| -rw-r--r-- | bp2build/cc_library_static_conversion_test.go | 11 | ||||
| -rw-r--r-- | bp2build/cc_object_conversion_test.go | 6 | ||||
| -rw-r--r-- | bpfix/bpfix/bpfix.go | 70 | ||||
| -rw-r--r-- | bpfix/bpfix/bpfix_test.go | 272 | ||||
| -rw-r--r-- | cc/bp2build.go | 44 | ||||
| -rw-r--r-- | cc/library.go | 16 | ||||
| -rw-r--r-- | cc/object.go | 11 | ||||
| -rw-r--r-- | cc/snapshot_prebuilt.go | 19 |
15 files changed, 622 insertions, 52 deletions
diff --git a/android/bazel.go b/android/bazel.go index 992d8aa27..8d137621d 100644 --- a/android/bazel.go +++ b/android/bazel.go @@ -180,7 +180,6 @@ var ( // also depends on //system/logging/liblog:liblog (http://b/186822772) "libc_ndk", // http://b/187013218, cc_library_static, depends on //bionic/libm:libm (http://b/183064661) "libc_malloc_hooks", // http://b/187016307, cc_library, ld.lld: error: undefined symbol: __malloc_hook - "libm", // http://b/183064661, cc_library, math.h:25:16: error: unexpected token in argument list // http://b/186823769: Needs C++ STL support, includes from unconverted standard libraries in //external/libcxx // c++_static @@ -189,7 +188,7 @@ var ( "libBionicBenchmarksUtils", // cc_library_static, fatal error: 'map' file not found, from libcxx "fmtlib", // cc_library_static, fatal error: 'cassert' file not found, from libcxx "fmtlib_ndk", // cc_library_static, fatal error: 'cassert' file not found - "libbase", // http://b/186826479, cc_library, fatal error: 'memory' file not found, from libcxx + "libbase", // Requires liblog. http://b/186826479, cc_library, fatal error: 'memory' file not found, from libcxx. // http://b/186024507: Includes errors because of the system_shared_libs default value. // Missing -isystem bionic/libc/include through the libc/libm/libdl diff --git a/android/module.go b/android/module.go index 196b095dd..126d629ab 100644 --- a/android/module.go +++ b/android/module.go @@ -2812,30 +2812,57 @@ func (m *moduleContext) blueprintModuleContext() blueprint.ModuleContext { return m.bp } -// SrcIsModule decodes module references in the format ":name" into the module name, or empty string if the input -// was not a module reference. +// SrcIsModule decodes module references in the format ":unqualified-name" or "//namespace:name" +// into the module name, or empty string if the input was not a module reference. func SrcIsModule(s string) (module string) { - if len(s) > 1 && s[0] == ':' { - return s[1:] + if len(s) > 1 { + if s[0] == ':' { + module = s[1:] + if !isUnqualifiedModuleName(module) { + // The module name should be unqualified but is not so do not treat it as a module. + module = "" + } + } else if s[0] == '/' && s[1] == '/' { + module = s + } } - return "" + return module } -// SrcIsModule decodes module references in the format ":name{.tag}" into the module name and tag, ":name" into the -// module name and an empty string for the tag, or empty strings if the input was not a module reference. +// SrcIsModule decodes module references in the format ":unqualified-name{.tag}" or +// "//namespace:name{.tag}" into the module name and an empty string for the tag, or empty strings +// if the input was not a module reference. func SrcIsModuleWithTag(s string) (module, tag string) { - if len(s) > 1 && s[0] == ':' { - module = s[1:] - if tagStart := strings.IndexByte(module, '{'); tagStart > 0 { - if module[len(module)-1] == '}' { - tag = module[tagStart+1 : len(module)-1] - module = module[:tagStart] - return module, tag + if len(s) > 1 { + if s[0] == ':' { + module = s[1:] + } else if s[0] == '/' && s[1] == '/' { + module = s + } + + if module != "" { + if tagStart := strings.IndexByte(module, '{'); tagStart > 0 { + if module[len(module)-1] == '}' { + tag = module[tagStart+1 : len(module)-1] + module = module[:tagStart] + } + } + + if s[0] == ':' && !isUnqualifiedModuleName(module) { + // The module name should be unqualified but is not so do not treat it as a module. + module = "" + tag = "" } } - return module, "" } - return "", "" + + return module, tag +} + +// isUnqualifiedModuleName makes sure that the supplied module is an unqualified module name, i.e. +// does not contain any /. +func isUnqualifiedModuleName(module string) bool { + return strings.IndexByte(module, '/') == -1 } type sourceOrOutputDependencyTag struct { diff --git a/android/module_test.go b/android/module_test.go index 9ac929179..9e2b0ca29 100644 --- a/android/module_test.go +++ b/android/module_test.go @@ -55,6 +55,27 @@ func TestSrcIsModule(t *testing.T) { }, wantModule: "foo:bar", }, + { + name: "fully qualified", + args: args{ + s: "//foo:bar", + }, + wantModule: "//foo:bar", + }, + { + name: "fully qualified with tag", + args: args{ + s: "//foo:bar{.tag}", + }, + wantModule: "//foo:bar{.tag}", + }, + { + name: "invalid unqualified name", + args: args{ + s: ":foo/bar", + }, + wantModule: "", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -128,6 +149,35 @@ func TestSrcIsModuleWithTag(t *testing.T) { }, wantModule: "foo.bar}", }, + { + name: "fully qualified", + args: args{ + s: "//foo:bar", + }, + wantModule: "//foo:bar", + }, + { + name: "fully qualified with tag", + args: args{ + s: "//foo:bar{.tag}", + }, + wantModule: "//foo:bar", + wantTag: ".tag", + }, + { + name: "invalid unqualified name", + args: args{ + s: ":foo/bar", + }, + wantModule: "", + }, + { + name: "invalid unqualified name with tag", + args: args{ + s: ":foo/bar{.tag}", + }, + wantModule: "", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/android/paths.go b/android/paths.go index c5e4806cf..99d5ba7bc 100644 --- a/android/paths.go +++ b/android/paths.go @@ -1268,10 +1268,11 @@ var _ resPathProvider = SourcePath{} // PathForModuleSrc returns a Path representing the paths... under the // module's local source directory. func PathForModuleSrc(ctx ModuleMissingDepsPathContext, pathComponents ...string) Path { - p, err := validatePath(pathComponents...) - if err != nil { - reportPathError(ctx, err) - } + // Just join the components textually just to make sure that it does not corrupt a fully qualified + // module reference, e.g. if the pathComponents is "://other:foo" then using filepath.Join() or + // validatePath() will corrupt it, e.g. replace "//" with "/". If the path is not a module + // reference then it will be validated by expandOneSrcPath anyway when it calls expandOneSrcPath. + p := strings.Join(pathComponents, string(filepath.Separator)) paths, err := expandOneSrcPath(ctx, p, nil) if err != nil { if depErr, ok := err.(missingDependencyError); ok { diff --git a/android/paths_test.go b/android/paths_test.go index 6f5d79e7e..7675905fc 100644 --- a/android/paths_test.go +++ b/android/paths_test.go @@ -1125,6 +1125,12 @@ type pathForModuleSrcTestCase struct { rels []string src string rel string + + // Make test specific preparations to the test fixture. + preparer FixturePreparer + + // A test specific error handler. + errorHandler FixtureErrorHandler } func testPathForModuleSrc(t *testing.T, tests []pathForModuleSrcTestCase) { @@ -1157,14 +1163,23 @@ func testPathForModuleSrc(t *testing.T, tests []pathForModuleSrcTestCase) { "foo/src_special/$": nil, } + errorHandler := test.errorHandler + if errorHandler == nil { + errorHandler = FixtureExpectsNoErrors + } + result := GroupFixturePreparers( FixtureRegisterWithContext(func(ctx RegistrationContext) { ctx.RegisterModuleType("test", pathForModuleSrcTestModuleFactory) ctx.RegisterModuleType("output_file_provider", pathForModuleSrcOutputFileProviderModuleFactory) - ctx.RegisterModuleType("filegroup", FileGroupFactory) }), + PrepareForTestWithFilegroup, + PrepareForTestWithNamespace, mockFS.AddToFixture(), - ).RunTest(t) + OptionalFixturePreparer(test.preparer), + ). + ExtendWithErrorHandler(errorHandler). + RunTest(t) m := result.ModuleForTests("foo", "").Module().(*pathForModuleSrcTestModule) @@ -1333,6 +1348,74 @@ func TestPathForModuleSrc(t *testing.T) { src: "foo/src_special/$", rel: "src_special/$", }, + { + // This test makes sure that an unqualified module name cannot contain characters that make + // it appear as a qualified module name. + name: "output file provider, invalid fully qualified name", + bp: ` + test { + name: "foo", + src: "://other:b", + srcs: ["://other:c"], + }`, + preparer: FixtureAddTextFile("other/Android.bp", ` + soong_namespace {} + + output_file_provider { + name: "b", + outs: ["gen/b"], + } + + output_file_provider { + name: "c", + outs: ["gen/c"], + } + `), + src: "foo/:/other:b", + rel: ":/other:b", + srcs: []string{"foo/:/other:c"}, + rels: []string{":/other:c"}, + }, + { + name: "output file provider, missing fully qualified name", + bp: ` + test { + name: "foo", + src: "//other:b", + srcs: ["//other:c"], + }`, + errorHandler: FixtureExpectsAllErrorsToMatchAPattern([]string{ + `"foo" depends on undefined module "//other:b"`, + `"foo" depends on undefined module "//other:c"`, + }), + }, + { + // TODO(b/193228441): Fix broken test. + name: "output file provider, fully qualified name", + bp: ` + test { + name: "foo", + src: "//other:b", + srcs: ["//other:c"], + }`, + preparer: FixtureAddTextFile("other/Android.bp", ` + soong_namespace {} + + output_file_provider { + name: "b", + outs: ["gen/b"], + } + + output_file_provider { + name: "c", + outs: ["gen/c"], + } + `), + errorHandler: FixtureExpectsAllErrorsToMatchAPattern([]string{ + `"foo": missing dependencies: //other:b, is the property annotated with android:"path"`, + `"foo": missing dependency on "//other:c", is the property annotated with android:"path"`, + }), + }, } testPathForModuleSrc(t, tests) diff --git a/bazel/properties.go b/bazel/properties.go index 0dd47da73..7ecc92bdb 100644 --- a/bazel/properties.go +++ b/bazel/properties.go @@ -558,6 +558,19 @@ func (lla LabelListAttribute) HasConfigurableValues() bool { return len(lla.ConfigurableValues) > 0 } +// IsEmpty returns true if the attribute has no values under any configuration. +func (lla LabelListAttribute) IsEmpty() bool { + if len(lla.Value.Includes) > 0 { + return false + } + for axis, _ := range lla.ConfigurableValues { + if lla.ConfigurableValues[axis].HasConfigurableValues() { + return false + } + } + return true +} + // ResolveExcludes handles excludes across the various axes, ensuring that items are removed from // the base value and included in default values as appropriate. func (lla *LabelListAttribute) ResolveExcludes() { diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go index 285677a1c..4f720f56c 100644 --- a/bp2build/cc_library_conversion_test.go +++ b/bp2build/cc_library_conversion_test.go @@ -674,6 +674,10 @@ filegroup { blueprint: soongCcLibraryPreamble, expectedBazelTargets: []string{`cc_library( name = "a", + asflags = [ + "-Ifoo/bar", + "-I$(BINDIR)/foo/bar", + ], copts = [ "-Ifoo/bar", "-I$(BINDIR)/foo/bar", diff --git a/bp2build/cc_library_static_conversion_test.go b/bp2build/cc_library_static_conversion_test.go index 40edec80b..c33889fc8 100644 --- a/bp2build/cc_library_static_conversion_test.go +++ b/bp2build/cc_library_static_conversion_test.go @@ -1413,7 +1413,7 @@ cc_library_static { func TestCcLibraryStaticProductVariableStringReplacement(t *testing.T) { runCcLibraryStaticTestCase(t, bp2buildTestCase{ - description: "cc_library_static product variable selects", + description: "cc_library_static product variable string replacement", moduleTypeUnderTest: "cc_library_static", moduleTypeUnderTestFactory: cc.LibraryStaticFactory, moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, @@ -1422,7 +1422,7 @@ func TestCcLibraryStaticProductVariableStringReplacement(t *testing.T) { blueprint: soongCcLibraryStaticPreamble + ` cc_library_static { name: "foo_static", - srcs: ["common.c"], + srcs: ["common.S"], product_variables: { platform_sdk_version: { asflags: ["-DPLATFORM_SDK_VERSION=%d"], @@ -1431,7 +1431,10 @@ cc_library_static { } `, expectedBazelTargets: []string{`cc_library_static( name = "foo_static", - asflags = select({ + asflags = [ + "-I.", + "-I$(BINDIR)/.", + ] + select({ "//build/bazel/product_variables:platform_sdk_version": ["-DPLATFORM_SDK_VERSION=$(Platform_sdk_version)"], "//conditions:default": [], }), @@ -1440,7 +1443,7 @@ cc_library_static { "-I$(BINDIR)/.", ], linkstatic = True, - srcs_c = ["common.c"], + srcs_as = ["common.S"], )`}, }) } diff --git a/bp2build/cc_object_conversion_test.go b/bp2build/cc_object_conversion_test.go index 8ede2267d..df4924bfe 100644 --- a/bp2build/cc_object_conversion_test.go +++ b/bp2build/cc_object_conversion_test.go @@ -211,6 +211,7 @@ func TestCcObjectProductVariable(t *testing.T) { asflags: ["-DPLATFORM_SDK_VERSION=%d"], }, }, + srcs: ["src.S"], } `, expectedBazelTargets: []string{`cc_object( @@ -220,6 +221,7 @@ func TestCcObjectProductVariable(t *testing.T) { "//conditions:default": [], }), copts = ["-fno-addrsig"], + srcs_as = ["src.S"], )`, }, }) @@ -240,7 +242,7 @@ func TestCcObjectCflagsOneArch(t *testing.T) { cflags: ["-fPIC"], // string list }, arm: { - srcs: ["arch/arm/file.S"], // label list + srcs: ["arch/arm/file.cpp"], // label list }, }, } @@ -257,7 +259,7 @@ func TestCcObjectCflagsOneArch(t *testing.T) { "//conditions:default": [], }), srcs = ["a.cpp"] + select({ - "//build/bazel/platforms/arch:arm": ["arch/arm/file.S"], + "//build/bazel/platforms/arch:arm": ["arch/arm/file.cpp"], "//conditions:default": [], }), )`, diff --git a/bpfix/bpfix/bpfix.go b/bpfix/bpfix/bpfix.go index adb0a7bb9..a60863036 100644 --- a/bpfix/bpfix/bpfix.go +++ b/bpfix/bpfix/bpfix.go @@ -136,6 +136,10 @@ var fixSteps = []FixStep{ Name: "removeScudoProperty", Fix: runPatchListMod(removeObsoleteProperty("sanitize.scudo")), }, + { + Name: "formatFlagProperties", + Fix: runPatchListMod(formatFlagProperties), + }, } func NewFixRequest() FixRequest { @@ -1343,3 +1347,69 @@ func inList(s string, list []string) bool { } return false } + +func formatFlagProperty(mod *parser.Module, field string, buf []byte, patchlist *parser.PatchList) error { + // the comment or empty lines in the value of the field are skipped + listValue, ok := getLiteralListProperty(mod, field) + if !ok { + // if do not find + return nil + } + for i := 0; i < len(listValue.Values); i++ { + curValue, ok := listValue.Values[i].(*parser.String) + if !ok { + return fmt.Errorf("Expecting string for %s.%s fields", mod.Type, field) + } + if !strings.HasPrefix(curValue.Value, "-") { + return fmt.Errorf("Expecting the string `%s` starting with '-'", curValue.Value) + } + if i+1 < len(listValue.Values) { + nextValue, ok := listValue.Values[i+1].(*parser.String) + if !ok { + return fmt.Errorf("Expecting string for %s.%s fields", mod.Type, field) + } + if !strings.HasPrefix(nextValue.Value, "-") { + // delete the line + err := patchlist.Add(curValue.Pos().Offset, curValue.End().Offset+2, "") + if err != nil { + return err + } + // replace the line + value := "\"" + curValue.Value + " " + nextValue.Value + "\"," + err = patchlist.Add(nextValue.Pos().Offset, nextValue.End().Offset+1, value) + if err != nil { + return err + } + // combined two lines to one + i++ + } + } + } + return nil +} + +func formatFlagProperties(mod *parser.Module, buf []byte, patchlist *parser.PatchList) error { + relevantFields := []string{ + // cc flags + "asflags", + "cflags", + "clang_asflags", + "clang_cflags", + "conlyflags", + "cppflags", + "ldflags", + "tidy_flags", + // java flags + "aaptflags", + "dxflags", + "javacflags", + "kotlincflags", + } + for _, field := range relevantFields { + err := formatFlagProperty(mod, field, buf, patchlist) + if err != nil { + return err + } + } + return nil +} diff --git a/bpfix/bpfix/bpfix_test.go b/bpfix/bpfix/bpfix_test.go index b994e2547..d8772c10d 100644 --- a/bpfix/bpfix/bpfix_test.go +++ b/bpfix/bpfix/bpfix_test.go @@ -1336,3 +1336,275 @@ func TestRewriteTestModuleTypes(t *testing.T) { }) } } + +func TestFormatFlagProperty(t *testing.T) { + tests := []struct { + name string + in string + out string + }{ + { + name: "group options and values for apptflags, dxflags, javacflags, and kotlincflags", + in: ` + android_test { + name: "foo", + aaptflags: [ + // comment1_1 + "--flag1", + // comment1_2 + "1", + // comment2_1 + // comment2_2 + "--flag2", + // comment3_1 + // comment3_2 + // comment3_3 + "--flag3", + // comment3_4 + // comment3_5 + // comment3_6 + "3", + // other comment1_1 + // other comment1_2 + ], + dxflags: [ + "--flag1", + // comment1_1 + "1", + // comment2_1 + "--flag2", + // comment3_1 + "--flag3", + // comment3_2 + "3", + ], + javacflags: [ + "--flag1", + + "1", + "--flag2", + "--flag3", + "3", + ], + kotlincflags: [ + + "--flag1", + "1", + + "--flag2", + "--flag3", + "3", + + ], + } + `, + out: ` + android_test { + name: "foo", + aaptflags: [ + // comment1_1 + // comment1_2 + "--flag1 1", + // comment2_1 + // comment2_2 + "--flag2", + // comment3_1 + // comment3_2 + // comment3_3 + // comment3_4 + // comment3_5 + // comment3_6 + "--flag3 3", + // other comment1_1 + // other comment1_2 + ], + dxflags: [ + // comment1_1 + "--flag1 1", + // comment2_1 + "--flag2", + // comment3_1 + // comment3_2 + "--flag3 3", + ], + javacflags: [ + + "--flag1 1", + "--flag2", + "--flag3 3", + ], + kotlincflags: [ + + "--flag1 1", + + "--flag2", + "--flag3 3", + + ], + } + `, + }, + { + name: "group options and values for asflags, cflags, clang_asflags, clang_cflags, conlyflags, cppflags, ldflags, and tidy_flags", + in: ` + cc_test { + name: "foo", + asflags: [ + // comment1_1 + "--flag1", + "1", + // comment2_1 + // comment2_2 + "--flag2", + // comment2_3 + "2", + // comment3_1 + // comment3_2 + "--flag3", + // comment3_3 + // comment3_4 + // comment3_4 + "3", + // comment4_1 + // comment4_2 + // comment4_3 + "--flag4", + ], + cflags: [ + "--flag1", + "1", + "--flag2", + "2", + "--flag3", + "3", + "--flag4", + ], + clang_asflags: [ + "--flag1", + "1", + "--flag2", + "2", + "--flag3", + "3", + "--flag4", + ], + clang_cflags: [ + "--flag1", + "1", + "--flag2", + "2", + "--flag3", + "3", + "--flag4", + ], + conlyflags: [ + "--flag1", + "1", + "--flag2", + "2", + "--flag3", + "3", + "--flag4", + ], + cppflags: [ + "--flag1", + "1", + "--flag2", + "2", + "--flag3", + "3", + "--flag4", + ], + ldflags: [ + "--flag1", + "1", + "--flag2", + "2", + "--flag3", + "3", + "--flag4", + ], + tidy_flags: [ + "--flag1", + "1", + "--flag2", + "2", + "--flag3", + "3", + "--flag4", + ], + } + `, + out: ` + cc_test { + name: "foo", + asflags: [ + // comment1_1 + "--flag1 1", + // comment2_1 + // comment2_2 + // comment2_3 + "--flag2 2", + // comment3_1 + // comment3_2 + // comment3_3 + // comment3_4 + // comment3_4 + "--flag3 3", + // comment4_1 + // comment4_2 + // comment4_3 + "--flag4", + ], + cflags: [ + "--flag1 1", + "--flag2 2", + "--flag3 3", + "--flag4", + ], + clang_asflags: [ + "--flag1 1", + "--flag2 2", + "--flag3 3", + "--flag4", + ], + clang_cflags: [ + "--flag1 1", + "--flag2 2", + "--flag3 3", + "--flag4", + ], + conlyflags: [ + "--flag1 1", + "--flag2 2", + "--flag3 3", + "--flag4", + ], + cppflags: [ + "--flag1 1", + "--flag2 2", + "--flag3 3", + "--flag4", + ], + ldflags: [ + "--flag1 1", + "--flag2 2", + "--flag3 3", + "--flag4", + ], + tidy_flags: [ + "--flag1 1", + "--flag2 2", + "--flag3 3", + "--flag4", + ], + } + `, + }, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + runPass(t, test.in, test.out, runPatchListMod(formatFlagProperties)) + }) + } +} diff --git a/cc/bp2build.go b/cc/bp2build.go index 76c5f3be9..536f1125d 100644 --- a/cc/bp2build.go +++ b/cc/bp2build.go @@ -90,8 +90,11 @@ func depsBp2BuildMutator(ctx android.BottomUpMutatorContext) { // TODO(b/186024507, b/186489250): Temporarily exclude adding // system_shared_libs deps until libc and libm builds. - // allDeps = append(allDeps, lib.SharedProperties.Shared.System_shared_libs...) - // allDeps = append(allDeps, lib.StaticProperties.Static.System_shared_libs...) + if lib.static() { + allDeps = append(allDeps, lib.StaticProperties.Static.System_shared_libs...) + } else if lib.shared() { + allDeps = append(allDeps, lib.SharedProperties.Shared.System_shared_libs...) + } // Deps in the target/arch nested static: { .. } and shared: { .. } props of a cc_library. // target: { <target>: shared: { ... } } @@ -253,7 +256,7 @@ func bp2buildParseStaticOrSharedProps(ctx android.TopDownMutatorContext, module Copts: bazel.StringListAttribute{Value: props.Cflags}, Srcs: bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, props.Srcs)), Static_deps: bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, props.Static_libs)), - Dynamic_deps: bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, props.Shared_libs)), + Dynamic_deps: bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, append(props.Shared_libs, props.System_shared_libs...))), Whole_archive_deps: bazel.MakeLabelListAttribute(android.BazelLabelForModuleWholeDeps(ctx, props.Whole_static_libs)), } @@ -385,16 +388,6 @@ func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Modul return result } - // Parse the list of copts. - parseCopts := func(baseCompilerProps *BaseCompilerProperties) []string { - var copts []string - copts = append(copts, parseCommandLineFlags(baseCompilerProps.Cflags)...) - for _, dir := range parseLocalIncludeDirs(baseCompilerProps) { - copts = append(copts, includeFlags(dir)...) - } - return copts - } - // Parse srcs from an arch or OS's props value. parseSrcs := func(baseCompilerProps *BaseCompilerProperties) bazel.LabelList { // Add srcs-like dependencies such as generated files. @@ -410,11 +403,15 @@ func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Modul for _, props := range module.compiler.compilerProps() { if baseCompilerProps, ok := props.(*BaseCompilerProperties); ok { srcs.SetValue(parseSrcs(baseCompilerProps)) - copts.Value = parseCopts(baseCompilerProps) + copts.Value = parseCommandLineFlags(baseCompilerProps.Cflags) asFlags.Value = parseCommandLineFlags(baseCompilerProps.Asflags) conlyFlags.Value = parseCommandLineFlags(baseCompilerProps.Conlyflags) cppFlags.Value = parseCommandLineFlags(baseCompilerProps.Cppflags) + for _, dir := range parseLocalIncludeDirs(baseCompilerProps) { + copts.Value = append(copts.Value, includeFlags(dir)...) + asFlags.Value = append(asFlags.Value, includeFlags(dir)...) + } break } } @@ -424,8 +421,10 @@ func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Modul // "-I<module-dir>" in its copts. if c, ok := module.compiler.(*baseCompiler); ok && c.includeBuildDirectory() { copts.Value = append(copts.Value, includeFlags(".")...) + asFlags.Value = append(asFlags.Value, includeFlags(".")...) } else if c, ok := module.compiler.(*libraryDecorator); ok && c.includeBuildDirectory() { copts.Value = append(copts.Value, includeFlags(".")...) + asFlags.Value = append(asFlags.Value, includeFlags(".")...) } archVariantCompilerProps := module.GetArchVariantProperties(ctx, &BaseCompilerProperties{}) @@ -440,8 +439,15 @@ func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Modul srcs.SetSelectValue(axis, config, srcsList) } - copts.SetSelectValue(axis, config, parseCopts(baseCompilerProps)) - asFlags.SetSelectValue(axis, config, parseCommandLineFlags(baseCompilerProps.Asflags)) + archVariantCopts := parseCommandLineFlags(baseCompilerProps.Cflags) + archVariantAsflags := parseCommandLineFlags(baseCompilerProps.Asflags) + for _, dir := range parseLocalIncludeDirs(baseCompilerProps) { + archVariantCopts = append(archVariantCopts, includeFlags(dir)...) + archVariantAsflags = append(archVariantAsflags, includeFlags(dir)...) + } + + copts.SetSelectValue(axis, config, archVariantCopts) + asFlags.SetSelectValue(axis, config, archVariantAsflags) conlyFlags.SetSelectValue(axis, config, parseCommandLineFlags(baseCompilerProps.Conlyflags)) cppFlags.SetSelectValue(axis, config, parseCommandLineFlags(baseCompilerProps.Cppflags)) } @@ -554,7 +560,9 @@ func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module) staticDeps.Value = android.BazelLabelForModuleDepsExcludes(ctx, staticLibs, baseLinkerProps.Exclude_static_libs) wholeArchiveLibs := android.FirstUniqueStrings(baseLinkerProps.Whole_static_libs) wholeArchiveDeps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleWholeDepsExcludes(ctx, wholeArchiveLibs, baseLinkerProps.Exclude_static_libs)) - sharedLibs := android.FirstUniqueStrings(baseLinkerProps.Shared_libs) + // TODO(b/186024507): Handle system_shared_libs as its own attribute, so that the appropriate default + // may be supported. + sharedLibs := android.FirstUniqueStrings(append(baseLinkerProps.Shared_libs, baseLinkerProps.System_shared_libs...)) dynamicDeps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDepsExcludes(ctx, sharedLibs, baseLinkerProps.Exclude_shared_libs)) headerLibs := android.FirstUniqueStrings(baseLinkerProps.Header_libs) @@ -581,7 +589,7 @@ func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module) staticDeps.SetSelectValue(axis, config, android.BazelLabelForModuleDepsExcludes(ctx, staticLibs, baseLinkerProps.Exclude_static_libs)) wholeArchiveLibs := android.FirstUniqueStrings(baseLinkerProps.Whole_static_libs) wholeArchiveDeps.SetSelectValue(axis, config, android.BazelLabelForModuleWholeDepsExcludes(ctx, wholeArchiveLibs, baseLinkerProps.Exclude_static_libs)) - sharedLibs := android.FirstUniqueStrings(baseLinkerProps.Shared_libs) + sharedLibs := android.FirstUniqueStrings(append(baseLinkerProps.Shared_libs, baseLinkerProps.System_shared_libs...)) dynamicDeps.SetSelectValue(axis, config, android.BazelLabelForModuleDepsExcludes(ctx, sharedLibs, baseLinkerProps.Exclude_shared_libs)) headerLibs := android.FirstUniqueStrings(baseLinkerProps.Header_libs) diff --git a/cc/library.go b/cc/library.go index 4fd7c7475..56c460c24 100644 --- a/cc/library.go +++ b/cc/library.go @@ -300,6 +300,12 @@ func CcLibraryBp2Build(ctx android.TopDownMutatorContext) { srcs := compilerAttrs.srcs + asFlags := compilerAttrs.asFlags + if compilerAttrs.asSrcs.IsEmpty() && sharedAttrs.Srcs_as.IsEmpty() && staticAttrs.Srcs_as.IsEmpty() { + // Skip asflags for BUILD file simplicity if there are no assembly sources. + asFlags = bazel.MakeStringListAttribute(nil) + } + attrs := &bazelCcLibraryAttributes{ Srcs: srcs, Srcs_c: compilerAttrs.cSrcs, @@ -308,7 +314,7 @@ func CcLibraryBp2Build(ctx android.TopDownMutatorContext) { Copts: compilerAttrs.copts, Cppflags: compilerAttrs.cppFlags, Conlyflags: compilerAttrs.conlyFlags, - Asflags: compilerAttrs.asFlags, + Asflags: asFlags, Implementation_deps: linkerAttrs.deps, Deps: linkerAttrs.exportedDeps, @@ -2370,6 +2376,12 @@ func ccLibraryStaticBp2BuildInternal(ctx android.TopDownMutatorContext, module * linkerAttrs := bp2BuildParseLinkerProps(ctx, module) exportedIncludes := bp2BuildParseExportedIncludes(ctx, module) + asFlags := compilerAttrs.asFlags + if compilerAttrs.asSrcs.IsEmpty() { + // Skip asflags for BUILD file simplicity if there are no assembly sources. + asFlags = bazel.MakeStringListAttribute(nil) + } + attrs := &bazelCcLibraryStaticAttributes{ Copts: compilerAttrs.copts, Srcs: compilerAttrs.srcs, @@ -2386,7 +2398,7 @@ func ccLibraryStaticBp2BuildInternal(ctx android.TopDownMutatorContext, module * Srcs_c: compilerAttrs.cSrcs, Conlyflags: compilerAttrs.conlyFlags, Srcs_as: compilerAttrs.asSrcs, - Asflags: compilerAttrs.asFlags, + Asflags: asFlags, } props := bazel.BazelTargetModuleProperties{ diff --git a/cc/object.go b/cc/object.go index 9f2db2ec2..5ded0e94c 100644 --- a/cc/object.go +++ b/cc/object.go @@ -123,6 +123,7 @@ func ObjectFactory() android.Module { // For bp2build conversion. type bazelObjectAttributes struct { Srcs bazel.LabelListAttribute + Srcs_as bazel.LabelListAttribute Hdrs bazel.LabelListAttribute Deps bazel.LabelListAttribute Copts bazel.StringListAttribute @@ -179,13 +180,19 @@ func ObjectBp2Build(ctx android.TopDownMutatorContext) { // and this isn't typically done for cc_object. srcs := compilerAttrs.srcs srcs.Append(compilerAttrs.cSrcs) - srcs.Append(compilerAttrs.asSrcs) + + asFlags := compilerAttrs.asFlags + if compilerAttrs.asSrcs.IsEmpty() { + // Skip asflags for BUILD file simplicity if there are no assembly sources. + asFlags = bazel.MakeStringListAttribute(nil) + } attrs := &bazelObjectAttributes{ Srcs: srcs, + Srcs_as: compilerAttrs.asSrcs, Deps: deps, Copts: compilerAttrs.copts, - Asflags: compilerAttrs.asFlags, + Asflags: asFlags, } props := bazel.BazelTargetModuleProperties{ diff --git a/cc/snapshot_prebuilt.go b/cc/snapshot_prebuilt.go index fb89224f3..4f031ff96 100644 --- a/cc/snapshot_prebuilt.go +++ b/cc/snapshot_prebuilt.go @@ -264,6 +264,7 @@ var recoverySnapshotImageSingleton recoverySnapshotImage func init() { VendorSnapshotImageSingleton.Init(android.InitRegistrationContext) recoverySnapshotImageSingleton.init(android.InitRegistrationContext) + android.RegisterMakeVarsProvider(pctx, snapshotMakeVarsProvider) } const ( @@ -383,6 +384,24 @@ var SnapshotInfoProvider = blueprint.NewMutatorProvider(SnapshotInfo{}, "deps") var _ android.ImageInterface = (*snapshot)(nil) +func snapshotMakeVarsProvider(ctx android.MakeVarsContext) { + snapshotSet := map[string]struct{}{} + ctx.VisitAllModules(func(m android.Module) { + if s, ok := m.(*snapshot); ok { + if _, ok := snapshotSet[s.Name()]; ok { + // arch variant generates duplicated modules + // skip this as we only need to know the path of the module. + return + } + snapshotSet[s.Name()] = struct{}{} + imageNameVersion := strings.Split(s.image.imageVariantName(ctx.DeviceConfig()), ".") + ctx.Strict( + strings.Join([]string{strings.ToUpper(imageNameVersion[0]), s.baseSnapshot.Version(), "SNAPSHOT_DIR"}, "_"), + ctx.ModuleDir(s)) + } + }) +} + func vendorSnapshotFactory() android.Module { return snapshotFactory(VendorSnapshotImageSingleton) } |