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()
|
mod := ctx.Module().base()
|
||||||
// Assert passed-in attributes include Name
|
// Assert passed-in attributes include Name
|
||||||
if len(attrs.Name) == 0 {
|
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 {
|
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
|
// A macro call in the BUILD file representing a Soong module, with space
|
||||||
// for expanding more attributes.
|
// for expanding more attributes.
|
||||||
soongModuleTarget = `soong_module(
|
soongModuleTargetTemplate = `soong_module(
|
||||||
name = "%s",
|
name = "%s",
|
||||||
soong_module_name = "%s",
|
soong_module_name = "%s",
|
||||||
soong_module_type = "%s",
|
soong_module_type = "%s",
|
||||||
|
@ -31,10 +31,13 @@ load("//build/bazel/queryview_rules:soong_module.bzl", "soong_module")
|
||||||
soong_module_deps = %s,
|
soong_module_deps = %s,
|
||||||
%s)`
|
%s)`
|
||||||
|
|
||||||
bazelTarget = `%s(
|
ruleTargetTemplate = `%s(
|
||||||
name = "%s",
|
name = "%s",
|
||||||
%s)`
|
%s)`
|
||||||
|
|
||||||
|
unnamedRuleTargetTemplate = `%s(
|
||||||
|
%s)`
|
||||||
|
|
||||||
// A simple provider to mark and differentiate Soong module rule shims from
|
// A simple provider to mark and differentiate Soong module rule shims from
|
||||||
// regular Bazel rules. Every Soong module rule shim returns a
|
// regular Bazel rules. Every Soong module rule shim returns a
|
||||||
// SoongModuleInfo provider, and can only depend on rules returning
|
// 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
|
// Return the Bazel target with rule class and attributes, ready to be
|
||||||
// code-generated.
|
// code-generated.
|
||||||
attributes := propsToAttributes(props.Attrs)
|
attributes := propsToAttributes(props.Attrs)
|
||||||
|
var content string
|
||||||
targetName := m.TargetName()
|
targetName := m.TargetName()
|
||||||
|
if targetName != "" {
|
||||||
|
content = fmt.Sprintf(ruleTargetTemplate, ruleClass, targetName, attributes)
|
||||||
|
} else {
|
||||||
|
content = fmt.Sprintf(unnamedRuleTargetTemplate, ruleClass, attributes)
|
||||||
|
}
|
||||||
return BazelTarget{
|
return BazelTarget{
|
||||||
name: targetName,
|
name: targetName,
|
||||||
packageName: m.TargetPackage(),
|
packageName: m.TargetPackage(),
|
||||||
ruleClass: ruleClass,
|
ruleClass: ruleClass,
|
||||||
bzlLoadLocation: bzlLoadLocation,
|
bzlLoadLocation: bzlLoadLocation,
|
||||||
content: fmt.Sprintf(
|
content: content,
|
||||||
bazelTarget,
|
|
||||||
ruleClass,
|
|
||||||
targetName,
|
|
||||||
attributes,
|
|
||||||
),
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -436,7 +437,7 @@ func generateSoongModuleTarget(ctx bpToBuildContext, m blueprint.Module) (BazelT
|
||||||
return BazelTarget{
|
return BazelTarget{
|
||||||
name: targetName,
|
name: targetName,
|
||||||
content: fmt.Sprintf(
|
content: fmt.Sprintf(
|
||||||
soongModuleTarget,
|
soongModuleTargetTemplate,
|
||||||
targetName,
|
targetName,
|
||||||
ctx.ModuleName(m),
|
ctx.ModuleName(m),
|
||||||
canonicalizeModuleType(ctx.ModuleType(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 := 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) {
|
for _, k := range android.SortedStringKeys(attrs) {
|
||||||
attrStrings = append(attrStrings, fmt.Sprintf(" %s = %s,", k, attrs[k]))
|
attrStrings = append(attrStrings, fmt.Sprintf(" %s = %s,", k, attrs[k]))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue