For test apexes, base_apex_name is the api domain
apex_test do not "override" the source apexes that they test. However,
similar to override_apexes, test apexes have the same path
(/apex/<apex_name>) on device. Instead of creating another property,
reuse the existing base_apex_name property. The use case for this will
be for creating selection statements for stub/impl selection.
Test: go test ./bp2build
Change-Id: I4b7548e0e0fc920e407e1c5e5c00e87efc6e70c9
diff --git a/apex/apex.go b/apex/apex.go
index 69547c3..e01406b 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -3703,6 +3703,8 @@
commonAttrs := android.CommonAttributes{}
if a.testApex {
commonAttrs.Testonly = proptools.BoolPtr(true)
+ // Set the api_domain of the test apex
+ attrs.Base_apex_name = proptools.StringPtr(cc.GetApiDomain(a.Name()))
}
return attrs, props, commonAttrs
diff --git a/bp2build/apex_conversion_test.go b/bp2build/apex_conversion_test.go
index 1cc3f22..390cabe 100644
--- a/bp2build/apex_conversion_test.go
+++ b/bp2build/apex_conversion_test.go
@@ -1475,10 +1475,11 @@
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("apex", "test_com.android.apogee", AttrNameToString{
- "file_contexts": `"file_contexts_file"`,
- "manifest": `"apex_manifest.json"`,
- "testonly": `True`,
- "tests": `[":cc_test_1"]`,
+ "file_contexts": `"file_contexts_file"`,
+ "base_apex_name": `"com.android.apogee"`,
+ "manifest": `"apex_manifest.json"`,
+ "testonly": `True`,
+ "tests": `[":cc_test_1"]`,
}),
}})
}
diff --git a/cc/bp2build.go b/cc/bp2build.go
index 6e91bff..ca8d609 100644
--- a/cc/bp2build.go
+++ b/cc/bp2build.go
@@ -1210,7 +1210,11 @@
}
)
-func getApiDomain(apexName string) string {
+// GetApiDomain returns the canonical name of the apex. This is synonymous to the apex_name definition.
+// https://cs.android.com/android/_/android/platform/build/soong/+/e3f0281b8897da1fe23b2f4f3a05f1dc87bcc902:apex/prebuilt.go;l=81-83;drc=2dc7244af985a6ad701b22f1271e606cabba527f;bpv=1;bpt=0
+// For test apexes, it uses a naming convention heuristic to determine the api domain.
+// TODO (b/281548611): Move this build/soong/android
+func GetApiDomain(apexName string) string {
if apiDomain, exists := testApexNameToApiDomain[apexName]; exists {
return apiDomain
}
@@ -1233,7 +1237,7 @@
defer apiDomainConfigSettingLock.Unlock()
// Return if a config_setting has already been created
- apiDomain := getApiDomain(apexName)
+ apiDomain := GetApiDomain(apexName)
acsm := getApiDomainConfigSettingMap(ctx.Config())
if _, exists := (*acsm)[apiDomain]; exists {
return
@@ -1270,7 +1274,7 @@
if apexAvailable == android.AvailableToAnyApex {
return bazel.AndroidAndInApex
}
- apiDomain := getApiDomain(apexAvailable)
+ apiDomain := GetApiDomain(apexAvailable)
return "//build/bazel/rules/apex:" + apiDomain
}