diff --git a/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkActionFactory.java b/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkActionFactory.java index 9846ee271f06dd..b2fbdd82666f4a 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkActionFactory.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkActionFactory.java @@ -144,7 +144,7 @@ private void checkToolchainParameterIsSet(Object toolchainUnchecked) throws Eval if (toolchainUnchecked == Starlark.UNBOUND) { throw Starlark.errorf( "Couldn't identify if tools are from implicit dependencies or a toolchain. Please" - + " set the toolchain parameter."); + + " set the toolchain parameter. If you're not using a toolchain, set it to 'None'."); } } diff --git a/src/test/java/com/google/devtools/build/lib/analysis/AutoExecGroupsTest.java b/src/test/java/com/google/devtools/build/lib/analysis/AutoExecGroupsTest.java index c44579070fdd28..6c61a7f84a69aa 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/AutoExecGroupsTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/AutoExecGroupsTest.java @@ -186,6 +186,7 @@ private void createCustomRule( " implementation = _impl,", " attrs = {", " '_tool': attr.label(default = '//toolchain:a_tool', cfg = 'exec', executable = True),", + " '_nonexecutable_tool': attr.label(default = '//toolchain:b_tool', cfg = 'exec'),", extraAttributes, " },", " exec_groups = {", @@ -404,6 +405,43 @@ public void toolInExecutableIdentified_noToolchainParameter_noError() throws Exc assertNoEvents(); } + @Test + public void toolWithFilesToRunExecutable_noToolchainParameter_reportsError() throws Exception { + createCustomRule( + /* action= */ "ctx.actions.run", + /* actionParameters= */ "executable =" + + " ctx.attr._nonexecutable_tool[DefaultInfo].files_to_run.executable,", + /* extraAttributes= */ "", + /* toolchains= */ "['//rule:toolchain_type_1', '//rule:toolchain_type_2']", + /* execGroups= */ "", + /* execCompatibleWith= */ ""); + useConfiguration("--incompatible_auto_exec_groups"); + + reporter.removeHandler(failFastHandler); + getConfiguredTarget("//test:custom_rule_name"); + + assertContainsEvent( + "Couldn't identify if tools are from implicit dependencies or a toolchain. Please set" + + " the toolchain parameter. If you're not using a toolchain, set it to 'None'."); + } + + @Test + public void toolWithFilesToRunExecutable_toolchainParameterSetToNone_noError() throws Exception { + createCustomRule( + /* action= */ "ctx.actions.run", + /* actionParameters= */ "toolchain = None," + + " executable = ctx.attr._nonexecutable_tool[DefaultInfo].files_to_run.executable,", + /* extraAttributes= */ "", + /* toolchains= */ "['//rule:toolchain_type_1', '//rule:toolchain_type_2']", + /* execGroups= */ "", + /* execCompatibleWith= */ ""); + useConfiguration("--incompatible_auto_exec_groups"); + + getConfiguredTarget("//test:custom_rule_name"); + + assertNoEvents(); + } + @Test public void toolInExecutableUnidentified_noToolchainParameter_reportsError() throws Exception { createCustomRule( @@ -420,7 +458,7 @@ public void toolInExecutableUnidentified_noToolchainParameter_reportsError() thr assertContainsEvent( "Couldn't identify if tools are from implicit dependencies or a toolchain. Please set" - + " the toolchain parameter."); + + " the toolchain parameter. If you're not using a toolchain, set it to 'None'."); } @Test @@ -441,7 +479,7 @@ public void toolWithFilesToRunInExecutableUnidentified_noToolchainParameter_repo assertContainsEvent( "Couldn't identify if tools are from implicit dependencies or a toolchain. Please set" - + " the toolchain parameter."); + + " the toolchain parameter. If you're not using a toolchain, set it to 'None'."); } @Test @@ -465,7 +503,7 @@ public void toolInToolsUnidentified_noToolchainParameter_reportsError(String act assertContainsEvent( "Couldn't identify if tools are from implicit dependencies or a toolchain. Please set" - + " the toolchain parameter."); + + " the toolchain parameter. If you're not using a toolchain, set it to 'None'."); } @Test @@ -489,7 +527,7 @@ public void toolWithFilesToRunInToolsUnidentified_noToolchainParameter_reportsEr assertContainsEvent( "Couldn't identify if tools are from implicit dependencies or a toolchain. Please set" - + " the toolchain parameter."); + + " the toolchain parameter. If you're not using a toolchain, set it to 'None'."); } @Test @@ -512,7 +550,7 @@ public void depsetInTools_noToolchainParameter_reportsError(String action) throw assertContainsEvent( "Couldn't identify if tools are from implicit dependencies or a toolchain. Please set" - + " the toolchain parameter."); + + " the toolchain parameter. If you're not using a toolchain, set it to 'None'."); } @Test