Allow stubs implementation to be omitted
When defining a stubs library, allow specifying that the
implementation library does not need to be installed. This allows for
cases where the implementation is deployed in some non-standard way -
e.g. inside a Microdroid virtual machine.
Without this, we get build errors like: "TARGET module
com.android.compos requires non-existent TARGET module: libvm_payload".
Default behavior is unchanged. The change is protected by an allowlist
to limit usage to the immediate use case.
Bug: 243512108
Test: builds; soong tests pass
Test: Remove allowlist, see build failure
Change-Id: Iaae75f2e93b842f5944a7518cc95069d62c5a638
diff --git a/android/neverallow.go b/android/neverallow.go
index 293bac8..ad9880a 100644
--- a/android/neverallow.go
+++ b/android/neverallow.go
@@ -59,6 +59,7 @@
AddNeverAllowRules(createInitFirstStageRules()...)
AddNeverAllowRules(createProhibitFrameworkAccessRules()...)
AddNeverAllowRules(createBp2BuildRule())
+ AddNeverAllowRules(createCcStubsRule())
}
// Add a NeverAllow rule to the set of rules to apply.
@@ -214,6 +215,17 @@
}
}
+func createCcStubsRule() Rule {
+ ccStubsImplementationInstallableProjectsAllowedList := []string{
+ "packages/modules/Virtualization/vm_payload",
+ }
+
+ return NeverAllow().
+ NotIn(ccStubsImplementationInstallableProjectsAllowedList...).
+ WithMatcher("stubs.implementation_installable", isSetMatcherInstance).
+ Because("implementation_installable can only be used in allowed projects.")
+}
+
func createUncompressDexRules() []Rule {
return []Rule{
NeverAllow().
diff --git a/android/neverallow_test.go b/android/neverallow_test.go
index 4772799..5f5f9a1 100644
--- a/android/neverallow_test.go
+++ b/android/neverallow_test.go
@@ -367,6 +367,22 @@
"framework can't be used when building against SDK",
},
},
+ // Test for the rule restricting use of implementation_installable
+ {
+ name: `"implementation_installable" outside allowed list`,
+ fs: map[string][]byte{
+ "Android.bp": []byte(`
+ cc_library {
+ name: "outside_allowed_list",
+ stubs: {
+ implementation_installable: true,
+ },
+ }`),
+ },
+ expectedErrors: []string{
+ `module "outside_allowed_list": violates neverallow`,
+ },
+ },
}
var prepareForNeverAllowTest = GroupFixturePreparers(
@@ -419,6 +435,10 @@
Platform struct {
Shared_libs []string
}
+
+ Stubs struct {
+ Implementation_installable *bool
+ }
}
type mockCcLibraryModule struct {