in tools/migration/crosstool_to_starlark_lib.go [289:328]
func getRule(cToolchainIdentifiers map[string]CToolchainIdentifier,
allowedCompilers []string) string {
cpus := make(map[string]bool)
shouldUseCompilerAttribute := false
for _, val := range cToolchainIdentifiers {
cpus[val.cpu] = true
if val.compiler != "" {
shouldUseCompilerAttribute = true
}
}
var cpuValues []string
for cpu := range cpus {
cpuValues = append(cpuValues, cpu)
}
var args []string
sort.Strings(cpuValues)
args = append(args,
fmt.Sprintf(
`"cpu": attr.string(mandatory=True, values=["%s"]),`,
strings.Join(cpuValues, "\", \"")))
if shouldUseCompilerAttribute {
// If there are two CToolchains that share the cpu we need the compiler attribute
// for our cc_toolchain_config rule.
allowedCompilers = getUniqueValues(allowedCompilers)
args = append(args,
fmt.Sprintf(`"compiler": attr.string(mandatory=True, values=["%s"]),`,
strings.Join(allowedCompilers, "\", \"")))
}
return fmt.Sprintf(`cc_toolchain_config = rule(
implementation = _impl,
attrs = {
%s
},
provides = [CcToolchainConfigInfo],
executable = True,
)
`, strings.Join(args, "\n "))
}