summaryrefslogtreecommitdiff
path: root/phony/phony.go
diff options
context:
space:
mode:
Diffstat (limited to 'phony/phony.go')
-rw-r--r--phony/phony.go98
1 files changed, 95 insertions, 3 deletions
diff --git a/phony/phony.go b/phony/phony.go
index 760b79b8a..b421176be 100644
--- a/phony/phony.go
+++ b/phony/phony.go
@@ -23,9 +23,17 @@ import (
)
func init() {
- android.RegisterModuleType("phony", PhonyFactory)
+ registerPhonyModuleTypes(android.InitRegistrationContext)
}
+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)
+
type phony struct {
android.ModuleBase
requiredModuleNames []string
@@ -41,7 +49,7 @@ func PhonyFactory() android.Module {
}
func (p *phony) GenerateAndroidBuildActions(ctx android.ModuleContext) {
- p.requiredModuleNames = ctx.RequiredModuleNames()
+ p.requiredModuleNames = ctx.RequiredModuleNames(ctx)
p.hostRequiredModuleNames = ctx.HostRequiredModuleNames()
p.targetRequiredModuleNames = ctx.TargetRequiredModuleNames()
}
@@ -52,7 +60,6 @@ func (p *phony) AndroidMk() android.AndroidMkData {
fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)", " # phony.phony")
fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
fmt.Fprintln(w, "LOCAL_MODULE :=", name)
- data.Entries.WriteLicenseVariables(w)
if p.Host() {
fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
}
@@ -68,7 +75,92 @@ func (p *phony) AndroidMk() android.AndroidMkData {
fmt.Fprintln(w, "LOCAL_TARGET_REQUIRED_MODULES :=",
strings.Join(p.targetRequiredModuleNames, " "))
}
+ // AconfigUpdateAndroidMkData may have added elements to Extra. Process them here.
+ for _, extra := range data.Extra {
+ extra(w, nil)
+ }
fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)")
},
}
}
+
+type PhonyRule struct {
+ android.ModuleBase
+ android.DefaultableModuleBase
+
+ properties PhonyProperties
+}
+
+type PhonyProperties struct {
+ // The Phony_deps is the set of all dependencies for this target,
+ // and it can function similarly to .PHONY in a makefile.
+ // Additionally, dependencies within it can even include genrule.
+ Phony_deps []string
+}
+
+// The phony_rule provides functionality similar to the .PHONY in a makefile.
+// It can create a phony target and include relevant dependencies associated with it.
+func PhonyRuleFactory() android.Module {
+ module := &PhonyRule{}
+ android.InitAndroidModule(module)
+ module.AddProperties(&module.properties)
+ android.InitDefaultableModule(module)
+ return module
+}
+
+func (p *PhonyRule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+}
+
+func (p *PhonyRule) AndroidMk() android.AndroidMkData {
+ return android.AndroidMkData{
+ Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
+ if len(p.properties.Phony_deps) > 0 {
+ depModulesStr := strings.Join(p.properties.Phony_deps, " ")
+ fmt.Fprintln(w, ".PHONY:", name)
+ fmt.Fprintln(w, name, ":", depModulesStr)
+ }
+ },
+ }
+}
+
+// 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
+}