Skip to content

Commit b51396a

Browse files
ShreeM01kotlaja
andauthored
Add 'toolchain' parameter to actions.{run,run_shell} (bazelbuild#16964)
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 Co-authored-by: Googler <[email protected]>
1 parent 0ea070b commit b51396a

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,8 @@ public void run(
362362
Object inputManifestsUnchecked,
363363
Object execGroupUnchecked,
364364
Object shadowedActionUnchecked,
365-
Object resourceSetUnchecked)
365+
Object resourceSetUnchecked,
366+
Object toolchainUnchecked)
366367
throws EvalException {
367368
context.checkMutable("actions.run");
368369

@@ -455,7 +456,8 @@ public void runShell(
455456
Object inputManifestsUnchecked,
456457
Object execGroupUnchecked,
457458
Object shadowedActionUnchecked,
458-
Object resourceSetUnchecked)
459+
Object resourceSetUnchecked,
460+
Object toolchainUnchecked)
459461
throws EvalException {
460462
context.checkMutable("actions.run_shell");
461463
RuleContext ruleContext = getRuleContext();

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

Lines changed: 44 additions & 2 deletions
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 net.starlark.java.annot.Param;
2021
import net.starlark.java.annot.ParamType;
@@ -457,6 +458,25 @@ void symlink(
457458
+ " <code>--experimental_action_resource_set</code> is false, the default"
458459
+ " values are used.<p>The callback must be top-level (lambda and nested"
459460
+ " functions aren't allowed)."),
461+
@Param(
462+
name = "toolchain",
463+
allowedTypes = {
464+
@ParamType(type = Label.class),
465+
@ParamType(type = String.class),
466+
@ParamType(type = NoneType.class),
467+
},
468+
defaultValue = "None",
469+
named = true,
470+
positional = false,
471+
doc =
472+
"<p>Toolchain type of the executable or tools used in this action. The parameter"
473+
+ " must be set, so that, the action executes on the correct execution"
474+
+ " platform. </p><p>It's a no-op right now, but we recommend to set it when a"
475+
+ " toolchain is used, because it will be required in the future Bazel"
476+
+ " releases.</p><p>Note that the rule which creates this action needs to"
477+
+ " define this toolchain inside its 'rule()' function.</p><p>When `toolchain`"
478+
+ " and `exec_group` parameters are both set, `exec_group` will be used. An"
479+
+ " error is raised in case the `exec_group` doesn't specify the same."),
460480
})
461481
void run(
462482
Sequence<?> outputs,
@@ -473,7 +493,8 @@ void run(
473493
Object inputManifestsUnchecked,
474494
Object execGroupUnchecked,
475495
Object shadowedAction,
476-
Object resourceSetUnchecked)
496+
Object resourceSetUnchecked,
497+
Object toolchainUnchecked)
477498
throws EvalException;
478499

479500
@StarlarkMethod(
@@ -674,6 +695,26 @@ void run(
674695
doc =
675696
"A callback function for estimating resource usage if run locally. See"
676697
+ "<a href=\"#run.resource_set\"><code>ctx.actions.run()</code></a>."),
698+
@Param(
699+
name = "toolchain",
700+
allowedTypes = {
701+
@ParamType(type = Label.class),
702+
@ParamType(type = String.class),
703+
@ParamType(type = NoneType.class),
704+
},
705+
defaultValue = "None",
706+
named = true,
707+
positional = false,
708+
doc =
709+
"<p>Toolchain type of the executable or tools used in this action. The parameter"
710+
+ " must be set, so that, the action executes on the correct execution"
711+
+ " platform. </p><p>It's a no-op right now, but we recommend to set it when a"
712+
+ " toolchain is used, because it will be required in the future Bazel"
713+
+ " releases.</p><p>Note that the rule which creates this action needs to"
714+
+ " define this toolchain inside its 'rule()' function.</p><p>When `toolchain`"
715+
+ " and `exec_group` parameters are both set, `exec_group` will be used. An"
716+
+ " error is raised in case the `exec_group` doesn't specify the same."
717+
+ " toolchain.</p>"),
677718
})
678719
void runShell(
679720
Sequence<?> outputs,
@@ -689,7 +730,8 @@ void runShell(
689730
Object inputManifestsUnchecked,
690731
Object execGroupUnchecked,
691732
Object shadowedAction,
692-
Object resourceSetUnchecked)
733+
Object resourceSetUnchecked,
734+
Object toolchainUnchecked)
693735
throws EvalException;
694736

695737
@StarlarkMethod(

0 commit comments

Comments
 (0)