bp2build support for instruction_set
Convert `instruction_set: "arm"` to an "arm_isa_arm" bazel feature. Bug: 215719349 Test: go tests Change-Id: Ib976d23d2a57e8c0ab5d83ec994a0b7f3c69a7fe
This commit is contained in:
@@ -581,3 +581,32 @@ cc_library {
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcBinaryWithInstructionSet(t *testing.T) {
|
||||
runCcBinaryTests(t, ccBinaryBp2buildTestCase{
|
||||
description: "instruction set",
|
||||
blueprint: `
|
||||
{rule_name} {
|
||||
name: "foo",
|
||||
arch: {
|
||||
arm: {
|
||||
instruction_set: "arm",
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
targets: []testBazelTarget{
|
||||
{"cc_binary", "foo", AttrNameToString{
|
||||
"features": `select({
|
||||
"//build/bazel/platforms/arch:arm": [
|
||||
"arm_isa_arm",
|
||||
"-arm_isa_thumb",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
"local_includes": `["."]`,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
@@ -2566,3 +2566,29 @@ cc_library {
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcLibraryWithInstructionSet(t *testing.T) {
|
||||
runCcLibraryTestCase(t, Bp2buildTestCase{
|
||||
ModuleTypeUnderTest: "cc_library",
|
||||
ModuleTypeUnderTestFactory: cc.LibraryFactory,
|
||||
Blueprint: `cc_library {
|
||||
name: "foo",
|
||||
arch: {
|
||||
arm: {
|
||||
instruction_set: "arm",
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: makeCcLibraryTargets("foo", AttrNameToString{
|
||||
"features": `select({
|
||||
"//build/bazel/platforms/arch:arm": [
|
||||
"arm_isa_arm",
|
||||
"-arm_isa_thumb",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
"local_includes": `["."]`,
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
@@ -282,6 +282,8 @@ type baseAttributes struct {
|
||||
compilerAttributes
|
||||
linkerAttributes
|
||||
|
||||
// A combination of compilerAttributes.features and linkerAttributes.features
|
||||
features bazel.StringListAttribute
|
||||
protoDependency *bazel.LabelAttribute
|
||||
}
|
||||
|
||||
@@ -323,6 +325,8 @@ type compilerAttributes struct {
|
||||
|
||||
stubsSymbolFile *string
|
||||
stubsVersions bazel.StringListAttribute
|
||||
|
||||
features bazel.StringListAttribute
|
||||
}
|
||||
|
||||
type filterOutFn func(string) bool
|
||||
@@ -386,6 +390,13 @@ func (ca *compilerAttributes) bp2buildForAxisAndConfig(ctx android.BazelConversi
|
||||
ca.absoluteIncludes.SetSelectValue(axis, config, props.Include_dirs)
|
||||
ca.localIncludes.SetSelectValue(axis, config, localIncludeDirs)
|
||||
|
||||
instructionSet := proptools.StringDefault(props.Instruction_set, "")
|
||||
if instructionSet == "arm" {
|
||||
ca.features.SetSelectValue(axis, config, []string{"arm_isa_arm", "-arm_isa_thumb"})
|
||||
} else if instructionSet != "" && instructionSet != "thumb" {
|
||||
ctx.ModuleErrorf("Unknown value for instruction_set: %s", instructionSet)
|
||||
}
|
||||
|
||||
// In Soong, cflags occur on the command line before -std=<val> flag, resulting in the value being
|
||||
// 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
|
||||
@@ -686,9 +697,13 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module)
|
||||
(&compilerAttrs).srcs.Add(&convertedLSrcs.srcName)
|
||||
(&compilerAttrs).cSrcs.Add(&convertedLSrcs.cSrcName)
|
||||
|
||||
features := compilerAttrs.features.Clone().Append(linkerAttrs.features)
|
||||
features.DeduplicateAxesFromBase()
|
||||
|
||||
return baseAttributes{
|
||||
compilerAttrs,
|
||||
linkerAttrs,
|
||||
*features,
|
||||
protoDep.protoDep,
|
||||
}
|
||||
}
|
||||
|
@@ -359,7 +359,7 @@ func libraryBp2Build(ctx android.TopDownMutatorContext, m *Module) {
|
||||
C_std: compilerAttrs.cStd,
|
||||
Use_version_lib: linkerAttrs.useVersionLib,
|
||||
|
||||
Features: linkerAttrs.features,
|
||||
Features: baseAttributes.features,
|
||||
}
|
||||
|
||||
sharedTargetAttrs := &bazelCcLibrarySharedAttributes{
|
||||
@@ -391,7 +391,7 @@ func libraryBp2Build(ctx android.TopDownMutatorContext, m *Module) {
|
||||
All: linkerAttrs.stripAll,
|
||||
None: linkerAttrs.stripNone,
|
||||
},
|
||||
Features: linkerAttrs.features,
|
||||
Features: baseAttributes.features,
|
||||
}
|
||||
|
||||
if compilerAttrs.stubsSymbolFile != nil && len(compilerAttrs.stubsVersions.Value) > 0 {
|
||||
@@ -2600,7 +2600,7 @@ func sharedOrStaticLibraryBp2Build(ctx android.TopDownMutatorContext, module *Mo
|
||||
Conlyflags: compilerAttrs.conlyFlags,
|
||||
Asflags: asFlags,
|
||||
|
||||
Features: linkerAttrs.features,
|
||||
Features: baseAttributes.features,
|
||||
}
|
||||
} else {
|
||||
commonAttrs.Dynamic_deps.Add(baseAttributes.protoDependency)
|
||||
@@ -2637,7 +2637,7 @@ func sharedOrStaticLibraryBp2Build(ctx android.TopDownMutatorContext, module *Mo
|
||||
None: linkerAttrs.stripNone,
|
||||
},
|
||||
|
||||
Features: linkerAttrs.features,
|
||||
Features: baseAttributes.features,
|
||||
}
|
||||
if compilerAttrs.stubsSymbolFile != nil && len(compilerAttrs.stubsVersions.Value) > 0 {
|
||||
hasStubs := true
|
||||
|
Reference in New Issue
Block a user