Delete ctx.action()
The function has been deprecated for a long time and is disabled by --incompatible_new_actions_api.
RELNOTES: None.
PiperOrigin-RevId: 318284100
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkRuleContext.java b/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkRuleContext.java
index 7fa6f5b..60cb655 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkRuleContext.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkRuleContext.java
@@ -82,7 +82,6 @@
import com.google.devtools.build.lib.syntax.EvalException;
import com.google.devtools.build.lib.syntax.EvalUtils;
import com.google.devtools.build.lib.syntax.Location;
-import com.google.devtools.build.lib.syntax.NoneType;
import com.google.devtools.build.lib.syntax.Printer;
import com.google.devtools.build.lib.syntax.Sequence;
import com.google.devtools.build.lib.syntax.Starlark;
@@ -873,72 +872,6 @@
return pkg.getSourceRoot().get().relativize(pkg.getBuildFile().getPath()).getPathString();
}
- /**
- * A Starlark built-in function to create and register a SpawnAction using a dictionary of
- * parameters: action( inputs = [input1, input2, ...], outputs = [output1, output2, ...],
- * executable = executable, arguments = [argument1, argument2, ...], mnemonic = 'Mnemonic',
- * command = 'command', )
- */
- @Override
- public NoneType action(
- Sequence<?> outputs,
- Object inputs,
- Object executableUnchecked,
- Object toolsUnchecked,
- Object arguments,
- Object mnemonicUnchecked,
- Object commandUnchecked,
- Object progressMessage,
- Boolean useDefaultShellEnv,
- Object envUnchecked,
- Object executionRequirementsUnchecked,
- Object inputManifestsUnchecked,
- StarlarkThread thread)
- throws EvalException {
- checkDeprecated(
- "ctx.actions.run or ctx.actions.run_shell", "ctx.action", thread.getSemantics());
- checkMutable("action");
- if ((commandUnchecked == Starlark.NONE) == (executableUnchecked == Starlark.NONE)) {
- throw Starlark.errorf("You must specify either 'command' or 'executable' argument");
- }
- boolean hasCommand = commandUnchecked != Starlark.NONE;
- if (!hasCommand) {
- actions()
- .run(
- outputs,
- inputs,
- /*unusedInputsList=*/ Starlark.NONE,
- executableUnchecked,
- toolsUnchecked,
- arguments,
- mnemonicUnchecked,
- progressMessage,
- useDefaultShellEnv,
- envUnchecked,
- executionRequirementsUnchecked,
- inputManifestsUnchecked,
- /* execGroupUnchecked= */ Starlark.NONE);
-
- } else {
- actions()
- .runShell(
- outputs,
- inputs,
- toolsUnchecked,
- arguments,
- mnemonicUnchecked,
- commandUnchecked,
- progressMessage,
- useDefaultShellEnv,
- envUnchecked,
- executionRequirementsUnchecked,
- inputManifestsUnchecked,
- /* execGroupUnchecked= */ Starlark.NONE,
- thread);
- }
- return Starlark.NONE;
- }
-
@Override
public String expandLocation(String input, Sequence<?> targets, StarlarkThread thread)
throws EvalException {
diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/StarlarkRuleContextApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/StarlarkRuleContextApi.java
index b7b398b..bd4b120 100644
--- a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/StarlarkRuleContextApi.java
+++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/StarlarkRuleContextApi.java
@@ -26,7 +26,6 @@
import com.google.devtools.build.lib.syntax.ClassObject;
import com.google.devtools.build.lib.syntax.Dict;
import com.google.devtools.build.lib.syntax.EvalException;
-import com.google.devtools.build.lib.syntax.NoneType;
import com.google.devtools.build.lib.syntax.Sequence;
import com.google.devtools.build.lib.syntax.StarlarkSemantics.FlagIdentifier;
import com.google.devtools.build.lib.syntax.StarlarkThread;
@@ -526,164 +525,6 @@
String getBuildFileRelativePath() throws EvalException;
@StarlarkMethod(
- name = "action",
- doc =
- "DEPRECATED. Use <a href=\"actions.html#run\">ctx.actions.run()</a> or"
- + " <a href=\"actions.html#run_shell\">ctx.actions.run_shell()</a>. <br>"
- + "Creates an action that runs an executable or a shell command."
- + " You must specify either <code>command</code> or <code>executable</code>.\n"
- + "Actions and genrules are very similar, but have different use cases. Actions are "
- + "used inside rules, and genrules are used inside macros. Genrules also have make "
- + "variable expansion.",
- parameters = {
- @Param(
- name = "outputs",
- type = Sequence.class,
- generic1 = FileApi.class,
- named = true,
- positional = false,
- doc = "List of the output files of the action."),
- @Param(
- name = "inputs",
- allowedTypes = {
- @ParamType(type = Sequence.class),
- @ParamType(type = Depset.class),
- },
- generic1 = FileApi.class,
- defaultValue = "[]",
- named = true,
- positional = false,
- doc = "List of the input files of the action."),
- @Param(
- name = "executable",
- type = Object.class,
- allowedTypes = {
- @ParamType(type = FileApi.class),
- @ParamType(type = String.class),
- @ParamType(type = NoneType.class),
- },
- noneable = true,
- defaultValue = "None",
- named = true,
- positional = false,
- doc = "The executable file to be called by the action."),
- @Param(
- name = "tools",
- allowedTypes = {
- @ParamType(type = Sequence.class),
- @ParamType(type = Depset.class),
- },
- generic1 = FileApi.class,
- defaultValue = "unbound",
- named = true,
- positional = false,
- doc =
- "List of the any tools needed by the action. Tools are inputs with additional "
- + "runfiles that are automatically made available to the action."),
- @Param(
- name = "arguments",
- allowedTypes = {
- @ParamType(type = Sequence.class),
- },
- defaultValue = "[]",
- named = true,
- positional = false,
- doc =
- "Command line arguments of the action. Must be a list of strings or actions.args() "
- + "objects."),
- @Param(
- name = "mnemonic",
- type = String.class,
- noneable = true,
- defaultValue = "None",
- named = true,
- positional = false,
- doc = "A one-word description of the action, e.g. CppCompile or GoLink."),
- @Param(
- name = "command",
- type = Object.class,
- allowedTypes = {
- @ParamType(type = String.class),
- @ParamType(type = Sequence.class, generic1 = String.class),
- @ParamType(type = NoneType.class),
- },
- noneable = true,
- defaultValue = "None",
- named = true,
- positional = false,
- doc =
- "Shell command to execute. It is usually preferable to "
- + "use <code>executable</code> instead. "
- + "Arguments are available with <code>$1</code>, <code>$2</code>, etc."),
- @Param(
- name = "progress_message",
- type = String.class,
- noneable = true,
- defaultValue = "None",
- named = true,
- positional = false,
- doc =
- "Progress message to show to the user during the build, "
- + "e.g. \"Compiling foo.cc to create foo.o\"."),
- @Param(
- name = "use_default_shell_env",
- type = Boolean.class,
- defaultValue = "False",
- named = true,
- positional = false,
- doc = "Whether the action should use the built in shell environment or not."),
- @Param(
- name = "env",
- type = Dict.class,
- noneable = true,
- defaultValue = "None",
- named = true,
- positional = false,
- doc = "Sets the dictionary of environment variables."),
- @Param(
- name = "execution_requirements",
- type = Dict.class,
- noneable = true,
- defaultValue = "None",
- named = true,
- positional = false,
- doc =
- "Information for scheduling the action. See "
- + "<a href=\"$BE_ROOT/common-definitions.html#common.tags\">tags</a> "
- + "for useful keys."),
- @Param(
- // TODO(bazel-team): The name here isn't accurate anymore. This is technically
- // experimental,
- // so folks shouldn't be too attached, but consider renaming to be more accurate/opaque.
- name = "input_manifests",
- type = Sequence.class,
- noneable = true,
- defaultValue = "None",
- named = true,
- positional = false,
- doc =
- "(Experimental) sets the input runfiles metadata; "
- + "they are typically generated by resolve_command.")
- },
- allowReturnNones = true,
- useStarlarkThread = true)
- NoneType action(
- Sequence<?> outputs,
- Object inputs,
- Object executableUnchecked,
- Object toolsUnchecked,
- Object arguments,
- Object mnemonicUnchecked,
- Object commandUnchecked,
- Object progressMessage,
- Boolean useDefaultShellEnv,
- Object envUnchecked,
- Object executionRequirementsUnchecked,
- Object inputManifestsUnchecked,
- StarlarkThread thread)
- throws EvalException;
-
- @StarlarkMethod(
name = "expand_location",
doc =
"Expands all <code>$(location ...)</code> templates in the given string by replacing "
diff --git a/src/test/java/com/google/devtools/build/lib/skylark/StarlarkRuleContextTest.java b/src/test/java/com/google/devtools/build/lib/skylark/StarlarkRuleContextTest.java
index 953edf1..c1d2bcc 100644
--- a/src/test/java/com/google/devtools/build/lib/skylark/StarlarkRuleContextTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skylark/StarlarkRuleContextTest.java
@@ -146,8 +146,7 @@
"cc_library(name = 'cc_with_features',",
" srcs = ['dummy.cc'],",
" features = ['f1', '-f3'],",
- ")"
- );
+ ")");
}
private void setRuleContext(StarlarkRuleContext ctx) throws Exception {
@@ -276,25 +275,27 @@
@Test
public void testMandatoryProvidersListWithNative() throws Exception {
setStarlarkSemanticsOptions("--incompatible_disallow_struct_provider_syntax=false");
- scratch.file("test/BUILD",
- "load('//test:rules.bzl', 'my_rule', 'my_other_rule')",
- "my_rule(name = 'mylib',",
- " srcs = ['a.py'])",
- "testing_rule_for_mandatory_providers(name = 'skyrule1',",
- " deps = [':mylib'])",
- "my_other_rule(name = 'my_other_lib',",
- " srcs = ['a.py'])",
- "testing_rule_for_mandatory_providers(name = 'skyrule2',",
- " deps = [':my_other_lib'])");
- scratch.file("test/rules.bzl",
- "def my_rule_impl(ctx):",
- " return struct(a = [])",
- "my_rule = rule(implementation = my_rule_impl, ",
- " attrs = { 'srcs' : attr.label_list(allow_files=True)})",
- "def my_other_rule_impl(ctx):",
- " return struct(b = [])",
- "my_other_rule = rule(implementation = my_other_rule_impl, ",
- " attrs = { 'srcs' : attr.label_list(allow_files=True)})");
+ scratch.file(
+ "test/BUILD",
+ "load('//test:rules.bzl', 'my_rule', 'my_other_rule')",
+ "my_rule(name = 'mylib',",
+ " srcs = ['a.py'])",
+ "testing_rule_for_mandatory_providers(name = 'skyrule1',",
+ " deps = [':mylib'])",
+ "my_other_rule(name = 'my_other_lib',",
+ " srcs = ['a.py'])",
+ "testing_rule_for_mandatory_providers(name = 'skyrule2',",
+ " deps = [':my_other_lib'])");
+ scratch.file(
+ "test/rules.bzl",
+ "def my_rule_impl(ctx):",
+ " return struct(a = [])",
+ "my_rule = rule(implementation = my_rule_impl, ",
+ " attrs = { 'srcs' : attr.label_list(allow_files=True)})",
+ "def my_other_rule_impl(ctx):",
+ " return struct(b = [])",
+ "my_other_rule = rule(implementation = my_other_rule_impl, ",
+ " attrs = { 'srcs' : attr.label_list(allow_files=True)})");
reporter.removeHandler(failFastHandler);
assertThat(getConfiguredTarget("//test:skyrule1")).isNotNull();
@@ -327,8 +328,7 @@
"load('//test:macros.bzl', 'starlark_rule')",
"starlark_rule(name = 'skyrule',",
" srcs = ['sub/my_sub_lib.h'])");
- scratch.file("test/sub/BUILD",
- "cc_library(name = 'my_sub_lib', srcs = ['my_sub_lib.h'])");
+ scratch.file("test/sub/BUILD", "cc_library(name = 'my_sub_lib', srcs = ['my_sub_lib.h'])");
scratch.file(
"test/macros.bzl",
"def _impl(ctx):",
@@ -354,8 +354,7 @@
"load('//test:macros.bzl', 'macro_starlark_rule')",
"macro_starlark_rule(name = 'm_starlark',",
" srcs = ['sub/my_sub_lib.h'])");
- scratch.file("test/sub/BUILD",
- "cc_library(name = 'my_sub_lib', srcs = ['my_sub_lib.h'])");
+ scratch.file("test/sub/BUILD", "cc_library(name = 'my_sub_lib', srcs = ['my_sub_lib.h'])");
scratch.file(
"test/macros.bzl",
"def _impl(ctx):",
@@ -403,12 +402,14 @@
scratch.file("/r/WORKSPACE");
scratch.file("/r/BUILD", "cc_library(name = 'cclib',", " srcs = ['sub/my_sub_lib.h'])");
scratch.file("/r/sub/BUILD", "cc_library(name = 'my_sub_lib', srcs = ['my_sub_lib.h'])");
- scratch.overwriteFile("WORKSPACE",
+ scratch.overwriteFile(
+ "WORKSPACE",
new ImmutableList.Builder<String>()
.addAll(analysisMock.getWorkspaceContents(mockToolsConfig))
.add("local_repository(name='r', path='/r')")
.build());
- invalidatePackages(/*alsoConfigs=*/false); // Repository shuffling messes with toolchain labels.
+ invalidatePackages(
+ /*alsoConfigs=*/ false); // Repository shuffling messes with toolchain labels.
reporter.removeHandler(failFastHandler);
getConfiguredTarget("@r//:cclib");
assertContainsEvent(
@@ -432,8 +433,7 @@
"test/BUILD",
"load('//test:macros.bzl', 'macro_starlark_rule')",
"macro_starlark_rule(name = 'm_starlark')");
- scratch.file("test/sub/BUILD",
- "cc_library(name = 'my_sub_lib', srcs = ['my_sub_lib.h'])");
+ scratch.file("test/sub/BUILD", "cc_library(name = 'my_sub_lib', srcs = ['my_sub_lib.h'])");
scratch.file(
"test/macros.bzl",
"def _impl(ctx):",
@@ -455,13 +455,14 @@
@Test
public void testPackageBoundaryError_NativeMacro() throws Exception {
- scratch.file("test/BUILD",
+ scratch.file(
+ "test/BUILD",
"load('//test:macros.bzl', 'macro_native_rule')",
"macro_native_rule(name = 'm_native',",
" srcs = ['sub/my_sub_lib.h'])");
- scratch.file("test/sub/BUILD",
- "cc_library(name = 'my_sub_lib', srcs = ['my_sub_lib.h'])");
- scratch.file("test/macros.bzl",
+ scratch.file("test/sub/BUILD", "cc_library(name = 'my_sub_lib', srcs = ['my_sub_lib.h'])");
+ scratch.file(
+ "test/macros.bzl",
"def macro_native_rule(name, deps=[], srcs=[]): ",
" native.cc_library(name = name, deps = deps, srcs = srcs)");
reporter.removeHandler(failFastHandler);
@@ -949,7 +950,6 @@
assertThat(result).isEqualTo("File");
}
-
@Test
public void testDeriveTreeArtifactNextToSibling() throws Exception {
setRuleContext(createRuleContext("//foo:foo"));
@@ -997,7 +997,6 @@
assertThat(fragment.getPathString()).isEqualTo("foo/t.exe.params");
}
-
@Test
public void testLabelKeyedStringDictConvertsToTargetToStringMap() throws Exception {
scratch.file(
@@ -1185,8 +1184,9 @@
invalidatePackages();
getConfiguredTarget("//:r");
- assertContainsEvent("in label_dict attribute of my_rule rule //:r: "
- + "source file '//:myfile.cpp' is misplaced here (expected no files)");
+ assertContainsEvent(
+ "in label_dict attribute of my_rule rule //:r: "
+ + "source file '//:myfile.cpp' is misplaced here (expected no files)");
}
@Test
@@ -1282,8 +1282,9 @@
invalidatePackages();
getConfiguredTarget("//:r");
- assertContainsEvent("in label_dict attribute of my_rule rule //:r: "
- + "'//:dep' does not have mandatory providers: 'my_provider'");
+ assertContainsEvent(
+ "in label_dict attribute of my_rule rule //:r: "
+ + "'//:dep' does not have mandatory providers: 'my_provider'");
}
@Test
@@ -1308,8 +1309,8 @@
invalidatePackages();
getConfiguredTarget("//:r");
- assertContainsEvent("in label_dict attribute of my_rule rule //:r: "
- + "attribute must be non empty");
+ assertContainsEvent(
+ "in label_dict attribute of my_rule rule //:r: " + "attribute must be non empty");
}
@Test
@@ -1351,10 +1352,7 @@
" }",
")");
- scratch.file(
- "BUILD",
- "load('//:my_rule.bzl', 'my_rule')",
- "my_rule(name='r')");
+ scratch.file("BUILD", "load('//:my_rule.bzl', 'my_rule')", "my_rule(name='r')");
invalidatePackages();
getConfiguredTarget("//:r");
@@ -1375,10 +1373,7 @@
" }",
")");
- scratch.file(
- "BUILD",
- "load('//:my_rule.bzl', 'my_rule')",
- "my_rule(name='r')");
+ scratch.file("BUILD", "load('//:my_rule.bzl', 'my_rule')", "my_rule(name='r')");
invalidatePackages();
createRuleContext("//:r");
@@ -1418,7 +1413,8 @@
@Test
public void testRelativeLabelInExternalRepository() throws Exception {
- scratch.file("external_rule.bzl",
+ scratch.file(
+ "external_rule.bzl",
"def _impl(ctx):",
" return",
"external_rule = rule(",
@@ -1428,21 +1424,21 @@
" }",
")");
- scratch.file("BUILD",
- "filegroup(name='dep')");
+ scratch.file("BUILD", "filegroup(name='dep')");
scratch.file("/r/WORKSPACE");
- scratch.file("/r/a/BUILD",
- "load('@//:external_rule.bzl', 'external_rule')",
- "external_rule(name='r')");
+ scratch.file(
+ "/r/a/BUILD", "load('@//:external_rule.bzl', 'external_rule')", "external_rule(name='r')");
- scratch.overwriteFile("WORKSPACE",
+ scratch.overwriteFile(
+ "WORKSPACE",
new ImmutableList.Builder<String>()
.addAll(analysisMock.getWorkspaceContents(mockToolsConfig))
.add("local_repository(name='r', path='/r')")
.build());
- invalidatePackages(/*alsoConfigs=*/false); // Repository shuffling messes with toolchain labels.
+ invalidatePackages(
+ /*alsoConfigs=*/ false); // Repository shuffling messes with toolchain labels.
setRuleContext(createRuleContext("@r//a:r"));
Label depLabel = (Label) ev.eval("ruleContext.attr.internal_dep.label");
assertThat(depLabel).isEqualTo(Label.parseAbsolute("//:dep", ImmutableMap.of()));
@@ -1451,7 +1447,8 @@
@Test
public void testCallerRelativeLabelInExternalRepository() throws Exception {
scratch.file("BUILD");
- scratch.file("external_rule.bzl",
+ scratch.file(
+ "external_rule.bzl",
"def _impl(ctx):",
" return",
"external_rule = rule(",
@@ -1464,20 +1461,20 @@
")");
scratch.file("/r/WORKSPACE");
- scratch.file("/r/BUILD",
- "filegroup(name='dep')");
+ scratch.file("/r/BUILD", "filegroup(name='dep')");
- scratch.file("/r/a/BUILD",
- "load('@//:external_rule.bzl', 'external_rule')",
- "external_rule(name='r')");
+ scratch.file(
+ "/r/a/BUILD", "load('@//:external_rule.bzl', 'external_rule')", "external_rule(name='r')");
- scratch.overwriteFile("WORKSPACE",
+ scratch.overwriteFile(
+ "WORKSPACE",
new ImmutableList.Builder<String>()
.addAll(analysisMock.getWorkspaceContents(mockToolsConfig))
.add("local_repository(name='r', path='/r')")
.build());
- invalidatePackages(/*alsoConfigs=*/false); // Repository shuffling messes with toolchain labels.
+ invalidatePackages(
+ /*alsoConfigs=*/ false); // Repository shuffling messes with toolchain labels.
setRuleContext(createRuleContext("@r//a:r"));
Label depLabel = (Label) ev.eval("ruleContext.attr.internal_dep.label");
assertThat(depLabel).isEqualTo(Label.parseAbsolute("@r//:dep", ImmutableMap.of()));
@@ -1496,17 +1493,14 @@
scratch.file(
"/r2/test.bzl",
"def macro(name, path):",
- " native.local_repository(name = name, path = path)"
- );
+ " native.local_repository(name = name, path = path)");
scratch.file("/r2/WORKSPACE");
scratch.file(
- "/r2/other_test.bzl",
- "def other_macro(name, path):",
- " print(name + ': ' + path)"
- );
+ "/r2/other_test.bzl", "def other_macro(name, path):", " print(name + ': ' + path)");
scratch.file("BUILD");
- scratch.overwriteFile("WORKSPACE",
+ scratch.overwriteFile(
+ "WORKSPACE",
new ImmutableList.Builder<String>()
.addAll(analysisMock.getWorkspaceContents(mockToolsConfig))
.add("local_repository(name='r2', path='/r2')")
@@ -1518,7 +1512,8 @@
.add("macro(NEXT_NAME, '/r2')") // and we can still use macro outside of its chunk.
.build());
- invalidatePackages(/*alsoConfigs=*/false); // Repository shuffling messes with toolchain labels.
+ invalidatePackages(
+ /*alsoConfigs=*/ false); // Repository shuffling messes with toolchain labels.
assertThat(getConfiguredTarget("@r1//:test")).isNotNull();
}
@@ -1532,14 +1527,16 @@
scratch.file("/baz/WORKSPACE");
scratch.file("/baz/baz.txt");
scratch.file("/baz/BUILD", "filegroup(name = 'baz', srcs = ['baz.txt'])");
- scratch.overwriteFile("WORKSPACE",
+ scratch.overwriteFile(
+ "WORKSPACE",
new ImmutableList.Builder<String>()
.addAll(analysisMock.getWorkspaceContents(mockToolsConfig))
.add("local_repository(name = 'foo', path = '/bar')")
.add("local_repository(name = 'foo', path = '/baz')")
.build());
- invalidatePackages(/*alsoConfigs=*/false); // Repository shuffling messes with toolchain labels.
+ invalidatePackages(
+ /*alsoConfigs=*/ false); // Repository shuffling messes with toolchain labels.
assertThat(
(List)
getConfiguredTargetAndData("@foo//:baz")
@@ -1552,7 +1549,8 @@
scratch.overwriteFile("BUILD");
scratch.overwriteFile("bar.bzl", "dummy = 1");
- scratch.overwriteFile("WORKSPACE",
+ scratch.overwriteFile(
+ "WORKSPACE",
new ImmutableList.Builder<String>()
.addAll(analysisMock.getWorkspaceContents(mockToolsConfig))
.add("local_repository(name = 'foo', path = '/bar')")
@@ -1560,8 +1558,7 @@
.add("local_repository(name = 'foo', path = '/baz')")
.build());
- invalidatePackages(
- /*alsoConfigs=*/ false); // Repository shuffling messes with toolchains.
+ invalidatePackages(/*alsoConfigs=*/ false); // Repository shuffling messes with toolchains.
assertThrows(Exception.class, () -> createRuleContext("@foo//:baz"));
assertContainsEvent(
"Cannot redefine repository after any load statement in the WORKSPACE file "
@@ -1803,8 +1800,7 @@
scratch.file("/bar/bar.txt");
scratch.file("/bar/BUILD", "exports_files(['bar.txt'])");
FileSystemUtils.appendIsoLatin1(
- scratch.resolve("WORKSPACE"),
- "local_repository(name = 'foo', path = '/bar')");
+ scratch.resolve("WORKSPACE"), "local_repository(name = 'foo', path = '/bar')");
scratch.file(
"test/BUILD",
"genrule(",
@@ -1860,33 +1856,33 @@
}
private final String testingRuleDefinition =
- linesAsString(
- "def _testing_impl(ctx):",
- " pass",
- "testing_rule = rule(",
- " implementation = _testing_impl,",
- " attrs = {'dep': attr.label()},",
- ")");
+ linesAsString(
+ "def _testing_impl(ctx):",
+ " pass",
+ "testing_rule = rule(",
+ " implementation = _testing_impl,",
+ " attrs = {'dep': attr.label()},",
+ ")");
private final String simpleBuildDefinition =
- linesAsString(
- "load(':rules.bzl', 'undertest_rule', 'testing_rule')",
- "undertest_rule(",
- " name = 'undertest',",
- ")",
- "testing_rule(",
- " name = 'testing',",
- " dep = ':undertest',",
- ")");
+ linesAsString(
+ "load(':rules.bzl', 'undertest_rule', 'testing_rule')",
+ "undertest_rule(",
+ " name = 'undertest',",
+ ")",
+ "testing_rule(",
+ " name = 'testing',",
+ " dep = ':undertest',",
+ ")");
@Test
public void testDependencyActionsProvider() throws Exception {
- scratch.file("test/rules.bzl",
+ scratch.file(
+ "test/rules.bzl",
getSimpleUnderTestDefinition(
"ctx.actions.run_shell(outputs=[out], command='echo foo123 > ' + out.path)"),
testingRuleDefinition);
- scratch.file("test/BUILD",
- simpleBuildDefinition);
+ scratch.file("test/BUILD", simpleBuildDefinition);
StarlarkRuleContext ruleContext = createRuleContext("//test:testing");
setRuleContext(ruleContext);
@@ -1905,12 +1901,12 @@
@Test
public void testNoAccessToDependencyActionsWithoutStarlarkTest() throws Exception {
reporter.removeHandler(failFastHandler);
- scratch.file("test/rules.bzl",
+ scratch.file(
+ "test/rules.bzl",
getSimpleNontestableUnderTestDefinition(
"ctx.actions.run_shell(outputs=[out], command='echo foo123 > ' + out.path)"),
testingRuleDefinition);
- scratch.file("test/BUILD",
- simpleBuildDefinition);
+ scratch.file("test/BUILD", simpleBuildDefinition);
StarlarkRuleContext ruleContext = createRuleContext("//test:testing");
setRuleContext(ruleContext);
@@ -1943,8 +1939,7 @@
" _skylark_testable = True,",
")",
testingRuleDefinition);
- scratch.file("test/BUILD",
- simpleBuildDefinition);
+ scratch.file("test/BUILD", simpleBuildDefinition);
StarlarkRuleContext ruleContext = createRuleContext("//test:testing");
setRuleContext(ruleContext);
ev.update("file1", ev.eval("ruleContext.attr.dep.out1"));
@@ -1994,8 +1989,7 @@
" _skylark_testable = True,",
")",
testingRuleDefinition);
- scratch.file("test/BUILD",
- simpleBuildDefinition);
+ scratch.file("test/BUILD", simpleBuildDefinition);
StarlarkRuleContext ruleContext = createRuleContext("//test:testing");
setRuleContext(ruleContext);
@@ -2014,11 +2008,12 @@
@Test
public void testNoAccessToCreatedActionsWithoutStarlarkTest() throws Exception {
- scratch.file("test/rules.bzl",
+ scratch.file(
+ "test/rules.bzl",
getSimpleNontestableUnderTestDefinition(
- "ctx.actions.run_shell(outputs=[out], command='echo foo123 > ' + out.path)")
- );
- scratch.file("test/BUILD",
+ "ctx.actions.run_shell(outputs=[out], command='echo foo123 > ' + out.path)"));
+ scratch.file(
+ "test/BUILD",
"load(':rules.bzl', 'undertest_rule')",
"undertest_rule(",
" name = 'undertest',",
@@ -2032,12 +2027,12 @@
@Test
public void testSpawnActionInterface() throws Exception {
- scratch.file("test/rules.bzl",
+ scratch.file(
+ "test/rules.bzl",
getSimpleUnderTestDefinition(
"ctx.actions.run_shell(outputs=[out], command='echo foo123 > ' + out.path)"),
testingRuleDefinition);
- scratch.file("test/BUILD",
- simpleBuildDefinition);
+ scratch.file("test/BUILD", simpleBuildDefinition);
StarlarkRuleContext ruleContext = createRuleContext("//test:testing");
setRuleContext(ruleContext);
ev.update("file", ev.eval("ruleContext.attr.dep.files.to_list()[0]"));
@@ -2148,12 +2143,11 @@
@Test
public void testFileWriteActionInterface() throws Exception {
- scratch.file("test/rules.bzl",
- getSimpleUnderTestDefinition(
- "ctx.actions.write(output=out, content='foo123')"),
+ scratch.file(
+ "test/rules.bzl",
+ getSimpleUnderTestDefinition("ctx.actions.write(output=out, content='foo123')"),
testingRuleDefinition);
- scratch.file("test/BUILD",
- simpleBuildDefinition);
+ scratch.file("test/BUILD", simpleBuildDefinition);
StarlarkRuleContext ruleContext = createRuleContext("//test:testing");
setRuleContext(ruleContext);
ev.update("file", ev.eval("ruleContext.attr.dep.files.to_list()[0]"));
@@ -2262,10 +2256,9 @@
" _skylark_testable = True,",
")",
testingRuleDefinition);
- scratch.file("test/template.txt",
- "aaaaa",
- "bcdef");
- scratch.file("test/BUILD",
+ scratch.file("test/template.txt", "aaaaa", "bcdef");
+ scratch.file(
+ "test/BUILD",
"load(':rules.bzl', 'undertest_rule', 'testing_rule')",
"undertest_rule(",
" name = 'undertest',",
@@ -2292,7 +2285,8 @@
}
private void setUpCoverageInstrumentedTest() throws Exception {
- scratch.file("test/BUILD",
+ scratch.file(
+ "test/BUILD",
"cc_library(",
" name = 'foo',",
" srcs = ['foo.cc'],",
@@ -2397,7 +2391,6 @@
"actions.run_shell(command = 'foo', outputs = [file])",
"actions.write(file, 'foo')",
"check_placeholders('foo', [])",
- "action(command = 'foo', outputs = [file])",
"runfiles()",
"resolve_command(command = 'foo')",
"resolve_tools()");
@@ -2405,7 +2398,8 @@
@Test
public void testFrozenRuleContextHasInaccessibleAttributes() throws Exception {
setStarlarkSemanticsOptions("--incompatible_new_actions_api=false");
- scratch.file("test/BUILD",
+ scratch.file(
+ "test/BUILD",
"load('//test:rules.bzl', 'main_rule', 'dep_rule')",
"dep_rule(name = 'dep')",
"main_rule(name = 'main', deps = [':dep'])");
@@ -2450,20 +2444,18 @@
setStarlarkSemanticsOptions("--incompatible_new_actions_api=false");
List<String> attributes = new ArrayList<>();
attributes.addAll(ctxAttributes);
- attributes.addAll(ImmutableList.of(
- "rule.attr",
- "rule.executable",
- "rule.file",
- "rule.files",
- "rule.kind"));
- scratch.file("test/BUILD",
+ attributes.addAll(
+ ImmutableList.of("rule.attr", "rule.executable", "rule.file", "rule.files", "rule.kind"));
+ scratch.file(
+ "test/BUILD",
"load('//test:rules.bzl', 'my_rule')",
"my_rule(name = 'dep')",
"my_rule(name = 'mid', deps = [':dep'])",
"my_rule(name = 'main', deps = [':mid'])");
scratch.file("test/rules.bzl");
for (String attribute : attributes) {
- scratch.overwriteFile("test/rules.bzl",
+ scratch.overwriteFile(
+ "test/rules.bzl",
"def _rule_impl(ctx):",
" pass",
"def _aspect_impl(target, ctx):",
@@ -2496,20 +2488,16 @@
}
private static final List<String> deprecatedActionsApi =
- ImmutableList.of(
- "new_file('foo.txt')",
- "new_file(file, 'foo.txt')",
- "action(command = 'foo', outputs = [file])");
+ ImmutableList.of("new_file('foo.txt')", "new_file(file, 'foo.txt')");
@Test
public void testIncompatibleNewActionsApi() throws Exception {
- scratch.file("test/BUILD",
- "load('//test:rules.bzl', 'main_rule')",
- "main_rule(name = 'main')");
+ scratch.file("test/BUILD", "load('//test:rules.bzl', 'main_rule')", "main_rule(name = 'main')");
scratch.file("test/rules.bzl");
for (String actionApi : deprecatedActionsApi) {
- scratch.overwriteFile("test/rules.bzl",
+ scratch.overwriteFile(
+ "test/rules.bzl",
"def _main_impl(ctx):",
" file = ctx.outputs.file",
" foo = ctx." + actionApi,
@@ -2519,8 +2507,7 @@
" 'deps': attr.label_list()",
" },",
" outputs = {'file': 'output.txt'},",
- ")"
- );
+ ")");
setStarlarkSemanticsOptions("--incompatible_new_actions_api=true");
invalidatePackages();
AssertionError e =
@@ -2537,12 +2524,14 @@
@Test
public void testMapAttributeOrdering() throws Exception {
- scratch.file("a/a.bzl",
+ scratch.file(
+ "a/a.bzl",
"key_provider = provider(fields=['keys'])",
"def _impl(ctx):",
" return [key_provider(keys=ctx.attr.value.keys())]",
"a = rule(implementation=_impl, attrs={'value': attr.string_dict()})");
- scratch.file("a/BUILD",
+ scratch.file(
+ "a/BUILD",
"load(':a.bzl', 'a')",
"a(name='a', value={'c': 'c', 'b': 'b', 'a': 'a', 'f': 'f', 'e': 'e', 'd': 'd'})");
@@ -2617,8 +2606,9 @@
reporter.removeHandler(failFastHandler);
getConfiguredTarget("//test:my_non_build_setting");
- assertContainsEvent("attempting to access 'build_setting_value' of non-build setting "
- + "//test:my_non_build_setting");
+ assertContainsEvent(
+ "attempting to access 'build_setting_value' of non-build setting "
+ + "//test:my_non_build_setting");
}
private void createToolchains() throws Exception {