bp2build: group shared/static attrs into a struct. am: c4dc9b4f08
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1733748 Change-Id: I0e9616eb608efdb08ae51da51c04a85e39aca424
This commit is contained in:
@@ -385,19 +385,23 @@ cc_library { name: "shared_dep_for_both" }
|
|||||||
"-I$(BINDIR)/foo/bar",
|
"-I$(BINDIR)/foo/bar",
|
||||||
],
|
],
|
||||||
dynamic_deps = [":shared_dep_for_both"],
|
dynamic_deps = [":shared_dep_for_both"],
|
||||||
dynamic_deps_for_shared = [":shared_dep_for_shared"],
|
|
||||||
dynamic_deps_for_static = [":shared_dep_for_static"],
|
|
||||||
implementation_deps = [":static_dep_for_both"],
|
implementation_deps = [":static_dep_for_both"],
|
||||||
shared_copts = ["sharedflag"],
|
shared = {
|
||||||
shared_srcs = ["sharedonly.cpp"],
|
"copts": ["sharedflag"],
|
||||||
|
"dynamic_deps": [":shared_dep_for_shared"],
|
||||||
|
"srcs": ["sharedonly.cpp"],
|
||||||
|
"static_deps": [":static_dep_for_shared"],
|
||||||
|
"whole_archive_deps": [":whole_static_lib_for_shared"],
|
||||||
|
},
|
||||||
srcs = ["both.cpp"],
|
srcs = ["both.cpp"],
|
||||||
static_copts = ["staticflag"],
|
static = {
|
||||||
static_deps_for_shared = [":static_dep_for_shared"],
|
"copts": ["staticflag"],
|
||||||
static_deps_for_static = [":static_dep_for_static"],
|
"dynamic_deps": [":shared_dep_for_static"],
|
||||||
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_both"],
|
whole_archive_deps = [":whole_static_lib_for_both"],
|
||||||
whole_archive_deps_for_shared = [":whole_static_lib_for_shared"],
|
|
||||||
whole_archive_deps_for_static = [":whole_static_lib_for_static"],
|
|
||||||
)`},
|
)`},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -437,9 +441,13 @@ cc_prebuilt_library_static { name: "whole_static_lib_for_both" }
|
|||||||
"-Ifoo/bar",
|
"-Ifoo/bar",
|
||||||
"-I$(BINDIR)/foo/bar",
|
"-I$(BINDIR)/foo/bar",
|
||||||
],
|
],
|
||||||
|
shared = {
|
||||||
|
"whole_archive_deps": [":whole_static_lib_for_shared_alwayslink"],
|
||||||
|
},
|
||||||
|
static = {
|
||||||
|
"whole_archive_deps": [":whole_static_lib_for_static_alwayslink"],
|
||||||
|
},
|
||||||
whole_archive_deps = [":whole_static_lib_for_both_alwayslink"],
|
whole_archive_deps = [":whole_static_lib_for_both_alwayslink"],
|
||||||
whole_archive_deps_for_shared = [":whole_static_lib_for_shared_alwayslink"],
|
|
||||||
whole_archive_deps_for_static = [":whole_static_lib_for_static_alwayslink"],
|
|
||||||
)`},
|
)`},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -529,52 +537,56 @@ cc_library_static { name: "android_dep_for_shared" }
|
|||||||
"-Ifoo/bar",
|
"-Ifoo/bar",
|
||||||
"-I$(BINDIR)/foo/bar",
|
"-I$(BINDIR)/foo/bar",
|
||||||
],
|
],
|
||||||
dynamic_deps_for_shared = select({
|
|
||||||
"//build/bazel/platforms/arch:arm": [":arm_shared_dep_for_shared"],
|
|
||||||
"//conditions:default": [],
|
|
||||||
}),
|
|
||||||
implementation_deps = [":static_dep_for_both"],
|
implementation_deps = [":static_dep_for_both"],
|
||||||
shared_copts = ["sharedflag"] + select({
|
shared = {
|
||||||
"//build/bazel/platforms/arch:arm": ["-DARM_SHARED"],
|
"copts": ["sharedflag"] + select({
|
||||||
"//conditions:default": [],
|
"//build/bazel/platforms/arch:arm": ["-DARM_SHARED"],
|
||||||
}) + select({
|
"//conditions:default": [],
|
||||||
"//build/bazel/platforms/os:android": ["-DANDROID_SHARED"],
|
}) + select({
|
||||||
"//conditions:default": [],
|
"//build/bazel/platforms/os:android": ["-DANDROID_SHARED"],
|
||||||
}) + select({
|
"//conditions:default": [],
|
||||||
"//build/bazel/platforms/os_arch:android_arm": ["-DANDROID_ARM_SHARED"],
|
}) + select({
|
||||||
"//conditions:default": [],
|
"//build/bazel/platforms/os_arch:android_arm": ["-DANDROID_ARM_SHARED"],
|
||||||
}),
|
"//conditions:default": [],
|
||||||
shared_srcs = ["sharedonly.cpp"] + select({
|
}),
|
||||||
"//build/bazel/platforms/arch:arm": ["arm_shared.cpp"],
|
"dynamic_deps": select({
|
||||||
"//conditions:default": [],
|
"//build/bazel/platforms/arch:arm": [":arm_shared_dep_for_shared"],
|
||||||
}) + select({
|
"//conditions:default": [],
|
||||||
"//build/bazel/platforms/os:android": ["android_shared.cpp"],
|
}),
|
||||||
"//conditions:default": [],
|
"srcs": ["sharedonly.cpp"] + select({
|
||||||
}),
|
"//build/bazel/platforms/arch:arm": ["arm_shared.cpp"],
|
||||||
|
"//conditions:default": [],
|
||||||
|
}) + select({
|
||||||
|
"//build/bazel/platforms/os:android": ["android_shared.cpp"],
|
||||||
|
"//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({
|
||||||
|
"//build/bazel/platforms/arch:arm": [":arm_whole_static_dep_for_shared"],
|
||||||
|
"//conditions:default": [],
|
||||||
|
}),
|
||||||
|
},
|
||||||
srcs = ["both.cpp"],
|
srcs = ["both.cpp"],
|
||||||
static_copts = ["staticflag"] + select({
|
static = {
|
||||||
"//build/bazel/platforms/arch:x86": ["-DX86_STATIC"],
|
"copts": ["staticflag"] + select({
|
||||||
"//conditions:default": [],
|
"//build/bazel/platforms/arch:x86": ["-DX86_STATIC"],
|
||||||
}),
|
"//conditions:default": [],
|
||||||
static_deps_for_shared = [":static_dep_for_shared"] + select({
|
}),
|
||||||
"//build/bazel/platforms/arch:arm": [":arm_static_dep_for_shared"],
|
"srcs": ["staticonly.cpp"] + select({
|
||||||
"//conditions:default": [],
|
"//build/bazel/platforms/arch:x86": ["x86_static.cpp"],
|
||||||
}) + select({
|
"//conditions:default": [],
|
||||||
"//build/bazel/platforms/os:android": [":android_dep_for_shared"],
|
}),
|
||||||
"//conditions:default": [],
|
"static_deps": [":static_dep_for_static"] + select({
|
||||||
}),
|
"//build/bazel/platforms/arch:x86": [":x86_dep_for_static"],
|
||||||
static_deps_for_static = [":static_dep_for_static"] + select({
|
"//conditions:default": [],
|
||||||
"//build/bazel/platforms/arch:x86": [":x86_dep_for_static"],
|
}),
|
||||||
"//conditions:default": [],
|
},
|
||||||
}),
|
|
||||||
static_srcs = ["staticonly.cpp"] + select({
|
|
||||||
"//build/bazel/platforms/arch:x86": ["x86_static.cpp"],
|
|
||||||
"//conditions:default": [],
|
|
||||||
}),
|
|
||||||
whole_archive_deps_for_shared = select({
|
|
||||||
"//build/bazel/platforms/arch:arm": [":arm_whole_static_dep_for_shared"],
|
|
||||||
"//conditions:default": [],
|
|
||||||
}),
|
|
||||||
)`},
|
)`},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -666,20 +678,22 @@ filegroup {
|
|||||||
"-Ifoo/bar",
|
"-Ifoo/bar",
|
||||||
"-I$(BINDIR)/foo/bar",
|
"-I$(BINDIR)/foo/bar",
|
||||||
],
|
],
|
||||||
shared_srcs = [
|
shared = {
|
||||||
":shared_filegroup_cpp_srcs",
|
"srcs": [
|
||||||
"shared_source.cc",
|
":shared_filegroup_cpp_srcs",
|
||||||
"shared_source.cpp",
|
"shared_source.cc",
|
||||||
],
|
"shared_source.cpp",
|
||||||
shared_srcs_as = [
|
],
|
||||||
"shared_source.s",
|
"srcs_as": [
|
||||||
"shared_source.S",
|
"shared_source.s",
|
||||||
":shared_filegroup_as_srcs",
|
"shared_source.S",
|
||||||
],
|
":shared_filegroup_as_srcs",
|
||||||
shared_srcs_c = [
|
],
|
||||||
"shared_source.c",
|
"srcs_c": [
|
||||||
":shared_filegroup_c_srcs",
|
"shared_source.c",
|
||||||
],
|
":shared_filegroup_c_srcs",
|
||||||
|
],
|
||||||
|
},
|
||||||
srcs = [
|
srcs = [
|
||||||
":both_filegroup_cpp_srcs",
|
":both_filegroup_cpp_srcs",
|
||||||
"both_source.cc",
|
"both_source.cc",
|
||||||
@@ -694,20 +708,22 @@ filegroup {
|
|||||||
"both_source.c",
|
"both_source.c",
|
||||||
":both_filegroup_c_srcs",
|
":both_filegroup_c_srcs",
|
||||||
],
|
],
|
||||||
static_srcs = [
|
static = {
|
||||||
":static_filegroup_cpp_srcs",
|
"srcs": [
|
||||||
"static_source.cc",
|
":static_filegroup_cpp_srcs",
|
||||||
"static_source.cpp",
|
"static_source.cc",
|
||||||
],
|
"static_source.cpp",
|
||||||
static_srcs_as = [
|
],
|
||||||
"static_source.s",
|
"srcs_as": [
|
||||||
"static_source.S",
|
"static_source.s",
|
||||||
":static_filegroup_as_srcs",
|
"static_source.S",
|
||||||
],
|
":static_filegroup_as_srcs",
|
||||||
static_srcs_c = [
|
],
|
||||||
"static_source.c",
|
"srcs_c": [
|
||||||
":static_filegroup_c_srcs",
|
"static_source.c",
|
||||||
],
|
":static_filegroup_c_srcs",
|
||||||
|
],
|
||||||
|
},
|
||||||
)`},
|
)`},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@@ -142,15 +142,14 @@ func depsBp2BuildMutator(ctx android.BottomUpMutatorContext) {
|
|||||||
// staticOrSharedAttributes are the Bazel-ified versions of StaticOrSharedProperties --
|
// staticOrSharedAttributes are the Bazel-ified versions of StaticOrSharedProperties --
|
||||||
// properties which apply to either the shared or static version of a cc_library module.
|
// properties which apply to either the shared or static version of a cc_library module.
|
||||||
type staticOrSharedAttributes struct {
|
type staticOrSharedAttributes struct {
|
||||||
srcs bazel.LabelListAttribute
|
Srcs bazel.LabelListAttribute
|
||||||
srcs_c bazel.LabelListAttribute
|
Srcs_c bazel.LabelListAttribute
|
||||||
srcs_as bazel.LabelListAttribute
|
Srcs_as bazel.LabelListAttribute
|
||||||
|
Copts bazel.StringListAttribute
|
||||||
|
|
||||||
copts bazel.StringListAttribute
|
Static_deps bazel.LabelListAttribute
|
||||||
|
Dynamic_deps bazel.LabelListAttribute
|
||||||
staticDeps bazel.LabelListAttribute
|
Whole_archive_deps bazel.LabelListAttribute
|
||||||
dynamicDeps bazel.LabelListAttribute
|
|
||||||
wholeArchiveDeps bazel.LabelListAttribute
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func groupSrcsByExtension(ctx android.TopDownMutatorContext, srcs bazel.LabelListAttribute) (cppSrcs, cSrcs, asSrcs bazel.LabelListAttribute) {
|
func groupSrcsByExtension(ctx android.TopDownMutatorContext, srcs bazel.LabelListAttribute) (cppSrcs, cSrcs, asSrcs bazel.LabelListAttribute) {
|
||||||
@@ -251,19 +250,19 @@ func bp2buildParseStaticOrSharedProps(ctx android.TopDownMutatorContext, module
|
|||||||
}
|
}
|
||||||
|
|
||||||
attrs := staticOrSharedAttributes{
|
attrs := staticOrSharedAttributes{
|
||||||
copts: bazel.StringListAttribute{Value: props.Cflags},
|
Copts: bazel.StringListAttribute{Value: props.Cflags},
|
||||||
srcs: bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, props.Srcs)),
|
Srcs: bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, props.Srcs)),
|
||||||
staticDeps: bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, props.Static_libs)),
|
Static_deps: bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, props.Static_libs)),
|
||||||
dynamicDeps: bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, props.Shared_libs)),
|
Dynamic_deps: bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, props.Shared_libs)),
|
||||||
wholeArchiveDeps: bazel.MakeLabelListAttribute(android.BazelLabelForModuleWholeDeps(ctx, props.Whole_static_libs)),
|
Whole_archive_deps: bazel.MakeLabelListAttribute(android.BazelLabelForModuleWholeDeps(ctx, props.Whole_static_libs)),
|
||||||
}
|
}
|
||||||
|
|
||||||
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.staticDeps.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, props.Static_libs))
|
attrs.Static_deps.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, props.Static_libs))
|
||||||
attrs.dynamicDeps.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, props.Shared_libs))
|
attrs.Dynamic_deps.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, props.Shared_libs))
|
||||||
attrs.wholeArchiveDeps.SetSelectValue(axis, config, android.BazelLabelForModuleWholeDeps(ctx, props.Whole_static_libs))
|
attrs.Whole_archive_deps.SetSelectValue(axis, config, android.BazelLabelForModuleWholeDeps(ctx, props.Whole_static_libs))
|
||||||
}
|
}
|
||||||
|
|
||||||
if isStatic {
|
if isStatic {
|
||||||
@@ -284,10 +283,10 @@ func bp2buildParseStaticOrSharedProps(ctx android.TopDownMutatorContext, module
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cppSrcs, cSrcs, asSrcs := groupSrcsByExtension(ctx, attrs.srcs)
|
cppSrcs, cSrcs, asSrcs := groupSrcsByExtension(ctx, attrs.Srcs)
|
||||||
attrs.srcs = cppSrcs
|
attrs.Srcs = cppSrcs
|
||||||
attrs.srcs_c = cSrcs
|
attrs.Srcs_c = cSrcs
|
||||||
attrs.srcs_as = asSrcs
|
attrs.Srcs_as = asSrcs
|
||||||
|
|
||||||
return attrs
|
return attrs
|
||||||
}
|
}
|
||||||
|
@@ -237,29 +237,12 @@ type bazelCcLibraryAttributes struct {
|
|||||||
Linkopts bazel.StringListAttribute
|
Linkopts bazel.StringListAttribute
|
||||||
Use_libcrt bazel.BoolAttribute
|
Use_libcrt bazel.BoolAttribute
|
||||||
|
|
||||||
// Attributes pertaining to shared variant.
|
// This is shared only.
|
||||||
Shared_srcs bazel.LabelListAttribute
|
Version_script bazel.LabelAttribute
|
||||||
Shared_srcs_c bazel.LabelListAttribute
|
|
||||||
Shared_srcs_as bazel.LabelListAttribute
|
|
||||||
Shared_copts bazel.StringListAttribute
|
|
||||||
|
|
||||||
Exported_deps_for_shared bazel.LabelListAttribute
|
// Common properties shared between both shared and static variants.
|
||||||
Static_deps_for_shared bazel.LabelListAttribute
|
Shared staticOrSharedAttributes
|
||||||
Dynamic_deps_for_shared bazel.LabelListAttribute
|
Static staticOrSharedAttributes
|
||||||
Whole_archive_deps_for_shared bazel.LabelListAttribute
|
|
||||||
User_link_flags bazel.StringListAttribute
|
|
||||||
Version_script bazel.LabelAttribute
|
|
||||||
|
|
||||||
// Attributes pertaining to static variant.
|
|
||||||
Static_srcs bazel.LabelListAttribute
|
|
||||||
Static_srcs_c bazel.LabelListAttribute
|
|
||||||
Static_srcs_as bazel.LabelListAttribute
|
|
||||||
Static_copts bazel.StringListAttribute
|
|
||||||
|
|
||||||
Exported_deps_for_static bazel.LabelListAttribute
|
|
||||||
Static_deps_for_static bazel.LabelListAttribute
|
|
||||||
Dynamic_deps_for_static bazel.LabelListAttribute
|
|
||||||
Whole_archive_deps_for_static bazel.LabelListAttribute
|
|
||||||
|
|
||||||
Strip stripAttributes
|
Strip stripAttributes
|
||||||
}
|
}
|
||||||
@@ -334,6 +317,8 @@ func CcLibraryBp2Build(ctx android.TopDownMutatorContext) {
|
|||||||
Linkopts: linkerAttrs.linkopts,
|
Linkopts: linkerAttrs.linkopts,
|
||||||
Use_libcrt: linkerAttrs.useLibcrt,
|
Use_libcrt: linkerAttrs.useLibcrt,
|
||||||
|
|
||||||
|
Version_script: linkerAttrs.versionScript,
|
||||||
|
|
||||||
Strip: stripAttributes{
|
Strip: stripAttributes{
|
||||||
Keep_symbols: linkerAttrs.stripKeepSymbols,
|
Keep_symbols: linkerAttrs.stripKeepSymbols,
|
||||||
Keep_symbols_and_debug_frame: linkerAttrs.stripKeepSymbolsAndDebugFrame,
|
Keep_symbols_and_debug_frame: linkerAttrs.stripKeepSymbolsAndDebugFrame,
|
||||||
@@ -342,22 +327,9 @@ func CcLibraryBp2Build(ctx android.TopDownMutatorContext) {
|
|||||||
None: linkerAttrs.stripNone,
|
None: linkerAttrs.stripNone,
|
||||||
},
|
},
|
||||||
|
|
||||||
Shared_srcs: sharedAttrs.srcs,
|
Shared: sharedAttrs,
|
||||||
Shared_srcs_c: sharedAttrs.srcs_c,
|
|
||||||
Shared_srcs_as: sharedAttrs.srcs_as,
|
|
||||||
Shared_copts: sharedAttrs.copts,
|
|
||||||
Static_deps_for_shared: sharedAttrs.staticDeps,
|
|
||||||
Whole_archive_deps_for_shared: sharedAttrs.wholeArchiveDeps,
|
|
||||||
Dynamic_deps_for_shared: sharedAttrs.dynamicDeps,
|
|
||||||
Version_script: linkerAttrs.versionScript,
|
|
||||||
|
|
||||||
Static_srcs: staticAttrs.srcs,
|
Static: staticAttrs,
|
||||||
Static_srcs_c: staticAttrs.srcs_c,
|
|
||||||
Static_srcs_as: staticAttrs.srcs_as,
|
|
||||||
Static_copts: staticAttrs.copts,
|
|
||||||
Static_deps_for_static: staticAttrs.staticDeps,
|
|
||||||
Whole_archive_deps_for_static: staticAttrs.wholeArchiveDeps,
|
|
||||||
Dynamic_deps_for_static: staticAttrs.dynamicDeps,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
props := bazel.BazelTargetModuleProperties{
|
props := bazel.BazelTargetModuleProperties{
|
||||||
|
Reference in New Issue
Block a user