From 57d8af4d7b387b99c036eda2e649e999e3266094 Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 8 Dec 2022 07:51:13 -0800 Subject: [PATCH] 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 --- .../starlark/StarlarkActionFactory.java | 6 ++- .../StarlarkActionFactoryApi.java | 46 ++++++++++++++++++- 2 files changed, 48 insertions(+), 4 deletions(-) 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 de77b7e696a5d5..18c71cfa90839a 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 @@ -362,7 +362,8 @@ public void run( Object inputManifestsUnchecked, Object execGroupUnchecked, Object shadowedActionUnchecked, - Object resourceSetUnchecked) + Object resourceSetUnchecked, + Object toolchainUnchecked) throws EvalException { context.checkMutable("actions.run"); @@ -455,7 +456,8 @@ public void runShell( Object inputManifestsUnchecked, Object execGroupUnchecked, Object shadowedActionUnchecked, - Object resourceSetUnchecked) + Object resourceSetUnchecked, + Object toolchainUnchecked) throws EvalException { context.checkMutable("actions.run_shell"); RuleContext ruleContext = getRuleContext(); diff --git a/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/StarlarkActionFactoryApi.java b/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/StarlarkActionFactoryApi.java index 27fee5e251c79a..434412a1d16c07 100644 --- a/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/StarlarkActionFactoryApi.java +++ b/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/StarlarkActionFactoryApi.java @@ -15,6 +15,7 @@ package com.google.devtools.build.lib.starlarkbuildapi; import com.google.devtools.build.docgen.annot.DocCategory; +import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.collect.nestedset.Depset; import net.starlark.java.annot.Param; import net.starlark.java.annot.ParamType; @@ -457,6 +458,25 @@ void symlink( + " --experimental_action_resource_set is false, the default" + " values are used.

The callback must be top-level (lambda and nested" + " functions aren't allowed)."), + @Param( + name = "toolchain", + allowedTypes = { + @ParamType(type = Label.class), + @ParamType(type = String.class), + @ParamType(type = NoneType.class), + }, + defaultValue = "None", + named = true, + positional = false, + doc = + "

Toolchain type of the executable or tools used in this action. The parameter" + + " must be set, so that, the action executes on the correct execution" + + " platform.

It's a no-op right now, but we recommend to set it when a" + + " toolchain is used, because it will be required in the future Bazel" + + " releases.

Note that the rule which creates this action needs to" + + " define this toolchain inside its 'rule()' function.

When `toolchain`" + + " and `exec_group` parameters are both set, `exec_group` will be used. An" + + " error is raised in case the `exec_group` doesn't specify the same."), }) void run( Sequence outputs, @@ -473,7 +493,8 @@ void run( Object inputManifestsUnchecked, Object execGroupUnchecked, Object shadowedAction, - Object resourceSetUnchecked) + Object resourceSetUnchecked, + Object toolchainUnchecked) throws EvalException; @StarlarkMethod( @@ -674,6 +695,26 @@ void run( doc = "A callback function for estimating resource usage if run locally. See" + "ctx.actions.run()."), + @Param( + name = "toolchain", + allowedTypes = { + @ParamType(type = Label.class), + @ParamType(type = String.class), + @ParamType(type = NoneType.class), + }, + defaultValue = "None", + named = true, + positional = false, + doc = + "

Toolchain type of the executable or tools used in this action. The parameter" + + " must be set, so that, the action executes on the correct execution" + + " platform.

It's a no-op right now, but we recommend to set it when a" + + " toolchain is used, because it will be required in the future Bazel" + + " releases.

Note that the rule which creates this action needs to" + + " define this toolchain inside its 'rule()' function.

When `toolchain`" + + " and `exec_group` parameters are both set, `exec_group` will be used. An" + + " error is raised in case the `exec_group` doesn't specify the same." + + " toolchain.

"), }) void runShell( Sequence outputs, @@ -689,7 +730,8 @@ void runShell( Object inputManifestsUnchecked, Object execGroupUnchecked, Object shadowedAction, - Object resourceSetUnchecked) + Object resourceSetUnchecked, + Object toolchainUnchecked) throws EvalException; @StarlarkMethod(