summaryrefslogtreecommitdiff
path: root/cc
diff options
context:
space:
mode:
Diffstat (limited to 'cc')
-rw-r--r--cc/Android.bp1
-rw-r--r--cc/afdo.go4
-rw-r--r--cc/api_level.go6
-rw-r--r--cc/bp2build.go160
-rw-r--r--cc/cc.go54
-rw-r--r--cc/cc_test.go2
-rw-r--r--cc/compiler.go12
-rw-r--r--cc/config/global.go1
-rw-r--r--cc/config/vndk.go1
-rw-r--r--cc/coverage.go2
-rw-r--r--cc/generated_cc_library.go38
-rw-r--r--cc/image.go7
-rw-r--r--cc/library.go29
-rw-r--r--cc/rs.go11
-rw-r--r--cc/sanitize.go4
-rw-r--r--cc/stl.go13
-rw-r--r--cc/test.go65
-rw-r--r--cc/testing.go24
18 files changed, 319 insertions, 115 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/afdo.go b/cc/afdo.go
index bc7cd5212..23d196dba 100644
--- a/cc/afdo.go
+++ b/cc/afdo.go
@@ -131,6 +131,10 @@ func (c *Module) fdoProfileMutator(ctx android.BottomUpMutatorContext) {
return
}
+ if !c.afdo.afdoEnabled() {
+ return
+ }
+
ctx.VisitDirectDepsWithTag(FdoProfileTag, func(m android.Module) {
if ctx.OtherModuleHasProvider(m, FdoProfileProvider) {
info := ctx.OtherModuleProvider(m, FdoProfileProvider).(FdoProfileInfo)
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 6e00aa828..9e485d6d0 100644
--- a/cc/bp2build.go
+++ b/cc/bp2build.go
@@ -22,6 +22,7 @@ import (
"android/soong/android"
"android/soong/bazel"
"android/soong/cc/config"
+ "android/soong/genrule"
"github.com/google/blueprint"
@@ -43,6 +44,12 @@ const (
rScriptSrcPartition = "renderScript"
+ xsdSrcPartition = "xsd"
+
+ genrulePartition = "genrule"
+
+ hdrPartition = "hdr"
+
stubsSuffix = "_stub_libs_current"
)
@@ -155,6 +162,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 +173,15 @@ 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)},
+ genrulePartition: bazel.LabelPartition{LabelMapper: genrule.GenruleCcHeaderLabelMapper},
+ 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 +420,12 @@ type compilerAttributes struct {
srcs bazel.LabelListAttribute
// xsd config sources
- xsdInSrcs bazel.StringListAttribute
+ xsdSrcs bazel.LabelListAttribute
+ exportXsdSrcs bazel.LabelListAttribute
+
+ // genrule headers
+ genruleHeaders bazel.LabelListAttribute
+ exportGenruleHeaders bazel.LabelListAttribute
// Lex sources and options
lSrcs bazel.LabelListAttribute
@@ -494,14 +516,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 +587,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 +601,22 @@ 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.genruleHeaders = partitionedImplHdrs[genrulePartition]
+ ca.exportGenruleHeaders = partitionedHdrs[genrulePartition]
+
ca.srcs = partitionedSrcs[cppSrcPartition]
ca.cSrcs = partitionedSrcs[cSrcPartition]
ca.asSrcs = partitionedSrcs[asSrcPartition]
@@ -604,11 +637,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 +653,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 +700,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 +744,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 +814,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 +833,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 +843,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 +859,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 +889,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 +906,17 @@ 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).deps.Append(compilerAttrs.exportGenruleHeaders)
+ (&linkerAttrs).implementationDeps.Append(compilerAttrs.genruleHeaders)
+
+ (&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
@@ -1748,16 +1800,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 {
diff --git a/cc/cc.go b/cc/cc.go
index 84b80a10c..be67286c6 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -569,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 {
@@ -851,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
@@ -1201,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()...)
}
@@ -2149,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())
@@ -2163,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)
}
@@ -2220,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)
@@ -2307,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)
}
@@ -2342,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)
}
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/compiler.go b/cc/compiler.go
index 16f4a6ec0..5bed8a72f 100644
--- a/cc/compiler.go
+++ b/cc/compiler.go
@@ -189,13 +189,13 @@ type BaseCompilerProperties struct {
// build the recovery variant of the C/C++ module.
Exclude_generated_sources []string
}
- Vendor_ramdisk struct {
+ Ramdisk, Vendor_ramdisk struct {
// list of source files that should not be used to
- // build the vendor ramdisk variant of the C/C++ module.
+ // build the ramdisk variants of the C/C++ module.
Exclude_srcs []string `android:"path"`
- // List of additional cflags that should be used to build the vendor ramdisk
- // variant of the C/C++ module.
+ // List of additional cflags that should be used to build the ramdisk
+ // variants of the C/C++ module.
Cflags []string
}
Platform struct {
@@ -351,6 +351,7 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
CheckBadCompilerFlags(ctx, "vendor.cflags", compiler.Properties.Target.Vendor.Cflags)
CheckBadCompilerFlags(ctx, "product.cflags", compiler.Properties.Target.Product.Cflags)
CheckBadCompilerFlags(ctx, "recovery.cflags", compiler.Properties.Target.Recovery.Cflags)
+ CheckBadCompilerFlags(ctx, "ramdisk.cflags", compiler.Properties.Target.Ramdisk.Cflags)
CheckBadCompilerFlags(ctx, "vendor_ramdisk.cflags", compiler.Properties.Target.Vendor_ramdisk.Cflags)
CheckBadCompilerFlags(ctx, "platform.cflags", compiler.Properties.Target.Platform.Cflags)
@@ -536,6 +537,9 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
if ctx.inVendorRamdisk() {
flags.Local.CFlags = append(flags.Local.CFlags, esc(compiler.Properties.Target.Vendor_ramdisk.Cflags)...)
}
+ if ctx.inRamdisk() {
+ flags.Local.CFlags = append(flags.Local.CFlags, esc(compiler.Properties.Target.Ramdisk.Cflags)...)
+ }
if !ctx.useSdk() {
flags.Local.CFlags = append(flags.Local.CFlags, esc(compiler.Properties.Target.Platform.Cflags)...)
}
diff --git a/cc/config/global.go b/cc/config/global.go
index 266d2789b..ff5ab051e 100644
--- a/cc/config/global.go
+++ b/cc/config/global.go
@@ -149,6 +149,7 @@ var (
commonGlobalLldflags = []string{
"-fuse-ld=lld",
"-Wl,--icf=safe",
+ "-Wl,--no-demangle",
}
deviceGlobalCppflags = []string{
diff --git a/cc/config/vndk.go b/cc/config/vndk.go
index dd612ce63..f9b3eac82 100644
--- a/cc/config/vndk.go
+++ b/cc/config/vndk.go
@@ -21,6 +21,7 @@ package config
var VndkMustUseVendorVariantList = []string{
"android.hardware.nfc@1.2",
"libbinder",
+ "libdumpstateutil",
"libcrypto",
"libexpat",
"libgatekeeper",
diff --git a/cc/coverage.go b/cc/coverage.go
index c0f697398..cbd8a6f3e 100644
--- a/cc/coverage.go
+++ b/cc/coverage.go
@@ -48,6 +48,7 @@ func (cov *coverage) props() []interface{} {
func getGcovProfileLibraryName(ctx ModuleContextIntf) string {
// This function should only ever be called for a cc.Module, so the
// following statement should always succeed.
+ // LINT.IfChange
if ctx.useSdk() {
return "libprofile-extras_ndk"
} else {
@@ -63,6 +64,7 @@ func getClangProfileLibraryName(ctx ModuleContextIntf) string {
} else {
return "libprofile-clang-extras"
}
+ // LINT.ThenChange(library.go)
}
func (cov *coverage) deps(ctx DepsContext, deps Deps) Deps {
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/image.go b/cc/image.go
index e65a9aadb..f91762adc 100644
--- a/cc/image.go
+++ b/cc/image.go
@@ -678,10 +678,17 @@ func squashVendorRamdiskSrcs(m *Module) {
}
}
+func squashRamdiskSrcs(m *Module) {
+ if lib, ok := m.compiler.(*libraryDecorator); ok {
+ lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, lib.baseCompiler.Properties.Target.Ramdisk.Exclude_srcs...)
+ }
+}
+
func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
m := module.(*Module)
if variant == android.RamdiskVariation {
m.MakeAsPlatform()
+ squashRamdiskSrcs(m)
} else if variant == android.VendorRamdiskVariation {
m.MakeAsPlatform()
squashVendorRamdiskSrcs(m)
diff --git a/cc/library.go b/cc/library.go
index 266fa7511..df1dbc5b4 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -32,6 +32,20 @@ import (
"github.com/google/blueprint/proptools"
)
+var (
+ alwaysLinkLibraries = map[string]bool{
+ // Coverage libraries are _always_ added as a whole_static_dep. By converting as these as
+ // alwayslink = True, we can add these as to deps (e.g. as a regular static dep) in Bazel
+ // without any extra complications in cc_shared_library roots to prevent linking the same
+ // library repeatedly.
+ "libprofile-extras_ndk": true,
+ "libprofile-extras": true,
+ "libprofile-clang-extras_ndk": true,
+ "libprofile-clang-extras_cfi_support": true,
+ "libprofile-clang-extras": true,
+ }
+)
+
// LibraryProperties is a collection of properties shared by cc library rules/cc.
type LibraryProperties struct {
// local file name to pass to the linker as -unexported_symbols_list
@@ -435,6 +449,10 @@ func libraryBp2Build(ctx android.TopDownMutatorContext, m *Module) {
Bzl_load_location: "//build/bazel/rules/cc:cc_library_shared.bzl",
}
+ if _, ok := alwaysLinkLibraries[m.Name()]; ok {
+ staticTargetAttrs.Alwayslink = proptools.BoolPtr(true)
+ }
+
var tagsForStaticVariant bazel.StringListAttribute
if compilerAttrs.stubsSymbolFile == nil && len(compilerAttrs.stubsVersions.Value) == 0 {
tagsForStaticVariant = android.ApexAvailableTagsWithoutTestApexes(ctx, m)
@@ -2951,6 +2969,10 @@ func sharedOrStaticLibraryBp2Build(ctx android.TopDownMutatorContext, module *Mo
var attrs interface{}
if isStatic {
commonAttrs.Deps.Add(baseAttributes.protoDependency)
+ var alwayslink *bool
+ if _, ok := alwaysLinkLibraries[module.Name()]; ok && isStatic {
+ alwayslink = proptools.BoolPtr(true)
+ }
attrs = &bazelCcLibraryStaticAttributes{
staticOrSharedAttributes: commonAttrs,
Rtti: compilerAttrs.rtti,
@@ -2964,8 +2986,10 @@ func sharedOrStaticLibraryBp2Build(ctx android.TopDownMutatorContext, module *Mo
Conlyflags: compilerAttrs.conlyFlags,
Asflags: asFlags,
- Features: *features,
+ Alwayslink: alwayslink,
+ Features: *features,
}
+
} else {
commonAttrs.Dynamic_deps.Add(baseAttributes.protoDependency)
@@ -3047,7 +3071,8 @@ type bazelCcLibraryStaticAttributes struct {
Conlyflags bazel.StringListAttribute
Asflags bazel.StringListAttribute
- Features bazel.StringListAttribute
+ Alwayslink *bool
+ Features bazel.StringListAttribute
}
// TODO(b/199902614): Can this be factored to share with the other Attributes?
diff --git a/cc/rs.go b/cc/rs.go
index 65072591f..93acdc7db 100644
--- a/cc/rs.go
+++ b/cc/rs.go
@@ -101,11 +101,12 @@ func rsGenerateCpp(ctx android.ModuleContext, rsFiles android.Paths, rsFlags str
func rsFlags(ctx ModuleContext, flags Flags, properties *BaseCompilerProperties) Flags {
targetApi := String(properties.Renderscript.Target_api)
if targetApi == "" && ctx.useSdk() {
- switch ctx.sdkVersion() {
- case "current", "system_current", "test_current":
- // Nothing
- default:
- targetApi = android.GetNumericSdkVersion(ctx.sdkVersion())
+ targetApiLevel := android.ApiLevelOrPanic(ctx, ctx.sdkVersion())
+ if targetApiLevel.IsCurrent() || targetApiLevel.IsPreview() {
+ // If the target level is current or preview, leave the 'target-api' unset.
+ // This signals to llvm-rs-cc that the development API should be used.
+ } else {
+ targetApi = targetApiLevel.String()
}
}
diff --git a/cc/sanitize.go b/cc/sanitize.go
index 626005b44..c1ef97034 100644
--- a/cc/sanitize.go
+++ b/cc/sanitize.go
@@ -56,10 +56,6 @@ var (
// higher number of "optimized out" stack variables.
// b/112437883.
"-instcombine-lower-dbg-declare=0",
- // TODO(b/159343917): HWASan and GlobalISel don't play nicely, and
- // GlobalISel is the default at -O0 on aarch64.
- "--aarch64-enable-global-isel-at-O=-1",
- "-fast-isel=false",
"-hwasan-use-after-scope=1",
"-dom-tree-reachability-max-bbs-to-explore=128",
}
diff --git a/cc/stl.go b/cc/stl.go
index f1433efbf..8f92dcb40 100644
--- a/cc/stl.go
+++ b/cc/stl.go
@@ -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..0be230151 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,13 +720,15 @@ func testBinaryBp2build(ctx android.TopDownMutatorContext, m *Module) {
m.convertTidyAttributes(ctx, &testBinaryAttrs.tidyAttributes)
- 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
- }
- }
+ testBinary := m.linker.(*testBinary)
+ gtest := testBinary.gtest()
+ gtestIsolated := testBinary.isolated(ctx)
+ // Use the underling bool pointer for Gtest in attrs
+ // This ensures that if this property is not set in Android.bp file, it will not be set in BUILD file either
+ // cc_test macro will default gtest to True
+ testBinaryAttrs.Gtest = testBinary.LinkerProperties.Gtest
+
+ addImplicitGtestDeps(ctx, &testBinaryAttrs, gtest, gtestIsolated)
for _, testProps := range m.GetProperties() {
if p, ok := testProps.(*TestBinaryProperties); ok {
@@ -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, gtest, 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 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,