From 1f96994e53811242fe7ea8a8e9b0aced1de69d02 Mon Sep 17 00:00:00 2001 From: Nelson Li Date: Mon, 1 Apr 2024 11:30:56 +0800 Subject: [PATCH] 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 --- phony/phony.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/phony/phony.go b/phony/phony.go index 68fbf48d0..54692386a 100644 --- a/phony/phony.go +++ b/phony/phony.go @@ -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 +}