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

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

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

View file

@ -139,6 +139,14 @@ type EarlyModuleContext interface {
// Context.RegisterModuleType().
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
// module.
BlueprintsFile() string
@ -406,6 +414,13 @@ func (d *baseModuleContext) ModuleType() string {
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 {
_, ok := d.module.propertyPos[name]
return ok
@ -796,7 +811,7 @@ func (m *moduleContext) Rule(pctx PackageContext, name string,
func (m *moduleContext) Build(pctx PackageContext, params BuildParams) {
m.scope.ReparentTo(pctx)
def, err := parseBuildParams(m.scope, &params)
def, err := parseBuildParams(m.scope, &params, m.ModuleTags())
if err != nil {
panic(err)
}

View file

@ -275,8 +275,25 @@ type buildDef struct {
Optional bool
}
func parseBuildParams(scope scope, params *BuildParams) (*buildDef,
error) {
func formatTags(tags map[string]string, rule Rule) string {
// 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
rule := params.Rule
@ -360,6 +377,10 @@ func parseBuildParams(scope scope, params *BuildParams) (*buildDef,
simpleNinjaString(strings.Join(params.SymlinkOutputs, " ")))
}
if len(tags) > 0 {
setVariable("tags", simpleNinjaString(formatTags(tags, rule)))
}
argNameScope := rule.scope()
if len(params.Args) > 0 {

View file

@ -394,6 +394,10 @@ func validateArgName(argName string) error {
return fmt.Errorf("%q contains a '.' character", argName)
}
if argName == "tags" {
return fmt.Errorf("\"tags\" is a reserved argument name")
}
for _, builtin := range builtinRuleArgs {
if argName == builtin {
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) {
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 {
panic(err)
}