Merge "bp2build: Add support for export_.*headers props"

This commit is contained in:
Liz Kammer
2021-09-24 13:13:05 +00:00
committed by Gerrit Code Review
10 changed files with 288 additions and 139 deletions

View File

@@ -218,13 +218,6 @@ var (
"libc_ndk", // http://b/187013218, cc_library_static, depends on //bionic/libm:libm (http://b/183064661) "libc_ndk", // http://b/187013218, cc_library_static, depends on //bionic/libm:libm (http://b/183064661)
"libc_malloc_hooks", // http://b/187016307, cc_library, ld.lld: error: undefined symbol: __malloc_hook "libc_malloc_hooks", // http://b/187016307, cc_library, ld.lld: error: undefined symbol: __malloc_hook
// There are unexported symbols that don't surface on a shared library build,
// from the source static archive
// e.g. _Unwind_{GetRegionStart,GetLanguageSpecificData,GetIP,Set{IP,GR},Resume,{Raise,Delete}Exception}, pthread_atfork
// ... from: cxa_{personality,exception}.o, system_error.o, wrappers_c_bionic.o
// cf. http://b/198403271
"libc++",
// http://b/186823769: Needs C++ STL support, includes from unconverted standard libraries in //external/libcxx // http://b/186823769: Needs C++ STL support, includes from unconverted standard libraries in //external/libcxx
// c++_static // c++_static
"libbase_ndk", // http://b/186826477, cc_library, no such target '//build/bazel/platforms/os:darwin' when --platforms //build/bazel/platforms:android_x86 is added "libbase_ndk", // http://b/186826477, cc_library, no such target '//build/bazel/platforms/os:darwin' when --platforms //build/bazel/platforms:android_x86 is added

View File

@@ -635,6 +635,7 @@ func extractStructProperties(structValue reflect.Value, indent int) map[string]s
// Ignore zero-valued fields // Ignore zero-valued fields
continue continue
} }
// if the struct is embedded (anonymous), flatten the properties into the containing struct // if the struct is embedded (anonymous), flatten the properties into the containing struct
if field.Anonymous { if field.Anonymous {
if field.Type.Kind() == reflect.Ptr { if field.Type.Kind() == reflect.Ptr {

View File

@@ -349,21 +349,21 @@ cc_library {
expectedBazelTargets: []string{`cc_library( expectedBazelTargets: []string{`cc_library(
name = "a", name = "a",
copts = ["bothflag"], copts = ["bothflag"],
dynamic_deps = [":shared_dep_for_both"],
implementation_deps = [":static_dep_for_both"], implementation_deps = [":static_dep_for_both"],
implementation_dynamic_deps = [":shared_dep_for_both"],
shared = { shared = {
"copts": ["sharedflag"], "copts": ["sharedflag"],
"dynamic_deps": [":shared_dep_for_shared"], "implementation_deps": [":static_dep_for_shared"],
"implementation_dynamic_deps": [":shared_dep_for_shared"],
"srcs": ["sharedonly.cpp"], "srcs": ["sharedonly.cpp"],
"static_deps": [":static_dep_for_shared"],
"whole_archive_deps": [":whole_static_lib_for_shared"], "whole_archive_deps": [":whole_static_lib_for_shared"],
}, },
srcs = ["both.cpp"], srcs = ["both.cpp"],
static = { static = {
"copts": ["staticflag"], "copts": ["staticflag"],
"dynamic_deps": [":shared_dep_for_static"], "implementation_deps": [":static_dep_for_static"],
"implementation_dynamic_deps": [":shared_dep_for_static"],
"srcs": ["staticonly.cpp"], "srcs": ["staticonly.cpp"],
"static_deps": [":static_dep_for_static"],
"whole_archive_deps": [":whole_static_lib_for_static"], "whole_archive_deps": [":whole_static_lib_for_static"],
}, },
whole_archive_deps = [":whole_static_lib_for_both"], whole_archive_deps = [":whole_static_lib_for_both"],
@@ -371,6 +371,105 @@ cc_library {
}) })
} }
func TestCcLibraryDeps(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
description: "cc_library shared/static props",
moduleTypeUnderTest: "cc_library",
moduleTypeUnderTestFactory: cc.LibraryFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
filesystem: map[string]string{
"both.cpp": "",
"sharedonly.cpp": "",
"staticonly.cpp": "",
},
blueprint: soongCcLibraryPreamble + `
cc_library {
name: "a",
srcs: ["both.cpp"],
cflags: ["bothflag"],
shared_libs: ["implementation_shared_dep_for_both", "shared_dep_for_both"],
export_shared_lib_headers: ["shared_dep_for_both"],
static_libs: ["implementation_static_dep_for_both", "static_dep_for_both"],
export_static_lib_headers: ["static_dep_for_both", "whole_static_dep_for_both"],
whole_static_libs: ["not_explicitly_exported_whole_static_dep_for_both", "whole_static_dep_for_both"],
static: {
srcs: ["staticonly.cpp"],
cflags: ["staticflag"],
shared_libs: ["implementation_shared_dep_for_static", "shared_dep_for_static"],
export_shared_lib_headers: ["shared_dep_for_static"],
static_libs: ["implementation_static_dep_for_static", "static_dep_for_static"],
export_static_lib_headers: ["static_dep_for_static", "whole_static_dep_for_static"],
whole_static_libs: ["not_explicitly_exported_whole_static_dep_for_static", "whole_static_dep_for_static"],
},
shared: {
srcs: ["sharedonly.cpp"],
cflags: ["sharedflag"],
shared_libs: ["implementation_shared_dep_for_shared", "shared_dep_for_shared"],
export_shared_lib_headers: ["shared_dep_for_shared"],
static_libs: ["implementation_static_dep_for_shared", "static_dep_for_shared"],
export_static_lib_headers: ["static_dep_for_shared", "whole_static_dep_for_shared"],
whole_static_libs: ["not_explicitly_exported_whole_static_dep_for_shared", "whole_static_dep_for_shared"],
},
include_build_directory: false,
}
` + simpleModuleDoNotConvertBp2build("cc_library_static", "static_dep_for_shared") +
simpleModuleDoNotConvertBp2build("cc_library_static", "implementation_static_dep_for_shared") +
simpleModuleDoNotConvertBp2build("cc_library_static", "static_dep_for_static") +
simpleModuleDoNotConvertBp2build("cc_library_static", "implementation_static_dep_for_static") +
simpleModuleDoNotConvertBp2build("cc_library_static", "static_dep_for_both") +
simpleModuleDoNotConvertBp2build("cc_library_static", "implementation_static_dep_for_both") +
simpleModuleDoNotConvertBp2build("cc_library_static", "whole_static_dep_for_shared") +
simpleModuleDoNotConvertBp2build("cc_library_static", "not_explicitly_exported_whole_static_dep_for_shared") +
simpleModuleDoNotConvertBp2build("cc_library_static", "whole_static_dep_for_static") +
simpleModuleDoNotConvertBp2build("cc_library_static", "not_explicitly_exported_whole_static_dep_for_static") +
simpleModuleDoNotConvertBp2build("cc_library_static", "whole_static_dep_for_both") +
simpleModuleDoNotConvertBp2build("cc_library_static", "not_explicitly_exported_whole_static_dep_for_both") +
simpleModuleDoNotConvertBp2build("cc_library", "shared_dep_for_shared") +
simpleModuleDoNotConvertBp2build("cc_library", "implementation_shared_dep_for_shared") +
simpleModuleDoNotConvertBp2build("cc_library", "shared_dep_for_static") +
simpleModuleDoNotConvertBp2build("cc_library", "implementation_shared_dep_for_static") +
simpleModuleDoNotConvertBp2build("cc_library", "shared_dep_for_both") +
simpleModuleDoNotConvertBp2build("cc_library", "implementation_shared_dep_for_both"),
expectedBazelTargets: []string{`cc_library(
name = "a",
copts = ["bothflag"],
deps = [":static_dep_for_both"],
dynamic_deps = [":shared_dep_for_both"],
implementation_deps = [":implementation_static_dep_for_both"],
implementation_dynamic_deps = [":implementation_shared_dep_for_both"],
shared = {
"copts": ["sharedflag"],
"deps": [":static_dep_for_shared"],
"dynamic_deps": [":shared_dep_for_shared"],
"implementation_deps": [":implementation_static_dep_for_shared"],
"implementation_dynamic_deps": [":implementation_shared_dep_for_shared"],
"srcs": ["sharedonly.cpp"],
"whole_archive_deps": [
":not_explicitly_exported_whole_static_dep_for_shared",
":whole_static_dep_for_shared",
],
},
srcs = ["both.cpp"],
static = {
"copts": ["staticflag"],
"deps": [":static_dep_for_static"],
"dynamic_deps": [":shared_dep_for_static"],
"implementation_deps": [":implementation_static_dep_for_static"],
"implementation_dynamic_deps": [":implementation_shared_dep_for_static"],
"srcs": ["staticonly.cpp"],
"whole_archive_deps": [
":not_explicitly_exported_whole_static_dep_for_static",
":whole_static_dep_for_static",
],
},
whole_archive_deps = [
":not_explicitly_exported_whole_static_dep_for_both",
":whole_static_dep_for_both",
],
)`},
})
}
func TestCcLibraryWholeStaticLibsAlwaysLink(t *testing.T) { func TestCcLibraryWholeStaticLibsAlwaysLink(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{ runCcLibraryTestCase(t, bp2buildTestCase{
moduleTypeUnderTest: "cc_library", moduleTypeUnderTest: "cc_library",
@@ -506,7 +605,14 @@ cc_library_static { name: "android_dep_for_shared" }
"//build/bazel/platforms/os_arch:android_arm": ["-DANDROID_ARM_SHARED"], "//build/bazel/platforms/os_arch:android_arm": ["-DANDROID_ARM_SHARED"],
"//conditions:default": [], "//conditions:default": [],
}), }),
"dynamic_deps": select({ "implementation_deps": [":static_dep_for_shared"] + select({
"//build/bazel/platforms/arch:arm": [":arm_static_dep_for_shared"],
"//conditions:default": [],
}) + select({
"//build/bazel/platforms/os:android": [":android_dep_for_shared"],
"//conditions:default": [],
}),
"implementation_dynamic_deps": select({
"//build/bazel/platforms/arch:arm": [":arm_shared_dep_for_shared"], "//build/bazel/platforms/arch:arm": [":arm_shared_dep_for_shared"],
"//conditions:default": [], "//conditions:default": [],
}), }),
@@ -517,13 +623,6 @@ cc_library_static { name: "android_dep_for_shared" }
"//build/bazel/platforms/os:android": ["android_shared.cpp"], "//build/bazel/platforms/os:android": ["android_shared.cpp"],
"//conditions:default": [], "//conditions:default": [],
}), }),
"static_deps": [":static_dep_for_shared"] + select({
"//build/bazel/platforms/arch:arm": [":arm_static_dep_for_shared"],
"//conditions:default": [],
}) + select({
"//build/bazel/platforms/os:android": [":android_dep_for_shared"],
"//conditions:default": [],
}),
"whole_archive_deps": select({ "whole_archive_deps": select({
"//build/bazel/platforms/arch:arm": [":arm_whole_static_dep_for_shared"], "//build/bazel/platforms/arch:arm": [":arm_whole_static_dep_for_shared"],
"//conditions:default": [], "//conditions:default": [],
@@ -535,12 +634,12 @@ cc_library_static { name: "android_dep_for_shared" }
"//build/bazel/platforms/arch:x86": ["-DX86_STATIC"], "//build/bazel/platforms/arch:x86": ["-DX86_STATIC"],
"//conditions:default": [], "//conditions:default": [],
}), }),
"srcs": ["staticonly.cpp"] + select({ "implementation_deps": [":static_dep_for_static"] + select({
"//build/bazel/platforms/arch:x86": ["x86_static.cpp"], "//build/bazel/platforms/arch:x86": [":x86_dep_for_static"],
"//conditions:default": [], "//conditions:default": [],
}), }),
"static_deps": [":static_dep_for_static"] + select({ "srcs": ["staticonly.cpp"] + select({
"//build/bazel/platforms/arch:x86": [":x86_dep_for_static"], "//build/bazel/platforms/arch:x86": ["x86_static.cpp"],
"//conditions:default": [], "//conditions:default": [],
}), }),
}, },
@@ -767,7 +866,7 @@ cc_library {
`, `,
expectedBazelTargets: []string{`cc_library( expectedBazelTargets: []string{`cc_library(
name = "a", name = "a",
dynamic_deps = [":mylib"], implementation_dynamic_deps = [":mylib"],
)`}, )`},
}) })
} }
@@ -1013,13 +1112,6 @@ cc_library {
expectedBazelTargets: []string{ expectedBazelTargets: []string{
`cc_library( `cc_library(
name = "foo_static", name = "foo_static",
dynamic_deps = select({
"//build/bazel/platforms/arch:arm": [],
"//conditions:default": [":arm_shared_lib_excludes"],
}) + select({
"//build/bazel/product_variables:malloc_not_svelte": [":malloc_not_svelte_shared_lib"],
"//conditions:default": [],
}),
implementation_deps = select({ implementation_deps = select({
"//build/bazel/platforms/arch:arm": [], "//build/bazel/platforms/arch:arm": [],
"//conditions:default": [":arm_static_lib_excludes_bp2build_cc_library_static"], "//conditions:default": [":arm_static_lib_excludes_bp2build_cc_library_static"],
@@ -1027,6 +1119,13 @@ cc_library {
"//build/bazel/product_variables:malloc_not_svelte": [], "//build/bazel/product_variables:malloc_not_svelte": [],
"//conditions:default": [":malloc_not_svelte_static_lib_excludes_bp2build_cc_library_static"], "//conditions:default": [":malloc_not_svelte_static_lib_excludes_bp2build_cc_library_static"],
}), }),
implementation_dynamic_deps = select({
"//build/bazel/platforms/arch:arm": [],
"//conditions:default": [":arm_shared_lib_excludes"],
}) + select({
"//build/bazel/product_variables:malloc_not_svelte": [":malloc_not_svelte_shared_lib"],
"//conditions:default": [],
}),
srcs_c = ["common.c"], srcs_c = ["common.c"],
whole_archive_deps = select({ whole_archive_deps = select({
"//build/bazel/platforms/arch:arm": [], "//build/bazel/platforms/arch:arm": [],

View File

@@ -224,7 +224,10 @@ cc_library_headers {
cc_library_headers { cc_library_headers {
name: "foo_headers", name: "foo_headers",
target: { target: {
android: { header_libs: ["android-lib"], export_header_lib_headers: ["exported-lib"] }, android: {
header_libs: ["android-lib", "exported-lib"],
export_header_lib_headers: ["exported-lib"]
},
}, },
include_build_directory: false, include_build_directory: false,
}`, }`,

View File

@@ -149,10 +149,6 @@ cc_library_shared {
"-Dflag1", "-Dflag1",
"-Dflag2", "-Dflag2",
], ],
dynamic_deps = [
":shared_lib_1",
":shared_lib_2",
],
export_includes = [ export_includes = [
"export_include_dir_1", "export_include_dir_1",
"export_include_dir_2", "export_include_dir_2",
@@ -161,6 +157,10 @@ cc_library_shared {
":header_lib_1", ":header_lib_1",
":header_lib_2", ":header_lib_2",
], ],
implementation_dynamic_deps = [
":shared_lib_1",
":shared_lib_2",
],
local_includes = [ local_includes = [
"local_include_dir_1", "local_include_dir_1",
"local_include_dir_2", "local_include_dir_2",
@@ -201,7 +201,7 @@ cc_library_shared {
}`, }`,
expectedBazelTargets: []string{`cc_library_shared( expectedBazelTargets: []string{`cc_library_shared(
name = "foo_shared", name = "foo_shared",
dynamic_deps = select({ implementation_dynamic_deps = select({
"//build/bazel/platforms/arch:arm64": [":shared_dep"], "//build/bazel/platforms/arch:arm64": [":shared_dep"],
"//conditions:default": [], "//conditions:default": [],
}), }),
@@ -232,7 +232,7 @@ cc_library_shared {
}`, }`,
expectedBazelTargets: []string{`cc_library_shared( expectedBazelTargets: []string{`cc_library_shared(
name = "foo_shared", name = "foo_shared",
dynamic_deps = select({ implementation_dynamic_deps = select({
"//build/bazel/platforms/os:android": [":shared_dep"], "//build/bazel/platforms/os:android": [":shared_dep"],
"//conditions:default": [], "//conditions:default": [],
}), }),
@@ -269,7 +269,7 @@ cc_library_shared {
}`, }`,
expectedBazelTargets: []string{`cc_library_shared( expectedBazelTargets: []string{`cc_library_shared(
name = "foo_shared", name = "foo_shared",
dynamic_deps = [":shared_dep"] + select({ implementation_dynamic_deps = [":shared_dep"] + select({
"//build/bazel/platforms/arch:arm64": [":shared_dep3"], "//build/bazel/platforms/arch:arm64": [":shared_dep3"],
"//conditions:default": [], "//conditions:default": [],
}) + select({ }) + select({

View File

@@ -142,7 +142,7 @@ func shouldGenerateAttribute(prop string) bool {
} }
func shouldSkipStructField(field reflect.StructField) bool { func shouldSkipStructField(field reflect.StructField) bool {
if field.PkgPath != "" { if field.PkgPath != "" && !field.Anonymous {
// Skip unexported fields. Some properties are // Skip unexported fields. Some properties are
// internal to Soong only, and these fields do not have PkgPath. // internal to Soong only, and these fields do not have PkgPath.
return true return true

View File

@@ -20,6 +20,7 @@ specific-but-shared functionality among tests in package
*/ */
import ( import (
"fmt"
"strings" "strings"
"testing" "testing"
@@ -358,3 +359,11 @@ func registerCustomModuleForBp2buildConversion(ctx *android.TestContext) {
ctx.RegisterBp2BuildMutator("custom", customBp2BuildMutator) ctx.RegisterBp2BuildMutator("custom", customBp2BuildMutator)
ctx.RegisterForBazelConversion() ctx.RegisterForBazelConversion()
} }
func simpleModuleDoNotConvertBp2build(typ, name string) string {
return fmt.Sprintf(`
%s {
name: "%s",
bazel_module: { bp2build_available: false },
}`, typ, name)
}

View File

@@ -20,6 +20,7 @@ import (
"android/soong/android" "android/soong/android"
"android/soong/bazel" "android/soong/bazel"
"github.com/google/blueprint" "github.com/google/blueprint"
"github.com/google/blueprint/proptools" "github.com/google/blueprint/proptools"
@@ -33,9 +34,11 @@ type staticOrSharedAttributes struct {
Srcs_as bazel.LabelListAttribute Srcs_as bazel.LabelListAttribute
Copts bazel.StringListAttribute Copts bazel.StringListAttribute
Static_deps bazel.LabelListAttribute Deps bazel.LabelListAttribute
Dynamic_deps bazel.LabelListAttribute Implementation_deps bazel.LabelListAttribute
Whole_archive_deps bazel.LabelListAttribute Dynamic_deps bazel.LabelListAttribute
Implementation_dynamic_deps bazel.LabelListAttribute
Whole_archive_deps bazel.LabelListAttribute
System_dynamic_deps bazel.LabelListAttribute System_dynamic_deps bazel.LabelListAttribute
} }
@@ -131,16 +134,50 @@ func bp2BuildParseStaticProps(ctx android.TopDownMutatorContext, module *Module)
return bp2BuildParseLibProps(ctx, module, true) return bp2BuildParseLibProps(ctx, module, true)
} }
type depsPartition struct {
export bazel.LabelList
implementation bazel.LabelList
}
type bazelLabelForDepsFn func(android.TopDownMutatorContext, []string) bazel.LabelList
func partitionExportedAndImplementationsDeps(ctx android.TopDownMutatorContext, allDeps, exportedDeps []string, fn bazelLabelForDepsFn) depsPartition {
implementation, export := android.FilterList(allDeps, exportedDeps)
return depsPartition{
export: fn(ctx, export),
implementation: fn(ctx, implementation),
}
}
type bazelLabelForDepsExcludesFn func(android.TopDownMutatorContext, []string, []string) bazel.LabelList
func partitionExportedAndImplementationsDepsExcludes(ctx android.TopDownMutatorContext, allDeps, excludes, exportedDeps []string, fn bazelLabelForDepsExcludesFn) depsPartition {
implementation, export := android.FilterList(allDeps, exportedDeps)
return depsPartition{
export: fn(ctx, export, excludes),
implementation: fn(ctx, implementation, excludes),
}
}
func bp2buildParseStaticOrSharedProps(ctx android.TopDownMutatorContext, module *Module, lib *libraryDecorator, isStatic bool) staticOrSharedAttributes { func bp2buildParseStaticOrSharedProps(ctx android.TopDownMutatorContext, module *Module, lib *libraryDecorator, isStatic bool) staticOrSharedAttributes {
attrs := staticOrSharedAttributes{} attrs := staticOrSharedAttributes{}
setAttrs := func(axis bazel.ConfigurationAxis, config string, props StaticOrSharedProperties) { setAttrs := func(axis bazel.ConfigurationAxis, config string, props StaticOrSharedProperties) {
attrs.Copts.SetSelectValue(axis, config, props.Cflags) attrs.Copts.SetSelectValue(axis, config, props.Cflags)
attrs.Srcs.SetSelectValue(axis, config, android.BazelLabelForModuleSrc(ctx, props.Srcs)) attrs.Srcs.SetSelectValue(axis, config, android.BazelLabelForModuleSrc(ctx, props.Srcs))
attrs.Static_deps.SetSelectValue(axis, config, bazelLabelForStaticDeps(ctx, props.Static_libs))
attrs.Dynamic_deps.SetSelectValue(axis, config, bazelLabelForSharedDeps(ctx, props.Shared_libs))
attrs.Whole_archive_deps.SetSelectValue(axis, config, bazelLabelForWholeDeps(ctx, props.Whole_static_libs))
attrs.System_dynamic_deps.SetSelectValue(axis, config, bazelLabelForSharedDeps(ctx, props.System_shared_libs)) attrs.System_dynamic_deps.SetSelectValue(axis, config, bazelLabelForSharedDeps(ctx, props.System_shared_libs))
staticDeps := partitionExportedAndImplementationsDeps(ctx, props.Static_libs, props.Export_static_lib_headers, bazelLabelForStaticDeps)
attrs.Deps.SetSelectValue(axis, config, staticDeps.export)
attrs.Implementation_deps.SetSelectValue(axis, config, staticDeps.implementation)
sharedDeps := partitionExportedAndImplementationsDeps(ctx, props.Shared_libs, props.Export_shared_lib_headers, bazelLabelForSharedDeps)
attrs.Dynamic_deps.SetSelectValue(axis, config, sharedDeps.export)
attrs.Implementation_dynamic_deps.SetSelectValue(axis, config, sharedDeps.implementation)
attrs.Whole_archive_deps.SetSelectValue(axis, config, bazelLabelForWholeDeps(ctx, props.Whole_static_libs))
} }
// system_dynamic_deps distinguishes between nil/empty list behavior: // system_dynamic_deps distinguishes between nil/empty list behavior:
// nil -> use default values // nil -> use default values
@@ -328,11 +365,13 @@ func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Modul
// Convenience struct to hold all attributes parsed from linker properties. // Convenience struct to hold all attributes parsed from linker properties.
type linkerAttributes struct { type linkerAttributes struct {
deps bazel.LabelListAttribute deps bazel.LabelListAttribute
dynamicDeps bazel.LabelListAttribute implementationDeps bazel.LabelListAttribute
systemDynamicDeps bazel.LabelListAttribute dynamicDeps bazel.LabelListAttribute
wholeArchiveDeps bazel.LabelListAttribute implementationDynamicDeps bazel.LabelListAttribute
exportedDeps bazel.LabelListAttribute wholeArchiveDeps bazel.LabelListAttribute
systemDynamicDeps bazel.LabelListAttribute
useLibcrt bazel.BoolAttribute useLibcrt bazel.BoolAttribute
linkopts bazel.StringListAttribute linkopts bazel.StringListAttribute
versionScript bazel.LabelAttribute versionScript bazel.LabelAttribute
@@ -355,12 +394,16 @@ func getBp2BuildLinkerFlags(linkerProperties *BaseLinkerProperties) []string {
// bp2BuildParseLinkerProps parses the linker properties of a module, including // bp2BuildParseLinkerProps parses the linker properties of a module, including
// configurable attribute values. // configurable attribute values.
func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module) linkerAttributes { func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module) linkerAttributes {
var headerDeps bazel.LabelListAttribute var headerDeps bazel.LabelListAttribute
var staticDeps bazel.LabelListAttribute var implementationHeaderDeps bazel.LabelListAttribute
var exportedDeps bazel.LabelListAttribute var deps bazel.LabelListAttribute
var implementationDeps bazel.LabelListAttribute
var dynamicDeps bazel.LabelListAttribute var dynamicDeps bazel.LabelListAttribute
var implementationDynamicDeps bazel.LabelListAttribute
var wholeArchiveDeps bazel.LabelListAttribute var wholeArchiveDeps bazel.LabelListAttribute
systemSharedDeps := bazel.LabelListAttribute{ForceSpecifyEmptyList: true} systemSharedDeps := bazel.LabelListAttribute{ForceSpecifyEmptyList: true}
var linkopts bazel.StringListAttribute var linkopts bazel.StringListAttribute
var versionScript bazel.LabelAttribute var versionScript bazel.LabelAttribute
var useLibcrt bazel.BoolAttribute var useLibcrt bazel.BoolAttribute
@@ -386,12 +429,16 @@ func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module)
for axis, configToProps := range module.GetArchVariantProperties(ctx, &BaseLinkerProperties{}) { for axis, configToProps := range module.GetArchVariantProperties(ctx, &BaseLinkerProperties{}) {
for config, props := range configToProps { for config, props := range configToProps {
if baseLinkerProps, ok := props.(*BaseLinkerProperties); ok { if baseLinkerProps, ok := props.(*BaseLinkerProperties); ok {
// Excludes to parallel Soong: // Excludes to parallel Soong:
// https://cs.android.com/android/platform/superproject/+/master:build/soong/cc/linker.go;l=247-249;drc=088b53577dde6e40085ffd737a1ae96ad82fc4b0 // https://cs.android.com/android/platform/superproject/+/master:build/soong/cc/linker.go;l=247-249;drc=088b53577dde6e40085ffd737a1ae96ad82fc4b0
staticLibs := android.FirstUniqueStrings(baseLinkerProps.Static_libs) staticLibs := android.FirstUniqueStrings(baseLinkerProps.Static_libs)
staticDeps.SetSelectValue(axis, config, bazelLabelForStaticDepsExcludes(ctx, staticLibs, baseLinkerProps.Exclude_static_libs)) staticDeps := partitionExportedAndImplementationsDepsExcludes(ctx, staticLibs, baseLinkerProps.Exclude_static_libs, baseLinkerProps.Export_static_lib_headers, bazelLabelForStaticDepsExcludes)
wholeArchiveLibs := android.FirstUniqueStrings(baseLinkerProps.Whole_static_libs) deps.SetSelectValue(axis, config, staticDeps.export)
wholeArchiveDeps.SetSelectValue(axis, config, bazelLabelForWholeDepsExcludes(ctx, wholeArchiveLibs, baseLinkerProps.Exclude_static_libs)) implementationDeps.SetSelectValue(axis, config, staticDeps.implementation)
wholeStaticLibs := android.FirstUniqueStrings(baseLinkerProps.Whole_static_libs)
wholeArchiveDeps.SetSelectValue(axis, config, bazelLabelForWholeDepsExcludes(ctx, wholeStaticLibs, baseLinkerProps.Exclude_static_libs))
systemSharedLibs := baseLinkerProps.System_shared_libs systemSharedLibs := baseLinkerProps.System_shared_libs
// systemSharedLibs distinguishes between nil/empty list behavior: // systemSharedLibs distinguishes between nil/empty list behavior:
@@ -403,12 +450,15 @@ func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module)
systemSharedDeps.SetSelectValue(axis, config, bazelLabelForSharedDeps(ctx, systemSharedLibs)) systemSharedDeps.SetSelectValue(axis, config, bazelLabelForSharedDeps(ctx, systemSharedLibs))
sharedLibs := android.FirstUniqueStrings(baseLinkerProps.Shared_libs) sharedLibs := android.FirstUniqueStrings(baseLinkerProps.Shared_libs)
dynamicDeps.SetSelectValue(axis, config, bazelLabelForSharedDepsExcludes(ctx, sharedLibs, baseLinkerProps.Exclude_shared_libs)) sharedDeps := partitionExportedAndImplementationsDepsExcludes(ctx, sharedLibs, baseLinkerProps.Exclude_shared_libs, baseLinkerProps.Export_shared_lib_headers, bazelLabelForSharedDepsExcludes)
dynamicDeps.SetSelectValue(axis, config, sharedDeps.export)
implementationDynamicDeps.SetSelectValue(axis, config, sharedDeps.implementation)
headerLibs := android.FirstUniqueStrings(baseLinkerProps.Header_libs) headerLibs := android.FirstUniqueStrings(baseLinkerProps.Header_libs)
headerDeps.SetSelectValue(axis, config, bazelLabelForHeaderDeps(ctx, headerLibs)) hDeps := partitionExportedAndImplementationsDeps(ctx, headerLibs, baseLinkerProps.Export_header_lib_headers, bazelLabelForHeaderDeps)
exportedLibs := android.FirstUniqueStrings(baseLinkerProps.Export_header_lib_headers)
exportedDeps.SetSelectValue(axis, config, bazelLabelForHeaderDeps(ctx, exportedLibs)) headerDeps.SetSelectValue(axis, config, hDeps.export)
implementationHeaderDeps.SetSelectValue(axis, config, hDeps.implementation)
linkopts.SetSelectValue(axis, config, getBp2BuildLinkerFlags(baseLinkerProps)) linkopts.SetSelectValue(axis, config, getBp2BuildLinkerFlags(baseLinkerProps))
if baseLinkerProps.Version_script != nil { if baseLinkerProps.Version_script != nil {
@@ -430,8 +480,8 @@ func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module)
productVarToDepFields := map[string]productVarDep{ productVarToDepFields := map[string]productVarDep{
// product variables do not support exclude_shared_libs // product variables do not support exclude_shared_libs
"Shared_libs": productVarDep{attribute: &dynamicDeps, depResolutionFunc: bazelLabelForSharedDepsExcludes}, "Shared_libs": productVarDep{attribute: &implementationDynamicDeps, depResolutionFunc: bazelLabelForSharedDepsExcludes},
"Static_libs": productVarDep{"Exclude_static_libs", &staticDeps, bazelLabelForStaticDepsExcludes}, "Static_libs": productVarDep{"Exclude_static_libs", &implementationDeps, bazelLabelForStaticDepsExcludes},
"Whole_static_libs": productVarDep{"Exclude_static_libs", &wholeArchiveDeps, bazelLabelForWholeDepsExcludes}, "Whole_static_libs": productVarDep{"Exclude_static_libs", &wholeArchiveDeps, bazelLabelForWholeDepsExcludes},
} }
@@ -471,21 +521,26 @@ func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module)
} }
} }
staticDeps.ResolveExcludes() headerDeps.Append(deps)
implementationHeaderDeps.Append(implementationDeps)
headerDeps.ResolveExcludes()
implementationHeaderDeps.ResolveExcludes()
dynamicDeps.ResolveExcludes() dynamicDeps.ResolveExcludes()
implementationDynamicDeps.ResolveExcludes()
wholeArchiveDeps.ResolveExcludes() wholeArchiveDeps.ResolveExcludes()
headerDeps.Append(staticDeps)
return linkerAttributes{ return linkerAttributes{
deps: headerDeps, deps: headerDeps,
exportedDeps: exportedDeps, implementationDeps: implementationHeaderDeps,
dynamicDeps: dynamicDeps, dynamicDeps: dynamicDeps,
systemDynamicDeps: systemSharedDeps, implementationDynamicDeps: implementationDynamicDeps,
wholeArchiveDeps: wholeArchiveDeps, wholeArchiveDeps: wholeArchiveDeps,
linkopts: linkopts, systemDynamicDeps: systemSharedDeps,
useLibcrt: useLibcrt,
versionScript: versionScript, linkopts: linkopts,
useLibcrt: useLibcrt,
versionScript: versionScript,
// Strip properties // Strip properties
stripKeepSymbols: stripKeepSymbols, stripKeepSymbols: stripKeepSymbols,

View File

@@ -232,12 +232,15 @@ type bazelCcLibraryAttributes struct {
Conlyflags bazel.StringListAttribute Conlyflags bazel.StringListAttribute
Asflags bazel.StringListAttribute Asflags bazel.StringListAttribute
Hdrs bazel.LabelListAttribute Hdrs bazel.LabelListAttribute
Deps bazel.LabelListAttribute
Implementation_deps bazel.LabelListAttribute Deps bazel.LabelListAttribute
Dynamic_deps bazel.LabelListAttribute Implementation_deps bazel.LabelListAttribute
Whole_archive_deps bazel.LabelListAttribute Dynamic_deps bazel.LabelListAttribute
System_dynamic_deps bazel.LabelListAttribute Implementation_dynamic_deps bazel.LabelListAttribute
Whole_archive_deps bazel.LabelListAttribute
System_dynamic_deps bazel.LabelListAttribute
Export_includes bazel.StringListAttribute Export_includes bazel.StringListAttribute
Export_system_includes bazel.StringListAttribute Export_system_includes bazel.StringListAttribute
Local_includes bazel.StringListAttribute Local_includes bazel.StringListAttribute
@@ -306,18 +309,19 @@ func CcLibraryBp2Build(ctx android.TopDownMutatorContext) {
Conlyflags: compilerAttrs.conlyFlags, Conlyflags: compilerAttrs.conlyFlags,
Asflags: asFlags, Asflags: asFlags,
Implementation_deps: linkerAttrs.deps, Implementation_deps: linkerAttrs.implementationDeps,
Deps: linkerAttrs.exportedDeps, Deps: linkerAttrs.deps,
Dynamic_deps: linkerAttrs.dynamicDeps, Implementation_dynamic_deps: linkerAttrs.implementationDynamicDeps,
Whole_archive_deps: linkerAttrs.wholeArchiveDeps, Dynamic_deps: linkerAttrs.dynamicDeps,
System_dynamic_deps: linkerAttrs.systemDynamicDeps, Whole_archive_deps: linkerAttrs.wholeArchiveDeps,
Export_includes: exportedIncludes.Includes, System_dynamic_deps: linkerAttrs.systemDynamicDeps,
Export_system_includes: exportedIncludes.SystemIncludes, Export_includes: exportedIncludes.Includes,
Local_includes: compilerAttrs.localIncludes, Export_system_includes: exportedIncludes.SystemIncludes,
Absolute_includes: compilerAttrs.absoluteIncludes, Local_includes: compilerAttrs.localIncludes,
Linkopts: linkerAttrs.linkopts, Absolute_includes: compilerAttrs.absoluteIncludes,
Use_libcrt: linkerAttrs.useLibcrt, Linkopts: linkerAttrs.linkopts,
Rtti: compilerAttrs.rtti, Use_libcrt: linkerAttrs.useLibcrt,
Rtti: compilerAttrs.rtti,
Version_script: linkerAttrs.versionScript, Version_script: linkerAttrs.versionScript,
@@ -2349,9 +2353,11 @@ func ccSharedOrStaticBp2BuildMutatorInternal(ctx android.TopDownMutatorContext,
compilerAttrs.cSrcs.Append(libSharedOrStaticAttrs.Srcs_c) compilerAttrs.cSrcs.Append(libSharedOrStaticAttrs.Srcs_c)
compilerAttrs.asSrcs.Append(libSharedOrStaticAttrs.Srcs_as) compilerAttrs.asSrcs.Append(libSharedOrStaticAttrs.Srcs_as)
compilerAttrs.copts.Append(libSharedOrStaticAttrs.Copts) compilerAttrs.copts.Append(libSharedOrStaticAttrs.Copts)
linkerAttrs.exportedDeps.Append(libSharedOrStaticAttrs.Static_deps)
linkerAttrs.deps.Append(libSharedOrStaticAttrs.Deps)
linkerAttrs.implementationDeps.Append(libSharedOrStaticAttrs.Implementation_deps)
linkerAttrs.dynamicDeps.Append(libSharedOrStaticAttrs.Dynamic_deps) linkerAttrs.dynamicDeps.Append(libSharedOrStaticAttrs.Dynamic_deps)
linkerAttrs.wholeArchiveDeps.Append(libSharedOrStaticAttrs.Whole_archive_deps) linkerAttrs.implementationDynamicDeps.Append(libSharedOrStaticAttrs.Implementation_dynamic_deps)
linkerAttrs.systemDynamicDeps.Append(libSharedOrStaticAttrs.System_dynamic_deps) linkerAttrs.systemDynamicDeps.Append(libSharedOrStaticAttrs.System_dynamic_deps)
asFlags := compilerAttrs.asFlags asFlags := compilerAttrs.asFlags
@@ -2360,16 +2366,24 @@ func ccSharedOrStaticBp2BuildMutatorInternal(ctx android.TopDownMutatorContext,
asFlags = bazel.MakeStringListAttribute(nil) asFlags = bazel.MakeStringListAttribute(nil)
} }
commonAttrs := staticOrSharedAttributes{
Srcs: compilerAttrs.srcs,
Srcs_c: compilerAttrs.cSrcs,
Srcs_as: compilerAttrs.asSrcs,
Copts: compilerAttrs.copts,
Deps: linkerAttrs.deps,
Implementation_deps: linkerAttrs.implementationDeps,
Dynamic_deps: linkerAttrs.dynamicDeps,
Implementation_dynamic_deps: linkerAttrs.implementationDynamicDeps,
Whole_archive_deps: linkerAttrs.wholeArchiveDeps,
System_dynamic_deps: linkerAttrs.systemDynamicDeps,
}
var attrs interface{} var attrs interface{}
if isStatic { if isStatic {
attrs = &bazelCcLibraryStaticAttributes{ attrs = &bazelCcLibraryStaticAttributes{
Copts: compilerAttrs.copts, staticOrSharedAttributes: commonAttrs,
Srcs: compilerAttrs.srcs,
Implementation_deps: linkerAttrs.deps,
Deps: linkerAttrs.exportedDeps,
Whole_archive_deps: linkerAttrs.wholeArchiveDeps,
Dynamic_deps: linkerAttrs.dynamicDeps,
System_dynamic_deps: linkerAttrs.systemDynamicDeps,
Linkopts: linkerAttrs.linkopts, Linkopts: linkerAttrs.linkopts,
Use_libcrt: linkerAttrs.useLibcrt, Use_libcrt: linkerAttrs.useLibcrt,
@@ -2380,24 +2394,13 @@ func ccSharedOrStaticBp2BuildMutatorInternal(ctx android.TopDownMutatorContext,
Absolute_includes: compilerAttrs.absoluteIncludes, Absolute_includes: compilerAttrs.absoluteIncludes,
Cppflags: compilerAttrs.cppFlags, Cppflags: compilerAttrs.cppFlags,
Srcs_c: compilerAttrs.cSrcs,
Conlyflags: compilerAttrs.conlyFlags, Conlyflags: compilerAttrs.conlyFlags,
Srcs_as: compilerAttrs.asSrcs,
Asflags: asFlags, Asflags: asFlags,
} }
} else { } else {
attrs = &bazelCcLibrarySharedAttributes{ attrs = &bazelCcLibrarySharedAttributes{
Srcs: compilerAttrs.srcs, staticOrSharedAttributes: commonAttrs,
Srcs_c: compilerAttrs.cSrcs,
Srcs_as: compilerAttrs.asSrcs,
Implementation_deps: linkerAttrs.deps,
Deps: linkerAttrs.exportedDeps,
Whole_archive_deps: linkerAttrs.wholeArchiveDeps,
Dynamic_deps: linkerAttrs.dynamicDeps,
System_dynamic_deps: linkerAttrs.systemDynamicDeps,
Copts: compilerAttrs.copts,
Cppflags: compilerAttrs.cppFlags, Cppflags: compilerAttrs.cppFlags,
Conlyflags: compilerAttrs.conlyFlags, Conlyflags: compilerAttrs.conlyFlags,
Asflags: asFlags, Asflags: asFlags,
@@ -2432,16 +2435,12 @@ func ccSharedOrStaticBp2BuildMutatorInternal(ctx android.TopDownMutatorContext,
// TODO(b/199902614): Can this be factored to share with the other Attributes? // TODO(b/199902614): Can this be factored to share with the other Attributes?
type bazelCcLibraryStaticAttributes struct { type bazelCcLibraryStaticAttributes struct {
Copts bazel.StringListAttribute staticOrSharedAttributes
Srcs bazel.LabelListAttribute
Implementation_deps bazel.LabelListAttribute Linkopts bazel.StringListAttribute
Deps bazel.LabelListAttribute Use_libcrt bazel.BoolAttribute
Whole_archive_deps bazel.LabelListAttribute Rtti bazel.BoolAttribute
Dynamic_deps bazel.LabelListAttribute
System_dynamic_deps bazel.LabelListAttribute
Linkopts bazel.StringListAttribute
Use_libcrt bazel.BoolAttribute
Rtti bazel.BoolAttribute
Export_includes bazel.StringListAttribute Export_includes bazel.StringListAttribute
Export_system_includes bazel.StringListAttribute Export_system_includes bazel.StringListAttribute
Local_includes bazel.StringListAttribute Local_includes bazel.StringListAttribute
@@ -2449,9 +2448,7 @@ type bazelCcLibraryStaticAttributes struct {
Hdrs bazel.LabelListAttribute Hdrs bazel.LabelListAttribute
Cppflags bazel.StringListAttribute Cppflags bazel.StringListAttribute
Srcs_c bazel.LabelListAttribute
Conlyflags bazel.StringListAttribute Conlyflags bazel.StringListAttribute
Srcs_as bazel.LabelListAttribute
Asflags bazel.StringListAttribute Asflags bazel.StringListAttribute
} }
@@ -2461,29 +2458,21 @@ func CcLibraryStaticBp2Build(ctx android.TopDownMutatorContext) {
// TODO(b/199902614): Can this be factored to share with the other Attributes? // TODO(b/199902614): Can this be factored to share with the other Attributes?
type bazelCcLibrarySharedAttributes struct { type bazelCcLibrarySharedAttributes struct {
Srcs bazel.LabelListAttribute staticOrSharedAttributes
Srcs_c bazel.LabelListAttribute
Srcs_as bazel.LabelListAttribute
Implementation_deps bazel.LabelListAttribute
Deps bazel.LabelListAttribute
Whole_archive_deps bazel.LabelListAttribute
Dynamic_deps bazel.LabelListAttribute
System_dynamic_deps bazel.LabelListAttribute
Linkopts bazel.StringListAttribute Linkopts bazel.StringListAttribute
Use_libcrt bazel.BoolAttribute Use_libcrt bazel.BoolAttribute
Rtti bazel.BoolAttribute Rtti bazel.BoolAttribute
Strip stripAttributes
Export_includes bazel.StringListAttribute Export_includes bazel.StringListAttribute
Export_system_includes bazel.StringListAttribute Export_system_includes bazel.StringListAttribute
Local_includes bazel.StringListAttribute Local_includes bazel.StringListAttribute
Absolute_includes bazel.StringListAttribute Absolute_includes bazel.StringListAttribute
Hdrs bazel.LabelListAttribute Hdrs bazel.LabelListAttribute
Version_script bazel.LabelAttribute
Copts bazel.StringListAttribute Strip stripAttributes
Version_script bazel.LabelAttribute
Cppflags bazel.StringListAttribute Cppflags bazel.StringListAttribute
Conlyflags bazel.StringListAttribute Conlyflags bazel.StringListAttribute
Asflags bazel.StringListAttribute Asflags bazel.StringListAttribute

View File

@@ -135,8 +135,8 @@ func CcLibraryHeadersBp2Build(ctx android.TopDownMutatorContext) {
attrs := &bazelCcLibraryHeadersAttributes{ attrs := &bazelCcLibraryHeadersAttributes{
Export_includes: exportedIncludes.Includes, Export_includes: exportedIncludes.Includes,
Export_system_includes: exportedIncludes.SystemIncludes, Export_system_includes: exportedIncludes.SystemIncludes,
Implementation_deps: linkerAttrs.deps, Implementation_deps: linkerAttrs.implementationDeps,
Deps: linkerAttrs.exportedDeps, Deps: linkerAttrs.deps,
System_dynamic_deps: linkerAttrs.systemDynamicDeps, System_dynamic_deps: linkerAttrs.systemDynamicDeps,
} }