bp2build support for stem
By default, the artifacts generated by cc_binary and cc_library in Soong
track the module name. But Soong supports overidding this using the stem
property. e.g.
```
cc_library {
name: "foo.1.2",
stem: "foo",
}
```
will generate foo.so
This CL adds this property to bp2build
Test: bp2build unit tests
Bug: 240563612
Change-Id: I1dfed870d5bad450511b72c397d2355c01fa3b60
diff --git a/bp2build/cc_binary_conversion_test.go b/bp2build/cc_binary_conversion_test.go
index 610a9ca..d37722b 100644
--- a/bp2build/cc_binary_conversion_test.go
+++ b/bp2build/cc_binary_conversion_test.go
@@ -1106,3 +1106,40 @@
},
})
}
+
+func TestCcBinaryStem(t *testing.T) {
+ runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{
+ description: "cc_binary with stem property",
+ blueprint: `
+cc_binary {
+ name: "foo_with_stem_simple",
+ stem: "foo",
+}
+cc_binary {
+ name: "foo_with_arch_variant_stem",
+ arch: {
+ arm: {
+ stem: "foo-arm",
+ },
+ arm64: {
+ stem: "foo-arm64",
+ },
+ },
+}
+`,
+ targets: []testBazelTarget{
+ {"cc_binary", "foo_with_stem_simple", AttrNameToString{
+ "stem": `"foo"`,
+ "local_includes": `["."]`,
+ }},
+ {"cc_binary", "foo_with_arch_variant_stem", AttrNameToString{
+ "stem": `select({
+ "//build/bazel/platforms/arch:arm": "foo-arm",
+ "//build/bazel/platforms/arch:arm64": "foo-arm64",
+ "//conditions:default": None,
+ })`,
+ "local_includes": `["."]`,
+ }},
+ },
+ })
+}
diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go
index c2dba67..20f3bf6 100644
--- a/bp2build/cc_library_conversion_test.go
+++ b/bp2build/cc_library_conversion_test.go
@@ -4812,3 +4812,42 @@
},
})
}
+
+func TestCcLibraryWithStem(t *testing.T) {
+ runCcLibraryTestCase(t, Bp2buildTestCase{
+ Description: "cc_library with stem property",
+ ModuleTypeUnderTest: "cc_library_shared",
+ ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
+ Blueprint: soongCcLibraryPreamble + `
+cc_library_shared {
+ name: "foo_with_stem_simple",
+ stem: "foo",
+}
+cc_library_shared {
+ name: "foo_with_arch_variant_stem",
+ arch: {
+ arm: {
+ stem: "foo-arm",
+ },
+ arm64: {
+ stem: "foo-arm64",
+ },
+ },
+}
+`,
+ ExpectedBazelTargets: []string{
+ MakeBazelTarget("cc_library_shared", "foo_with_stem_simple", AttrNameToString{
+ "stem": `"foo"`,
+ "local_includes": `["."]`,
+ }),
+ MakeBazelTarget("cc_library_shared", "foo_with_arch_variant_stem", AttrNameToString{
+ "stem": `select({
+ "//build/bazel/platforms/arch:arm": "foo-arm",
+ "//build/bazel/platforms/arch:arm64": "foo-arm64",
+ "//conditions:default": None,
+ })`,
+ "local_includes": `["."]`,
+ }),
+ },
+ })
+}
diff --git a/cc/bp2build.go b/cc/bp2build.go
index 34cc574..1e83ca3 100644
--- a/cc/bp2build.go
+++ b/cc/bp2build.go
@@ -434,6 +434,7 @@
features bazel.StringListAttribute
+ stem bazel.StringAttribute
suffix bazel.StringAttribute
fdoProfile bazel.LabelAttribute
@@ -819,6 +820,9 @@
compilerAttrs.stubsVersions.SetSelectValue(axis, cfg, versions)
}
}
+ if stem := libraryProps.Stem; stem != nil {
+ compilerAttrs.stem.SetSelectValue(axis, cfg, stem)
+ }
if suffix := libraryProps.Suffix; suffix != nil {
compilerAttrs.suffix.SetSelectValue(axis, cfg, suffix)
}
@@ -1737,6 +1741,7 @@
type binaryLinkerAttrs struct {
Linkshared *bool
+ Stem bazel.StringAttribute
Suffix bazel.StringAttribute
}
@@ -1754,6 +1759,9 @@
// nonconfigurable attribute. Only 4 AOSP modules use this feature, defer handling
ctx.ModuleErrorf("bp2build cannot migrate a module with arch/target-specific static_executable values")
}
+ if stem := linkerProps.Stem; stem != nil {
+ attrs.Stem.SetSelectValue(axis, config, stem)
+ }
if suffix := linkerProps.Suffix; suffix != nil {
attrs.Suffix.SetSelectValue(axis, config, suffix)
}
diff --git a/cc/library.go b/cc/library.go
index 98096a8..47df53e 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -408,6 +408,7 @@
sharedTargetAttrs.Stubs_symbol_file = compilerAttrs.stubsSymbolFile
}
+ sharedTargetAttrs.Stem = compilerAttrs.stem
sharedTargetAttrs.Suffix = compilerAttrs.suffix
for axis, configToProps := range m.GetArchVariantProperties(ctx, &LibraryProperties{}) {
@@ -2987,6 +2988,7 @@
Features: *features,
+ Stem: compilerAttrs.stem,
Suffix: compilerAttrs.suffix,
bazelCcHeaderAbiCheckerAttributes: bp2buildParseAbiCheckerProps(ctx, module),
@@ -3072,6 +3074,7 @@
Inject_bssl_hash bazel.BoolAttribute
+ Stem bazel.StringAttribute
Suffix bazel.StringAttribute
bazelCcHeaderAbiCheckerAttributes