Merge "Refactor cquery processing to generalize transitions" am: 209feec9e3
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1657220 Change-Id: I248fcd7a9b1c5fef2be4d8ba3af01df35f4d38cb
This commit is contained in:
committed by
Automerger Merge Worker
commit
0bb06887ba
@@ -344,73 +344,39 @@ func (context *bazelContext) mainBzlFileContents() []byte {
|
|||||||
# This file is generated by soong_build. Do not edit.
|
# 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 {
|
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):
|
_config_node_transition = transition(
|
||||||
return {
|
implementation = _config_node_transition_impl,
|
||||||
"//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,
|
|
||||||
inputs = [],
|
inputs = [],
|
||||||
outputs = [
|
outputs = [
|
||||||
"//command_line_option:platforms",
|
"//command_line_option:platforms",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
x86_transition = transition(
|
def _passthrough_rule_impl(ctx):
|
||||||
implementation = _x86_transition_impl,
|
return [DefaultInfo(files = depset(ctx.files.deps))]
|
||||||
inputs = [],
|
|
||||||
outputs = [
|
config_node = rule(
|
||||||
"//command_line_option:platforms",
|
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
|
# 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
|
# are required for the build. Building this target will build the entire Bazel
|
||||||
# build tree.
|
# build tree.
|
||||||
mixed_build_root = rule(
|
mixed_build_root = rule(
|
||||||
implementation = _mixed_build_root_impl,
|
implementation = _passthrough_rule_impl,
|
||||||
attrs = {
|
attrs = {
|
||||||
"deps_x86_64" : attr.label_list(cfg = x86_64_transition),
|
"deps" : attr.label_list(),
|
||||||
"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"),
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -446,44 +412,42 @@ func (context *bazelContext) mainBuildFileContents() []byte {
|
|||||||
// architecture mapping.
|
// architecture mapping.
|
||||||
formatString := `
|
formatString := `
|
||||||
# This file is generated by soong_build. Do not edit.
|
# 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",
|
mixed_build_root(name = "buildroot",
|
||||||
deps_x86_64 = [%s],
|
deps = [%s],
|
||||||
deps_x86 = [%s],
|
|
||||||
deps_arm64 = [%s],
|
|
||||||
deps_arm = [%s],
|
|
||||||
)
|
)
|
||||||
|
|
||||||
phony_root(name = "phonyroot",
|
phony_root(name = "phonyroot",
|
||||||
deps = [":buildroot"],
|
deps = [":buildroot"],
|
||||||
)
|
)
|
||||||
`
|
`
|
||||||
var deps_x86_64 []string = nil
|
configNodeFormatString := `
|
||||||
var deps_x86 []string = nil
|
config_node(name = "%s",
|
||||||
var deps_arm64 []string = nil
|
arch = "%s",
|
||||||
var deps_arm []string = nil
|
deps = [%s],
|
||||||
|
)
|
||||||
|
`
|
||||||
|
|
||||||
|
configNodesSection := ""
|
||||||
|
|
||||||
|
labelsByArch := map[string][]string{}
|
||||||
for val, _ := range context.requests {
|
for val, _ := range context.requests {
|
||||||
labelString := fmt.Sprintf("\"%s\"", canonicalizeLabel(val.label))
|
labelString := fmt.Sprintf("\"%s\"", canonicalizeLabel(val.label))
|
||||||
switch getArchString(val) {
|
archString := getArchString(val)
|
||||||
case "x86_64":
|
labelsByArch[archString] = append(labelsByArch[archString], labelString)
|
||||||
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))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return []byte(fmt.Sprintf(formatString,
|
configNodeLabels := []string{}
|
||||||
strings.Join(deps_x86_64, ",\n "),
|
for archString, labels := range labelsByArch {
|
||||||
strings.Join(deps_x86, ",\n "),
|
configNodeLabels = append(configNodeLabels, fmt.Sprintf("\":%s\"", archString))
|
||||||
strings.Join(deps_arm64, ",\n "),
|
labelsString := strings.Join(labels, ",\n ")
|
||||||
strings.Join(deps_arm, ",\n ")))
|
configNodesSection += fmt.Sprintf(configNodeFormatString, archString, archString, labelsString)
|
||||||
|
}
|
||||||
|
|
||||||
|
return []byte(fmt.Sprintf(formatString, configNodesSection, strings.Join(configNodeLabels, ",\n ")))
|
||||||
}
|
}
|
||||||
|
|
||||||
func indent(original string) string {
|
func indent(original string) string {
|
||||||
|
Reference in New Issue
Block a user