Merge "Refactor cquery processing to generalize transitions"
This commit is contained in:
@@ -344,73 +344,39 @@ func (context *bazelContext) mainBzlFileContents() []byte {
|
||||
# This file is generated by soong_build. Do not edit.
|
||||
#####################################################
|
||||
|
||||
def _x86_64_transition_impl(settings, attr):
|
||||
def _config_node_transition_impl(settings, attr):
|
||||
return {
|
||||
"//command_line_option:platforms": "@sourceroot//build/bazel/platforms:generic_x86_64",
|
||||
"//command_line_option:platforms": "@sourceroot//build/bazel/platforms:generic_%s" % attr.arch,
|
||||
}
|
||||
|
||||
def _x86_transition_impl(settings, attr):
|
||||
return {
|
||||
"//command_line_option:platforms": "@sourceroot//build/bazel/platforms:generic_x86",
|
||||
}
|
||||
|
||||
def _arm64_transition_impl(settings, attr):
|
||||
return {
|
||||
"//command_line_option:platforms": "@sourceroot//build/bazel/platforms:generic_arm64",
|
||||
}
|
||||
|
||||
def _arm_transition_impl(settings, attr):
|
||||
return {
|
||||
"//command_line_option:platforms": "@sourceroot//build/bazel/platforms:generic_arm",
|
||||
}
|
||||
|
||||
x86_64_transition = transition(
|
||||
implementation = _x86_64_transition_impl,
|
||||
_config_node_transition = transition(
|
||||
implementation = _config_node_transition_impl,
|
||||
inputs = [],
|
||||
outputs = [
|
||||
"//command_line_option:platforms",
|
||||
],
|
||||
)
|
||||
|
||||
x86_transition = transition(
|
||||
implementation = _x86_transition_impl,
|
||||
inputs = [],
|
||||
outputs = [
|
||||
"//command_line_option:platforms",
|
||||
],
|
||||
def _passthrough_rule_impl(ctx):
|
||||
return [DefaultInfo(files = depset(ctx.files.deps))]
|
||||
|
||||
config_node = rule(
|
||||
implementation = _passthrough_rule_impl,
|
||||
attrs = {
|
||||
"arch" : attr.string(mandatory = True),
|
||||
"deps" : attr.label_list(cfg = _config_node_transition),
|
||||
"_allowlist_function_transition": attr.label(default = "@bazel_tools//tools/allowlists/function_transition_allowlist"),
|
||||
},
|
||||
)
|
||||
|
||||
arm64_transition = transition(
|
||||
implementation = _arm64_transition_impl,
|
||||
inputs = [],
|
||||
outputs = [
|
||||
"//command_line_option:platforms",
|
||||
],
|
||||
)
|
||||
|
||||
arm_transition = transition(
|
||||
implementation = _arm_transition_impl,
|
||||
inputs = [],
|
||||
outputs = [
|
||||
"//command_line_option:platforms",
|
||||
],
|
||||
)
|
||||
|
||||
def _mixed_build_root_impl(ctx):
|
||||
all_files = ctx.files.deps_x86_64 + ctx.files.deps_x86 + ctx.files.deps_arm64 + ctx.files.deps_arm
|
||||
return [DefaultInfo(files = depset(all_files))]
|
||||
|
||||
# Rule representing the root of the build, to depend on all Bazel targets that
|
||||
# are required for the build. Building this target will build the entire Bazel
|
||||
# build tree.
|
||||
mixed_build_root = rule(
|
||||
implementation = _mixed_build_root_impl,
|
||||
implementation = _passthrough_rule_impl,
|
||||
attrs = {
|
||||
"deps_x86_64" : attr.label_list(cfg = x86_64_transition),
|
||||
"deps_x86" : attr.label_list(cfg = x86_transition),
|
||||
"deps_arm64" : attr.label_list(cfg = arm64_transition),
|
||||
"deps_arm" : attr.label_list(cfg = arm_transition),
|
||||
"_allowlist_function_transition": attr.label(default = "@bazel_tools//tools/allowlists/function_transition_allowlist"),
|
||||
"deps" : attr.label_list(),
|
||||
},
|
||||
)
|
||||
|
||||
@@ -446,44 +412,42 @@ func (context *bazelContext) mainBuildFileContents() []byte {
|
||||
// architecture mapping.
|
||||
formatString := `
|
||||
# This file is generated by soong_build. Do not edit.
|
||||
load(":main.bzl", "mixed_build_root", "phony_root")
|
||||
load(":main.bzl", "config_node", "mixed_build_root", "phony_root")
|
||||
|
||||
%s
|
||||
|
||||
mixed_build_root(name = "buildroot",
|
||||
deps_x86_64 = [%s],
|
||||
deps_x86 = [%s],
|
||||
deps_arm64 = [%s],
|
||||
deps_arm = [%s],
|
||||
deps = [%s],
|
||||
)
|
||||
|
||||
phony_root(name = "phonyroot",
|
||||
deps = [":buildroot"],
|
||||
)
|
||||
`
|
||||
var deps_x86_64 []string = nil
|
||||
var deps_x86 []string = nil
|
||||
var deps_arm64 []string = nil
|
||||
var deps_arm []string = nil
|
||||
configNodeFormatString := `
|
||||
config_node(name = "%s",
|
||||
arch = "%s",
|
||||
deps = [%s],
|
||||
)
|
||||
`
|
||||
|
||||
configNodesSection := ""
|
||||
|
||||
labelsByArch := map[string][]string{}
|
||||
for val, _ := range context.requests {
|
||||
labelString := fmt.Sprintf("\"%s\"", canonicalizeLabel(val.label))
|
||||
switch getArchString(val) {
|
||||
case "x86_64":
|
||||
deps_x86_64 = append(deps_x86_64, labelString)
|
||||
case "x86":
|
||||
deps_x86 = append(deps_x86, labelString)
|
||||
case "arm64":
|
||||
deps_arm64 = append(deps_arm64, labelString)
|
||||
case "arm":
|
||||
deps_arm = append(deps_arm, labelString)
|
||||
default:
|
||||
panic(fmt.Sprintf("unhandled architecture %s for %v", getArchString(val), val))
|
||||
}
|
||||
archString := getArchString(val)
|
||||
labelsByArch[archString] = append(labelsByArch[archString], labelString)
|
||||
}
|
||||
|
||||
return []byte(fmt.Sprintf(formatString,
|
||||
strings.Join(deps_x86_64, ",\n "),
|
||||
strings.Join(deps_x86, ",\n "),
|
||||
strings.Join(deps_arm64, ",\n "),
|
||||
strings.Join(deps_arm, ",\n ")))
|
||||
configNodeLabels := []string{}
|
||||
for archString, labels := range labelsByArch {
|
||||
configNodeLabels = append(configNodeLabels, fmt.Sprintf("\":%s\"", archString))
|
||||
labelsString := strings.Join(labels, ",\n ")
|
||||
configNodesSection += fmt.Sprintf(configNodeFormatString, archString, archString, labelsString)
|
||||
}
|
||||
|
||||
return []byte(fmt.Sprintf(formatString, configNodesSection, strings.Join(configNodeLabels, ",\n ")))
|
||||
}
|
||||
|
||||
func indent(original string) string {
|
||||
|
Reference in New Issue
Block a user