Loading android/base_module_context.go +8 −0 Original line number Diff line number Diff line Loading @@ -87,6 +87,10 @@ type BaseModuleContext interface { // This method shouldn't be used directly, prefer the type-safe android.OtherModuleProvider instead. otherModuleProvider(m blueprint.Module, provider blueprint.AnyProviderKey) (any, bool) // OtherModuleIsAutoGenerated returns true if the module is auto generated by another module // instead of being defined in Android.bp file. OtherModuleIsAutoGenerated(m blueprint.Module) bool // Provider returns the value for a provider for the current module. If the value is // not set it returns nil and false. It panics if called before the appropriate // mutator or GenerateBuildActions pass for the provider. The value returned may be a deep Loading Loading @@ -275,6 +279,10 @@ func (b *baseModuleContext) otherModuleProvider(m blueprint.Module, provider blu return b.bp.OtherModuleProvider(m, provider) } func (b *baseModuleContext) OtherModuleIsAutoGenerated(m blueprint.Module) bool { return b.bp.OtherModuleIsAutoGenerated(m) } func (b *baseModuleContext) provider(provider blueprint.AnyProviderKey) (any, bool) { return b.bp.Provider(provider) } Loading android/neverallow.go +40 −0 Original line number Diff line number Diff line Loading @@ -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. Loading Loading @@ -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 { Loading Loading @@ -354,6 +372,10 @@ func neverallowMutator(ctx BottomUpMutatorContext) { continue } if !n.appliesToBpDefinedModule(ctx) { continue } ctx.ModuleErrorf("violates " + n.String()) } } Loading Loading @@ -477,6 +499,8 @@ type Rule interface { WithoutMatcher(properties string, matcher ValueMatcher) Rule DefinedInBpFile() Rule Because(reason string) Rule } Loading @@ -498,6 +522,8 @@ type rule struct { unlessProps ruleProperties onlyBootclasspathJar bool definedInBp bool } // Create a new NeverAllow rule. Loading Loading @@ -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 Loading Loading @@ -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} } Loading android/neverallow_test.go +28 −0 Original line number Diff line number Diff line Loading @@ -374,6 +374,20 @@ var neverallowTests = []struct { `is_auto_generated property is only allowed for filesystem modules in build/soong/fsgen directory`, }, }, // Test for the rule restricting use of prebuilt_* module { name: `"prebuilt_usr_srec" defined in Android.bp file`, fs: map[string][]byte{ "a/b/Android.bp": []byte(` prebuilt_usr_srec { name: "foo", } `), }, expectedErrors: []string{ `module type not allowed to be defined in bp file`, }, }, } var prepareForNeverAllowTest = GroupFixturePreparers( Loading @@ -383,6 +397,7 @@ var prepareForNeverAllowTest = GroupFixturePreparers( ctx.RegisterModuleType("java_library_host", newMockJavaLibraryModule) ctx.RegisterModuleType("java_device_for_host", newMockJavaLibraryModule) ctx.RegisterModuleType("filesystem", newMockFilesystemModule) ctx.RegisterModuleType("prebuilt_usr_srec", newMockPrebuiltUsrSrecModule) }), ) Loading Loading @@ -482,3 +497,16 @@ func newMockJavaLibraryModule() Module { func (p *mockJavaLibraryModule) GenerateAndroidBuildActions(ModuleContext) { } type mockPrebuiltUsrSrecModule struct { ModuleBase } func (p *mockPrebuiltUsrSrecModule) GenerateAndroidBuildActions(ModuleContext) { } func newMockPrebuiltUsrSrecModule() Module { m := &mockPrebuiltUsrSrecModule{} InitAndroidModule(m) return m } etc/prebuilt_etc.go +82 −4 Original line number Diff line number Diff line Loading @@ -59,16 +59,23 @@ func RegisterPrebuiltEtcBuildComponents(ctx android.RegistrationContext) { ctx.RegisterModuleType("prebuilt_usr_keylayout", PrebuiltUserKeyLayoutFactory) ctx.RegisterModuleType("prebuilt_usr_keychars", PrebuiltUserKeyCharsFactory) ctx.RegisterModuleType("prebuilt_usr_idc", PrebuiltUserIdcFactory) ctx.RegisterModuleType("prebuilt_usr_srec", PrebuiltUserSrecFactory) ctx.RegisterModuleType("prebuilt_font", PrebuiltFontFactory) ctx.RegisterModuleType("prebuilt_overlay", PrebuiltOverlayFactory) ctx.RegisterModuleType("prebuilt_firmware", PrebuiltFirmwareFactory) ctx.RegisterModuleType("prebuilt_dsp", PrebuiltDSPFactory) ctx.RegisterModuleType("prebuilt_rfsa", PrebuiltRFSAFactory) ctx.RegisterModuleType("prebuilt_renderscript_bitcode", PrebuiltRenderScriptBitcodeFactory) ctx.RegisterModuleType("prebuilt_media_audio", PrebuiltMediaAudioFactory) ctx.RegisterModuleType("prebuilt_media", PrebuiltMediaFactory) ctx.RegisterModuleType("prebuilt_voicepack", PrebuiltVoicepackFactory) ctx.RegisterModuleType("prebuilt_bin", PrebuiltBinaryFactory) ctx.RegisterModuleType("prebuilt_wallpaper", PrebuiltWallpaperFactory) ctx.RegisterModuleType("prebuilt_priv_app", PrebuiltPrivAppFactory) ctx.RegisterModuleType("prebuilt_rfs", PrebuiltRfsFactory) ctx.RegisterModuleType("prebuilt_framework", PrebuiltFrameworkFactory) ctx.RegisterModuleType("prebuilt_res", PrebuiltResFactory) ctx.RegisterModuleType("prebuilt_wlc_upt", PrebuiltWlcUptFactory) ctx.RegisterModuleType("prebuilt_odm", PrebuiltOdmFactory) ctx.RegisterModuleType("prebuilt_defaults", defaultsFactory) Loading Loading @@ -720,6 +727,17 @@ func PrebuiltUserIdcFactory() android.Module { return module } // prebuilt_usr_srec is for a prebuilt artifact that is installed in // <partition>/usr/srec/<sub_dir> directory. func PrebuiltUserSrecFactory() android.Module { module := &PrebuiltEtc{} InitPrebuiltEtcModule(module, "usr/srec") // This module is device-only android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst) android.InitDefaultableModule(module) return module } // prebuilt_font installs a font in <partition>/fonts directory. func PrebuiltFontFactory() android.Module { module := &PrebuiltEtc{} Loading Loading @@ -793,10 +811,10 @@ func PrebuiltRFSAFactory() android.Module { return module } // prebuilt_media_audio installs audio files in <partition>/media/audio directory. func PrebuiltMediaAudioFactory() android.Module { // prebuilt_media installs media files in <partition>/media directory. func PrebuiltMediaFactory() android.Module { module := &PrebuiltEtc{} InitPrebuiltEtcModule(module, "media/audio") InitPrebuiltEtcModule(module, "media") // This module is device-only android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) android.InitDefaultableModule(module) Loading Loading @@ -832,3 +850,63 @@ func PrebuiltWallpaperFactory() android.Module { android.InitDefaultableModule(module) return module } // prebuilt_priv_app installs files in <partition>/priv-app directory. func PrebuiltPrivAppFactory() android.Module { module := &PrebuiltEtc{} InitPrebuiltEtcModule(module, "priv-app") // This module is device-only android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) android.InitDefaultableModule(module) return module } // prebuilt_rfs installs files in <partition>/rfs directory. func PrebuiltRfsFactory() android.Module { module := &PrebuiltEtc{} InitPrebuiltEtcModule(module, "rfs") // This module is device-only android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) android.InitDefaultableModule(module) return module } // prebuilt_framework installs files in <partition>/framework directory. func PrebuiltFrameworkFactory() android.Module { module := &PrebuiltEtc{} InitPrebuiltEtcModule(module, "framework") // This module is device-only android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) android.InitDefaultableModule(module) return module } // prebuilt_res installs files in <partition>/res directory. func PrebuiltResFactory() android.Module { module := &PrebuiltEtc{} InitPrebuiltEtcModule(module, "res") // This module is device-only android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) android.InitDefaultableModule(module) return module } // prebuilt_wlc_upt installs files in <partition>/wlc_upt directory. func PrebuiltWlcUptFactory() android.Module { module := &PrebuiltEtc{} InitPrebuiltEtcModule(module, "wlc_upt") // This module is device-only android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) android.InitDefaultableModule(module) return module } // prebuilt_odm installs files in <partition>/odm directory. func PrebuiltOdmFactory() android.Module { module := &PrebuiltEtc{} InitPrebuiltEtcModule(module, "odm") // This module is device-only android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) android.InitDefaultableModule(module) return module } etc/prebuilt_etc_test.go +2 −2 Original line number Diff line number Diff line Loading @@ -591,7 +591,7 @@ func TestPrebuiltRFSADirPath(t *testing.T) { func TestPrebuiltMediaAutoDirPath(t *testing.T) { result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` prebuilt_media_audio { prebuilt_media { name: "foo", src: "Alarm_Beep_01.ogg", product_specific: true, Loading @@ -600,6 +600,6 @@ func TestPrebuiltMediaAutoDirPath(t *testing.T) { `) p := result.Module("foo", "android_common").(*PrebuiltEtc) expected := "out/soong/target/product/test_device/product/media/audio/alarms" expected := "out/soong/target/product/test_device/product/media/alarms" android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPaths[0]) } Loading
android/base_module_context.go +8 −0 Original line number Diff line number Diff line Loading @@ -87,6 +87,10 @@ type BaseModuleContext interface { // This method shouldn't be used directly, prefer the type-safe android.OtherModuleProvider instead. otherModuleProvider(m blueprint.Module, provider blueprint.AnyProviderKey) (any, bool) // OtherModuleIsAutoGenerated returns true if the module is auto generated by another module // instead of being defined in Android.bp file. OtherModuleIsAutoGenerated(m blueprint.Module) bool // Provider returns the value for a provider for the current module. If the value is // not set it returns nil and false. It panics if called before the appropriate // mutator or GenerateBuildActions pass for the provider. The value returned may be a deep Loading Loading @@ -275,6 +279,10 @@ func (b *baseModuleContext) otherModuleProvider(m blueprint.Module, provider blu return b.bp.OtherModuleProvider(m, provider) } func (b *baseModuleContext) OtherModuleIsAutoGenerated(m blueprint.Module) bool { return b.bp.OtherModuleIsAutoGenerated(m) } func (b *baseModuleContext) provider(provider blueprint.AnyProviderKey) (any, bool) { return b.bp.Provider(provider) } Loading
android/neverallow.go +40 −0 Original line number Diff line number Diff line Loading @@ -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. Loading Loading @@ -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 { Loading Loading @@ -354,6 +372,10 @@ func neverallowMutator(ctx BottomUpMutatorContext) { continue } if !n.appliesToBpDefinedModule(ctx) { continue } ctx.ModuleErrorf("violates " + n.String()) } } Loading Loading @@ -477,6 +499,8 @@ type Rule interface { WithoutMatcher(properties string, matcher ValueMatcher) Rule DefinedInBpFile() Rule Because(reason string) Rule } Loading @@ -498,6 +522,8 @@ type rule struct { unlessProps ruleProperties onlyBootclasspathJar bool definedInBp bool } // Create a new NeverAllow rule. Loading Loading @@ -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 Loading Loading @@ -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} } Loading
android/neverallow_test.go +28 −0 Original line number Diff line number Diff line Loading @@ -374,6 +374,20 @@ var neverallowTests = []struct { `is_auto_generated property is only allowed for filesystem modules in build/soong/fsgen directory`, }, }, // Test for the rule restricting use of prebuilt_* module { name: `"prebuilt_usr_srec" defined in Android.bp file`, fs: map[string][]byte{ "a/b/Android.bp": []byte(` prebuilt_usr_srec { name: "foo", } `), }, expectedErrors: []string{ `module type not allowed to be defined in bp file`, }, }, } var prepareForNeverAllowTest = GroupFixturePreparers( Loading @@ -383,6 +397,7 @@ var prepareForNeverAllowTest = GroupFixturePreparers( ctx.RegisterModuleType("java_library_host", newMockJavaLibraryModule) ctx.RegisterModuleType("java_device_for_host", newMockJavaLibraryModule) ctx.RegisterModuleType("filesystem", newMockFilesystemModule) ctx.RegisterModuleType("prebuilt_usr_srec", newMockPrebuiltUsrSrecModule) }), ) Loading Loading @@ -482,3 +497,16 @@ func newMockJavaLibraryModule() Module { func (p *mockJavaLibraryModule) GenerateAndroidBuildActions(ModuleContext) { } type mockPrebuiltUsrSrecModule struct { ModuleBase } func (p *mockPrebuiltUsrSrecModule) GenerateAndroidBuildActions(ModuleContext) { } func newMockPrebuiltUsrSrecModule() Module { m := &mockPrebuiltUsrSrecModule{} InitAndroidModule(m) return m }
etc/prebuilt_etc.go +82 −4 Original line number Diff line number Diff line Loading @@ -59,16 +59,23 @@ func RegisterPrebuiltEtcBuildComponents(ctx android.RegistrationContext) { ctx.RegisterModuleType("prebuilt_usr_keylayout", PrebuiltUserKeyLayoutFactory) ctx.RegisterModuleType("prebuilt_usr_keychars", PrebuiltUserKeyCharsFactory) ctx.RegisterModuleType("prebuilt_usr_idc", PrebuiltUserIdcFactory) ctx.RegisterModuleType("prebuilt_usr_srec", PrebuiltUserSrecFactory) ctx.RegisterModuleType("prebuilt_font", PrebuiltFontFactory) ctx.RegisterModuleType("prebuilt_overlay", PrebuiltOverlayFactory) ctx.RegisterModuleType("prebuilt_firmware", PrebuiltFirmwareFactory) ctx.RegisterModuleType("prebuilt_dsp", PrebuiltDSPFactory) ctx.RegisterModuleType("prebuilt_rfsa", PrebuiltRFSAFactory) ctx.RegisterModuleType("prebuilt_renderscript_bitcode", PrebuiltRenderScriptBitcodeFactory) ctx.RegisterModuleType("prebuilt_media_audio", PrebuiltMediaAudioFactory) ctx.RegisterModuleType("prebuilt_media", PrebuiltMediaFactory) ctx.RegisterModuleType("prebuilt_voicepack", PrebuiltVoicepackFactory) ctx.RegisterModuleType("prebuilt_bin", PrebuiltBinaryFactory) ctx.RegisterModuleType("prebuilt_wallpaper", PrebuiltWallpaperFactory) ctx.RegisterModuleType("prebuilt_priv_app", PrebuiltPrivAppFactory) ctx.RegisterModuleType("prebuilt_rfs", PrebuiltRfsFactory) ctx.RegisterModuleType("prebuilt_framework", PrebuiltFrameworkFactory) ctx.RegisterModuleType("prebuilt_res", PrebuiltResFactory) ctx.RegisterModuleType("prebuilt_wlc_upt", PrebuiltWlcUptFactory) ctx.RegisterModuleType("prebuilt_odm", PrebuiltOdmFactory) ctx.RegisterModuleType("prebuilt_defaults", defaultsFactory) Loading Loading @@ -720,6 +727,17 @@ func PrebuiltUserIdcFactory() android.Module { return module } // prebuilt_usr_srec is for a prebuilt artifact that is installed in // <partition>/usr/srec/<sub_dir> directory. func PrebuiltUserSrecFactory() android.Module { module := &PrebuiltEtc{} InitPrebuiltEtcModule(module, "usr/srec") // This module is device-only android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst) android.InitDefaultableModule(module) return module } // prebuilt_font installs a font in <partition>/fonts directory. func PrebuiltFontFactory() android.Module { module := &PrebuiltEtc{} Loading Loading @@ -793,10 +811,10 @@ func PrebuiltRFSAFactory() android.Module { return module } // prebuilt_media_audio installs audio files in <partition>/media/audio directory. func PrebuiltMediaAudioFactory() android.Module { // prebuilt_media installs media files in <partition>/media directory. func PrebuiltMediaFactory() android.Module { module := &PrebuiltEtc{} InitPrebuiltEtcModule(module, "media/audio") InitPrebuiltEtcModule(module, "media") // This module is device-only android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) android.InitDefaultableModule(module) Loading Loading @@ -832,3 +850,63 @@ func PrebuiltWallpaperFactory() android.Module { android.InitDefaultableModule(module) return module } // prebuilt_priv_app installs files in <partition>/priv-app directory. func PrebuiltPrivAppFactory() android.Module { module := &PrebuiltEtc{} InitPrebuiltEtcModule(module, "priv-app") // This module is device-only android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) android.InitDefaultableModule(module) return module } // prebuilt_rfs installs files in <partition>/rfs directory. func PrebuiltRfsFactory() android.Module { module := &PrebuiltEtc{} InitPrebuiltEtcModule(module, "rfs") // This module is device-only android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) android.InitDefaultableModule(module) return module } // prebuilt_framework installs files in <partition>/framework directory. func PrebuiltFrameworkFactory() android.Module { module := &PrebuiltEtc{} InitPrebuiltEtcModule(module, "framework") // This module is device-only android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) android.InitDefaultableModule(module) return module } // prebuilt_res installs files in <partition>/res directory. func PrebuiltResFactory() android.Module { module := &PrebuiltEtc{} InitPrebuiltEtcModule(module, "res") // This module is device-only android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) android.InitDefaultableModule(module) return module } // prebuilt_wlc_upt installs files in <partition>/wlc_upt directory. func PrebuiltWlcUptFactory() android.Module { module := &PrebuiltEtc{} InitPrebuiltEtcModule(module, "wlc_upt") // This module is device-only android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) android.InitDefaultableModule(module) return module } // prebuilt_odm installs files in <partition>/odm directory. func PrebuiltOdmFactory() android.Module { module := &PrebuiltEtc{} InitPrebuiltEtcModule(module, "odm") // This module is device-only android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) android.InitDefaultableModule(module) return module }
etc/prebuilt_etc_test.go +2 −2 Original line number Diff line number Diff line Loading @@ -591,7 +591,7 @@ func TestPrebuiltRFSADirPath(t *testing.T) { func TestPrebuiltMediaAutoDirPath(t *testing.T) { result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` prebuilt_media_audio { prebuilt_media { name: "foo", src: "Alarm_Beep_01.ogg", product_specific: true, Loading @@ -600,6 +600,6 @@ func TestPrebuiltMediaAutoDirPath(t *testing.T) { `) p := result.Module("foo", "android_common").(*PrebuiltEtc) expected := "out/soong/target/product/test_device/product/media/audio/alarms" expected := "out/soong/target/product/test_device/product/media/alarms" android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPaths[0]) }