summaryrefslogtreecommitdiff
path: root/android/neverallow.go
diff options
context:
space:
mode:
author Jihoon Kang <jihoonkang@google.com> 2024-11-01 21:21:25 +0000
committer Jihoon Kang <jihoonkang@google.com> 2024-11-01 22:28:27 +0000
commit2a7bf750e7fed942ecdb7f0b80b8fb226f584d61 (patch)
tree3923ad45435f22e62b063f0dfa3511cbaa52d372 /android/neverallow.go
parent0da5ae93286f56ac444306f9d4b101f9955763b8 (diff)
Add a neverallow rule for prebuilt_* module types
This change adds a neverallow rule to the following module types: - prebuilt_usr_srec - prebuilt_priv_app - prebuilt_rfs - prebuilt_framework - prebuilt_res - prebuilt_wlc_upt - prebuilt_odm that these modules cannot be defined in bp files, but can only be auto generated by other modules. Test: m nothing --no-skip-soong-tests Bug: 375053752 Change-Id: Ie1b73966d8ada3863c29f9aca710aa8c735286dd
Diffstat (limited to 'android/neverallow.go')
-rw-r--r--android/neverallow.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/android/neverallow.go b/android/neverallow.go
index 44ac2cd6c..7fb22bf13 100644
--- a/android/neverallow.go
+++ b/android/neverallow.go
@@ -63,6 +63,7 @@ func init() {
AddNeverAllowRules(createLimitDirgroupRule()...)
AddNeverAllowRules(createFilesystemIsAutoGeneratedRule())
AddNeverAllowRules(createKotlinPluginRule()...)
+ AddNeverAllowRules(createPrebuiltEtcBpDefineRule())
}
// Add a NeverAllow rule to the set of rules to apply.
@@ -321,6 +322,23 @@ func createKotlinPluginRule() []Rule {
}
}
+// These module types are introduced to convert PRODUCT_COPY_FILES to Soong,
+// and is only intended to be used by filesystem_creator.
+func createPrebuiltEtcBpDefineRule() Rule {
+ return NeverAllow().
+ ModuleType(
+ "prebuilt_usr_srec",
+ "prebuilt_priv_app",
+ "prebuilt_rfs",
+ "prebuilt_framework",
+ "prebuilt_res",
+ "prebuilt_wlc_upt",
+ "prebuilt_odm",
+ ).
+ DefinedInBpFile().
+ Because("module type not allowed to be defined in bp file")
+}
+
func neverallowMutator(ctx BottomUpMutatorContext) {
m, ok := ctx.Module().(Module)
if !ok {
@@ -354,6 +372,10 @@ func neverallowMutator(ctx BottomUpMutatorContext) {
continue
}
+ if !n.appliesToBpDefinedModule(ctx) {
+ continue
+ }
+
ctx.ModuleErrorf("violates " + n.String())
}
}
@@ -477,6 +499,8 @@ type Rule interface {
WithoutMatcher(properties string, matcher ValueMatcher) Rule
+ DefinedInBpFile() Rule
+
Because(reason string) Rule
}
@@ -498,6 +522,8 @@ type rule struct {
unlessProps ruleProperties
onlyBootclasspathJar bool
+
+ definedInBp bool
}
// Create a new NeverAllow rule.
@@ -571,6 +597,13 @@ func (r *rule) WithoutMatcher(properties string, matcher ValueMatcher) Rule {
return r
}
+// DefinedInBpFile specifies that this rule applies to modules that are defined
+// in bp files, and does not apply to modules that are auto generated by other modules.
+func (r *rule) DefinedInBpFile() Rule {
+ r.definedInBp = true
+ return r
+}
+
func selectMatcher(expected string) ValueMatcher {
if expected == "*" {
return anyMatcherInstance
@@ -665,6 +698,13 @@ func (r *rule) appliesToProperties(ctx BottomUpMutatorContext, properties []inte
return includeProps && !excludeProps
}
+func (r *rule) appliesToBpDefinedModule(ctx BottomUpMutatorContext) bool {
+ if !r.definedInBp {
+ return true
+ }
+ return !ctx.OtherModuleIsAutoGenerated(ctx.Module()) == r.definedInBp
+}
+
func StartsWith(prefix string) ValueMatcher {
return &startsWithMatcher{prefix}
}