Support pyhon_rule_defaults in Soong

This change adds support for `python_rule_defaults` in Soong, allowing
different targets to reuse the same dependencies. This resolves the
issue where different dependencies could not be synchronized due to the
lack of `python_rule_defaults` in Soong.

Bug: 331886818
Test: 1. Add phony_rule_defaults module in the Android.bp
      2. Add the module in `defaults`
Change-Id: If3579ea685529858567748e6f34bcf7c5477bcfc
This commit is contained in:
Nelson Li
2024-04-01 11:30:56 +08:00
parent 4d4eb59a2b
commit 1f96994e53

View File

@@ -29,6 +29,7 @@ func init() {
func registerPhonyModuleTypes(ctx android.RegistrationContext) {
ctx.RegisterModuleType("phony", PhonyFactory)
ctx.RegisterModuleType("phony_rule", PhonyRuleFactory)
ctx.RegisterModuleType("phony_rule_defaults", PhonyRuleDefaultsFactory)
}
var PrepareForTestWithPhony = android.FixtureRegisterWithContext(registerPhonyModuleTypes)
@@ -85,6 +86,7 @@ func (p *phony) AndroidMk() android.AndroidMkData {
type PhonyRule struct {
android.ModuleBase
android.DefaultableModuleBase
properties PhonyProperties
}
@@ -102,6 +104,7 @@ func PhonyRuleFactory() android.Module {
module := &PhonyRule{}
android.InitAndroidModule(module)
module.AddProperties(&module.properties)
android.InitDefaultableModule(module)
return module
}
@@ -119,3 +122,45 @@ func (p *PhonyRule) AndroidMk() android.AndroidMkData {
},
}
}
// PhonyRuleDefaults
type PhonyRuleDefaults struct {
android.ModuleBase
android.DefaultsModuleBase
}
// phony_rule_defaults provides a set of properties that can be inherited by other phony_rules.
//
// A module can use the properties from a phony_rule_defaults module using `defaults: ["defaults_module_name"]`. Each
// property in the defaults module that exists in the depending module will be prepended to the depending module's
// value for that property.
//
// Example:
//
// phony_rule_defaults {
// name: "add_module1_defaults",
// phony_deps: [
// "module1",
// ],
// }
//
// phony_rule {
// name: "example",
// defaults: ["add_module1_defaults"],
// }
//
// is functionally identical to:
//
// phony_rule {
// name: "example",
// phony_deps: [
// "module1",
// ],
// }
func PhonyRuleDefaultsFactory() android.Module {
module := &PhonyRuleDefaults{}
module.AddProperties(&PhonyProperties{})
android.InitDefaultsModule(module)
return module
}