Remove linter warnings that a feature or action_config may not be declared by setting it to None instead.
Also rename the rule from cc_toolchain_config_rule to cc_toolchain_config
Issue #5380
RELNOTES: None.
PiperOrigin-RevId: 238945434
diff --git a/tools/migration/crosstool_to_starlark_lib.go b/tools/migration/crosstool_to_starlark_lib.go
index 77b7565..675ab1c 100644
--- a/tools/migration/crosstool_to_starlark_lib.go
+++ b/tools/migration/crosstool_to_starlark_lib.go
@@ -304,7 +304,7 @@
fmt.Sprintf(`"compiler": attr.string(values=["%s"]),`,
strings.Join(compilerValues, "\", \"")))
}
- return fmt.Sprintf(`cc_toolchain_config_rule = rule(
+ return fmt.Sprintf(`cc_toolchain_config = rule(
implementation = _impl,
attrs = {
%s
@@ -1074,6 +1074,11 @@
fmt.Sprintf(
"%selse:\n%sfail(\"Unreachable\")\n",
getTabs(depth), getTabs(depth+1)))
+ } else {
+ b.WriteString(
+ fmt.Sprintf(
+ "%selse:\n%s%s = None\n",
+ getTabs(depth), getTabs(depth+1), field))
}
}
b.WriteString("\n")
diff --git a/tools/migration/crosstool_to_starlark_lib_test.go b/tools/migration/crosstool_to_starlark_lib_test.go
index bcbc997..459cb3a 100644
--- a/tools/migration/crosstool_to_starlark_lib_test.go
+++ b/tools/migration/crosstool_to_starlark_lib_test.go
@@ -1080,7 +1080,7 @@
}
}
-func TestNoFailUnreachableInFeaturesAndActionConfigsDeclaration(t *testing.T) {
+func TestFeaturesAndActionConfigsSetToNoneWhenAllOptionsAreExausted(t *testing.T) {
toolchainFeatureAEnabled := getCToolchain("1", "cpuA", "compilerA",
[]string{getFeature([]string{"name: 'A'", "enabled: true"})},
)
@@ -1118,8 +1118,9 @@
a_feature = feature(name = "A")
elif (ctx.attr.cpu == "cpuA" and ctx.attr.compiler == "compilerA"):
a_feature = feature(name = "A", enabled = True)
-
-` /* empty line after the elif means there's no else statement */},
+ else:
+ a_feature = None
+`},
{field: "action_config",
toolchains: []string{
toolchainActionConfigAEnabled, toolchainActionConfigADisabled, toolchainWithoutActionConfigA},
@@ -1128,8 +1129,9 @@
a_action = action_config(action_name = "A")
elif (ctx.attr.cpu == "cpuA" and ctx.attr.compiler == "compilerD"):
a_action = action_config(action_name = "A", enabled = True)
-
-` /* empty line after the elif means there's no else statement */ },
+ else:
+ a_action = None
+`},
}
for _, tc := range testCases {