Loading android/mutator.go +1 −1 Original line number Diff line number Diff line Loading @@ -202,7 +202,7 @@ var postDeps = []RegisterMutatorFunc{ RegisterPrebuiltsPostDepsMutators, RegisterVisibilityRuleEnforcer, RegisterLicensesDependencyChecker, RegisterNeverallowMutator, registerNeverallowMutator, RegisterOverridePostDepsMutators, } Loading android/neverallow.go +18 −2 Original line number Diff line number Diff line Loading @@ -42,7 +42,7 @@ import ( // counts as a match // - it has none of the "Without" properties matched (same rules as above) func RegisterNeverallowMutator(ctx RegisterMutatorsContext) { func registerNeverallowMutator(ctx RegisterMutatorsContext) { ctx.BottomUp("neverallow", neverallowMutator).Parallel() } Loading Loading @@ -661,6 +661,22 @@ func neverallowRules(config Config) []Rule { // Overrides the default neverallow rules for the supplied config. // // For testing only. func SetTestNeverallowRules(config Config, testRules []Rule) { func setTestNeverallowRules(config Config, testRules []Rule) { config.Once(neverallowRulesKey, func() interface{} { return testRules }) } // Prepares for a test by setting neverallow rules and enabling the mutator. // // If the supplied rules are nil then the default rules are used. func PrepareForTestWithNeverallowRules(testRules []Rule) FixturePreparer { return GroupFixturePreparers( FixtureModifyConfig(func(config Config) { if testRules != nil { setTestNeverallowRules(config, testRules) } }), FixtureRegisterWithContext(func(ctx RegistrationContext) { ctx.PostDepsMutators(registerNeverallowMutator) }), ) } android/neverallow_test.go +1 −7 Original line number Diff line number Diff line Loading @@ -292,7 +292,6 @@ var prepareForNeverAllowTest = GroupFixturePreparers( ctx.RegisterModuleType("java_library_host", newMockJavaLibraryModule) ctx.RegisterModuleType("java_device_for_host", newMockJavaLibraryModule) ctx.RegisterModuleType("makefile_goal", newMockMakefileGoalModule) ctx.PostDepsMutators(RegisterNeverallowMutator) }), ) Loading @@ -301,12 +300,7 @@ func TestNeverallow(t *testing.T) { t.Run(test.name, func(t *testing.T) { GroupFixturePreparers( prepareForNeverAllowTest, FixtureModifyConfig(func(config Config) { // If the test has its own rules then use them instead of the default ones. if test.rules != nil { SetTestNeverallowRules(config, test.rules) } }), PrepareForTestWithNeverallowRules(test.rules), test.fs.AddToFixture(), ). ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern(test.expectedErrors)). Loading apex/apex_test.go +20 −32 Original line number Diff line number Diff line Loading @@ -6658,45 +6658,33 @@ func testApexPermittedPackagesRules(t *testing.T, errmsg, bp string, apexBootJar public_key: "testkey.avbpubkey", private_key: "testkey.pem", }` fs := map[string][]byte{ fs := android.MockFS{ "lib1/src/A.java": nil, "lib2/src/B.java": nil, "system/sepolicy/apex/myapex-file_contexts": nil, } config := android.TestArchConfig(t.TempDir(), nil, bp, fs) android.SetTestNeverallowRules(config, rules) errorHandler := android.FixtureExpectsNoErrors if errmsg != "" { errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern(errmsg) } android.GroupFixturePreparers( android.PrepareForTestWithAndroidBuildComponents, java.PrepareForTestWithJavaBuildComponents, PrepareForTestWithApexBuildComponents, android.PrepareForTestWithNeverallowRules(rules), android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { updatableBootJars := make([]string, 0, len(apexBootJars)) for _, apexBootJar := range apexBootJars { updatableBootJars = append(updatableBootJars, "myapex:"+apexBootJar) } config.TestProductVariables.UpdatableBootJars = android.CreateTestConfiguredJarList(updatableBootJars) ctx := android.NewTestArchContext(config) ctx.RegisterModuleType("apex", BundleFactory) ctx.RegisterModuleType("apex_key", ApexKeyFactory) ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) cc.RegisterRequiredBuildComponentsForTest(ctx) java.RegisterRequiredBuildComponentsForTest(ctx) ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators) ctx.PreDepsMutators(RegisterPreDepsMutators) ctx.PostDepsMutators(RegisterPostDepsMutators) ctx.PostDepsMutators(android.RegisterNeverallowMutator) ctx.Register() _, errs := ctx.ParseBlueprintsFiles("Android.bp") android.FailIfErrored(t, errs) _, errs = ctx.PrepareBuildActions(config) if errmsg == "" { android.FailIfErrored(t, errs) } else if len(errs) > 0 { android.FailIfNoMatchingErrors(t, errmsg, errs) return } else { t.Fatalf("missing expected error %q (0 errors are returned)", errmsg) } variables.UpdatableBootJars = android.CreateTestConfiguredJarList(updatableBootJars) }), fs.AddToFixture(), ). ExtendWithErrorHandler(errorHandler). RunTestWithBp(t, bp) } func TestApexPermittedPackagesRules(t *testing.T) { Loading Loading
android/mutator.go +1 −1 Original line number Diff line number Diff line Loading @@ -202,7 +202,7 @@ var postDeps = []RegisterMutatorFunc{ RegisterPrebuiltsPostDepsMutators, RegisterVisibilityRuleEnforcer, RegisterLicensesDependencyChecker, RegisterNeverallowMutator, registerNeverallowMutator, RegisterOverridePostDepsMutators, } Loading
android/neverallow.go +18 −2 Original line number Diff line number Diff line Loading @@ -42,7 +42,7 @@ import ( // counts as a match // - it has none of the "Without" properties matched (same rules as above) func RegisterNeverallowMutator(ctx RegisterMutatorsContext) { func registerNeverallowMutator(ctx RegisterMutatorsContext) { ctx.BottomUp("neverallow", neverallowMutator).Parallel() } Loading Loading @@ -661,6 +661,22 @@ func neverallowRules(config Config) []Rule { // Overrides the default neverallow rules for the supplied config. // // For testing only. func SetTestNeverallowRules(config Config, testRules []Rule) { func setTestNeverallowRules(config Config, testRules []Rule) { config.Once(neverallowRulesKey, func() interface{} { return testRules }) } // Prepares for a test by setting neverallow rules and enabling the mutator. // // If the supplied rules are nil then the default rules are used. func PrepareForTestWithNeverallowRules(testRules []Rule) FixturePreparer { return GroupFixturePreparers( FixtureModifyConfig(func(config Config) { if testRules != nil { setTestNeverallowRules(config, testRules) } }), FixtureRegisterWithContext(func(ctx RegistrationContext) { ctx.PostDepsMutators(registerNeverallowMutator) }), ) }
android/neverallow_test.go +1 −7 Original line number Diff line number Diff line Loading @@ -292,7 +292,6 @@ var prepareForNeverAllowTest = GroupFixturePreparers( ctx.RegisterModuleType("java_library_host", newMockJavaLibraryModule) ctx.RegisterModuleType("java_device_for_host", newMockJavaLibraryModule) ctx.RegisterModuleType("makefile_goal", newMockMakefileGoalModule) ctx.PostDepsMutators(RegisterNeverallowMutator) }), ) Loading @@ -301,12 +300,7 @@ func TestNeverallow(t *testing.T) { t.Run(test.name, func(t *testing.T) { GroupFixturePreparers( prepareForNeverAllowTest, FixtureModifyConfig(func(config Config) { // If the test has its own rules then use them instead of the default ones. if test.rules != nil { SetTestNeverallowRules(config, test.rules) } }), PrepareForTestWithNeverallowRules(test.rules), test.fs.AddToFixture(), ). ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern(test.expectedErrors)). Loading
apex/apex_test.go +20 −32 Original line number Diff line number Diff line Loading @@ -6658,45 +6658,33 @@ func testApexPermittedPackagesRules(t *testing.T, errmsg, bp string, apexBootJar public_key: "testkey.avbpubkey", private_key: "testkey.pem", }` fs := map[string][]byte{ fs := android.MockFS{ "lib1/src/A.java": nil, "lib2/src/B.java": nil, "system/sepolicy/apex/myapex-file_contexts": nil, } config := android.TestArchConfig(t.TempDir(), nil, bp, fs) android.SetTestNeverallowRules(config, rules) errorHandler := android.FixtureExpectsNoErrors if errmsg != "" { errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern(errmsg) } android.GroupFixturePreparers( android.PrepareForTestWithAndroidBuildComponents, java.PrepareForTestWithJavaBuildComponents, PrepareForTestWithApexBuildComponents, android.PrepareForTestWithNeverallowRules(rules), android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { updatableBootJars := make([]string, 0, len(apexBootJars)) for _, apexBootJar := range apexBootJars { updatableBootJars = append(updatableBootJars, "myapex:"+apexBootJar) } config.TestProductVariables.UpdatableBootJars = android.CreateTestConfiguredJarList(updatableBootJars) ctx := android.NewTestArchContext(config) ctx.RegisterModuleType("apex", BundleFactory) ctx.RegisterModuleType("apex_key", ApexKeyFactory) ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) cc.RegisterRequiredBuildComponentsForTest(ctx) java.RegisterRequiredBuildComponentsForTest(ctx) ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators) ctx.PreDepsMutators(RegisterPreDepsMutators) ctx.PostDepsMutators(RegisterPostDepsMutators) ctx.PostDepsMutators(android.RegisterNeverallowMutator) ctx.Register() _, errs := ctx.ParseBlueprintsFiles("Android.bp") android.FailIfErrored(t, errs) _, errs = ctx.PrepareBuildActions(config) if errmsg == "" { android.FailIfErrored(t, errs) } else if len(errs) > 0 { android.FailIfNoMatchingErrors(t, errmsg, errs) return } else { t.Fatalf("missing expected error %q (0 errors are returned)", errmsg) } variables.UpdatableBootJars = android.CreateTestConfiguredJarList(updatableBootJars) }), fs.AddToFixture(), ). ExtendWithErrorHandler(errorHandler). RunTestWithBp(t, bp) } func TestApexPermittedPackagesRules(t *testing.T) { Loading