Skip to content

Commit a247502

Browse files
kotlajacopybara-github
authored andcommitted
Add 'toolchain' parameter to actions.{run,run_shell}
If set, the action executes on a specific execution platform connected to this toolchain (not to the default exec group). Design doc with more information: https://docs.google.com/document/d/1-rbP_hmKs9D639YWw5F_JyxPxL2bi6dSmmvj_WXak9M. PiperOrigin-RevId: 493894090 Change-Id: Ieb928cec469c01879eebe6249ff1db5df1da0527
1 parent 55f8213 commit a247502

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkActionFactory.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,8 @@ public void run(
369369
Object inputManifestsUnchecked,
370370
Object execGroupUnchecked,
371371
Object shadowedActionUnchecked,
372-
Object resourceSetUnchecked)
372+
Object resourceSetUnchecked,
373+
Object toolchainUnchecked)
373374
throws EvalException {
374375
context.checkMutable("actions.run");
375376

@@ -480,7 +481,8 @@ public void runShell(
480481
Object inputManifestsUnchecked,
481482
Object execGroupUnchecked,
482483
Object shadowedActionUnchecked,
483-
Object resourceSetUnchecked)
484+
Object resourceSetUnchecked,
485+
Object toolchainUnchecked)
484486
throws EvalException {
485487
context.checkMutable("actions.run_shell");
486488
RuleContext ruleContext = getRuleContext();

src/main/java/com/google/devtools/build/lib/starlarkbuildapi/StarlarkActionFactoryApi.java

+44-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package com.google.devtools.build.lib.starlarkbuildapi;
1616

1717
import com.google.devtools.build.docgen.annot.DocCategory;
18+
import com.google.devtools.build.lib.cmdline.Label;
1819
import com.google.devtools.build.lib.collect.nestedset.Depset;
1920
import com.google.devtools.build.lib.packages.semantics.BuildLanguageOptions;
2021
import net.starlark.java.annot.Param;
@@ -465,6 +466,25 @@ void symlink(
465466
+ " <code>--experimental_action_resource_set</code> is false, the default"
466467
+ " values are used.<p>The callback must be top-level (lambda and nested"
467468
+ " functions aren't allowed)."),
469+
@Param(
470+
name = "toolchain",
471+
allowedTypes = {
472+
@ParamType(type = Label.class),
473+
@ParamType(type = String.class),
474+
@ParamType(type = NoneType.class),
475+
},
476+
defaultValue = "None",
477+
named = true,
478+
positional = false,
479+
doc =
480+
"<p>Toolchain type of the executable or tools used in this action. The parameter"
481+
+ " must be set, so that, the action executes on the correct execution"
482+
+ " platform. </p><p>It's a no-op right now, but we recommend to set it when a"
483+
+ " toolchain is used, because it will be required in the future Bazel"
484+
+ " releases.</p><p>Note that the rule which creates this action needs to"
485+
+ " define this toolchain inside its 'rule()' function.</p><p>When `toolchain`"
486+
+ " and `exec_group` parameters are both set, `exec_group` will be used. An"
487+
+ " error is raised in case the `exec_group` doesn't specify the same."),
468488
})
469489
void run(
470490
Sequence<?> outputs,
@@ -481,7 +501,8 @@ void run(
481501
Object inputManifestsUnchecked,
482502
Object execGroupUnchecked,
483503
Object shadowedAction,
484-
Object resourceSetUnchecked)
504+
Object resourceSetUnchecked,
505+
Object toolchainUnchecked)
485506
throws EvalException;
486507

487508
@StarlarkMethod(
@@ -682,6 +703,26 @@ void run(
682703
doc =
683704
"A callback function for estimating resource usage if run locally. See"
684705
+ "<a href=\"#run.resource_set\"><code>ctx.actions.run()</code></a>."),
706+
@Param(
707+
name = "toolchain",
708+
allowedTypes = {
709+
@ParamType(type = Label.class),
710+
@ParamType(type = String.class),
711+
@ParamType(type = NoneType.class),
712+
},
713+
defaultValue = "None",
714+
named = true,
715+
positional = false,
716+
doc =
717+
"<p>Toolchain type of the executable or tools used in this action. The parameter"
718+
+ " must be set, so that, the action executes on the correct execution"
719+
+ " platform. </p><p>It's a no-op right now, but we recommend to set it when a"
720+
+ " toolchain is used, because it will be required in the future Bazel"
721+
+ " releases.</p><p>Note that the rule which creates this action needs to"
722+
+ " define this toolchain inside its 'rule()' function.</p><p>When `toolchain`"
723+
+ " and `exec_group` parameters are both set, `exec_group` will be used. An"
724+
+ " error is raised in case the `exec_group` doesn't specify the same."
725+
+ " toolchain.</p>"),
685726
})
686727
void runShell(
687728
Sequence<?> outputs,
@@ -697,7 +738,8 @@ void runShell(
697738
Object inputManifestsUnchecked,
698739
Object execGroupUnchecked,
699740
Object shadowedAction,
700-
Object resourceSetUnchecked)
741+
Object resourceSetUnchecked,
742+
Object toolchainUnchecked)
701743
throws EvalException;
702744

703745
@StarlarkMethod(

0 commit comments

Comments
 (0)