Convert apex_available (for supported modules) to bazel tags.
The tags will then be read by an aspect applied from apex attributes to
validate that the deps are explicitly opt-in to the appropriate apex.
The semantics of this is the same as the Soong apex_available property.
This also adds the "base_apex_name" attr to override_apex conversion so
that apex_available checks continue to work on the non-Google and non-Go
apex names.
Test: presubmits
Fixes: 218841706
Change-Id: I19b3637da9aa47573b252d74f62b601fbdc3784d
diff --git a/bp2build/apex_conversion_test.go b/bp2build/apex_conversion_test.go
index b6061e4..714b848 100644
--- a/bp2build/apex_conversion_test.go
+++ b/bp2build/apex_conversion_test.go
@@ -663,6 +663,7 @@
ExpectedBazelTargets: []string{
MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
"android_manifest": `"ApogeeAndroidManifest.xml"`,
+ "base_apex_name": `"com.android.apogee"`,
"binaries": `[
":cc_binary_1",
":sh_binary_2",
@@ -729,8 +730,9 @@
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
- "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
- "manifest": `"//a/b:apex_manifest.json"`,
+ "base_apex_name": `"com.android.apogee"`,
+ "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
+ "manifest": `"//a/b:apex_manifest.json"`,
}),
}})
}
@@ -763,8 +765,9 @@
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
- "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
- "manifest": `"//a/b:apogee_manifest.json"`,
+ "base_apex_name": `"com.android.apogee"`,
+ "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
+ "manifest": `"//a/b:apogee_manifest.json"`,
}),
}})
}
@@ -795,8 +798,9 @@
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
- "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
- "manifest": `"apex_manifest.json"`,
+ "base_apex_name": `"com.android.apogee"`,
+ "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
+ "manifest": `"apex_manifest.json"`,
}),
}})
}
@@ -828,8 +832,9 @@
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
- "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
- "manifest": `"apogee_manifest.json"`,
+ "base_apex_name": `"com.android.apogee"`,
+ "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
+ "manifest": `"apogee_manifest.json"`,
}),
}})
}
@@ -861,9 +866,10 @@
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
- "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
- "manifest": `"apex_manifest.json"`,
- "package_name": `"com.google.android.apogee"`,
+ "base_apex_name": `"com.android.apogee"`,
+ "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
+ "manifest": `"apex_manifest.json"`,
+ "package_name": `"com.google.android.apogee"`,
}),
}})
}
@@ -900,9 +906,10 @@
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
- "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
- "manifest": `"apex_manifest.json"`,
- "prebuilts": `[":prebuilt_file"]`,
+ "base_apex_name": `"com.android.apogee"`,
+ "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
+ "manifest": `"apex_manifest.json"`,
+ "prebuilts": `[":prebuilt_file"]`,
}),
}})
}
@@ -945,9 +952,10 @@
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
- "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
- "manifest": `"apex_manifest.json"`,
- "prebuilts": `[":prebuilt_file2"]`,
+ "base_apex_name": `"com.android.apogee"`,
+ "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
+ "manifest": `"apex_manifest.json"`,
+ "prebuilts": `[":prebuilt_file2"]`,
}),
}})
}
@@ -985,9 +993,10 @@
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
- "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
- "manifest": `"apex_manifest.json"`,
- "prebuilts": `[]`,
+ "base_apex_name": `"com.android.apogee"`,
+ "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
+ "manifest": `"apex_manifest.json"`,
+ "prebuilts": `[]`,
}),
}})
}
@@ -1019,6 +1028,7 @@
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
+ "base_apex_name": `"com.android.apogee"`,
"file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
"manifest": `"apex_manifest.json"`,
"logging_parent": `"foo.bar.baz"`,
@@ -1054,6 +1064,7 @@
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
+ "base_apex_name": `"com.android.apogee"`,
"file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
"manifest": `"apex_manifest.json"`,
"logging_parent": `"foo.bar.baz.override"`,
@@ -1099,8 +1110,9 @@
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
- "file_contexts": `":com.android.apogee-file_contexts"`,
- "manifest": `"apogee_manifest.json"`,
+ "base_apex_name": `"com.android.apogee"`,
+ "file_contexts": `":com.android.apogee-file_contexts"`,
+ "manifest": `"apogee_manifest.json"`,
}),
}})
}
@@ -1200,9 +1212,10 @@
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
- "file_contexts": `":com.android.apogee-file_contexts"`,
- "certificate": `":com.google.android.apogee.certificate"`,
- "manifest": `"apogee_manifest.json"`,
+ "base_apex_name": `"com.android.apogee"`,
+ "file_contexts": `":com.android.apogee-file_contexts"`,
+ "certificate": `":com.google.android.apogee.certificate"`,
+ "manifest": `"apogee_manifest.json"`,
}),
}})
}
@@ -1244,6 +1257,7 @@
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
+ "base_apex_name": `"com.android.apogee"`,
"file_contexts": `":com.android.apogee-file_contexts"`,
"certificate_name": `"com.google.android.apogee.certificate"`,
"manifest": `"apogee_manifest.json"`,
diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go
index edb0c43..a1e83d8 100644
--- a/bp2build/cc_library_conversion_test.go
+++ b/bp2build/cc_library_conversion_test.go
@@ -3645,3 +3645,49 @@
},
})
}
+
+func TestCcLibraryApexAvailable(t *testing.T) {
+ runCcLibraryTestCase(t, Bp2buildTestCase{
+ Description: "cc_library apex_available converted to tags",
+ ModuleTypeUnderTest: "cc_library",
+ ModuleTypeUnderTestFactory: cc.LibraryFactory,
+ Blueprint: soongCcLibraryPreamble + `
+cc_library {
+ name: "a",
+ srcs: ["a.cpp"],
+ apex_available: ["com.android.foo"],
+}
+`,
+ ExpectedBazelTargets: makeCcLibraryTargets("a", AttrNameToString{
+ "tags": `["apex_available=com.android.foo"]`,
+ "srcs": `["a.cpp"]`,
+ "local_includes": `["."]`,
+ }),
+ },
+ )
+}
+
+func TestCcLibraryApexAvailableMultiple(t *testing.T) {
+ runCcLibraryTestCase(t, Bp2buildTestCase{
+ Description: "cc_library apex_available converted to multiple tags",
+ ModuleTypeUnderTest: "cc_library",
+ ModuleTypeUnderTestFactory: cc.LibraryFactory,
+ Blueprint: soongCcLibraryPreamble + `
+cc_library {
+ name: "a",
+ srcs: ["a.cpp"],
+ apex_available: ["com.android.foo", "//apex_available:platform", "com.android.bar"],
+}
+`,
+ ExpectedBazelTargets: makeCcLibraryTargets("a", AttrNameToString{
+ "tags": `[
+ "apex_available=com.android.foo",
+ "apex_available=//apex_available:platform",
+ "apex_available=com.android.bar",
+ ]`,
+ "srcs": `["a.cpp"]`,
+ "local_includes": `["."]`,
+ }),
+ },
+ )
+}