Handle nameless modules during bp2build conversion.
So far it is `package` module. Test: treehugger Change-Id: Ibf3af0b0bf0a532e2ea1d478275a5ac3784ef170
This commit is contained in:
parent
8c6f4576ef
commit
fb58949414
4 changed files with 19 additions and 11 deletions
|
@ -1169,7 +1169,9 @@ func (attrs *CommonAttributes) fillCommonBp2BuildModuleAttrs(ctx *topDownMutator
|
|||
mod := ctx.Module().base()
|
||||
// Assert passed-in attributes include Name
|
||||
if len(attrs.Name) == 0 {
|
||||
ctx.ModuleErrorf("CommonAttributes in fillCommonBp2BuildModuleAttrs expects a `.Name`!")
|
||||
if ctx.ModuleType() != "package" {
|
||||
ctx.ModuleErrorf("CommonAttributes in fillCommonBp2BuildModuleAttrs expects a `.Name`!")
|
||||
}
|
||||
}
|
||||
|
||||
depsToLabelList := func(deps []string) bazel.LabelListAttribute {
|
||||
|
|
|
@ -23,7 +23,7 @@ load("//build/bazel/queryview_rules:soong_module.bzl", "soong_module")
|
|||
|
||||
// A macro call in the BUILD file representing a Soong module, with space
|
||||
// for expanding more attributes.
|
||||
soongModuleTarget = `soong_module(
|
||||
soongModuleTargetTemplate = `soong_module(
|
||||
name = "%s",
|
||||
soong_module_name = "%s",
|
||||
soong_module_type = "%s",
|
||||
|
@ -31,10 +31,13 @@ load("//build/bazel/queryview_rules:soong_module.bzl", "soong_module")
|
|||
soong_module_deps = %s,
|
||||
%s)`
|
||||
|
||||
bazelTarget = `%s(
|
||||
ruleTargetTemplate = `%s(
|
||||
name = "%s",
|
||||
%s)`
|
||||
|
||||
unnamedRuleTargetTemplate = `%s(
|
||||
%s)`
|
||||
|
||||
// A simple provider to mark and differentiate Soong module rule shims from
|
||||
// regular Bazel rules. Every Soong module rule shim returns a
|
||||
// SoongModuleInfo provider, and can only depend on rules returning
|
||||
|
|
|
@ -391,18 +391,19 @@ func generateBazelTarget(ctx bpToBuildContext, m bp2buildModule) (BazelTarget, e
|
|||
// Return the Bazel target with rule class and attributes, ready to be
|
||||
// code-generated.
|
||||
attributes := propsToAttributes(props.Attrs)
|
||||
var content string
|
||||
targetName := m.TargetName()
|
||||
if targetName != "" {
|
||||
content = fmt.Sprintf(ruleTargetTemplate, ruleClass, targetName, attributes)
|
||||
} else {
|
||||
content = fmt.Sprintf(unnamedRuleTargetTemplate, ruleClass, attributes)
|
||||
}
|
||||
return BazelTarget{
|
||||
name: targetName,
|
||||
packageName: m.TargetPackage(),
|
||||
ruleClass: ruleClass,
|
||||
bzlLoadLocation: bzlLoadLocation,
|
||||
content: fmt.Sprintf(
|
||||
bazelTarget,
|
||||
ruleClass,
|
||||
targetName,
|
||||
attributes,
|
||||
),
|
||||
content: content,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -436,7 +437,7 @@ func generateSoongModuleTarget(ctx bpToBuildContext, m blueprint.Module) (BazelT
|
|||
return BazelTarget{
|
||||
name: targetName,
|
||||
content: fmt.Sprintf(
|
||||
soongModuleTarget,
|
||||
soongModuleTargetTemplate,
|
||||
targetName,
|
||||
ctx.ModuleName(m),
|
||||
canonicalizeModuleType(ctx.ModuleType(m)),
|
||||
|
|
|
@ -429,7 +429,9 @@ func makeBazelTargetHostOrDevice(typ, name string, attrs AttrNameToString, hod a
|
|||
}
|
||||
|
||||
attrStrings := make([]string, 0, len(attrs)+1)
|
||||
attrStrings = append(attrStrings, fmt.Sprintf(` name = "%s",`, name))
|
||||
if name != "" {
|
||||
attrStrings = append(attrStrings, fmt.Sprintf(` name = "%s",`, name))
|
||||
}
|
||||
for _, k := range android.SortedStringKeys(attrs) {
|
||||
attrStrings = append(attrStrings, fmt.Sprintf(" %s = %s,", k, attrs[k]))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue