diff options
Diffstat (limited to 'cc')
| -rw-r--r-- | cc/Android.bp | 1 | ||||
| -rw-r--r-- | cc/api_level.go | 6 | ||||
| -rw-r--r-- | cc/bp2build.go | 171 | ||||
| -rw-r--r-- | cc/cc.go | 71 | ||||
| -rw-r--r-- | cc/cc_test.go | 2 | ||||
| -rw-r--r-- | cc/config/global.go | 19 | ||||
| -rw-r--r-- | cc/config/riscv64_device.go | 3 | ||||
| -rw-r--r-- | cc/config/toolchain.go | 2 | ||||
| -rw-r--r-- | cc/fuzz.go | 56 | ||||
| -rw-r--r-- | cc/generated_cc_library.go | 38 | ||||
| -rw-r--r-- | cc/library.go | 6 | ||||
| -rw-r--r-- | cc/linkable.go | 9 | ||||
| -rw-r--r-- | cc/lto.go | 70 | ||||
| -rw-r--r-- | cc/ndk_sysroot.go | 1 | ||||
| -rw-r--r-- | cc/sanitize.go | 4 | ||||
| -rw-r--r-- | cc/snapshot_prebuilt.go | 6 | ||||
| -rw-r--r-- | cc/snapshot_utils.go | 8 | ||||
| -rw-r--r-- | cc/stl.go | 13 | ||||
| -rw-r--r-- | cc/test.go | 53 | ||||
| -rw-r--r-- | cc/testing.go | 24 | ||||
| -rw-r--r-- | cc/util.go | 4 | ||||
| -rw-r--r-- | cc/vendor_snapshot.go | 33 |
22 files changed, 431 insertions, 169 deletions
diff --git a/cc/Android.bp b/cc/Android.bp index f49dc1a9e..e88ea03b3 100644 --- a/cc/Android.bp +++ b/cc/Android.bp @@ -32,6 +32,7 @@ bootstrap_go_package { "check.go", "coverage.go", "gen.go", + "generated_cc_library.go", "image.go", "linkable.go", "lto.go", diff --git a/cc/api_level.go b/cc/api_level.go index a5571f31f..69a0d3ae4 100644 --- a/cc/api_level.go +++ b/cc/api_level.go @@ -31,7 +31,11 @@ func MinApiForArch(ctx android.EarlyModuleContext, case android.Arm64, android.X86_64: return android.FirstLp64Version case android.Riscv64: - return android.FutureApiLevel + apiLevel, err := android.ApiLevelFromUser(ctx, "VanillaIceCream") + if err != nil { + panic(err) + } + return apiLevel default: panic(fmt.Errorf("Unknown arch %q", arch)) } diff --git a/cc/bp2build.go b/cc/bp2build.go index 5459595e2..9895a2043 100644 --- a/cc/bp2build.go +++ b/cc/bp2build.go @@ -43,6 +43,10 @@ const ( rScriptSrcPartition = "renderScript" + xsdSrcPartition = "xsd" + + hdrPartition = "hdr" + stubsSuffix = "_stub_libs_current" ) @@ -155,6 +159,7 @@ func groupSrcsByExtension(ctx android.BazelConversionPathContext, srcs bazel.Lab lSrcPartition: bazel.LabelPartition{Extensions: []string{".l"}}, llSrcPartition: bazel.LabelPartition{Extensions: []string{".ll"}}, rScriptSrcPartition: bazel.LabelPartition{Extensions: []string{".fs", ".rscript"}}, + xsdSrcPartition: bazel.LabelPartition{LabelMapper: android.XsdLabelMapper(xsdConfigCppTarget)}, // C++ is the "catch-all" group, and comprises generated sources because we don't // know the language of these sources until the genrule is executed. cppSrcPartition: bazel.LabelPartition{Extensions: []string{".cpp", ".cc", ".cxx", ".mm"}, LabelMapper: addSuffixForFilegroup("_cpp_srcs"), Keep_remainder: true}, @@ -165,6 +170,14 @@ func groupSrcsByExtension(ctx android.BazelConversionPathContext, srcs bazel.Lab return bazel.PartitionLabelListAttribute(ctx, &srcs, labels) } +func partitionHeaders(ctx android.BazelConversionPathContext, hdrs bazel.LabelListAttribute) bazel.PartitionToLabelListAttribute { + labels := bazel.LabelPartitions{ + xsdSrcPartition: bazel.LabelPartition{LabelMapper: android.XsdLabelMapper(xsdConfigCppTarget)}, + hdrPartition: bazel.LabelPartition{Keep_remainder: true}, + } + return bazel.PartitionLabelListAttribute(ctx, &hdrs, labels) +} + // bp2BuildParseLibProps returns the attributes for a variant of a cc_library. func bp2BuildParseLibProps(ctx android.BazelConversionPathContext, module *Module, isStatic bool) staticOrSharedAttributes { lib, ok := module.compiler.(*libraryDecorator) @@ -403,7 +416,8 @@ type compilerAttributes struct { srcs bazel.LabelListAttribute // xsd config sources - xsdInSrcs bazel.StringListAttribute + xsdSrcs bazel.LabelListAttribute + exportXsdSrcs bazel.LabelListAttribute // Lex sources and options lSrcs bazel.LabelListAttribute @@ -494,14 +508,11 @@ func parseCommandLineFlags(soongFlags []string, filterOut ...filterOutFn) []stri func (ca *compilerAttributes) bp2buildForAxisAndConfig(ctx android.BazelConversionPathContext, axis bazel.ConfigurationAxis, config string, props *BaseCompilerProperties) { // If there's arch specific srcs or exclude_srcs, generate a select entry for it. // TODO(b/186153868): do this for OS specific srcs and exclude_srcs too. - srcsList, xsdList, ok := parseSrcs(ctx, props) + srcsList, ok := parseSrcs(ctx, props) if ok { ca.srcs.SetSelectValue(axis, config, srcsList) } - if len(xsdList) > 0 { - ca.xsdInSrcs.SetSelectValue(axis, config, xsdList) - } localIncludeDirs := props.Local_include_dirs if axis == bazel.NoConfigAxis { @@ -568,9 +579,11 @@ func (ca *compilerAttributes) convertProductVariables(ctx android.BazelConversio } } -func (ca *compilerAttributes) finalize(ctx android.BazelConversionPathContext, implementationHdrs bazel.LabelListAttribute) { +func (ca *compilerAttributes) finalize(ctx android.BazelConversionPathContext, implementationHdrs, exportHdrs bazel.LabelListAttribute) { ca.srcs.ResolveExcludes() partitionedSrcs := groupSrcsByExtension(ctx, ca.srcs) + partitionedImplHdrs := partitionHeaders(ctx, implementationHdrs) + partitionedHdrs := partitionHeaders(ctx, exportHdrs) ca.protoSrcs = partitionedSrcs[protoSrcPartition] ca.aidlSrcs = partitionedSrcs[aidlSrcPartition] @@ -580,10 +593,19 @@ func (ca *compilerAttributes) finalize(ctx android.BazelConversionPathContext, i if lla.IsEmpty() { continue } - lla.Append(implementationHdrs) + lla.Append(partitionedImplHdrs[hdrPartition]) partitionedSrcs[p] = lla } + ca.hdrs = partitionedHdrs[hdrPartition] + + ca.includesFromHeaders(ctx, partitionedImplHdrs[hdrPartition], partitionedHdrs[hdrPartition]) + + xsdSrcs := bazel.SubtractBazelLabelListAttribute(partitionedSrcs[xsdSrcPartition], partitionedHdrs[xsdSrcPartition]) + xsdSrcs.Append(partitionedImplHdrs[xsdSrcPartition]) + ca.exportXsdSrcs = partitionedHdrs[xsdSrcPartition] + ca.xsdSrcs = bazel.FirstUniqueBazelLabelListAttribute(xsdSrcs) + ca.srcs = partitionedSrcs[cppSrcPartition] ca.cSrcs = partitionedSrcs[cSrcPartition] ca.asSrcs = partitionedSrcs[asSrcPartition] @@ -604,11 +626,11 @@ func (ca *compilerAttributes) finalize(ctx android.BazelConversionPathContext, i } // Parse srcs from an arch or OS's props value. -func parseSrcs(ctx android.BazelConversionPathContext, props *BaseCompilerProperties) (bazel.LabelList, []string, bool) { +func parseSrcs(ctx android.BazelConversionPathContext, props *BaseCompilerProperties) (bazel.LabelList, bool) { anySrcs := false // Add srcs-like dependencies such as generated files. // First create a LabelList containing these dependencies, then merge the values with srcs. - genSrcs, xsd := android.PartitionXsdSrcs(ctx, props.Generated_sources) + genSrcs := props.Generated_sources generatedSrcsLabelList := android.BazelLabelForModuleDepsExcludes(ctx, genSrcs, props.Exclude_generated_sources) if len(props.Generated_sources) > 0 || len(props.Exclude_generated_sources) > 0 { anySrcs = true @@ -620,7 +642,7 @@ func parseSrcs(ctx android.BazelConversionPathContext, props *BaseCompilerProper anySrcs = true } - return bazel.AppendBazelLabelLists(allSrcsLabelList, generatedSrcsLabelList), xsd, anySrcs + return bazel.AppendBazelLabelLists(allSrcsLabelList, generatedSrcsLabelList), anySrcs } func bp2buildStdVal(std *string, prefix string, useGnu bool) *string { @@ -667,8 +689,43 @@ func packageFromLabel(label string) (string, bool) { return split[0][2:], true } -// includesFromLabelList extracts relative/absolute includes from a bazel.LabelList> -func includesFromLabelList(labelList bazel.LabelList) (relative, absolute []string) { +// includesFromHeaders gets the include directories needed from generated headers +func (ca *compilerAttributes) includesFromHeaders(ctx android.BazelConversionPathContext, implHdrs, hdrs bazel.LabelListAttribute) { + local, absolute := includesFromLabelListAttribute(implHdrs, ca.localIncludes, ca.absoluteIncludes) + localExport, absoluteExport := includesFromLabelListAttribute(hdrs, ca.includes.Includes, ca.includes.AbsoluteIncludes) + + ca.localIncludes = local + ca.absoluteIncludes = absolute + + ca.includes.Includes = localExport + ca.includes.AbsoluteIncludes = absoluteExport +} + +// includesFromLabelList extracts the packages from a LabelListAttribute that should be includes and +// combines them with existing local/absolute includes. +func includesFromLabelListAttribute(attr bazel.LabelListAttribute, existingLocal, existingAbsolute bazel.StringListAttribute) (bazel.StringListAttribute, bazel.StringListAttribute) { + localAttr := existingLocal.Clone() + absoluteAttr := existingAbsolute.Clone() + if !attr.Value.IsEmpty() { + l, a := includesFromLabelList(attr.Value, existingLocal.Value, existingAbsolute.Value) + localAttr.SetSelectValue(bazel.NoConfigAxis, "", l) + absoluteAttr.SetSelectValue(bazel.NoConfigAxis, "", a) + } + for axis, configToLabels := range attr.ConfigurableValues { + for c, labels := range configToLabels { + local := existingLocal.SelectValue(axis, c) + absolute := existingAbsolute.SelectValue(axis, c) + l, a := includesFromLabelList(labels, local, absolute) + localAttr.SetSelectValue(axis, c, l) + absoluteAttr.SetSelectValue(axis, c, a) + } + } + return *localAttr, *absoluteAttr +} + +// includesFromLabelList extracts relative/absolute includes from a bazel.LabelList. +func includesFromLabelList(labelList bazel.LabelList, existingRel, existingAbs []string) ([]string, []string) { + var relative, absolute []string for _, hdr := range labelList.Includes { if pkg, hasPkg := packageFromLabel(hdr.Label); hasPkg { absolute = append(absolute, pkg) @@ -676,6 +733,12 @@ func includesFromLabelList(labelList bazel.LabelList) (relative, absolute []stri relative = append(relative, pkg) } } + if len(relative)+len(existingRel) != 0 { + relative = android.FirstUniqueStrings(append(append([]string{}, existingRel...), relative...)) + } + if len(absolute)+len(existingAbs) != 0 { + absolute = android.FirstUniqueStrings(append(append([]string{}, existingAbs...), absolute...)) + } return relative, absolute } @@ -740,8 +803,6 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module) archVariantLinkerProps := module.GetArchVariantProperties(ctx, &BaseLinkerProperties{}) archVariantLibraryProperties := module.GetArchVariantProperties(ctx, &LibraryProperties{}) - var implementationHdrs bazel.LabelListAttribute - axisToConfigs := map[bazel.ConfigurationAxis]map[string]bool{} allAxesAndConfigs := func(cp android.ConfigurationAxisToArchVariantProperties) { for axis, configMap := range cp { @@ -761,6 +822,7 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module) linkerAttrs := linkerAttributes{} var aidlLibs bazel.LabelList + var implementationHdrs, exportHdrs bazel.LabelListAttribute // Iterate through these axes in a deterministic order. This is required // because processing certain dependencies may result in concatenating @@ -770,9 +832,9 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module) for _, axis := range bazel.SortedConfigurationAxes(axisToConfigs) { configs := axisToConfigs[axis] for cfg := range configs { - var allHdrs, allHdrsXsd []string + var allHdrs []string if baseCompilerProps, ok := archVariantCompilerProps[axis][cfg].(*BaseCompilerProperties); ok { - allHdrs, allHdrsXsd = android.PartitionXsdSrcs(ctx, baseCompilerProps.Generated_headers) + allHdrs = baseCompilerProps.Generated_headers if baseCompilerProps.Lex != nil { compilerAttrs.lexopts.SetSelectValue(axis, cfg, baseCompilerProps.Lex.Flags) @@ -786,36 +848,17 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module) aidlLibs.Append(android.BazelLabelForModuleDeps(ctx, baseCompilerProps.Aidl.Libs)) } - var exportHdrs, exportHdrsXsd []string + var exportedHdrs []string if baseLinkerProps, ok := archVariantLinkerProps[axis][cfg].(*BaseLinkerProperties); ok { - exportHdrs, exportHdrsXsd = android.PartitionXsdSrcs(ctx, baseLinkerProps.Export_generated_headers) + exportedHdrs = baseLinkerProps.Export_generated_headers (&linkerAttrs).bp2buildForAxisAndConfig(ctx, module, axis, cfg, baseLinkerProps) } - // in the synthetic bp2build workspace, xsd sources are compiled to a static library - xsdList := compilerAttrs.xsdInSrcs.SelectValue(axis, cfg) - allHdrsXsd = android.FirstUniqueStrings(append(xsdList, allHdrsXsd...)) - headers := maybePartitionExportedAndImplementationsDeps(ctx, !module.Binary(), allHdrs, exportHdrs, android.BazelLabelForModuleDeps) - xsdConfigLibs := maybePartitionExportedAndImplementationsDeps(ctx, !module.Binary(), allHdrsXsd, exportHdrsXsd, bazelLabelForXsdConfig) + headers := maybePartitionExportedAndImplementationsDeps(ctx, !module.Binary(), allHdrs, exportedHdrs, android.BazelLabelForModuleDeps) implementationHdrs.SetSelectValue(axis, cfg, headers.implementation) - compilerAttrs.hdrs.SetSelectValue(axis, cfg, headers.export) - - exportIncludes, exportAbsoluteIncludes := includesFromLabelList(headers.export) - compilerAttrs.includes.Includes.SetSelectValue(axis, cfg, exportIncludes) - compilerAttrs.includes.AbsoluteIncludes.SetSelectValue(axis, cfg, exportAbsoluteIncludes) - - includes, absoluteIncludes := includesFromLabelList(headers.implementation) - currAbsoluteIncludes := compilerAttrs.absoluteIncludes.SelectValue(axis, cfg) - currAbsoluteIncludes = android.FirstUniqueStrings(append(currAbsoluteIncludes, absoluteIncludes...)) - - compilerAttrs.absoluteIncludes.SetSelectValue(axis, cfg, currAbsoluteIncludes) - - currIncludes := compilerAttrs.localIncludes.SelectValue(axis, cfg) - currIncludes = android.FirstUniqueStrings(append(currIncludes, includes...)) - - compilerAttrs.localIncludes.SetSelectValue(axis, cfg, currIncludes) + exportHdrs.SetSelectValue(axis, cfg, headers.export) if libraryProps, ok := archVariantLibraryProperties[axis][cfg].(*LibraryProperties); ok { if axis == bazel.NoConfigAxis { @@ -835,14 +878,6 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module) } } - if len(allHdrsXsd) > 0 { - wholeStaticLibs := linkerAttrs.implementationWholeArchiveDeps.SelectValue(axis, cfg) - (&wholeStaticLibs).Append(xsdConfigLibs.implementation) - linkerAttrs.implementationWholeArchiveDeps.SetSelectValue(axis, cfg, wholeStaticLibs) - wholeStaticLibs = linkerAttrs.wholeArchiveDeps.SelectValue(axis, cfg) - (&wholeStaticLibs).Append(xsdConfigLibs.export) - linkerAttrs.wholeArchiveDeps.SetSelectValue(axis, cfg, wholeStaticLibs) - } } } @@ -860,11 +895,14 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module) (&compilerAttrs).convertProductVariables(ctx, productVariableProps) (&linkerAttrs).convertProductVariables(ctx, productVariableProps) - (&compilerAttrs).finalize(ctx, implementationHdrs) + (&compilerAttrs).finalize(ctx, implementationHdrs, exportHdrs) (&linkerAttrs).finalize(ctx) (&compilerAttrs.srcs).Add(bp2BuildYasm(ctx, module, compilerAttrs)) + (&linkerAttrs).wholeArchiveDeps.Append(compilerAttrs.exportXsdSrcs) + (&linkerAttrs).implementationWholeArchiveDeps.Append(compilerAttrs.xsdSrcs) + protoDep := bp2buildProto(ctx, module, compilerAttrs.protoSrcs) // bp2buildProto will only set wholeStaticLib or implementationWholeStaticLib, but we don't know @@ -1139,6 +1177,7 @@ type linkerAttributes struct { wholeArchiveDeps bazel.LabelListAttribute implementationWholeArchiveDeps bazel.LabelListAttribute systemDynamicDeps bazel.LabelListAttribute + usedSystemDynamicDepAsStaticDep map[string]bool usedSystemDynamicDepAsDynamicDep map[string]bool useVersionLib bazel.BoolAttribute @@ -1201,6 +1240,18 @@ func (la *linkerAttributes) bp2buildForAxisAndConfig(ctx android.BazelConversion // https://cs.android.com/android/platform/superproject/+/master:build/soong/cc/linker.go;l=247-249;drc=088b53577dde6e40085ffd737a1ae96ad82fc4b0 la.wholeArchiveDeps.SetSelectValue(axis, config, bazelLabelForWholeDepsExcludes(ctx, wholeStaticLibs, props.Exclude_static_libs)) + if isBinary && module.StaticExecutable() { + usedSystemStatic := android.FilterListPred(staticLibs, func(s string) bool { + return android.InList(s, soongSystemSharedLibs) && !android.InList(s, props.Exclude_static_libs) + }) + + for _, el := range usedSystemStatic { + if la.usedSystemDynamicDepAsStaticDep == nil { + la.usedSystemDynamicDepAsStaticDep = map[string]bool{} + } + la.usedSystemDynamicDepAsStaticDep[el] = true + } + } staticDeps := maybePartitionExportedAndImplementationsDepsExcludes( ctx, !isBinary, @@ -1233,6 +1284,7 @@ func (la *linkerAttributes) bp2buildForAxisAndConfig(ctx android.BazelConversion usedSystem := android.FilterListPred(sharedLibs, func(s string) bool { return android.InList(s, soongSystemSharedLibs) && !android.InList(s, excludeSharedLibs) }) + for _, el := range usedSystem { if la.usedSystemDynamicDepAsDynamicDep == nil { la.usedSystemDynamicDepAsDynamicDep = map[string]bool{} @@ -1625,6 +1677,15 @@ func (la *linkerAttributes) finalize(ctx android.BazelConversionPathContext) { } la.implementationDynamicDeps.Exclude(bazel.OsAndInApexAxis, bazel.AndroidPlatform, bazel.MakeLabelList(stubsToRemove)) } + if la.systemDynamicDeps.IsNil() && len(la.usedSystemDynamicDepAsStaticDep) > 0 { + toRemove := bazelLabelForStaticDeps(ctx, android.SortedKeys(la.usedSystemDynamicDepAsStaticDep)) + la.deps.Exclude(bazel.NoConfigAxis, "", toRemove) + la.deps.Exclude(bazel.OsConfigurationAxis, "android", toRemove) + la.deps.Exclude(bazel.OsConfigurationAxis, "linux_bionic", toRemove) + la.implementationDeps.Exclude(bazel.NoConfigAxis, "", toRemove) + la.implementationDeps.Exclude(bazel.OsConfigurationAxis, "android", toRemove) + la.implementationDeps.Exclude(bazel.OsConfigurationAxis, "linux_bionic", toRemove) + } la.deps.ResolveExcludes() la.implementationDeps.ResolveExcludes() @@ -1725,16 +1786,8 @@ func bazelLabelForStaticWholeModuleDeps(ctx android.BazelConversionPathContext, return label } -// Replaces //a/b/my_xsd_config with //a/b/my_xsd_config-cpp -func xsdConfigCppTarget(ctx android.BazelConversionPathContext, mod blueprint.Module) string { - callback := func(xsd android.XsdConfigBp2buildTargets) string { - return xsd.CppBp2buildTargetName() - } - return android.XsdConfigBp2buildTarget(ctx, mod, callback) -} - -func bazelLabelForXsdConfig(ctx android.BazelConversionPathContext, modules []string) bazel.LabelList { - return android.BazelLabelForModuleDepsWithFn(ctx, modules, xsdConfigCppTarget) +func xsdConfigCppTarget(xsd android.XsdConfigBp2buildTargets) string { + return xsd.CppBp2buildTargetName() } func bazelLabelForWholeDeps(ctx android.BazelConversionPathContext, modules []string) bazel.LabelList { @@ -1819,7 +1872,7 @@ func bp2buildSanitizerFeatures(ctx android.BazelConversionPathContext, m *Module if blocklist != nil { // Format the blocklist name to be used in a feature name blocklistFeatureSuffix := strings.Replace(strings.ToLower(*blocklist), ".", "_", -1) - features = append(features, "ubsan_blocklist_"+blocklistFeatureSuffix) + features = append(features, "sanitizer_blocklist_"+blocklistFeatureSuffix) } if sanitizerProps.Sanitize.Cfi != nil && !proptools.Bool(sanitizerProps.Sanitize.Cfi) { features = append(features, "-android_cfi") @@ -42,6 +42,7 @@ import ( func init() { RegisterCCBuildComponents(android.InitRegistrationContext) + pctx.Import("android/soong/android") pctx.Import("android/soong/cc/config") } @@ -568,6 +569,24 @@ type feature interface { props() []interface{} } +// Information returned from Generator about the source code it's generating +type GeneratedSource struct { + IncludeDirs android.Paths + Sources android.Paths + Headers android.Paths + ReexportedDirs android.Paths +} + +// generator allows injection of generated code +type Generator interface { + GeneratorProps() []interface{} + GeneratorInit(ctx BaseModuleContext) + GeneratorDeps(ctx DepsContext, deps Deps) Deps + GeneratorFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags + GeneratorSources(ctx ModuleContext) GeneratedSource + GeneratorBuildActions(ctx ModuleContext, flags Flags, deps PathDeps) +} + // compiler is the interface for a compiler helper object. Different module decorators may implement // this helper differently. type compiler interface { @@ -850,6 +869,7 @@ type Module struct { // type-specific logic. These members may reference different objects or the same object. // Functions of these decorators will be invoked to initialize and register type-specific // build statements. + generators []Generator compiler compiler linker linker installer installer @@ -1079,6 +1099,10 @@ func (c *Module) CcLibraryInterface() bool { return false } +func (c *Module) RlibStd() bool { + panic(fmt.Errorf("RlibStd called on non-Rust module: %q", c.BaseModuleName())) +} + func (c *Module) RustLibraryInterface() bool { return false } @@ -1196,6 +1220,9 @@ func (c *Module) VndkVersion() string { func (c *Module) Init() android.Module { c.AddProperties(&c.Properties, &c.VendorProperties) + for _, generator := range c.generators { + c.AddProperties(generator.GeneratorProps()...) + } if c.compiler != nil { c.AddProperties(c.compiler.compilerProps()...) } @@ -1367,7 +1394,7 @@ func (c *Module) isPgoCompile() bool { func (c *Module) isCfi() bool { if sanitize := c.sanitize; sanitize != nil { - return Bool(sanitize.Properties.Sanitize.Cfi) + return Bool(sanitize.Properties.SanitizeMutated.Cfi) } return false } @@ -2144,6 +2171,25 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { return } + for _, generator := range c.generators { + gen := generator.GeneratorSources(ctx) + deps.IncludeDirs = append(deps.IncludeDirs, gen.IncludeDirs...) + deps.ReexportedDirs = append(deps.ReexportedDirs, gen.ReexportedDirs...) + deps.GeneratedDeps = append(deps.GeneratedDeps, gen.Headers...) + deps.ReexportedGeneratedHeaders = append(deps.ReexportedGeneratedHeaders, gen.Headers...) + deps.ReexportedDeps = append(deps.ReexportedDeps, gen.Headers...) + if len(deps.Objs.objFiles) == 0 { + // If we are reusuing object files (which happens when we're a shared library and we're + // reusing our static variant's object files), then skip adding the actual source files, + // because we already have the object for it. + deps.GeneratedSources = append(deps.GeneratedSources, gen.Sources...) + } + } + + if ctx.Failed() { + return + } + if c.stubLibraryMultipleApexViolation(actx) { actx.PropertyErrorf("apex_available", "Stub libraries should have a single apex_available (test apexes excluded). Got %v", c.ApexAvailable()) @@ -2158,6 +2204,9 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { Toolchain: c.toolchain(ctx), EmitXrefs: ctx.Config().EmitXrefRules(), } + for _, generator := range c.generators { + flags = generator.GeneratorFlags(ctx, flags, deps) + } if c.compiler != nil { flags = c.compiler.compilerFlags(ctx, flags, deps) } @@ -2215,6 +2264,10 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags) + for _, generator := range c.generators { + generator.GeneratorBuildActions(ctx, flags, deps) + } + var objs Objects if c.compiler != nil { objs = c.compiler.compile(ctx, flags, deps) @@ -2302,6 +2355,9 @@ func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain { } func (c *Module) begin(ctx BaseModuleContext) { + for _, generator := range c.generators { + generator.GeneratorInit(ctx) + } if c.compiler != nil { c.compiler.compilerInit(ctx) } @@ -2337,6 +2393,9 @@ func (c *Module) begin(ctx BaseModuleContext) { func (c *Module) deps(ctx DepsContext) Deps { deps := Deps{} + for _, generator := range c.generators { + deps = generator.GeneratorDeps(ctx, deps) + } if c.compiler != nil { deps = c.compiler.compilerDeps(ctx, deps) } @@ -2945,20 +3004,20 @@ func checkLinkType(ctx android.BaseModuleContext, from LinkableInterface, to Lin ctx.ModuleErrorf("links %q built against newer API version %q", ctx.OtherModuleName(to.Module()), "current") } else { - fromApi, err := strconv.Atoi(from.SdkVersion()) + fromApi, err := android.ApiLevelFromUserWithConfig(ctx.Config(), from.SdkVersion()) if err != nil { ctx.PropertyErrorf("sdk_version", - "Invalid sdk_version value (must be int or current): %q", + "Invalid sdk_version value (must be int, preview or current): %q", from.SdkVersion()) } - toApi, err := strconv.Atoi(to.SdkVersion()) + toApi, err := android.ApiLevelFromUserWithConfig(ctx.Config(), to.SdkVersion()) if err != nil { ctx.PropertyErrorf("sdk_version", - "Invalid sdk_version value (must be int or current): %q", + "Invalid sdk_version value (must be int, preview or current): %q", to.SdkVersion()) } - if toApi > fromApi { + if toApi.GreaterThan(fromApi) { ctx.ModuleErrorf("links %q built against newer API version %q", ctx.OtherModuleName(to.Module()), to.SdkVersion()) } diff --git a/cc/cc_test.go b/cc/cc_test.go index 7534db222..d95ed3f3e 100644 --- a/cc/cc_test.go +++ b/cc/cc_test.go @@ -3261,7 +3261,7 @@ func TestLibDepAndroidMkExportInMixedBuilds(t *testing.T) { }, }, LabelToCcBinary: map[string]cquery.CcUnstrippedInfo{ - "//:test": cquery.CcUnstrippedInfo{ + "//:test__tf_internal": cquery.CcUnstrippedInfo{ CcAndroidMkInfo: tc.androidMkInfo, }, "//:binary": cquery.CcUnstrippedInfo{ diff --git a/cc/config/global.go b/cc/config/global.go index ceab49801..ff5ab051e 100644 --- a/cc/config/global.go +++ b/cc/config/global.go @@ -48,7 +48,6 @@ var ( "-Wno-multichar", "-O2", - "-g", "-fdebug-default-version=5", "-fno-strict-aliasing", @@ -111,6 +110,9 @@ var ( // Turn off FMA which got enabled by default in clang-r445002 (http://b/218805949) "-ffp-contract=off", + + // Using simple template names reduces the size of debug builds. + "-gsimple-template-names", } commonGlobalConlyflags = []string{} @@ -375,6 +377,21 @@ func init() { flags = append(flags, "-Wno-error=unknown-warning-option") } + switch ctx.Config().Getenv("CLANG_DEFAULT_DEBUG_LEVEL") { + case "debug_level_0": + flags = append(flags, "-g0") + case "debug_level_1": + flags = append(flags, "-g1") + case "debug_level_2": + flags = append(flags, "-g2") + case "debug_level_3": + flags = append(flags, "-g3") + case "debug_level_g": + flags = append(flags, "-g") + default: + flags = append(flags, "-g") + } + return strings.Join(flags, " ") }) diff --git a/cc/config/riscv64_device.go b/cc/config/riscv64_device.go index 3bc1e69c3..40919c0cf 100644 --- a/cc/config/riscv64_device.go +++ b/cc/config/riscv64_device.go @@ -26,9 +26,6 @@ var ( // Help catch common 32/64-bit errors. "-Werror=implicit-function-declaration", "-fno-emulated-tls", - // A temporary fix for SExtWRemoval miscompilation bug. - "-mllvm", - "-riscv-disable-sextw-removal=true", "-march=rv64gc_zba_zbb_zbs", } diff --git a/cc/config/toolchain.go b/cc/config/toolchain.go index a0ef57595..62f75d1bd 100644 --- a/cc/config/toolchain.go +++ b/cc/config/toolchain.go @@ -261,5 +261,3 @@ func LibFuzzerRuntimeLibrary(t Toolchain) string { func LibFuzzerRuntimeInterceptors(t Toolchain) string { return LibclangRuntimeLibrary(t, "fuzzer_interceptors") } - -var inList = android.InList diff --git a/cc/fuzz.go b/cc/fuzz.go index 636ad855b..227fe8bcf 100644 --- a/cc/fuzz.go +++ b/cc/fuzz.go @@ -29,6 +29,7 @@ import ( func init() { android.RegisterModuleType("cc_fuzz", LibFuzzFactory) android.RegisterParallelSingletonType("cc_fuzz_packaging", fuzzPackagingFactory) + android.RegisterParallelSingletonType("cc_fuzz_presubmit_packaging", fuzzPackagingFactoryPresubmit) } type FuzzProperties struct { @@ -258,25 +259,29 @@ func (fuzzBin *fuzzBinary) install(ctx ModuleContext, file android.Path) { func PackageFuzzModule(ctx android.ModuleContext, fuzzPackagedModule fuzz.FuzzPackagedModule, pctx android.PackageContext) fuzz.FuzzPackagedModule { fuzzPackagedModule.Corpus = android.PathsForModuleSrc(ctx, fuzzPackagedModule.FuzzProperties.Corpus) - builder := android.NewRuleBuilder(pctx, ctx) intermediateDir := android.PathForModuleOut(ctx, "corpus") + + // Create one rule per file to avoid MAX_ARG_STRLEN hardlimit. for _, entry := range fuzzPackagedModule.Corpus { - builder.Command().Text("cp"). - Input(entry). - Output(intermediateDir.Join(ctx, entry.Base())) + ctx.Build(pctx, android.BuildParams{ + Rule: android.Cp, + Output: intermediateDir.Join(ctx, entry.Base()), + Input: entry, + }) } - builder.Build("copy_corpus", "copy corpus") fuzzPackagedModule.CorpusIntermediateDir = intermediateDir fuzzPackagedModule.Data = android.PathsForModuleSrc(ctx, fuzzPackagedModule.FuzzProperties.Data) - builder = android.NewRuleBuilder(pctx, ctx) intermediateDir = android.PathForModuleOut(ctx, "data") + + // Create one rule per file to avoid MAX_ARG_STRLEN hardlimit. for _, entry := range fuzzPackagedModule.Data { - builder.Command().Text("cp"). - Input(entry). - Output(intermediateDir.Join(ctx, entry.Rel())) + ctx.Build(pctx, android.BuildParams{ + Rule: android.Cp, + Output: intermediateDir.Join(ctx, entry.Rel()), + Input: entry, + }) } - builder.Build("copy_data", "copy data") fuzzPackagedModule.DataIntermediateDir = intermediateDir if fuzzPackagedModule.FuzzProperties.Dictionary != nil { @@ -352,9 +357,10 @@ func NewFuzzer(hod android.HostOrDeviceSupported) *Module { // their architecture & target/host specific zip file. type ccRustFuzzPackager struct { fuzz.FuzzPackager - fuzzPackagingArchModules string - fuzzTargetSharedDepsInstallPairs string - allFuzzTargetsName string + fuzzPackagingArchModules string + fuzzTargetSharedDepsInstallPairs string + allFuzzTargetsName string + onlyIncludePresubmits bool } func fuzzPackagingFactory() android.Singleton { @@ -363,6 +369,18 @@ func fuzzPackagingFactory() android.Singleton { fuzzPackagingArchModules: "SOONG_FUZZ_PACKAGING_ARCH_MODULES", fuzzTargetSharedDepsInstallPairs: "FUZZ_TARGET_SHARED_DEPS_INSTALL_PAIRS", allFuzzTargetsName: "ALL_FUZZ_TARGETS", + onlyIncludePresubmits: false, + } + return fuzzPackager +} + +func fuzzPackagingFactoryPresubmit() android.Singleton { + + fuzzPackager := &ccRustFuzzPackager{ + fuzzPackagingArchModules: "SOONG_PRESUBMIT_FUZZ_PACKAGING_ARCH_MODULES", + fuzzTargetSharedDepsInstallPairs: "PRESUBMIT_FUZZ_TARGET_SHARED_DEPS_INSTALL_PAIRS", + allFuzzTargetsName: "ALL_PRESUBMIT_FUZZ_TARGETS", + onlyIncludePresubmits: true, } return fuzzPackager } @@ -386,7 +404,6 @@ func (s *ccRustFuzzPackager) GenerateBuildActions(ctx android.SingletonContext) if !ok || ccModule.PreventInstall() { return } - // Discard non-fuzz targets. if ok := fuzz.IsValid(ccModule.FuzzModuleStruct()); !ok { return @@ -403,6 +420,9 @@ func (s *ccRustFuzzPackager) GenerateBuildActions(ctx android.SingletonContext) } else if ccModule.Host() { hostOrTargetString = "host" } + if s.onlyIncludePresubmits == true { + hostOrTargetString = "presubmit-" + hostOrTargetString + } fpm := fuzz.FuzzPackagedModule{} if ok { @@ -427,6 +447,14 @@ func (s *ccRustFuzzPackager) GenerateBuildActions(ctx android.SingletonContext) // The executable. files = append(files, fuzz.FileToZip{SourceFilePath: android.OutputFileForModule(ctx, ccModule, "unstripped")}) + if s.onlyIncludePresubmits == true { + if fpm.FuzzProperties.Fuzz_config == nil { + return + } + if !BoolDefault(fpm.FuzzProperties.Fuzz_config.Use_for_presubmit, false){ + return + } + } archDirs[archOs], ok = s.BuildZipFile(ctx, module, fpm, files, builder, archDir, archString, hostOrTargetString, archOs, archDirs) if !ok { return diff --git a/cc/generated_cc_library.go b/cc/generated_cc_library.go new file mode 100644 index 000000000..55e19f9a9 --- /dev/null +++ b/cc/generated_cc_library.go @@ -0,0 +1,38 @@ +// Copyright 2023 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cc + +import ( + "android/soong/android" +) + +func GeneratedCcLibraryModuleFactory(moduleName string, callbacks Generator) android.Module { + module, _ := NewLibrary(android.HostAndDeviceSupported) + + // Can be used as both a static and a shared library. + module.sdkMemberTypes = []android.SdkMemberType{ + sharedLibrarySdkMemberType, + staticLibrarySdkMemberType, + staticAndSharedLibrarySdkMemberType, + } + + // TODO: Need to be bazelable + // module.bazelable = true + // module.bazelHandler = &ccLibraryBazelHandler{module: module} + + module.generators = append(module.generators, callbacks) + + return module.Init() +} diff --git a/cc/library.go b/cc/library.go index aec6433d8..266fa7511 100644 --- a/cc/library.go +++ b/cc/library.go @@ -1963,6 +1963,10 @@ func (library *libraryDecorator) optInAbiDiff(ctx android.ModuleContext, referen libName := strings.TrimSuffix(baseName, filepath.Ext(baseName)) errorMessage := "error: Please update ABI references with: $$ANDROID_BUILD_TOP/development/vndk/tools/header-checker/utils/create_reference_dumps.py -l " + libName + " -ref-dump-dir $$ANDROID_BUILD_TOP/" + refDumpDir + // Most opt-in libraries do not have dumps for all default architectures. + if ctx.Config().HasDeviceProduct() { + errorMessage += " -products " + ctx.Config().DeviceProduct() + } library.sourceAbiDiff(ctx, referenceDump, baseName, nameExt, isLlndkOrNdk, false /* allowExtensions */, "current", errorMessage) @@ -2271,7 +2275,7 @@ func (library *libraryDecorator) install(ctx ModuleContext, file android.Path) { // do not install vndk libs // vndk libs are packaged into VNDK APEX - if ctx.isVndk() && !ctx.IsVndkExt() { + if ctx.isVndk() && !ctx.IsVndkExt() && !ctx.Config().IsVndkDeprecated() { return } } else if library.hasStubsVariants() && !ctx.Host() && ctx.directlyInAnyApex() { diff --git a/cc/linkable.go b/cc/linkable.go index 19e6501de..209939916 100644 --- a/cc/linkable.go +++ b/cc/linkable.go @@ -87,6 +87,12 @@ type Snapshottable interface { // SnapshotStaticLibs returns the list of static library dependencies for this module. SnapshotStaticLibs() []string + // SnapshotDylibs returns the list of dylib library dependencies for this module. + SnapshotDylibs() []string + + // SnapshotRlibs returns the list of rlib library dependencies for this module. + SnapshotRlibs() []string + // IsSnapshotPrebuilt returns true if this module is a snapshot prebuilt. IsSnapshotPrebuilt() bool } @@ -239,6 +245,9 @@ type LinkableInterface interface { // Dylib returns true if this is an dylib module. Dylib() bool + // RlibStd returns true if this is an rlib which links against an rlib libstd. + RlibStd() bool + // Static returns true if this is a static library module. Static() bool @@ -47,6 +47,7 @@ type LTOProperties struct { } `android:"arch_variant"` LtoEnabled bool `blueprint:"mutated"` + LtoDefault bool `blueprint:"mutated"` // Dep properties indicate that this module needs to be built with LTO // since it is an object dependency of an LTO module. @@ -66,7 +67,37 @@ func (lto *lto) props() []interface{} { } func (lto *lto) begin(ctx BaseModuleContext) { - lto.Properties.LtoEnabled = lto.LTO(ctx) + // First, determine the module indepedent default LTO mode. + ltoDefault := GlobalThinLTO(ctx) + if ctx.Config().IsEnvTrue("DISABLE_LTO") { + ltoDefault = false + } else if ctx.Host() { + // Performance and binary size are less important for host binaries. + ltoDefault = false + } else if ctx.Arch().ArchType.Multilib == "lib32" { + // LP32 has many subtle issues and less test coverage. + ltoDefault = false + } + + // Then, determine the actual LTO mode to use. If different from `ltoDefault`, a variant needs + // to be created. + ltoEnabled := ltoDefault + if lto.Never() { + ltoEnabled = false + } else if lto.ThinLTO() { + // Module explicitly requests for LTO. + ltoEnabled = true + } else if ctx.testBinary() || ctx.testLibrary() { + // Do not enable LTO for tests for better debugging. + ltoEnabled = false + } else if ctx.isVndk() { + // FIXME: ThinLTO for VNDK produces different output. + // b/169217596 + ltoEnabled = false + } + + lto.Properties.LtoDefault = ltoDefault + lto.Properties.LtoEnabled = ltoEnabled } func (lto *lto) flags(ctx BaseModuleContext, flags Flags) Flags { @@ -80,7 +111,7 @@ func (lto *lto) flags(ctx BaseModuleContext, flags Flags) Flags { var ltoLdFlags []string // The module did not explicitly turn on LTO. Only leverage LTO's - // better dead code elinmination and CFG simplification, but do + // better dead code elimination and CFG simplification, but do // not perform costly optimizations for a balance between compile // time, binary size and performance. if !lto.ThinLTO() { @@ -118,34 +149,6 @@ func (lto *lto) flags(ctx BaseModuleContext, flags Flags) Flags { return flags } -// Determine which LTO mode to use for the given module. -func (lto *lto) LTO(ctx BaseModuleContext) bool { - if lto.Never() { - return false - } - if ctx.Config().IsEnvTrue("DISABLE_LTO") { - return false - } - // Module explicitly requests for LTO. - if lto.ThinLTO() { - return true - } - // LP32 has many subtle issues and less test coverage. - if ctx.Arch().ArchType.Multilib == "lib32" { - return false - } - // Performance and binary size are less important for host binaries and tests. - if ctx.Host() || ctx.testBinary() || ctx.testLibrary() { - return false - } - // FIXME: ThinLTO for VNDK produces different output. - // b/169217596 - if ctx.isVndk() { - return false - } - return GlobalThinLTO(ctx) -} - func (lto *lto) ThinLTO() bool { return lto != nil && proptools.Bool(lto.Properties.Lto.Thin) } @@ -155,15 +158,13 @@ func (lto *lto) Never() bool { } func GlobalThinLTO(ctx android.BaseModuleContext) bool { - return ctx.Config().IsEnvTrue("GLOBAL_THINLTO") + return !ctx.Config().IsEnvFalse("GLOBAL_THINLTO") } // Propagate lto requirements down from binaries func ltoDepsMutator(mctx android.TopDownMutatorContext) { - defaultLTOMode := GlobalThinLTO(mctx) - if m, ok := mctx.Module().(*Module); ok { - if m.lto == nil || m.lto.Properties.LtoEnabled == defaultLTOMode { + if m.lto == nil || m.lto.Properties.LtoEnabled == m.lto.Properties.LtoDefault { return } @@ -238,6 +239,7 @@ func ltoMutator(mctx android.BottomUpMutatorContext) { } variation.Properties.PreventInstall = true variation.Properties.HideFromMake = true + variation.lto.Properties.LtoDefault = m.lto.Properties.LtoDefault variation.lto.Properties.LtoDep = false variation.lto.Properties.NoLtoDep = false } diff --git a/cc/ndk_sysroot.go b/cc/ndk_sysroot.go index 0cf21b65a..feb388037 100644 --- a/cc/ndk_sysroot.go +++ b/cc/ndk_sysroot.go @@ -58,7 +58,6 @@ import ( func init() { RegisterNdkModuleTypes(android.InitRegistrationContext) - pctx.Import("android/soong/android") } func RegisterNdkModuleTypes(ctx android.RegistrationContext) { diff --git a/cc/sanitize.go b/cc/sanitize.go index 62e31d1ca..626005b44 100644 --- a/cc/sanitize.go +++ b/cc/sanitize.go @@ -646,10 +646,6 @@ func (sanitize *sanitize) begin(ctx BaseModuleContext) { if (ctx.Arch().ArchType != android.Arm64 && ctx.Arch().ArchType != android.Riscv64) || !ctx.toolchain().Bionic() { s.Scs = nil } - // ...but temporarily globally disabled on riscv64 (http://b/277909695). - if ctx.Arch().ArchType == android.Riscv64 { - s.Scs = nil - } // Memtag_heap is only implemented on AArch64. // Memtag ABI is Android specific for now, so disable for host. diff --git a/cc/snapshot_prebuilt.go b/cc/snapshot_prebuilt.go index a5729dfc0..bb1331051 100644 --- a/cc/snapshot_prebuilt.go +++ b/cc/snapshot_prebuilt.go @@ -100,6 +100,7 @@ const ( snapshotBinarySuffix = "_binary." snapshotObjectSuffix = "_object." SnapshotRlibSuffix = "_rlib." + SnapshotDylibSuffix = "_dylib." ) type SnapshotProperties struct { @@ -107,6 +108,7 @@ type SnapshotProperties struct { Static_libs []string `android:"arch_variant"` Shared_libs []string `android:"arch_variant"` Rlibs []string `android:"arch_variant"` + Dylibs []string `android:"arch_variant"` Vndk_libs []string `android:"arch_variant"` Binaries []string `android:"arch_variant"` Objects []string `android:"arch_variant"` @@ -186,6 +188,7 @@ func (s *snapshotModule) DepsMutator(ctx android.BottomUpMutatorContext) { staticLibs := collectSnapshotMap(s.properties.Static_libs, snapshotSuffix, SnapshotStaticSuffix) sharedLibs := collectSnapshotMap(s.properties.Shared_libs, snapshotSuffix, SnapshotSharedSuffix) rlibs := collectSnapshotMap(s.properties.Rlibs, snapshotSuffix, SnapshotRlibSuffix) + dylibs := collectSnapshotMap(s.properties.Dylibs, snapshotSuffix, SnapshotDylibSuffix) vndkLibs := collectSnapshotMap(s.properties.Vndk_libs, "", vndkSuffix) for k, v := range vndkLibs { sharedLibs[k] = v @@ -198,11 +201,12 @@ func (s *snapshotModule) DepsMutator(ctx android.BottomUpMutatorContext) { StaticLibs: staticLibs, SharedLibs: sharedLibs, Rlibs: rlibs, + Dylibs: dylibs, }) } type SnapshotInfo struct { - HeaderLibs, Binaries, Objects, StaticLibs, SharedLibs, Rlibs map[string]string + HeaderLibs, Binaries, Objects, StaticLibs, SharedLibs, Rlibs, Dylibs map[string]string } var SnapshotInfoProvider = blueprint.NewMutatorProvider(SnapshotInfo{}, "deps") diff --git a/cc/snapshot_utils.go b/cc/snapshot_utils.go index cf4617da3..1ee120eb8 100644 --- a/cc/snapshot_utils.go +++ b/cc/snapshot_utils.go @@ -57,6 +57,14 @@ func (m *Module) SnapshotStaticLibs() []string { return m.Properties.SnapshotStaticLibs } +func (m *Module) SnapshotRlibs() []string { + return []string{} +} + +func (m *Module) SnapshotDylibs() []string { + return []string{} +} + // snapshotLibraryInterface is an interface for libraries captured to VNDK / vendor snapshots. type snapshotLibraryInterface interface { libraryInterface @@ -80,8 +80,7 @@ func (stl *stl) begin(ctx BaseModuleContext) { return "" } s = deduplicateStlInput(s) - archHasNDKStl := ctx.Arch().ArchType != android.Riscv64 - if ctx.useSdk() && ctx.Device() && archHasNDKStl { + if ctx.useSdk() && ctx.Device() { switch s { case "", "system": return "ndk_system" @@ -120,11 +119,6 @@ func (stl *stl) begin(ctx BaseModuleContext) { }() } -func needsLibAndroidSupport(ctx BaseModuleContext) bool { - version := nativeApiLevelOrPanic(ctx, ctx.sdkVersion()) - return version.LessThan(android.FirstNonLibAndroidSupportVersion) -} - func staticUnwinder(ctx android.BaseModuleContext) string { vndkVersion := ctx.Module().(*Module).VndkVersion() @@ -184,11 +178,6 @@ func (stl *stl) deps(ctx BaseModuleContext, deps Deps) Deps { } else { deps.StaticLibs = append(deps.StaticLibs, stl.Properties.SelectedStl, "ndk_libc++abi") } - if needsLibAndroidSupport(ctx) { - // Use LateStaticLibs for ndk_libandroid_support so that its include directories - // come after ndk_libc++_static or ndk_libc++_shared. - deps.LateStaticLibs = append(deps.LateStaticLibs, "ndk_libandroid_support") - } deps.StaticLibs = append(deps.StaticLibs, "ndk_libunwind") default: panic(fmt.Errorf("Unknown stl: %q", stl.Properties.SelectedStl)) diff --git a/cc/test.go b/cc/test.go index 3f5f71007..53a097aba 100644 --- a/cc/test.go +++ b/cc/test.go @@ -267,7 +267,7 @@ func (test *testDecorator) gtest() bool { return BoolDefault(test.LinkerProperties.Gtest, true) } -func (test *testDecorator) isolated(ctx BaseModuleContext) bool { +func (test *testDecorator) isolated(ctx android.EarlyModuleContext) bool { return BoolDefault(test.LinkerProperties.Isolated, false) } @@ -641,14 +641,27 @@ type ccTestBazelHandler struct { var _ BazelHandler = (*ccTestBazelHandler)(nil) +// The top level target named $label is a test_suite target, +// not the internal cc_test executable target. +// +// This is to ensure `b test //$label` runs the test_suite target directly, +// which depends on tradefed_test targets, instead of the internal cc_test +// target, which doesn't have tradefed integrations. +// +// However, for cquery, we want the internal cc_test executable target, which +// has the suffix "__tf_internal". +func mixedBuildsTestLabel(label string) string { + return label + "__tf_internal" +} + func (handler *ccTestBazelHandler) QueueBazelCall(ctx android.BaseModuleContext, label string) { bazelCtx := ctx.Config().BazelContext - bazelCtx.QueueBazelRequest(label, cquery.GetCcUnstrippedInfo, android.GetConfigKey(ctx)) + bazelCtx.QueueBazelRequest(mixedBuildsTestLabel(label), cquery.GetCcUnstrippedInfo, android.GetConfigKey(ctx)) } func (handler *ccTestBazelHandler) ProcessBazelQueryResponse(ctx android.ModuleContext, label string) { bazelCtx := ctx.Config().BazelContext - info, err := bazelCtx.GetCcUnstrippedInfo(label, android.GetConfigKey(ctx)) + info, err := bazelCtx.GetCcUnstrippedInfo(mixedBuildsTestLabel(label), android.GetConfigKey(ctx)) if err != nil { ctx.ModuleErrorf(err.Error()) return @@ -669,8 +682,7 @@ func (handler *ccTestBazelHandler) ProcessBazelQueryResponse(ctx android.ModuleC type testBinaryAttributes struct { binaryAttributes - Gtest bool - Isolated bool + Gtest bool tidyAttributes tradefed.TestConfigAttributes @@ -708,14 +720,16 @@ func testBinaryBp2build(ctx android.TopDownMutatorContext, m *Module) { m.convertTidyAttributes(ctx, &testBinaryAttrs.tidyAttributes) + gtestIsolated := m.linker.(*testBinary).isolated(ctx) for _, propIntf := range m.GetProperties() { if testLinkerProps, ok := propIntf.(*TestLinkerProperties); ok { testBinaryAttrs.Gtest = proptools.BoolDefault(testLinkerProps.Gtest, true) - testBinaryAttrs.Isolated = proptools.BoolDefault(testLinkerProps.Isolated, true) break } } + addImplicitGtestDeps(ctx, &testBinaryAttrs, gtestIsolated) + for _, testProps := range m.GetProperties() { if p, ok := testProps.(*TestBinaryProperties); ok { useVendor := false // TODO Bug: 262914724 @@ -727,7 +741,7 @@ func testBinaryBp2build(ctx android.TopDownMutatorContext, m *Module) { p.Auto_gen_config, p.Test_options.Test_suite_tag, p.Test_config_template, - getTradefedConfigOptions(ctx, p, testBinaryAttrs.Isolated), + getTradefedConfigOptions(ctx, p, gtestIsolated), &testInstallBase, ) testBinaryAttrs.TestConfigAttributes = testConfigAttributes @@ -747,3 +761,28 @@ func testBinaryBp2build(ctx android.TopDownMutatorContext, m *Module) { }, &testBinaryAttrs) } + +// cc_test that builds using gtest needs some additional deps +// addImplicitGtestDeps makes these deps explicit in the generated BUILD files +func addImplicitGtestDeps(ctx android.BazelConversionPathContext, attrs *testBinaryAttributes, gtestIsolated bool) { + addDepsAndDedupe := func(lla *bazel.LabelListAttribute, modules []string) { + moduleLabels := android.BazelLabelForModuleDeps(ctx, modules) + lla.Value.Append(moduleLabels) + // Dedupe + lla.Value = bazel.FirstUniqueBazelLabelList(lla.Value) + } + // this must be kept in sync with Soong's implementation in: + // https://cs.android.com/android/_/android/platform/build/soong/+/460fb2d6d546b5ab493a7e5479998c4933a80f73:cc/test.go;l=300-313;drc=ec7314336a2b35ea30ce5438b83949c28e3ac429;bpv=1;bpt=0 + if attrs.Gtest { + // TODO - b/244433197: Handle canUseSdk + if gtestIsolated { + addDepsAndDedupe(&attrs.Deps, []string{"libgtest_isolated_main"}) + addDepsAndDedupe(&attrs.Dynamic_deps, []string{"liblog"}) + } else { + addDepsAndDedupe(&attrs.Deps, []string{ + "libgtest_main", + "libgtest", + }) + } + } +} diff --git a/cc/testing.go b/cc/testing.go index d346739bd..d1632aaa6 100644 --- a/cc/testing.go +++ b/cc/testing.go @@ -423,11 +423,6 @@ func commonDefaultModules() string { export_include_dirs: ["ndk_libc++_shared"], } - ndk_prebuilt_static_stl { - name: "ndk_libandroid_support", - export_include_dirs: ["ndk_libandroid_support"], - } - cc_library_static { name: "libgoogle-benchmark", sdk_version: "current", @@ -573,16 +568,15 @@ var PrepareForTestWithCcDefaultModules = android.GroupFixturePreparers( // Additional files needed in tests that disallow non-existent source. android.MockFS{ - "defaults/cc/common/libc.map.txt": nil, - "defaults/cc/common/libdl.map.txt": nil, - "defaults/cc/common/libm.map.txt": nil, - "defaults/cc/common/ndk_libandroid_support": nil, - "defaults/cc/common/ndk_libc++_shared": nil, - "defaults/cc/common/crtbegin_so.c": nil, - "defaults/cc/common/crtbegin.c": nil, - "defaults/cc/common/crtend_so.c": nil, - "defaults/cc/common/crtend.c": nil, - "defaults/cc/common/crtbrand.c": nil, + "defaults/cc/common/libc.map.txt": nil, + "defaults/cc/common/libdl.map.txt": nil, + "defaults/cc/common/libm.map.txt": nil, + "defaults/cc/common/ndk_libc++_shared": nil, + "defaults/cc/common/crtbegin_so.c": nil, + "defaults/cc/common/crtbegin.c": nil, + "defaults/cc/common/crtend_so.c": nil, + "defaults/cc/common/crtend.c": nil, + "defaults/cc/common/crtbrand.c": nil, "defaults/cc/common/libclang_rt.ubsan_minimal.android_arm64.a": nil, "defaults/cc/common/libclang_rt.ubsan_minimal.android_arm.a": nil, diff --git a/cc/util.go b/cc/util.go index 6d8ac435f..c93646b98 100644 --- a/cc/util.go +++ b/cc/util.go @@ -28,8 +28,8 @@ func includeDirsToFlags(dirs android.Paths) string { return android.JoinWithPrefix(dirs.Strings(), "-I") } -var indexList = android.IndexList -var inList = android.InList +var indexList = android.IndexList[string] +var inList = android.InList[string] var filterList = android.FilterList var removeListFromList = android.RemoveListFromList var removeFromList = android.RemoveFromList diff --git a/cc/vendor_snapshot.go b/cc/vendor_snapshot.go index d2531c03d..9ea337b8d 100644 --- a/cc/vendor_snapshot.go +++ b/cc/vendor_snapshot.go @@ -108,10 +108,10 @@ func isSnapshotAware(cfg android.DeviceConfig, m LinkableInterface, inProprietar return false } } - if sanitizable.Static() { + if sanitizable.Static() || sanitizable.Rlib() { return sanitizable.OutputFile().Valid() && !isPrivate(image, m) } - if sanitizable.Shared() || sanitizable.Rlib() { + if sanitizable.Shared() || sanitizable.Dylib() { if !sanitizable.OutputFile().Valid() { return false } @@ -153,6 +153,8 @@ type snapshotJsonFlags struct { SharedLibs []string `json:",omitempty"` StaticLibs []string `json:",omitempty"` RuntimeLibs []string `json:",omitempty"` + Dylibs []string `json:",omitempty"` + Rlibs []string `json:",omitempty"` // extra config files InitRc []string `json:",omitempty"` @@ -283,8 +285,17 @@ var ccSnapshotAction snapshot.GenerateSnapshotAction = func(s snapshot.SnapshotS if m.Shared() { prop.SharedLibs = m.SnapshotSharedLibs() } - // static libs dependencies are required to collect the NOTICE files. + + // dylibs collect both shared and dylib dependencies. + if m.Dylib() { + prop.SharedLibs = m.SnapshotSharedLibs() + prop.Dylibs = m.SnapshotDylibs() + } + + // static and rlib libs dependencies are required to collect the NOTICE files. prop.StaticLibs = m.SnapshotStaticLibs() + prop.Rlibs = m.SnapshotRlibs() + if sanitizable, ok := m.(PlatformSanitizeable); ok { if sanitizable.Static() && sanitizable.SanitizePropDefined() { prop.SanitizeMinimalDep = sanitizable.MinimalRuntimeDep() || sanitizable.MinimalRuntimeNeeded() @@ -299,13 +310,15 @@ var ccSnapshotAction snapshot.GenerateSnapshotAction = func(s snapshot.SnapshotS libType = "shared" } else if m.Rlib() { libType = "rlib" + } else if m.Dylib() { + libType = "dylib" } else { libType = "header" } var stem string - // install .a or .so + // install .a, .rlib, .dylib.so, or .so if libType != "header" { libPath := m.OutputFile().Path() stem = libPath.Base() @@ -328,6 +341,12 @@ var ccSnapshotAction snapshot.GenerateSnapshotAction = func(s snapshot.SnapshotS } } } + if m.Rlib() && m.RlibStd() { + // rlibs produce both rlib-std and dylib-std variants + ext := filepath.Ext(stem) + stem = strings.TrimSuffix(stem, ext) + ".rlib-std" + ext + prop.ModuleName += ".rlib-std" + } snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, libType, m.RelativeInstallPath(), stem) ret = append(ret, copyFile(ctx, libPath, snapshotLibOut, fake)) } else { @@ -341,8 +360,12 @@ var ccSnapshotAction snapshot.GenerateSnapshotAction = func(s snapshot.SnapshotS prop.StaticExecutable = m.StaticExecutable() prop.InstallInRoot = m.InstallInRoot() prop.SharedLibs = m.SnapshotSharedLibs() - // static libs dependencies are required to collect the NOTICE files. + prop.Dylibs = m.SnapshotDylibs() + + // static and rlib dependencies are required to collect the NOTICE files. prop.StaticLibs = m.SnapshotStaticLibs() + prop.Rlibs = m.SnapshotRlibs() + // install bin binPath := m.OutputFile().Path() snapshotBinOut := filepath.Join(snapshotArchDir, targetArch, "binary", binPath.Base()) |