Merge "bp2build: support strip properties."
This commit is contained in:
@@ -488,6 +488,9 @@ func prettyPrint(propertyValue reflect.Value, indent int) (string, error) {
|
|||||||
ret = "{\n"
|
ret = "{\n"
|
||||||
// Sort and print the struct props by the key.
|
// Sort and print the struct props by the key.
|
||||||
structProps := extractStructProperties(propertyValue, indent)
|
structProps := extractStructProperties(propertyValue, indent)
|
||||||
|
if len(structProps) == 0 {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
for _, k := range android.SortedStringKeys(structProps) {
|
for _, k := range android.SortedStringKeys(structProps) {
|
||||||
ret += makeIndent(indent + 1)
|
ret += makeIndent(indent + 1)
|
||||||
ret += fmt.Sprintf("%q: %s,\n", k, structProps[k])
|
ret += fmt.Sprintf("%q: %s,\n", k, structProps[k])
|
||||||
|
@@ -1231,3 +1231,173 @@ cc_library {
|
|||||||
}),
|
}),
|
||||||
)`}})
|
)`}})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCcLibraryStrip(t *testing.T) {
|
||||||
|
runCcLibraryTestCase(t, bp2buildTestCase{
|
||||||
|
description: "cc_library strip args",
|
||||||
|
moduleTypeUnderTest: "cc_library",
|
||||||
|
moduleTypeUnderTestFactory: cc.LibraryFactory,
|
||||||
|
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
|
||||||
|
depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
|
||||||
|
dir: "foo/bar",
|
||||||
|
filesystem: map[string]string{
|
||||||
|
"foo/bar/Android.bp": `
|
||||||
|
cc_library {
|
||||||
|
name: "nothing",
|
||||||
|
bazel_module: { bp2build_available: true },
|
||||||
|
}
|
||||||
|
cc_library {
|
||||||
|
name: "keep_symbols",
|
||||||
|
bazel_module: { bp2build_available: true },
|
||||||
|
strip: {
|
||||||
|
keep_symbols: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cc_library {
|
||||||
|
name: "keep_symbols_and_debug_frame",
|
||||||
|
bazel_module: { bp2build_available: true },
|
||||||
|
strip: {
|
||||||
|
keep_symbols_and_debug_frame: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cc_library {
|
||||||
|
name: "none",
|
||||||
|
bazel_module: { bp2build_available: true },
|
||||||
|
strip: {
|
||||||
|
none: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cc_library {
|
||||||
|
name: "keep_symbols_list",
|
||||||
|
bazel_module: { bp2build_available: true },
|
||||||
|
strip: {
|
||||||
|
keep_symbols_list: ["symbol"],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cc_library {
|
||||||
|
name: "all",
|
||||||
|
bazel_module: { bp2build_available: true },
|
||||||
|
strip: {
|
||||||
|
all: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
blueprint: soongCcLibraryPreamble,
|
||||||
|
expectedBazelTargets: []string{`cc_library(
|
||||||
|
name = "all",
|
||||||
|
copts = [
|
||||||
|
"-Ifoo/bar",
|
||||||
|
"-I$(BINDIR)/foo/bar",
|
||||||
|
],
|
||||||
|
strip = {
|
||||||
|
"all": True,
|
||||||
|
},
|
||||||
|
)`, `cc_library(
|
||||||
|
name = "keep_symbols",
|
||||||
|
copts = [
|
||||||
|
"-Ifoo/bar",
|
||||||
|
"-I$(BINDIR)/foo/bar",
|
||||||
|
],
|
||||||
|
strip = {
|
||||||
|
"keep_symbols": True,
|
||||||
|
},
|
||||||
|
)`, `cc_library(
|
||||||
|
name = "keep_symbols_and_debug_frame",
|
||||||
|
copts = [
|
||||||
|
"-Ifoo/bar",
|
||||||
|
"-I$(BINDIR)/foo/bar",
|
||||||
|
],
|
||||||
|
strip = {
|
||||||
|
"keep_symbols_and_debug_frame": True,
|
||||||
|
},
|
||||||
|
)`, `cc_library(
|
||||||
|
name = "keep_symbols_list",
|
||||||
|
copts = [
|
||||||
|
"-Ifoo/bar",
|
||||||
|
"-I$(BINDIR)/foo/bar",
|
||||||
|
],
|
||||||
|
strip = {
|
||||||
|
"keep_symbols_list": ["symbol"],
|
||||||
|
},
|
||||||
|
)`, `cc_library(
|
||||||
|
name = "none",
|
||||||
|
copts = [
|
||||||
|
"-Ifoo/bar",
|
||||||
|
"-I$(BINDIR)/foo/bar",
|
||||||
|
],
|
||||||
|
strip = {
|
||||||
|
"none": True,
|
||||||
|
},
|
||||||
|
)`, `cc_library(
|
||||||
|
name = "nothing",
|
||||||
|
copts = [
|
||||||
|
"-Ifoo/bar",
|
||||||
|
"-I$(BINDIR)/foo/bar",
|
||||||
|
],
|
||||||
|
)`},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCcLibraryStripWithArch(t *testing.T) {
|
||||||
|
runCcLibraryTestCase(t, bp2buildTestCase{
|
||||||
|
description: "cc_library strip args",
|
||||||
|
moduleTypeUnderTest: "cc_library",
|
||||||
|
moduleTypeUnderTestFactory: cc.LibraryFactory,
|
||||||
|
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
|
||||||
|
depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
|
||||||
|
dir: "foo/bar",
|
||||||
|
filesystem: map[string]string{
|
||||||
|
"foo/bar/Android.bp": `
|
||||||
|
cc_library {
|
||||||
|
name: "multi-arch",
|
||||||
|
bazel_module: { bp2build_available: true },
|
||||||
|
target: {
|
||||||
|
darwin: {
|
||||||
|
strip: {
|
||||||
|
keep_symbols_list: ["foo", "bar"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
arch: {
|
||||||
|
arm: {
|
||||||
|
strip: {
|
||||||
|
keep_symbols_and_debug_frame: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
arm64: {
|
||||||
|
strip: {
|
||||||
|
keep_symbols: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
blueprint: soongCcLibraryPreamble,
|
||||||
|
expectedBazelTargets: []string{`cc_library(
|
||||||
|
name = "multi-arch",
|
||||||
|
copts = [
|
||||||
|
"-Ifoo/bar",
|
||||||
|
"-I$(BINDIR)/foo/bar",
|
||||||
|
],
|
||||||
|
strip = {
|
||||||
|
"keep_symbols": select({
|
||||||
|
"//build/bazel/platforms/arch:arm64": True,
|
||||||
|
"//conditions:default": None,
|
||||||
|
}),
|
||||||
|
"keep_symbols_and_debug_frame": select({
|
||||||
|
"//build/bazel/platforms/arch:arm": True,
|
||||||
|
"//conditions:default": None,
|
||||||
|
}),
|
||||||
|
"keep_symbols_list": select({
|
||||||
|
"//build/bazel/platforms/os:darwin": [
|
||||||
|
"foo",
|
||||||
|
"bar",
|
||||||
|
],
|
||||||
|
"//conditions:default": [],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
)`},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@@ -485,13 +485,18 @@ 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
|
dynamicDeps bazel.LabelListAttribute
|
||||||
wholeArchiveDeps bazel.LabelListAttribute
|
wholeArchiveDeps bazel.LabelListAttribute
|
||||||
exportedDeps bazel.LabelListAttribute
|
exportedDeps bazel.LabelListAttribute
|
||||||
useLibcrt bazel.BoolAttribute
|
useLibcrt bazel.BoolAttribute
|
||||||
linkopts bazel.StringListAttribute
|
linkopts bazel.StringListAttribute
|
||||||
versionScript bazel.LabelAttribute
|
versionScript bazel.LabelAttribute
|
||||||
|
stripKeepSymbols bazel.BoolAttribute
|
||||||
|
stripKeepSymbolsAndDebugFrame bazel.BoolAttribute
|
||||||
|
stripKeepSymbolsList bazel.StringListAttribute
|
||||||
|
stripAll bazel.BoolAttribute
|
||||||
|
stripNone bazel.BoolAttribute
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME(b/187655838): Use the existing linkerFlags() function instead of duplicating logic here
|
// FIXME(b/187655838): Use the existing linkerFlags() function instead of duplicating logic here
|
||||||
@@ -515,6 +520,33 @@ func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module)
|
|||||||
var versionScript bazel.LabelAttribute
|
var versionScript bazel.LabelAttribute
|
||||||
var useLibcrt bazel.BoolAttribute
|
var useLibcrt bazel.BoolAttribute
|
||||||
|
|
||||||
|
var stripKeepSymbols bazel.BoolAttribute
|
||||||
|
var stripKeepSymbolsAndDebugFrame bazel.BoolAttribute
|
||||||
|
var stripKeepSymbolsList bazel.StringListAttribute
|
||||||
|
var stripAll bazel.BoolAttribute
|
||||||
|
var stripNone bazel.BoolAttribute
|
||||||
|
|
||||||
|
if libraryDecorator, ok := module.linker.(*libraryDecorator); ok {
|
||||||
|
stripProperties := libraryDecorator.stripper.StripProperties
|
||||||
|
stripKeepSymbols.Value = stripProperties.Strip.Keep_symbols
|
||||||
|
stripKeepSymbolsList.Value = stripProperties.Strip.Keep_symbols_list
|
||||||
|
stripKeepSymbolsAndDebugFrame.Value = stripProperties.Strip.Keep_symbols_and_debug_frame
|
||||||
|
stripAll.Value = stripProperties.Strip.All
|
||||||
|
stripNone.Value = stripProperties.Strip.None
|
||||||
|
}
|
||||||
|
|
||||||
|
for axis, configToProps := range module.GetArchVariantProperties(ctx, &StripProperties{}) {
|
||||||
|
for config, props := range configToProps {
|
||||||
|
if stripProperties, ok := props.(*StripProperties); ok {
|
||||||
|
stripKeepSymbols.SetSelectValue(axis, config, stripProperties.Strip.Keep_symbols)
|
||||||
|
stripKeepSymbolsList.SetSelectValue(axis, config, stripProperties.Strip.Keep_symbols_list)
|
||||||
|
stripKeepSymbolsAndDebugFrame.SetSelectValue(axis, config, stripProperties.Strip.Keep_symbols_and_debug_frame)
|
||||||
|
stripAll.SetSelectValue(axis, config, stripProperties.Strip.All)
|
||||||
|
stripNone.SetSelectValue(axis, config, stripProperties.Strip.None)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for _, linkerProps := range module.linker.linkerProps() {
|
for _, linkerProps := range module.linker.linkerProps() {
|
||||||
if baseLinkerProps, ok := linkerProps.(*BaseLinkerProperties); ok {
|
if baseLinkerProps, ok := linkerProps.(*BaseLinkerProperties); ok {
|
||||||
// Excludes to parallel Soong:
|
// Excludes to parallel Soong:
|
||||||
@@ -630,6 +662,13 @@ func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module)
|
|||||||
linkopts: linkopts,
|
linkopts: linkopts,
|
||||||
useLibcrt: useLibcrt,
|
useLibcrt: useLibcrt,
|
||||||
versionScript: versionScript,
|
versionScript: versionScript,
|
||||||
|
|
||||||
|
// Strip properties
|
||||||
|
stripKeepSymbols: stripKeepSymbols,
|
||||||
|
stripKeepSymbolsAndDebugFrame: stripKeepSymbolsAndDebugFrame,
|
||||||
|
stripKeepSymbolsList: stripKeepSymbolsList,
|
||||||
|
stripAll: stripAll,
|
||||||
|
stripNone: stripNone,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -259,6 +259,16 @@ type bazelCcLibraryAttributes struct {
|
|||||||
Static_deps_for_static bazel.LabelListAttribute
|
Static_deps_for_static bazel.LabelListAttribute
|
||||||
Dynamic_deps_for_static bazel.LabelListAttribute
|
Dynamic_deps_for_static bazel.LabelListAttribute
|
||||||
Whole_archive_deps_for_static bazel.LabelListAttribute
|
Whole_archive_deps_for_static bazel.LabelListAttribute
|
||||||
|
|
||||||
|
Strip stripAttributes
|
||||||
|
}
|
||||||
|
|
||||||
|
type stripAttributes struct {
|
||||||
|
Keep_symbols bazel.BoolAttribute
|
||||||
|
Keep_symbols_and_debug_frame bazel.BoolAttribute
|
||||||
|
Keep_symbols_list bazel.StringListAttribute
|
||||||
|
All bazel.BoolAttribute
|
||||||
|
None bazel.BoolAttribute
|
||||||
}
|
}
|
||||||
|
|
||||||
type bazelCcLibrary struct {
|
type bazelCcLibrary struct {
|
||||||
@@ -323,6 +333,14 @@ func CcLibraryBp2Build(ctx android.TopDownMutatorContext) {
|
|||||||
Linkopts: linkerAttrs.linkopts,
|
Linkopts: linkerAttrs.linkopts,
|
||||||
Use_libcrt: linkerAttrs.useLibcrt,
|
Use_libcrt: linkerAttrs.useLibcrt,
|
||||||
|
|
||||||
|
Strip: stripAttributes{
|
||||||
|
Keep_symbols: linkerAttrs.stripKeepSymbols,
|
||||||
|
Keep_symbols_and_debug_frame: linkerAttrs.stripKeepSymbolsAndDebugFrame,
|
||||||
|
Keep_symbols_list: linkerAttrs.stripKeepSymbolsList,
|
||||||
|
All: linkerAttrs.stripAll,
|
||||||
|
None: linkerAttrs.stripNone,
|
||||||
|
},
|
||||||
|
|
||||||
Shared_srcs: sharedAttrs.srcs,
|
Shared_srcs: sharedAttrs.srcs,
|
||||||
Shared_srcs_c: sharedAttrs.srcs_c,
|
Shared_srcs_c: sharedAttrs.srcs_c,
|
||||||
Shared_srcs_as: sharedAttrs.srcs_as,
|
Shared_srcs_as: sharedAttrs.srcs_as,
|
||||||
|
@@ -59,6 +59,7 @@ func (stripper *Stripper) NeedsStrip(actx android.ModuleContext) bool {
|
|||||||
return !forceDisable && (forceEnable || defaultEnable)
|
return !forceDisable && (forceEnable || defaultEnable)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Keep this consistent with //build/bazel/rules/stripped_shared_library.bzl.
|
||||||
func (stripper *Stripper) strip(actx android.ModuleContext, in android.Path, out android.ModuleOutPath,
|
func (stripper *Stripper) strip(actx android.ModuleContext, in android.Path, out android.ModuleOutPath,
|
||||||
flags StripFlags, isStaticLib bool) {
|
flags StripFlags, isStaticLib bool) {
|
||||||
if actx.Darwin() {
|
if actx.Darwin() {
|
||||||
|
Reference in New Issue
Block a user