Merge "convert hidden visibility flag to feature"
This commit is contained in:
commit
aea506707f
6 changed files with 287 additions and 6 deletions
|
@ -996,3 +996,44 @@ func TestCcBinaryWithThinLtoAndWholeProgramVtables(t *testing.T) {
|
|||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcBinaryHiddenVisibilityConvertedToFeature(t *testing.T) {
|
||||
runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{
|
||||
description: "cc_binary changes hidden visibility to feature",
|
||||
blueprint: `
|
||||
{rule_name} {
|
||||
name: "foo",
|
||||
cflags: ["-fvisibility=hidden"],
|
||||
}`,
|
||||
targets: []testBazelTarget{
|
||||
{"cc_binary", "foo", AttrNameToString{
|
||||
"local_includes": `["."]`,
|
||||
"features": `["visibility_hidden"]`,
|
||||
}},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcBinaryHiddenVisibilityConvertedToFeatureOsSpecific(t *testing.T) {
|
||||
runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{
|
||||
description: "cc_binary changes hidden visibility to feature for specific os",
|
||||
blueprint: `
|
||||
{rule_name} {
|
||||
name: "foo",
|
||||
target: {
|
||||
android: {
|
||||
cflags: ["-fvisibility=hidden"],
|
||||
},
|
||||
},
|
||||
}`,
|
||||
targets: []testBazelTarget{
|
||||
{"cc_binary", "foo", AttrNameToString{
|
||||
"local_includes": `["."]`,
|
||||
"features": `select({
|
||||
"//build/bazel/platforms/os:android": ["visibility_hidden"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
|
@ -4350,3 +4350,107 @@ cc_library {
|
|||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcLibraryHiddenVisibilityConvertedToFeature(t *testing.T) {
|
||||
runCcLibraryTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_library changes hidden visibility flag to feature",
|
||||
ModuleTypeUnderTest: "cc_library",
|
||||
ModuleTypeUnderTestFactory: cc.LibraryFactory,
|
||||
Blueprint: `
|
||||
cc_library {
|
||||
name: "foo",
|
||||
cflags: ["-fvisibility=hidden"],
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
|
||||
"features": `["visibility_hidden"]`,
|
||||
"local_includes": `["."]`,
|
||||
}),
|
||||
MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
|
||||
"features": `["visibility_hidden"]`,
|
||||
"local_includes": `["."]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcLibraryHiddenVisibilityConvertedToFeatureSharedSpecific(t *testing.T) {
|
||||
runCcLibraryTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_library changes hidden visibility flag to feature when specific to shared variant",
|
||||
ModuleTypeUnderTest: "cc_library",
|
||||
ModuleTypeUnderTestFactory: cc.LibraryFactory,
|
||||
Blueprint: `
|
||||
cc_library {
|
||||
name: "foo",
|
||||
shared: {
|
||||
cflags: ["-fvisibility=hidden"],
|
||||
},
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
|
||||
"local_includes": `["."]`,
|
||||
}),
|
||||
MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
|
||||
"features": `["visibility_hidden"]`,
|
||||
"local_includes": `["."]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcLibraryHiddenVisibilityConvertedToFeatureStaticSpecific(t *testing.T) {
|
||||
runCcLibraryTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_library changes hidden visibility flag to feature when specific to static variant",
|
||||
ModuleTypeUnderTest: "cc_library",
|
||||
ModuleTypeUnderTestFactory: cc.LibraryFactory,
|
||||
Blueprint: `
|
||||
cc_library {
|
||||
name: "foo",
|
||||
static: {
|
||||
cflags: ["-fvisibility=hidden"],
|
||||
},
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
|
||||
"features": `["visibility_hidden"]`,
|
||||
"local_includes": `["."]`,
|
||||
}),
|
||||
MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
|
||||
"local_includes": `["."]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcLibraryHiddenVisibilityConvertedToFeatureOsSpecific(t *testing.T) {
|
||||
runCcLibraryTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_library changes hidden visibility flag to feature when specific to an os",
|
||||
ModuleTypeUnderTest: "cc_library",
|
||||
ModuleTypeUnderTestFactory: cc.LibraryFactory,
|
||||
Blueprint: `
|
||||
cc_library {
|
||||
name: "foo",
|
||||
target: {
|
||||
android: {
|
||||
cflags: ["-fvisibility=hidden"],
|
||||
},
|
||||
},
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
|
||||
"features": `select({
|
||||
"//build/bazel/platforms/os:android": ["visibility_hidden"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
"local_includes": `["."]`,
|
||||
}),
|
||||
MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
|
||||
"features": `select({
|
||||
"//build/bazel/platforms/os:android": ["visibility_hidden"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
"local_includes": `["."]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1250,3 +1250,44 @@ cc_library_shared {
|
|||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcLibrarySharedHiddenVisibilityConvertedToFeature(t *testing.T) {
|
||||
runCcLibrarySharedTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_library_shared changes hidden visibility flag to feature",
|
||||
Blueprint: `
|
||||
cc_library_shared{
|
||||
name: "foo",
|
||||
cflags: ["-fvisibility=hidden"],
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
|
||||
"features": `["visibility_hidden"]`,
|
||||
"local_includes": `["."]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcLibrarySharedHiddenVisibilityConvertedToFeatureOsSpecific(t *testing.T) {
|
||||
runCcLibrarySharedTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_library_shared changes hidden visibility flag to feature for specific os",
|
||||
Blueprint: `
|
||||
cc_library_shared{
|
||||
name: "foo",
|
||||
target: {
|
||||
android: {
|
||||
cflags: ["-fvisibility=hidden"],
|
||||
},
|
||||
},
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
|
||||
"features": `select({
|
||||
"//build/bazel/platforms/os:android": ["visibility_hidden"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
"local_includes": `["."]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
|
@ -2032,3 +2032,44 @@ cc_library_static {
|
|||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcLibraryStaticHiddenVisibilityConvertedToFeature(t *testing.T) {
|
||||
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_library_static changes hidden visibility flag to feature",
|
||||
Blueprint: `
|
||||
cc_library_static {
|
||||
name: "foo",
|
||||
cflags: ["-fvisibility=hidden"],
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
|
||||
"features": `["visibility_hidden"]`,
|
||||
"local_includes": `["."]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcLibraryStaticHiddenVisibilityConvertedToFeatureOsSpecific(t *testing.T) {
|
||||
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_library_static changes hidden visibility flag to feature for specific os",
|
||||
Blueprint: `
|
||||
cc_library_static {
|
||||
name: "foo",
|
||||
target: {
|
||||
android: {
|
||||
cflags: ["-fvisibility=hidden"],
|
||||
},
|
||||
},
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
|
||||
"features": `select({
|
||||
"//build/bazel/platforms/os:android": ["visibility_hidden"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
"local_includes": `["."]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
|
@ -67,6 +67,8 @@ type staticOrSharedAttributes struct {
|
|||
|
||||
Apex_available []string
|
||||
|
||||
Features bazel.StringListAttribute
|
||||
|
||||
sdkAttributes
|
||||
|
||||
tidyAttributes
|
||||
|
@ -226,7 +228,7 @@ func bp2buildParseStaticOrSharedProps(ctx android.BazelConversionPathContext, mo
|
|||
attrs := staticOrSharedAttributes{}
|
||||
|
||||
setAttrs := func(axis bazel.ConfigurationAxis, config string, props StaticOrSharedProperties) {
|
||||
attrs.Copts.SetSelectValue(axis, config, parseCommandLineFlags(props.Cflags, filterOutStdFlag))
|
||||
attrs.Copts.SetSelectValue(axis, config, parseCommandLineFlags(props.Cflags, filterOutStdFlag, filterOutHiddenVisibility))
|
||||
attrs.Srcs.SetSelectValue(axis, config, android.BazelLabelForModuleSrc(ctx, props.Srcs))
|
||||
attrs.System_dynamic_deps.SetSelectValue(axis, config, bazelLabelForSharedDeps(ctx, props.System_shared_libs))
|
||||
|
||||
|
@ -270,6 +272,8 @@ func bp2buildParseStaticOrSharedProps(ctx android.BazelConversionPathContext, mo
|
|||
|
||||
attrs.Apex_available = android.ConvertApexAvailableToTags(apexAvailable)
|
||||
|
||||
attrs.Features.Append(convertHiddenVisibilityToFeatureStaticOrShared(ctx, module, isStatic))
|
||||
|
||||
if !partitionedSrcs[protoSrcPartition].IsEmpty() {
|
||||
// TODO(b/208815215): determine whether this is used and add support if necessary
|
||||
ctx.ModuleErrorf("Migrating static/shared only proto srcs is not currently supported")
|
||||
|
@ -428,6 +432,12 @@ type compilerAttributes struct {
|
|||
|
||||
type filterOutFn func(string) bool
|
||||
|
||||
// filterOutHiddenVisibility removes the flag specifying hidden visibility as
|
||||
// this flag is converted to a toolchain feature
|
||||
func filterOutHiddenVisibility(flag string) bool {
|
||||
return flag == config.VisibilityHiddenFlag
|
||||
}
|
||||
|
||||
func filterOutStdFlag(flag string) bool {
|
||||
return strings.HasPrefix(flag, "-std=")
|
||||
}
|
||||
|
@ -490,7 +500,7 @@ func (ca *compilerAttributes) bp2buildForAxisAndConfig(ctx android.BazelConversi
|
|||
// overridden. In Bazel we always allow overriding, via flags; however, this can cause
|
||||
// incompatibilities, so we remove "-std=" flags from Cflag properties while leaving it in other
|
||||
// cases.
|
||||
ca.copts.SetSelectValue(axis, config, parseCommandLineFlags(props.Cflags, filterOutStdFlag, filterOutClangUnknownCflags))
|
||||
ca.copts.SetSelectValue(axis, config, parseCommandLineFlags(props.Cflags, filterOutStdFlag, filterOutClangUnknownCflags, filterOutHiddenVisibility))
|
||||
ca.asFlags.SetSelectValue(axis, config, parseCommandLineFlags(props.Asflags, nil))
|
||||
ca.conlyFlags.SetSelectValue(axis, config, parseCommandLineFlags(props.Conlyflags, filterOutClangUnknownCflags))
|
||||
ca.cppFlags.SetSelectValue(axis, config, parseCommandLineFlags(props.Cppflags, filterOutClangUnknownCflags))
|
||||
|
@ -833,6 +843,7 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module)
|
|||
|
||||
features := compilerAttrs.features.Clone().Append(linkerAttrs.features).Append(bp2buildSanitizerFeatures(ctx, module))
|
||||
features = features.Append(bp2buildLtoFeatures(ctx, module))
|
||||
features = features.Append(convertHiddenVisibilityToFeatureBase(ctx, module))
|
||||
features.DeduplicateAxesFromBase()
|
||||
|
||||
addMuslSystemDynamicDeps(ctx, linkerAttrs)
|
||||
|
@ -1547,3 +1558,38 @@ func bp2buildLtoFeatures(ctx android.BazelConversionPathContext, m *Module) baze
|
|||
}
|
||||
return ltoStringFeatures
|
||||
}
|
||||
|
||||
func convertHiddenVisibilityToFeatureBase(ctx android.BazelConversionPathContext, m *Module) bazel.StringListAttribute {
|
||||
visibilityHiddenFeature := bazel.StringListAttribute{}
|
||||
bp2BuildPropParseHelper(ctx, m, &BaseCompilerProperties{}, func(axis bazel.ConfigurationAxis, configString string, props interface{}) {
|
||||
if baseCompilerProps, ok := props.(*BaseCompilerProperties); ok {
|
||||
convertHiddenVisibilityToFeatureHelper(&visibilityHiddenFeature, axis, configString, baseCompilerProps.Cflags)
|
||||
}
|
||||
})
|
||||
return visibilityHiddenFeature
|
||||
}
|
||||
|
||||
func convertHiddenVisibilityToFeatureStaticOrShared(ctx android.BazelConversionPathContext, m *Module, isStatic bool) bazel.StringListAttribute {
|
||||
visibilityHiddenFeature := bazel.StringListAttribute{}
|
||||
if isStatic {
|
||||
bp2BuildPropParseHelper(ctx, m, &StaticProperties{}, func(axis bazel.ConfigurationAxis, configString string, props interface{}) {
|
||||
if staticProps, ok := props.(*StaticProperties); ok {
|
||||
convertHiddenVisibilityToFeatureHelper(&visibilityHiddenFeature, axis, configString, staticProps.Static.Cflags)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
bp2BuildPropParseHelper(ctx, m, &SharedProperties{}, func(axis bazel.ConfigurationAxis, configString string, props interface{}) {
|
||||
if sharedProps, ok := props.(*SharedProperties); ok {
|
||||
convertHiddenVisibilityToFeatureHelper(&visibilityHiddenFeature, axis, configString, sharedProps.Shared.Cflags)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return visibilityHiddenFeature
|
||||
}
|
||||
|
||||
func convertHiddenVisibilityToFeatureHelper(feature *bazel.StringListAttribute, axis bazel.ConfigurationAxis, configString string, cflags []string) {
|
||||
if inList(config.VisibilityHiddenFlag, cflags) {
|
||||
feature.SetSelectValue(axis, configString, []string{"visibility_hidden"})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -311,6 +311,11 @@ func libraryBp2Build(ctx android.TopDownMutatorContext, m *Module) {
|
|||
asFlags = bazel.MakeStringListAttribute(nil)
|
||||
}
|
||||
|
||||
sharedFeatures := baseAttributes.features.Clone().Append(sharedAttrs.Features)
|
||||
sharedFeatures.DeduplicateAxesFromBase()
|
||||
staticFeatures := baseAttributes.features.Clone().Append(staticAttrs.Features)
|
||||
staticFeatures.DeduplicateAxesFromBase()
|
||||
|
||||
staticCommonAttrs := staticOrSharedAttributes{
|
||||
Srcs: *srcs.Clone().Append(staticAttrs.Srcs),
|
||||
Srcs_c: *compilerAttrs.cSrcs.Clone().Append(staticAttrs.Srcs_c),
|
||||
|
@ -366,7 +371,7 @@ func libraryBp2Build(ctx android.TopDownMutatorContext, m *Module) {
|
|||
Cpp_std: compilerAttrs.cppStd,
|
||||
C_std: compilerAttrs.cStd,
|
||||
|
||||
Features: baseAttributes.features,
|
||||
Features: *staticFeatures,
|
||||
}
|
||||
|
||||
sharedTargetAttrs := &bazelCcLibrarySharedAttributes{
|
||||
|
@ -390,7 +395,7 @@ func libraryBp2Build(ctx android.TopDownMutatorContext, m *Module) {
|
|||
Additional_linker_inputs: linkerAttrs.additionalLinkerInputs,
|
||||
|
||||
Strip: stripAttrsFromLinkerAttrs(&linkerAttrs),
|
||||
Features: baseAttributes.features,
|
||||
Features: *sharedFeatures,
|
||||
bazelCcHeaderAbiCheckerAttributes: bp2buildParseAbiCheckerProps(ctx, m),
|
||||
|
||||
Fdo_profile: compilerAttrs.fdoProfile,
|
||||
|
@ -2881,6 +2886,9 @@ func sharedOrStaticLibraryBp2Build(ctx android.TopDownMutatorContext, module *Mo
|
|||
asFlags = bazel.MakeStringListAttribute(nil)
|
||||
}
|
||||
|
||||
features := baseAttributes.features.Clone().Append(libSharedOrStaticAttrs.Features)
|
||||
features.DeduplicateAxesFromBase()
|
||||
|
||||
commonAttrs := staticOrSharedAttributes{
|
||||
Srcs: compilerAttrs.srcs,
|
||||
Srcs_c: compilerAttrs.cSrcs,
|
||||
|
@ -2922,7 +2930,7 @@ func sharedOrStaticLibraryBp2Build(ctx android.TopDownMutatorContext, module *Mo
|
|||
Conlyflags: compilerAttrs.conlyFlags,
|
||||
Asflags: asFlags,
|
||||
|
||||
Features: baseAttributes.features,
|
||||
Features: *features,
|
||||
}
|
||||
} else {
|
||||
commonAttrs.Dynamic_deps.Add(baseAttributes.protoDependency)
|
||||
|
@ -2951,7 +2959,7 @@ func sharedOrStaticLibraryBp2Build(ctx android.TopDownMutatorContext, module *Mo
|
|||
|
||||
Strip: stripAttrsFromLinkerAttrs(&linkerAttrs),
|
||||
|
||||
Features: baseAttributes.features,
|
||||
Features: *features,
|
||||
|
||||
Suffix: compilerAttrs.suffix,
|
||||
|
||||
|
|
Loading…
Reference in a new issue