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
This commit is contained in:
rosica 2019-03-18 01:50:08 -07:00 committed by Copybara-Service
parent 0c017ebc6d
commit 3b89ccfbe7
2 changed files with 13 additions and 6 deletions

View File

@ -304,7 +304,7 @@ func getRule(cToolchainIdentifiers map[string]CToolchainIdentifier) string {
fmt.Sprintf(`"compiler": attr.string(values=["%s"]),`, fmt.Sprintf(`"compiler": attr.string(values=["%s"]),`,
strings.Join(compilerValues, "\", \""))) strings.Join(compilerValues, "\", \"")))
} }
return fmt.Sprintf(`cc_toolchain_config_rule = rule( return fmt.Sprintf(`cc_toolchain_config = rule(
implementation = _impl, implementation = _impl,
attrs = { attrs = {
%s %s
@ -1074,6 +1074,11 @@ func getAssignmentStatement(field string, valToIds map[string][]string,
fmt.Sprintf( fmt.Sprintf(
"%selse:\n%sfail(\"Unreachable\")\n", "%selse:\n%sfail(\"Unreachable\")\n",
getTabs(depth), getTabs(depth+1))) 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") b.WriteString("\n")

View File

@ -1080,7 +1080,7 @@ func TestAllAndNoneAvailableErrorsWhenMoreThanOneElement(t *testing.T) {
} }
} }
func TestNoFailUnreachableInFeaturesAndActionConfigsDeclaration(t *testing.T) { func TestFeaturesAndActionConfigsSetToNoneWhenAllOptionsAreExausted(t *testing.T) {
toolchainFeatureAEnabled := getCToolchain("1", "cpuA", "compilerA", toolchainFeatureAEnabled := getCToolchain("1", "cpuA", "compilerA",
[]string{getFeature([]string{"name: 'A'", "enabled: true"})}, []string{getFeature([]string{"name: 'A'", "enabled: true"})},
) )
@ -1118,8 +1118,9 @@ func TestNoFailUnreachableInFeaturesAndActionConfigsDeclaration(t *testing.T) {
a_feature = feature(name = "A") a_feature = feature(name = "A")
elif (ctx.attr.cpu == "cpuA" and ctx.attr.compiler == "compilerA"): elif (ctx.attr.cpu == "cpuA" and ctx.attr.compiler == "compilerA"):
a_feature = feature(name = "A", enabled = True) a_feature = feature(name = "A", enabled = True)
else:
` /* empty line after the elif means there's no else statement */}, a_feature = None
`},
{field: "action_config", {field: "action_config",
toolchains: []string{ toolchains: []string{
toolchainActionConfigAEnabled, toolchainActionConfigADisabled, toolchainWithoutActionConfigA}, toolchainActionConfigAEnabled, toolchainActionConfigADisabled, toolchainWithoutActionConfigA},
@ -1128,8 +1129,9 @@ func TestNoFailUnreachableInFeaturesAndActionConfigsDeclaration(t *testing.T) {
a_action = action_config(action_name = "A") a_action = action_config(action_name = "A")
elif (ctx.attr.cpu == "cpuA" and ctx.attr.compiler == "compilerD"): elif (ctx.attr.cpu == "cpuA" and ctx.attr.compiler == "compilerD"):
a_action = action_config(action_name = "A", enabled = True) a_action = action_config(action_name = "A", enabled = True)
else:
` /* empty line after the elif means there's no else statement */ }, a_action = None
`},
} }
for _, tc := range testCases { for _, tc := range testCases {