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 @@ func getRule(cToolchainIdentifiers map[string]CToolchainIdentifier) string { 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 @@ func getAssignmentStatement(field string, valToIds map[string][]string, 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 TestAllAndNoneAvailableErrorsWhenMoreThanOneElement(t *testing.T) { } } -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 @@ func TestNoFailUnreachableInFeaturesAndActionConfigsDeclaration(t *testing.T) { 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 @@ func TestNoFailUnreachableInFeaturesAndActionConfigsDeclaration(t *testing.T) { 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 {