Merge "Plumb module tags through to ninja." am: 797fe25cb2 am: 27186d0a91 am: b50e951349

Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/2631633

Change-Id: I33994b667017f4dae6e9b412c0c19d49a75c64f4
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Treehugger Robot 2023-06-23 21:40:47 +00:00 committed by Automerger Merge Worker
commit 544470742f
4 changed files with 47 additions and 4 deletions

View file

@ -139,6 +139,14 @@ type EarlyModuleContext interface {
// Context.RegisterModuleType(). // Context.RegisterModuleType().
ModuleType() string ModuleType() string
// ModuleTags returns the tags for this module that should be passed to
// ninja for analysis. For example:
// [
// "module_name": "libfoo",
// "module_type": "cc_library",
// ]
ModuleTags() map[string]string
// BlueprintsFile returns the name of the blueprint file that contains the definition of this // BlueprintsFile returns the name of the blueprint file that contains the definition of this
// module. // module.
BlueprintsFile() string BlueprintsFile() string
@ -406,6 +414,13 @@ func (d *baseModuleContext) ModuleType() string {
return d.module.typeName return d.module.typeName
} }
func (d *baseModuleContext) ModuleTags() map[string]string {
return map[string]string{
"module_name": d.ModuleName(),
"module_type": d.ModuleType(),
}
}
func (d *baseModuleContext) ContainsProperty(name string) bool { func (d *baseModuleContext) ContainsProperty(name string) bool {
_, ok := d.module.propertyPos[name] _, ok := d.module.propertyPos[name]
return ok return ok
@ -796,7 +811,7 @@ func (m *moduleContext) Rule(pctx PackageContext, name string,
func (m *moduleContext) Build(pctx PackageContext, params BuildParams) { func (m *moduleContext) Build(pctx PackageContext, params BuildParams) {
m.scope.ReparentTo(pctx) m.scope.ReparentTo(pctx)
def, err := parseBuildParams(m.scope, &params) def, err := parseBuildParams(m.scope, &params, m.ModuleTags())
if err != nil { if err != nil {
panic(err) panic(err)
} }

View file

@ -275,8 +275,25 @@ type buildDef struct {
Optional bool Optional bool
} }
func parseBuildParams(scope scope, params *BuildParams) (*buildDef, func formatTags(tags map[string]string, rule Rule) string {
error) { // Maps in golang do not have a guaranteed iteration order, nor is there an
// ordered map type in the stdlib, but we need to deterministically generate
// the ninja file.
keys := make([]string, 0, len(tags))
for k := range tags {
keys = append(keys, k)
}
sort.Strings(keys)
pairs := make([]string, 0, len(keys))
for _, k := range keys {
pairs = append(pairs, k+"="+tags[k])
}
pairs = append(pairs, "rule_name="+rule.name())
return strings.Join(pairs, ";")
}
func parseBuildParams(scope scope, params *BuildParams,
tags map[string]string) (*buildDef, error) {
comment := params.Comment comment := params.Comment
rule := params.Rule rule := params.Rule
@ -360,6 +377,10 @@ func parseBuildParams(scope scope, params *BuildParams) (*buildDef,
simpleNinjaString(strings.Join(params.SymlinkOutputs, " "))) simpleNinjaString(strings.Join(params.SymlinkOutputs, " ")))
} }
if len(tags) > 0 {
setVariable("tags", simpleNinjaString(formatTags(tags, rule)))
}
argNameScope := rule.scope() argNameScope := rule.scope()
if len(params.Args) > 0 { if len(params.Args) > 0 {

View file

@ -394,6 +394,10 @@ func validateArgName(argName string) error {
return fmt.Errorf("%q contains a '.' character", argName) return fmt.Errorf("%q contains a '.' character", argName)
} }
if argName == "tags" {
return fmt.Errorf("\"tags\" is a reserved argument name")
}
for _, builtin := range builtinRuleArgs { for _, builtin := range builtinRuleArgs {
if argName == builtin { if argName == builtin {
return fmt.Errorf("%q conflicts with Ninja built-in", argName) return fmt.Errorf("%q conflicts with Ninja built-in", argName)

View file

@ -265,7 +265,10 @@ func (s *singletonContext) Rule(pctx PackageContext, name string,
func (s *singletonContext) Build(pctx PackageContext, params BuildParams) { func (s *singletonContext) Build(pctx PackageContext, params BuildParams) {
s.scope.ReparentTo(pctx) s.scope.ReparentTo(pctx)
def, err := parseBuildParams(s.scope, &params) def, err := parseBuildParams(s.scope, &params, map[string]string{
"module_name": s.name,
"module_type": "singleton",
})
if err != nil { if err != nil {
panic(err) panic(err)
} }