aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelStrategyModule.java
diff options
context:
space:
mode:
authorGravatar schmitt <schmitt@google.com>2017-05-09 11:30:32 -0400
committerGravatar Kristina Chodorow <kchodorow@google.com>2017-05-09 13:15:10 -0400
commit22f261d3041f6ee5ffd1976d5f5b46f8cc828ea0 (patch)
treee808dfc5cbfb17700f8e51cb6fe93e83798827c7 /src/main/java/com/google/devtools/build/lib/bazel/rules/BazelStrategyModule.java
parent006a80425e7dd521634c5735d2730f40e9e82e06 (diff)
Use BazelJavaSemantics for native Exoblaze and GoogleJavaSemantics for Exoblaze compatibility mode.
The functional change in this CL is that java_mutable_proto library now uses the "correct" java semantics depending on which blaze it is installed in. This required some refactoring of the ExoblazeRulesModule and ExoblazeRuleClassProvider to make them able to have parameters (like java semantics). To simplify module installation this change also extracts strategy management from being in "rules" modules to their own modules. Now modules don't need to inherit from each other anymore but can be installed alongside each other. It seems to be impossible to test the compatibility mode in TAP: java_mutable_proto library requires both Linux binaries (Blaze itself) and macOS binaries (ijar) which cannot both be inputs to the test today. So instead I manually tested this change in both Exoblaze native and compatibility mode. RELNOTES: None. PiperOrigin-RevId: 155507096
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/bazel/rules/BazelStrategyModule.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/rules/BazelStrategyModule.java83
1 files changed, 83 insertions, 0 deletions
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
new file mode 100644
index 0000000000..1edc643ac8
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelStrategyModule.java
@@ -0,0 +1,83 @@
+// Copyright 2014 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// 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;
+
+import com.google.common.collect.ImmutableList;
+import com.google.devtools.build.lib.buildtool.BuildRequest;
+import com.google.devtools.build.lib.exec.ExecutorBuilder;
+import com.google.devtools.build.lib.rules.android.WriteAdbArgsActionContext;
+import com.google.devtools.build.lib.runtime.BlazeModule;
+import com.google.devtools.build.lib.runtime.Command;
+import com.google.devtools.build.lib.runtime.CommandEnvironment;
+import com.google.devtools.common.options.Converters.AssignmentConverter;
+import com.google.devtools.common.options.Option;
+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 = "",
+ category = "strategy",
+ help =
+ "Specify how spawn actions are executed by default."
+ + "'standalone' means run all of them locally."
+ + "'sandboxed' means run them in namespaces based sandbox (available only on Linux)"
+ )
+ public String spawnStrategy;
+
+ @Option(
+ name = "genrule_strategy",
+ defaultValue = "",
+ category = "strategy",
+ help =
+ "Specify how to execute genrules."
+ + "'standalone' means run all of them locally."
+ + "'sandboxed' means run them in namespaces based sandbox (available only on Linux)"
+ )
+ public String genruleStrategy;
+
+ @Option(name = "strategy",
+ allowMultiple = true,
+ converter = AssignmentConverter.class,
+ defaultValue = "",
+ category = "strategy",
+ 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;
+ }
+
+ @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();
+ }
+
+ @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);
+ builder.addActionContextConsumer(new BazelActionContextConsumer(options));
+ }
+}