summaryrefslogtreecommitdiff
path: root/cc
diff options
context:
space:
mode:
Diffstat (limited to 'cc')
-rw-r--r--cc/bp2build.go408
-rw-r--r--cc/cc_test.go9
-rw-r--r--cc/library.go43
-rw-r--r--cc/object.go21
-rw-r--r--cc/vndk.go44
5 files changed, 381 insertions, 144 deletions
diff --git a/cc/bp2build.go b/cc/bp2build.go
index 95a3fe157..339a489d0 100644
--- a/cc/bp2build.go
+++ b/cc/bp2build.go
@@ -50,35 +50,51 @@ func depsBp2BuildMutator(ctx android.BottomUpMutatorContext) {
var allDeps []string
- for _, p := range module.GetTargetProperties(ctx, &BaseCompilerProperties{}) {
- // base compiler props
- if baseCompilerProps, ok := p.(*BaseCompilerProperties); ok {
+ for _, osProps := range module.GetTargetProperties(ctx, &BaseCompilerProperties{}) {
+ // os base compiler props
+ if baseCompilerProps, ok := osProps.Properties.(*BaseCompilerProperties); ok {
allDeps = append(allDeps, baseCompilerProps.Generated_headers...)
allDeps = append(allDeps, baseCompilerProps.Generated_sources...)
}
+ // os + arch base compiler props
+ for _, archProps := range osProps.ArchProperties {
+ if baseCompilerProps, ok := archProps.(*BaseCompilerProperties); ok {
+ allDeps = append(allDeps, baseCompilerProps.Generated_headers...)
+ allDeps = append(allDeps, baseCompilerProps.Generated_sources...)
+ }
+ }
}
- for _, p := range module.GetArchProperties(ctx, &BaseCompilerProperties{}) {
+ for _, props := range module.GetArchProperties(ctx, &BaseCompilerProperties{}) {
// arch specific compiler props
- if baseCompilerProps, ok := p.(*BaseCompilerProperties); ok {
+ if baseCompilerProps, ok := props.(*BaseCompilerProperties); ok {
allDeps = append(allDeps, baseCompilerProps.Generated_headers...)
allDeps = append(allDeps, baseCompilerProps.Generated_sources...)
}
}
- for _, p := range module.GetTargetProperties(ctx, &BaseLinkerProperties{}) {
- // arch specific linker props
- if baseLinkerProps, ok := p.(*BaseLinkerProperties); ok {
+ for _, osProps := range module.GetTargetProperties(ctx, &BaseLinkerProperties{}) {
+ // os specific linker props
+ if baseLinkerProps, ok := osProps.Properties.(*BaseLinkerProperties); ok {
allDeps = append(allDeps, baseLinkerProps.Header_libs...)
allDeps = append(allDeps, baseLinkerProps.Export_header_lib_headers...)
allDeps = append(allDeps, baseLinkerProps.Static_libs...)
allDeps = append(allDeps, baseLinkerProps.Whole_static_libs...)
}
+ // os + arch base compiler props
+ for _, archProps := range osProps.ArchProperties {
+ if baseLinkerProps, ok := archProps.(*BaseLinkerProperties); ok {
+ allDeps = append(allDeps, baseLinkerProps.Header_libs...)
+ allDeps = append(allDeps, baseLinkerProps.Export_header_lib_headers...)
+ allDeps = append(allDeps, baseLinkerProps.Static_libs...)
+ allDeps = append(allDeps, baseLinkerProps.Whole_static_libs...)
+ }
+ }
}
- for _, p := range module.GetArchProperties(ctx, &BaseLinkerProperties{}) {
+ for _, props := range module.GetArchProperties(ctx, &BaseLinkerProperties{}) {
// arch specific linker props
- if baseLinkerProps, ok := p.(*BaseLinkerProperties); ok {
+ if baseLinkerProps, ok := props.(*BaseLinkerProperties); ok {
allDeps = append(allDeps, baseLinkerProps.Header_libs...)
allDeps = append(allDeps, baseLinkerProps.Export_header_lib_headers...)
allDeps = append(allDeps, baseLinkerProps.Static_libs...)
@@ -88,24 +104,64 @@ func depsBp2BuildMutator(ctx android.BottomUpMutatorContext) {
// Deps in the static: { .. } and shared: { .. } props of a cc_library.
if lib, ok := module.compiler.(*libraryDecorator); ok {
- allDeps = append(allDeps, lib.SharedProperties.Shared.Static_libs...)
- allDeps = append(allDeps, lib.SharedProperties.Shared.Whole_static_libs...)
- allDeps = append(allDeps, lib.SharedProperties.Shared.Shared_libs...)
+ appendDeps := func(deps []string, p StaticOrSharedProperties) []string {
+ deps = append(deps, p.Static_libs...)
+ deps = append(deps, p.Whole_static_libs...)
+ deps = append(deps, p.Shared_libs...)
+ return deps
+ }
- allDeps = append(allDeps, lib.StaticProperties.Static.Static_libs...)
- allDeps = append(allDeps, lib.StaticProperties.Static.Whole_static_libs...)
- allDeps = append(allDeps, lib.StaticProperties.Static.Shared_libs...)
+ allDeps = appendDeps(allDeps, lib.SharedProperties.Shared)
+ allDeps = appendDeps(allDeps, lib.StaticProperties.Static)
// 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...)
+
+ // Deps in the target/arch nested static: { .. } and shared: { .. } props of a cc_library.
+ // target: { <target>: shared: { ... } }
+ for _, targetProps := range module.GetTargetProperties(ctx, &SharedProperties{}) {
+ if p, ok := targetProps.Properties.(*SharedProperties); ok {
+ allDeps = appendDeps(allDeps, p.Shared)
+ }
+ for _, archProperties := range targetProps.ArchProperties {
+ if p, ok := archProperties.(*SharedProperties); ok {
+ allDeps = appendDeps(allDeps, p.Shared)
+ }
+ }
+ }
+ // target: { <target>: static: { ... } }
+ for _, targetProps := range module.GetTargetProperties(ctx, &StaticProperties{}) {
+ if p, ok := targetProps.Properties.(*StaticProperties); ok {
+ allDeps = appendDeps(allDeps, p.Static)
+ }
+ for _, archProperties := range targetProps.ArchProperties {
+ if p, ok := archProperties.(*StaticProperties); ok {
+ allDeps = appendDeps(allDeps, p.Static)
+ }
+ }
+ }
+ // arch: { <arch>: shared: { ... } }
+ for _, properties := range module.GetArchProperties(ctx, &SharedProperties{}) {
+ if p, ok := properties.(*SharedProperties); ok {
+ allDeps = appendDeps(allDeps, p.Shared)
+ }
+ }
+ // arch: { <arch>: static: { ... } }
+ for _, properties := range module.GetArchProperties(ctx, &StaticProperties{}) {
+ if p, ok := properties.(*StaticProperties); ok {
+ allDeps = appendDeps(allDeps, p.Static)
+ }
+ }
}
ctx.AddDependency(module, nil, android.SortedUniqueStrings(allDeps)...)
}
-type sharedAttributes struct {
+// staticOrSharedAttributes are the Bazel-ified versions of StaticOrSharedProperties --
+// properties which apply to either the shared or static version of a cc_library module.
+type staticOrSharedAttributes struct {
copts bazel.StringListAttribute
srcs bazel.LabelListAttribute
staticDeps bazel.LabelListAttribute
@@ -114,84 +170,124 @@ type sharedAttributes struct {
}
// bp2buildParseSharedProps returns the attributes for the shared variant of a cc_library.
-func bp2BuildParseSharedProps(ctx android.TopDownMutatorContext, module *Module) sharedAttributes {
+func bp2BuildParseSharedProps(ctx android.TopDownMutatorContext, module *Module) staticOrSharedAttributes {
lib, ok := module.compiler.(*libraryDecorator)
if !ok {
- return sharedAttributes{}
+ return staticOrSharedAttributes{}
}
- copts := bazel.StringListAttribute{Value: lib.SharedProperties.Shared.Cflags}
-
- srcs := bazel.LabelListAttribute{
- Value: android.BazelLabelForModuleSrc(ctx, lib.SharedProperties.Shared.Srcs)}
-
- staticDeps := bazel.LabelListAttribute{
- Value: android.BazelLabelForModuleDeps(ctx, lib.SharedProperties.Shared.Static_libs)}
-
- dynamicDeps := bazel.LabelListAttribute{
- Value: android.BazelLabelForModuleDeps(ctx, lib.SharedProperties.Shared.Shared_libs)}
-
- wholeArchiveDeps := bazel.LabelListAttribute{
- Value: android.BazelLabelForModuleDeps(ctx, lib.SharedProperties.Shared.Whole_static_libs)}
-
- return sharedAttributes{
- copts: copts,
- srcs: srcs,
- staticDeps: staticDeps,
- dynamicDeps: dynamicDeps,
- wholeArchiveDeps: wholeArchiveDeps,
- }
-}
-
-type staticAttributes struct {
- copts bazel.StringListAttribute
- srcs bazel.LabelListAttribute
- staticDeps bazel.LabelListAttribute
- dynamicDeps bazel.LabelListAttribute
- wholeArchiveDeps bazel.LabelListAttribute
+ return bp2buildParseStaticOrSharedProps(ctx, module, lib, false)
}
// bp2buildParseStaticProps returns the attributes for the static variant of a cc_library.
-func bp2BuildParseStaticProps(ctx android.TopDownMutatorContext, module *Module) staticAttributes {
+func bp2BuildParseStaticProps(ctx android.TopDownMutatorContext, module *Module) staticOrSharedAttributes {
lib, ok := module.compiler.(*libraryDecorator)
if !ok {
- return staticAttributes{}
+ return staticOrSharedAttributes{}
}
- copts := bazel.StringListAttribute{Value: lib.StaticProperties.Static.Cflags}
+ return bp2buildParseStaticOrSharedProps(ctx, module, lib, true)
+}
- srcs := bazel.LabelListAttribute{
- Value: android.BazelLabelForModuleSrc(ctx, lib.StaticProperties.Static.Srcs)}
+func bp2buildParseStaticOrSharedProps(ctx android.TopDownMutatorContext, module *Module, lib *libraryDecorator, isStatic bool) staticOrSharedAttributes {
+ var props StaticOrSharedProperties
+ if isStatic {
+ props = lib.StaticProperties.Static
+ } else {
+ props = lib.SharedProperties.Shared
+ }
- staticDeps := bazel.LabelListAttribute{
- Value: android.BazelLabelForModuleDeps(ctx, lib.StaticProperties.Static.Static_libs)}
+ attrs := staticOrSharedAttributes{
+ copts: bazel.StringListAttribute{Value: props.Cflags},
+ srcs: bazel.LabelListAttribute{Value: android.BazelLabelForModuleSrc(ctx, props.Srcs)},
+ staticDeps: bazel.LabelListAttribute{Value: android.BazelLabelForModuleDeps(ctx, props.Static_libs)},
+ dynamicDeps: bazel.LabelListAttribute{Value: android.BazelLabelForModuleDeps(ctx, props.Shared_libs)},
+ wholeArchiveDeps: bazel.LabelListAttribute{Value: android.BazelLabelForModuleDeps(ctx, props.Whole_static_libs)},
+ }
- dynamicDeps := bazel.LabelListAttribute{
- Value: android.BazelLabelForModuleDeps(ctx, lib.StaticProperties.Static.Shared_libs)}
+ setArchAttrs := func(arch string, props StaticOrSharedProperties) {
+ attrs.copts.SetValueForArch(arch, props.Cflags)
+ attrs.srcs.SetValueForArch(arch, android.BazelLabelForModuleSrc(ctx, props.Srcs))
+ attrs.staticDeps.SetValueForArch(arch, android.BazelLabelForModuleDeps(ctx, props.Static_libs))
+ attrs.dynamicDeps.SetValueForArch(arch, android.BazelLabelForModuleDeps(ctx, props.Shared_libs))
+ attrs.wholeArchiveDeps.SetValueForArch(arch, android.BazelLabelForModuleDeps(ctx, props.Whole_static_libs))
+ }
- wholeArchiveDeps := bazel.LabelListAttribute{
- Value: android.BazelLabelForModuleDeps(ctx, lib.StaticProperties.Static.Whole_static_libs)}
+ setTargetAttrs := func(target string, props StaticOrSharedProperties) {
+ attrs.copts.SetOsValueForTarget(target, props.Cflags)
+ attrs.srcs.SetOsValueForTarget(target, android.BazelLabelForModuleSrc(ctx, props.Srcs))
+ attrs.staticDeps.SetOsValueForTarget(target, android.BazelLabelForModuleDeps(ctx, props.Static_libs))
+ attrs.dynamicDeps.SetOsValueForTarget(target, android.BazelLabelForModuleDeps(ctx, props.Shared_libs))
+ attrs.wholeArchiveDeps.SetOsValueForTarget(target, android.BazelLabelForModuleDeps(ctx, props.Whole_static_libs))
+ }
- return staticAttributes{
- copts: copts,
- srcs: srcs,
- staticDeps: staticDeps,
- dynamicDeps: dynamicDeps,
- wholeArchiveDeps: wholeArchiveDeps,
+ setTargetArchAttrs := func(target, arch string, props StaticOrSharedProperties) {
+ attrs.copts.SetOsArchValueForTarget(target, arch, props.Cflags)
+ attrs.srcs.SetOsArchValueForTarget(target, arch, android.BazelLabelForModuleSrc(ctx, props.Srcs))
+ attrs.staticDeps.SetOsArchValueForTarget(target, arch, android.BazelLabelForModuleDeps(ctx, props.Static_libs))
+ attrs.dynamicDeps.SetOsArchValueForTarget(target, arch, android.BazelLabelForModuleDeps(ctx, props.Shared_libs))
+ attrs.wholeArchiveDeps.SetOsArchValueForTarget(target, arch, android.BazelLabelForModuleDeps(ctx, props.Whole_static_libs))
}
+
+ if isStatic {
+ for arch, properties := range module.GetArchProperties(ctx, &StaticProperties{}) {
+ if staticOrSharedProps, ok := properties.(*StaticProperties); ok {
+ setArchAttrs(arch.Name, staticOrSharedProps.Static)
+ }
+ }
+ for target, p := range module.GetTargetProperties(ctx, &StaticProperties{}) {
+ if staticOrSharedProps, ok := p.Properties.(*StaticProperties); ok {
+ setTargetAttrs(target.Name, staticOrSharedProps.Static)
+ }
+ for arch, archProperties := range p.ArchProperties {
+ if staticOrSharedProps, ok := archProperties.(*StaticProperties); ok {
+ setTargetArchAttrs(target.Name, arch.Name, staticOrSharedProps.Static)
+ }
+ }
+ }
+ } else {
+ for arch, p := range module.GetArchProperties(ctx, &SharedProperties{}) {
+ if staticOrSharedProps, ok := p.(*SharedProperties); ok {
+ setArchAttrs(arch.Name, staticOrSharedProps.Shared)
+ }
+ }
+ for target, p := range module.GetTargetProperties(ctx, &SharedProperties{}) {
+ if staticOrSharedProps, ok := p.Properties.(*SharedProperties); ok {
+ setTargetAttrs(target.Name, staticOrSharedProps.Shared)
+ }
+ for arch, archProperties := range p.ArchProperties {
+ if staticOrSharedProps, ok := archProperties.(*SharedProperties); ok {
+ setTargetArchAttrs(target.Name, arch.Name, staticOrSharedProps.Shared)
+ }
+ }
+ }
+ }
+
+ return attrs
}
// Convenience struct to hold all attributes parsed from compiler properties.
type compilerAttributes struct {
- copts bazel.StringListAttribute
+ // Options for all languages
+ copts bazel.StringListAttribute
+ // Assembly options and sources
+ asFlags bazel.StringListAttribute
+ asSrcs bazel.LabelListAttribute
+ // C options and sources
+ conlyFlags bazel.StringListAttribute
+ cSrcs bazel.LabelListAttribute
+ // C++ options and sources
+ cppFlags bazel.StringListAttribute
srcs bazel.LabelListAttribute
- includes bazel.StringListAttribute
}
// bp2BuildParseCompilerProps returns copts, srcs and hdrs and other attributes.
func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Module) compilerAttributes {
var srcs bazel.LabelListAttribute
var copts bazel.StringListAttribute
+ var asFlags bazel.StringListAttribute
+ var conlyFlags bazel.StringListAttribute
+ var cppFlags bazel.StringListAttribute
// Creates the -I flags for a directory, while making the directory relative
// to the exec root for Bazel to work.
@@ -215,15 +311,21 @@ func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Modul
return append(includeDirs, baseCompilerProps.Local_include_dirs...)
}
- // Parse the list of copts.
- parseCopts := func(baseCompilerProps *BaseCompilerProperties) []string {
- var copts []string
- for _, flag := range append(baseCompilerProps.Cflags, baseCompilerProps.Cppflags...) {
+ parseCommandLineFlags := func(soongFlags []string) []string {
+ var result []string
+ for _, flag := range soongFlags {
// Soong's cflags can contain spaces, like `-include header.h`. For
// Bazel's copts, split them up to be compatible with the
// no_copts_tokenization feature.
- copts = append(copts, strings.Split(flag, " ")...)
+ result = append(result, strings.Split(flag, " ")...)
}
+ 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)...)
}
@@ -260,6 +362,9 @@ func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Modul
if baseCompilerProps, ok := props.(*BaseCompilerProperties); ok {
srcs.Value = parseSrcs(baseCompilerProps)
copts.Value = parseCopts(baseCompilerProps)
+ asFlags.Value = parseCommandLineFlags(baseCompilerProps.Asflags)
+ conlyFlags.Value = parseCommandLineFlags(baseCompilerProps.Conlyflags)
+ cppFlags.Value = parseCommandLineFlags(baseCompilerProps.Cppflags)
// Used for arch-specific srcs later.
baseSrcs = baseCompilerProps.Srcs
@@ -290,6 +395,9 @@ func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Modul
}
copts.SetValueForArch(arch.Name, parseCopts(baseCompilerProps))
+ asFlags.SetValueForArch(arch.Name, parseCommandLineFlags(baseCompilerProps.Asflags))
+ conlyFlags.SetValueForArch(arch.Name, parseCommandLineFlags(baseCompilerProps.Conlyflags))
+ cppFlags.SetValueForArch(arch.Name, parseCommandLineFlags(baseCompilerProps.Cppflags))
}
}
@@ -308,19 +416,67 @@ func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Modul
// TODO(b/186153868): handle the case with multiple variant types, e.g. when arch and os are both used.
srcs.SetValueForArch(bazel.CONDITIONS_DEFAULT, defaultsSrcs)
- // Handle OS specific props.
- for os, props := range module.GetTargetProperties(ctx, &BaseCompilerProperties{}) {
- if baseCompilerProps, ok := props.(*BaseCompilerProperties); ok {
+ // Handle target specific properties.
+ for os, osProps := range module.GetTargetProperties(ctx, &BaseCompilerProperties{}) {
+ if baseCompilerProps, ok := osProps.Properties.(*BaseCompilerProperties); ok {
srcsList := parseSrcs(baseCompilerProps)
// TODO(b/186153868): add support for os-specific srcs and exclude_srcs
- srcs.SetValueForOS(os.Name, bazel.SubtractBazelLabelList(srcsList, baseSrcsLabelList))
- copts.SetValueForOS(os.Name, parseCopts(baseCompilerProps))
+ srcs.SetOsValueForTarget(os.Name, bazel.SubtractBazelLabelList(srcsList, baseSrcsLabelList))
+ copts.SetOsValueForTarget(os.Name, parseCopts(baseCompilerProps))
+ asFlags.SetOsValueForTarget(os.Name, parseCommandLineFlags(baseCompilerProps.Asflags))
+ conlyFlags.SetOsValueForTarget(os.Name, parseCommandLineFlags(baseCompilerProps.Conlyflags))
+ cppFlags.SetOsValueForTarget(os.Name, parseCommandLineFlags(baseCompilerProps.Cppflags))
+ }
+ for arch, archProps := range osProps.ArchProperties {
+ if baseCompilerProps, ok := archProps.(*BaseCompilerProperties); ok {
+ srcsList := parseSrcs(baseCompilerProps)
+ // TODO(b/186153868): add support for os-specific srcs and exclude_srcs
+ srcs.SetOsArchValueForTarget(os.Name, arch.Name, bazel.SubtractBazelLabelList(srcsList, baseSrcsLabelList))
+ copts.SetOsArchValueForTarget(os.Name, arch.Name, parseCopts(baseCompilerProps))
+ asFlags.SetOsArchValueForTarget(os.Name, arch.Name, parseCommandLineFlags(baseCompilerProps.Asflags))
+ conlyFlags.SetOsArchValueForTarget(os.Name, arch.Name, parseCommandLineFlags(baseCompilerProps.Conlyflags))
+ cppFlags.SetOsArchValueForTarget(os.Name, arch.Name, parseCommandLineFlags(baseCompilerProps.Cppflags))
+ }
+ }
+ }
+
+ productVariableProps := android.ProductVariableProperties(ctx)
+ if props, exists := productVariableProps["Cflags"]; exists {
+ for _, prop := range props {
+ flags, ok := prop.Property.([]string)
+ if !ok {
+ ctx.ModuleErrorf("Could not convert product variable cflag property")
+ }
+ newFlags, _ := bazel.TryVariableSubstitutions(flags, prop.ProductConfigVariable)
+ copts.ProductValues = append(copts.ProductValues, bazel.ProductVariableValues{
+ ProductVariable: prop.ProductConfigVariable,
+ Values: newFlags,
+ })
}
}
+ // Branch srcs into three language-specific groups.
+ // 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.
+ // TODO(b/): Handle language detection of sources in a Bazel rule.
+ isCSrc := func(s string) bool {
+ return strings.HasSuffix(s, ".c")
+ }
+ isAsmSrc := func(s string) bool {
+ return strings.HasSuffix(s, ".S") || strings.HasSuffix(s, ".s")
+ }
+ cSrcs := bazel.FilterLabelListAttribute(srcs, isCSrc)
+ asSrcs := bazel.FilterLabelListAttribute(srcs, isAsmSrc)
+ srcs = bazel.SubtractBazelLabelListAttribute(srcs, cSrcs)
+ srcs = bazel.SubtractBazelLabelListAttribute(srcs, asSrcs)
return compilerAttributes{
- srcs: srcs,
- copts: copts,
+ copts: copts,
+ srcs: srcs,
+ asFlags: asFlags,
+ asSrcs: asSrcs,
+ cSrcs: cSrcs,
+ conlyFlags: conlyFlags,
+ cppFlags: cppFlags,
}
}
@@ -353,13 +509,18 @@ func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module)
var linkopts bazel.StringListAttribute
var versionScript bazel.LabelAttribute
+ getLibs := func(baseLinkerProps *BaseLinkerProperties) []string {
+ libs := baseLinkerProps.Header_libs
+ libs = append(libs, baseLinkerProps.Static_libs...)
+ libs = android.SortedUniqueStrings(libs)
+ return libs
+ }
+
for _, linkerProps := range module.linker.linkerProps() {
if baseLinkerProps, ok := linkerProps.(*BaseLinkerProperties); ok {
- libs := baseLinkerProps.Header_libs
- libs = append(libs, baseLinkerProps.Static_libs...)
+ libs := getLibs(baseLinkerProps)
exportedLibs := baseLinkerProps.Export_header_lib_headers
wholeArchiveLibs := baseLinkerProps.Whole_static_libs
- libs = android.SortedUniqueStrings(libs)
deps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, libs))
exportedDeps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, exportedLibs))
linkopts.Value = getBp2BuildLinkerFlags(baseLinkerProps)
@@ -376,13 +537,11 @@ func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module)
}
}
- for arch, p := range module.GetArchProperties(ctx, &BaseLinkerProperties{}) {
- if baseLinkerProps, ok := p.(*BaseLinkerProperties); ok {
- libs := baseLinkerProps.Header_libs
- libs = append(libs, baseLinkerProps.Static_libs...)
+ for arch, props := range module.GetArchProperties(ctx, &BaseLinkerProperties{}) {
+ if baseLinkerProps, ok := props.(*BaseLinkerProperties); ok {
+ libs := getLibs(baseLinkerProps)
exportedLibs := baseLinkerProps.Export_header_lib_headers
wholeArchiveLibs := baseLinkerProps.Whole_static_libs
- libs = android.SortedUniqueStrings(libs)
deps.SetValueForArch(arch.Name, android.BazelLabelForModuleDeps(ctx, libs))
exportedDeps.SetValueForArch(arch.Name, android.BazelLabelForModuleDeps(ctx, exportedLibs))
linkopts.SetValueForArch(arch.Name, getBp2BuildLinkerFlags(baseLinkerProps))
@@ -398,21 +557,34 @@ func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module)
}
}
- for os, p := range module.GetTargetProperties(ctx, &BaseLinkerProperties{}) {
- if baseLinkerProps, ok := p.(*BaseLinkerProperties); ok {
- libs := baseLinkerProps.Header_libs
- libs = append(libs, baseLinkerProps.Static_libs...)
+ for os, targetProperties := range module.GetTargetProperties(ctx, &BaseLinkerProperties{}) {
+ if baseLinkerProps, ok := targetProperties.Properties.(*BaseLinkerProperties); ok {
+ libs := getLibs(baseLinkerProps)
exportedLibs := baseLinkerProps.Export_header_lib_headers
wholeArchiveLibs := baseLinkerProps.Whole_static_libs
- libs = android.SortedUniqueStrings(libs)
- wholeArchiveDeps.SetValueForOS(os.Name, android.BazelLabelForModuleDeps(ctx, wholeArchiveLibs))
- deps.SetValueForOS(os.Name, android.BazelLabelForModuleDeps(ctx, libs))
- exportedDeps.SetValueForOS(os.Name, android.BazelLabelForModuleDeps(ctx, exportedLibs))
+ wholeArchiveDeps.SetOsValueForTarget(os.Name, android.BazelLabelForModuleDeps(ctx, wholeArchiveLibs))
+ deps.SetOsValueForTarget(os.Name, android.BazelLabelForModuleDeps(ctx, libs))
+ exportedDeps.SetOsValueForTarget(os.Name, android.BazelLabelForModuleDeps(ctx, exportedLibs))
- linkopts.SetValueForOS(os.Name, getBp2BuildLinkerFlags(baseLinkerProps))
+ linkopts.SetOsValueForTarget(os.Name, getBp2BuildLinkerFlags(baseLinkerProps))
sharedLibs := baseLinkerProps.Shared_libs
- dynamicDeps.SetValueForOS(os.Name, android.BazelLabelForModuleDeps(ctx, sharedLibs))
+ dynamicDeps.SetOsValueForTarget(os.Name, android.BazelLabelForModuleDeps(ctx, sharedLibs))
+ }
+ for arch, archProperties := range targetProperties.ArchProperties {
+ if baseLinkerProps, ok := archProperties.(*BaseLinkerProperties); ok {
+ libs := getLibs(baseLinkerProps)
+ exportedLibs := baseLinkerProps.Export_header_lib_headers
+ wholeArchiveLibs := baseLinkerProps.Whole_static_libs
+ wholeArchiveDeps.SetOsArchValueForTarget(os.Name, arch.Name, android.BazelLabelForModuleDeps(ctx, wholeArchiveLibs))
+ deps.SetOsArchValueForTarget(os.Name, arch.Name, android.BazelLabelForModuleDeps(ctx, libs))
+ exportedDeps.SetOsArchValueForTarget(os.Name, arch.Name, android.BazelLabelForModuleDeps(ctx, exportedLibs))
+
+ linkopts.SetOsArchValueForTarget(os.Name, arch.Name, getBp2BuildLinkerFlags(baseLinkerProps))
+
+ sharedLibs := baseLinkerProps.Shared_libs
+ dynamicDeps.SetOsArchValueForTarget(os.Name, arch.Name, android.BazelLabelForModuleDeps(ctx, sharedLibs))
+ }
}
}
@@ -461,32 +633,38 @@ func bp2BuildParseExportedIncludes(ctx android.TopDownMutatorContext, module *Mo
includeDirs = append(includeDirs, libraryDecorator.flagExporter.Properties.Export_include_dirs...)
includeDirsAttribute := bazel.MakeStringListAttribute(includeDirs)
- for arch, props := range module.GetArchProperties(ctx, &FlagExporterProperties{}) {
- if flagExporterProperties, ok := props.(*FlagExporterProperties); ok {
- archIncludeDirs := flagExporterProperties.Export_system_include_dirs
- archIncludeDirs = append(archIncludeDirs, flagExporterProperties.Export_include_dirs...)
+ getVariantIncludeDirs := func(includeDirs []string, flagExporterProperties *FlagExporterProperties) []string {
+ variantIncludeDirs := flagExporterProperties.Export_system_include_dirs
+ variantIncludeDirs = append(variantIncludeDirs, flagExporterProperties.Export_include_dirs...)
- // To avoid duplicate includes when base includes + arch includes are combined
- // FIXME: This doesn't take conflicts between arch and os includes into account
- archIncludeDirs = bazel.SubtractStrings(archIncludeDirs, includeDirs)
+ // To avoid duplicate includes when base includes + arch includes are combined
+ // TODO: This doesn't take conflicts between arch and os includes into account
+ variantIncludeDirs = bazel.SubtractStrings(variantIncludeDirs, includeDirs)
+ return variantIncludeDirs
+ }
+ for arch, props := range module.GetArchProperties(ctx, &FlagExporterProperties{}) {
+ if flagExporterProperties, ok := props.(*FlagExporterProperties); ok {
+ archIncludeDirs := getVariantIncludeDirs(includeDirs, flagExporterProperties)
if len(archIncludeDirs) > 0 {
includeDirsAttribute.SetValueForArch(arch.Name, archIncludeDirs)
}
}
}
- for os, props := range module.GetTargetProperties(ctx, &FlagExporterProperties{}) {
- if flagExporterProperties, ok := props.(*FlagExporterProperties); ok {
- osIncludeDirs := flagExporterProperties.Export_system_include_dirs
- osIncludeDirs = append(osIncludeDirs, flagExporterProperties.Export_include_dirs...)
-
- // To avoid duplicate includes when base includes + os includes are combined
- // FIXME: This doesn't take conflicts between arch and os includes into account
- osIncludeDirs = bazel.SubtractStrings(osIncludeDirs, includeDirs)
-
- if len(osIncludeDirs) > 0 {
- includeDirsAttribute.SetValueForOS(os.Name, osIncludeDirs)
+ for os, targetProperties := range module.GetTargetProperties(ctx, &FlagExporterProperties{}) {
+ if flagExporterProperties, ok := targetProperties.Properties.(*FlagExporterProperties); ok {
+ targetIncludeDirs := getVariantIncludeDirs(includeDirs, flagExporterProperties)
+ if len(targetIncludeDirs) > 0 {
+ includeDirsAttribute.SetOsValueForTarget(os.Name, targetIncludeDirs)
+ }
+ }
+ for arch, archProperties := range targetProperties.ArchProperties {
+ if flagExporterProperties, ok := archProperties.(*FlagExporterProperties); ok {
+ targetIncludeDirs := getVariantIncludeDirs(includeDirs, flagExporterProperties)
+ if len(targetIncludeDirs) > 0 {
+ includeDirsAttribute.SetOsArchValueForTarget(os.Name, arch.Name, targetIncludeDirs)
+ }
}
}
}
diff --git a/cc/cc_test.go b/cc/cc_test.go
index d82619a04..5acafbe2a 100644
--- a/cc/cc_test.go
+++ b/cc/cc_test.go
@@ -554,6 +554,13 @@ func TestVndk(t *testing.T) {
}
}
+ cc_library {
+ name: "libclang_rt.hwasan-llndk",
+ llndk: {
+ symbol_file: "libclang_rt.hwasan.map.txt",
+ }
+ }
+
cc_library_headers {
name: "libllndk_headers",
llndk: {
@@ -661,7 +668,7 @@ func TestVndk(t *testing.T) {
"VNDK-product: libvndk_product.so",
"VNDK-product: libvndk_sp_product_private-x.so",
})
- checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt", []string{"libc.so", "libdl.so", "libft2.so", "libllndk.so", "libm.so"})
+ checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt", []string{"libc.so", "libclang_rt.hwasan-llndk.so", "libdl.so", "libft2.so", "libllndk.so", "libm.so"})
checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk-private.so", "libvndk.so", "libvndk_product.so"})
checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt", []string{"libc++.so", "libvndk_sp-x.so", "libvndk_sp_private-x.so", "libvndk_sp_product_private-x.so"})
checkVndkLibrariesOutput(t, ctx, "vndkprivate.libraries.txt", []string{"libft2.so", "libvndk-private.so", "libvndk_sp_private-x.so", "libvndk_sp_product_private-x.so"})
diff --git a/cc/library.go b/cc/library.go
index c918b96ba..9fb7a2451 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -230,6 +230,13 @@ type bazelCcLibraryAttributes struct {
Copts bazel.StringListAttribute
Includes bazel.StringListAttribute
Linkopts bazel.StringListAttribute
+
+ Cppflags bazel.StringListAttribute
+ Srcs_c bazel.LabelListAttribute
+ Conlyflags bazel.StringListAttribute
+ Srcs_as bazel.LabelListAttribute
+ Asflags bazel.StringListAttribute
+
// Attributes pertaining to shared variant.
Shared_copts bazel.StringListAttribute
Shared_srcs bazel.LabelListAttribute
@@ -239,6 +246,7 @@ type bazelCcLibraryAttributes struct {
Whole_archive_deps_for_shared bazel.LabelListAttribute
User_link_flags bazel.StringListAttribute
Version_script bazel.LabelAttribute
+
// Attributes pertaining to static variant.
Static_copts bazel.StringListAttribute
Static_srcs bazel.LabelListAttribute
@@ -294,20 +302,27 @@ func CcLibraryBp2Build(ctx android.TopDownMutatorContext) {
srcs.Append(compilerAttrs.srcs)
attrs := &bazelCcLibraryAttributes{
- Srcs: srcs,
- Implementation_deps: linkerAttrs.deps,
- Deps: linkerAttrs.exportedDeps,
- Dynamic_deps: linkerAttrs.dynamicDeps,
- Whole_archive_deps: linkerAttrs.wholeArchiveDeps,
- Copts: compilerAttrs.copts,
- Includes: exportedIncludes,
- Linkopts: linkerAttrs.linkopts,
+ Srcs: srcs,
+ Implementation_deps: linkerAttrs.deps,
+ Deps: linkerAttrs.exportedDeps,
+ Dynamic_deps: linkerAttrs.dynamicDeps,
+ Whole_archive_deps: linkerAttrs.wholeArchiveDeps,
+ Copts: compilerAttrs.copts,
+ Includes: exportedIncludes,
+ Linkopts: linkerAttrs.linkopts,
+ Cppflags: compilerAttrs.cppFlags,
+ Srcs_c: compilerAttrs.cSrcs,
+ Conlyflags: compilerAttrs.conlyFlags,
+ Srcs_as: compilerAttrs.asSrcs,
+ Asflags: compilerAttrs.asFlags,
+
Shared_copts: sharedAttrs.copts,
Shared_srcs: sharedAttrs.srcs,
Static_deps_for_shared: sharedAttrs.staticDeps,
Whole_archive_deps_for_shared: sharedAttrs.wholeArchiveDeps,
Dynamic_deps_for_shared: sharedAttrs.dynamicDeps,
Version_script: linkerAttrs.versionScript,
+
Static_copts: staticAttrs.copts,
Static_srcs: staticAttrs.srcs,
Static_deps_for_static: staticAttrs.staticDeps,
@@ -2230,6 +2245,12 @@ type bazelCcLibraryStaticAttributes struct {
Linkstatic bool
Includes bazel.StringListAttribute
Hdrs bazel.LabelListAttribute
+
+ Cppflags bazel.StringListAttribute
+ Srcs_c bazel.LabelListAttribute
+ Conlyflags bazel.StringListAttribute
+ Srcs_as bazel.LabelListAttribute
+ Asflags bazel.StringListAttribute
}
type bazelCcLibraryStatic struct {
@@ -2259,6 +2280,12 @@ func ccLibraryStaticBp2BuildInternal(ctx android.TopDownMutatorContext, module *
Linkopts: linkerAttrs.linkopts,
Linkstatic: true,
Includes: exportedIncludes,
+
+ Cppflags: compilerAttrs.cppFlags,
+ Srcs_c: compilerAttrs.cSrcs,
+ Conlyflags: compilerAttrs.conlyFlags,
+ Srcs_as: compilerAttrs.asSrcs,
+ Asflags: compilerAttrs.asFlags,
}
props := bazel.BazelTargetModuleProperties{
diff --git a/cc/object.go b/cc/object.go
index d8f1ababa..cd711617b 100644
--- a/cc/object.go
+++ b/cc/object.go
@@ -116,7 +116,7 @@ type bazelObjectAttributes struct {
Hdrs bazel.LabelListAttribute
Deps bazel.LabelListAttribute
Copts bazel.StringListAttribute
- Asflags []string
+ Asflags bazel.StringListAttribute
}
type bazelObject struct {
@@ -157,7 +157,7 @@ func ObjectBp2Build(ctx android.TopDownMutatorContext) {
// Set arch-specific configurable attributes
compilerAttrs := bp2BuildParseCompilerProps(ctx, m)
- var asFlags []string
+ var asFlags bazel.StringListAttribute
var deps bazel.LabelListAttribute
for _, props := range m.linker.linkerProps() {
@@ -176,16 +176,23 @@ func ObjectBp2Build(ctx android.TopDownMutatorContext) {
ctx.ModuleErrorf("Could not convert product variable asflag property")
return
}
- // TODO(b/183595873) handle other product variable usages -- as selects?
- if newFlags, subbed := bazel.TryVariableSubstitutions(flags, prop.ProductConfigVariable); subbed {
- asFlags = append(asFlags, newFlags...)
- }
+ newFlags, _ := bazel.TryVariableSubstitutions(flags, prop.ProductConfigVariable)
+ asFlags.ProductValues = append(asFlags.ProductValues, bazel.ProductVariableValues{
+ ProductVariable: prop.ProductConfigVariable,
+ Values: newFlags,
+ })
}
}
// TODO(b/183595872) warn/error if we're not handling product variables
+ // Don't split cc_object srcs across languages. Doing so would add complexity,
+ // and this isn't typically done for cc_object.
+ srcs := compilerAttrs.srcs
+ srcs.Append(compilerAttrs.cSrcs)
+ srcs.Append(compilerAttrs.asSrcs)
+
attrs := &bazelObjectAttributes{
- Srcs: compilerAttrs.srcs,
+ Srcs: srcs,
Deps: deps,
Copts: compilerAttrs.copts,
Asflags: asFlags,
diff --git a/cc/vndk.go b/cc/vndk.go
index 0254edc66..6a56c34db 100644
--- a/cc/vndk.go
+++ b/cc/vndk.go
@@ -234,7 +234,6 @@ type moduleListerFunc func(ctx android.SingletonContext) (moduleNames, fileNames
var (
llndkLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsLLNDK && !m.Header() })
- llndkLibrariesWithoutHWASAN = vndkModuleListRemover(llndkLibraries, "libclang_rt.hwasan-")
vndkSPLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKSP })
vndkCoreLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKCore })
vndkPrivateLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKPrivate })
@@ -419,10 +418,6 @@ func init() {
}
func RegisterVndkLibraryTxtTypes(ctx android.RegistrationContext) {
- // Make uses LLNDK_LIBRARIES to determine which libraries to install.
- // HWASAN is only part of the LL-NDK in builds in which libc depends on HWASAN.
- // Therefore, by removing the library here, we cause it to only be installed if libc
- // depends on it.
ctx.RegisterSingletonModuleType("llndk_libraries_txt", llndkLibrariesTxtFactory)
ctx.RegisterSingletonModuleType("vndksp_libraries_txt", vndkSPLibrariesTxtFactory)
ctx.RegisterSingletonModuleType("vndkcore_libraries_txt", vndkCoreLibrariesTxtFactory)
@@ -434,8 +429,9 @@ func RegisterVndkLibraryTxtTypes(ctx android.RegistrationContext) {
type vndkLibrariesTxt struct {
android.SingletonModuleBase
- lister moduleListerFunc
- makeVarName string
+ lister moduleListerFunc
+ makeVarName string
+ filterOutFromMakeVar string
properties VndkLibrariesTxtProperties
@@ -454,8 +450,12 @@ var _ android.OutputFileProducer = &vndkLibrariesTxt{}
// llndk_libraries_txt is a singleton module whose content is a list of LLNDK libraries
// generated by Soong but can be referenced by other modules.
// For example, apex_vndk can depend on these files as prebuilt.
+// Make uses LLNDK_LIBRARIES to determine which libraries to install.
+// HWASAN is only part of the LL-NDK in builds in which libc depends on HWASAN.
+// Therefore, by removing the library here, we cause it to only be installed if libc
+// depends on it.
func llndkLibrariesTxtFactory() android.SingletonModule {
- return newVndkLibrariesTxt(llndkLibrariesWithoutHWASAN, "LLNDK_LIBRARIES")
+ return newVndkLibrariesWithMakeVarFilter(llndkLibraries, "LLNDK_LIBRARIES", "libclang_rt.hwasan-")
}
// vndksp_libraries_txt is a singleton module whose content is a list of VNDKSP libraries
@@ -493,16 +493,21 @@ func vndkUsingCoreVariantLibrariesTxtFactory() android.SingletonModule {
return newVndkLibrariesTxt(vndkUsingCoreVariantLibraries, "VNDK_USING_CORE_VARIANT_LIBRARIES")
}
-func newVndkLibrariesTxt(lister moduleListerFunc, makeVarName string) android.SingletonModule {
+func newVndkLibrariesWithMakeVarFilter(lister moduleListerFunc, makeVarName string, filter string) android.SingletonModule {
m := &vndkLibrariesTxt{
- lister: lister,
- makeVarName: makeVarName,
+ lister: lister,
+ makeVarName: makeVarName,
+ filterOutFromMakeVar: filter,
}
m.AddProperties(&m.properties)
android.InitAndroidModule(m)
return m
}
+func newVndkLibrariesTxt(lister moduleListerFunc, makeVarName string) android.SingletonModule {
+ return newVndkLibrariesWithMakeVarFilter(lister, makeVarName, "")
+}
+
func insertVndkVersion(filename string, vndkVersion string) string {
if index := strings.LastIndex(filename, "."); index != -1 {
return filename[:index] + "." + vndkVersion + filename[index:]
@@ -542,8 +547,21 @@ func (txt *vndkLibrariesTxt) AndroidMkEntries() []android.AndroidMkEntries {
}
func (txt *vndkLibrariesTxt) MakeVars(ctx android.MakeVarsContext) {
- ctx.Strict(txt.makeVarName, strings.Join(txt.moduleNames, " "))
-
+ filter := func(modules []string, prefix string) []string {
+ if prefix == "" {
+ return modules
+ }
+ var result []string
+ for _, module := range modules {
+ if strings.HasPrefix(module, prefix) {
+ continue
+ } else {
+ result = append(result, module)
+ }
+ }
+ return result
+ }
+ ctx.Strict(txt.makeVarName, strings.Join(filter(txt.moduleNames, txt.filterOutFromMakeVar), " "))
}
// PrebuiltEtcModule interface