Move the --spawn_strategy and related flags to the ExecutionOptions.
RELNOTES: None.
PiperOrigin-RevId: 227842576
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelStrategyModule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelStrategyModule.java
index e309103..b5236a2 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelStrategyModule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelStrategyModule.java
@@ -18,6 +18,7 @@
import com.google.devtools.build.lib.analysis.actions.FileWriteActionContext;
import com.google.devtools.build.lib.analysis.actions.TemplateExpansionContext;
import com.google.devtools.build.lib.buildtool.BuildRequest;
+import com.google.devtools.build.lib.exec.ExecutionOptions;
import com.google.devtools.build.lib.exec.ExecutorBuilder;
import com.google.devtools.build.lib.exec.SpawnCache;
import com.google.devtools.build.lib.rules.android.WriteAdbArgsActionContext;
@@ -28,91 +29,22 @@
import com.google.devtools.build.lib.runtime.Command;
import com.google.devtools.build.lib.runtime.CommandEnvironment;
import com.google.devtools.build.lib.util.RegexFilter;
-import com.google.devtools.common.options.Converters.AssignmentConverter;
-import com.google.devtools.common.options.Option;
-import com.google.devtools.common.options.OptionDocumentationCategory;
-import com.google.devtools.common.options.OptionEffectTag;
import com.google.devtools.common.options.OptionsBase;
-import java.util.List;
import java.util.Map;
/** Module which registers the strategy options for Bazel. */
public class BazelStrategyModule extends BlazeModule {
- /**
- * Execution options affecting how we execute the build actions (but not their semantics).
- */
- public static class BazelExecutionOptions extends OptionsBase {
- @Option(
- name = "spawn_strategy",
- defaultValue = "",
- documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
- effectTags = {OptionEffectTag.UNKNOWN},
- help =
- "Specify how spawn actions are executed by default. "
- + "'standalone' means run all of them locally without any kind of sandboxing. "
- + "'sandboxed' means to run them in a sandboxed environment with limited privileges "
- + "(details depend on platform support)."
- )
- public String spawnStrategy;
-
- @Option(
- name = "genrule_strategy",
- defaultValue = "",
- documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
- effectTags = {OptionEffectTag.UNKNOWN},
- help =
- "Specify how to execute genrules. This flag will be phased out. Instead, use "
- + "--spawn_strategy=<value> to control all actions or --strategy=Genrule=<value> "
- + "to control genrules only.")
- public String genruleStrategy;
-
- @Option(
- name = "strategy",
- allowMultiple = true,
- converter = AssignmentConverter.class,
- defaultValue = "",
- documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
- effectTags = {OptionEffectTag.UNKNOWN},
- help =
- "Specify how to distribute compilation of other spawn actions. "
- + "Example: 'Javac=local' means to spawn Java compilation locally. "
- + "'JavaIjar=sandboxed' means to spawn Java Ijar actions in a sandbox. "
- )
- public List<Map.Entry<String, String>> strategy;
-
- @Option(
- name = "strategy_regexp",
- allowMultiple = true,
- converter = RegexFilterAssignmentConverter.class,
- documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
- effectTags = {OptionEffectTag.UNKNOWN},
- defaultValue = "",
- help =
- "Override which spawn strategy should be used to execute spawn actions that have "
- + "descriptions matching a certain regex_filter. See --per_file_copt for details on"
- + "regex_filter matching. "
- + "The first regex_filter that matches the description is used. "
- + "This option overrides other flags for specifying strategy. "
- + "Example: --strategy_regexp=//foo.*\\.cc,-//foo/bar=local means to run actions "
- + "using local strategy if their descriptions match //foo.*.cc but not //foo/bar. "
- + "Example: --strategy_regexp='Compiling.*/bar=local "
- + " --strategy_regexp=Compiling=sandboxed will run 'Compiling //foo/bar/baz' with "
- + "the 'local' strategy, but reversing the order would run it with 'sandboxed'. "
- )
- public List<Map.Entry<RegexFilter, String>> strategyByRegexp;
- }
-
@Override
public Iterable<Class<? extends OptionsBase>> getCommandOptions(Command command) {
return "build".equals(command.name())
- ? ImmutableList.<Class<? extends OptionsBase>>of(BazelExecutionOptions.class)
- : ImmutableList.<Class<? extends OptionsBase>>of();
+ ? ImmutableList.of(ExecutionOptions.class)
+ : ImmutableList.of();
}
@Override
public void executorInit(CommandEnvironment env, BuildRequest request, ExecutorBuilder builder) {
builder.addActionContext(new WriteAdbArgsActionContext(env.getClientEnv().get("HOME")));
- BazelExecutionOptions options = env.getOptions().getOptions(BazelExecutionOptions.class);
+ ExecutionOptions options = env.getOptions().getOptions(ExecutionOptions.class);
// Default strategies for certain mnemonics - they can be overridden by --strategy= flags.
builder.addStrategyByMnemonic("Javac", "worker");
diff --git a/src/main/java/com/google/devtools/build/lib/exec/ExecutionOptions.java b/src/main/java/com/google/devtools/build/lib/exec/ExecutionOptions.java
index e0d9c33..1919b25 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/ExecutionOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/ExecutionOptions.java
@@ -22,6 +22,7 @@
import com.google.devtools.build.lib.util.ResourceConverter;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.common.options.BoolOrEnumConverter;
+import com.google.devtools.common.options.Converters.AssignmentConverter;
import com.google.devtools.common.options.Option;
import com.google.devtools.common.options.OptionDocumentationCategory;
import com.google.devtools.common.options.OptionEffectTag;
@@ -30,6 +31,7 @@
import com.google.devtools.common.options.OptionsParsingException;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
/**
* Options affecting the execution phase of a build.
@@ -52,6 +54,62 @@
public static final ExecutionOptions DEFAULTS = Options.getDefaults(ExecutionOptions.class);
@Option(
+ name = "spawn_strategy",
+ defaultValue = "",
+ documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
+ effectTags = {OptionEffectTag.UNKNOWN},
+ help =
+ "Specify how spawn actions are executed by default. "
+ + "'standalone' means run all of them locally without any kind of sandboxing. "
+ + "'sandboxed' means to run them in a sandboxed environment with limited privileges "
+ + "(details depend on platform support).")
+ public String spawnStrategy;
+
+ @Option(
+ name = "genrule_strategy",
+ defaultValue = "",
+ documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
+ effectTags = {OptionEffectTag.UNKNOWN},
+ help =
+ "Specify how to execute genrules. This flag will be phased out. Instead, use "
+ + "--spawn_strategy=<value> to control all actions or --strategy=Genrule=<value> "
+ + "to control genrules only.")
+ public String genruleStrategy;
+
+ @Option(
+ name = "strategy",
+ allowMultiple = true,
+ converter = AssignmentConverter.class,
+ defaultValue = "",
+ documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
+ effectTags = {OptionEffectTag.UNKNOWN},
+ help =
+ "Specify how to distribute compilation of other spawn actions. "
+ + "Example: 'Javac=local' means to spawn Java compilation locally. "
+ + "'JavaIjar=sandboxed' means to spawn Java Ijar actions in a sandbox. ")
+ public List<Map.Entry<String, String>> strategy;
+
+ @Option(
+ name = "strategy_regexp",
+ allowMultiple = true,
+ converter = RegexFilterAssignmentConverter.class,
+ documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
+ effectTags = {OptionEffectTag.UNKNOWN},
+ defaultValue = "",
+ help =
+ "Override which spawn strategy should be used to execute spawn actions that have "
+ + "descriptions matching a certain regex_filter. See --per_file_copt for details on"
+ + "regex_filter matching. "
+ + "The first regex_filter that matches the description is used. "
+ + "This option overrides other flags for specifying strategy. "
+ + "Example: --strategy_regexp=//foo.*\\.cc,-//foo/bar=local means to run actions "
+ + "using local strategy if their descriptions match //foo.*.cc but not //foo/bar. "
+ + "Example: --strategy_regexp='Compiling.*/bar=local "
+ + " --strategy_regexp=Compiling=sandboxed will run 'Compiling //foo/bar/baz' with "
+ + "the 'local' strategy, but reversing the order would run it with 'sandboxed'. ")
+ public List<Map.Entry<RegexFilter, String>> strategyByRegexp;
+
+ @Option(
name = "materialize_param_files",
defaultValue = "false",
documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/RegexFilterAssignmentConverter.java b/src/main/java/com/google/devtools/build/lib/exec/RegexFilterAssignmentConverter.java
similarity index 96%
rename from src/main/java/com/google/devtools/build/lib/bazel/rules/RegexFilterAssignmentConverter.java
rename to src/main/java/com/google/devtools/build/lib/exec/RegexFilterAssignmentConverter.java
index f7c97f8..65b60b4 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/RegexFilterAssignmentConverter.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/RegexFilterAssignmentConverter.java
@@ -11,7 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
-package com.google.devtools.build.lib.bazel.rules;
+package com.google.devtools.build.lib.exec;
import com.google.common.collect.Maps;
import com.google.devtools.build.lib.util.RegexFilter;