diff options
author | 2018-04-17 08:49:01 -0700 | |
---|---|---|
committer | 2018-04-17 08:50:49 -0700 | |
commit | 57d6c33d691a2021bde812f9a8780283799558f6 (patch) | |
tree | 8c8f2340d549b3ad223209b481ab09d30fac1248 /src/main/java/com/google/devtools | |
parent | 9c8c77502ff52907a327e6bdc9ac282da0af6b44 (diff) |
A slight refactoring of RunCommand.
RELNOTES: None.
PiperOrigin-RevId: 193203414
Diffstat (limited to 'src/main/java/com/google/devtools')
6 files changed, 48 insertions, 8 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/Bazel.java b/src/main/java/com/google/devtools/build/lib/bazel/Bazel.java index 135d0408f5..47c0e8553e 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/Bazel.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/Bazel.java @@ -53,7 +53,8 @@ public final class Bazel { com.google.devtools.build.lib.bazel.rules.BazelStrategyModule.class, com.google.devtools.build.lib.buildeventservice.BazelBuildEventServiceModule.class, com.google.devtools.build.lib.profiler.callcounts.CallcountsModule.class, - com.google.devtools.build.lib.profiler.memory.AllocationTrackerModule.class); + com.google.devtools.build.lib.profiler.memory.AllocationTrackerModule.class, + BazelBuiltinCommandModule.class); public static void main(String[] args) { BlazeVersionInfo.setBuildInfo(tryGetBuildInfo()); diff --git a/src/main/java/com/google/devtools/build/lib/bazel/BazelBuiltinCommandModule.java b/src/main/java/com/google/devtools/build/lib/bazel/BazelBuiltinCommandModule.java new file mode 100644 index 0000000000..be9e9eb3e0 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/bazel/BazelBuiltinCommandModule.java @@ -0,0 +1,25 @@ +// Copyright 2018 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; + +import com.google.devtools.build.lib.exec.StandaloneTestStrategy; +import com.google.devtools.build.lib.runtime.BuiltinCommandModule; +import com.google.devtools.build.lib.runtime.commands.RunCommand; + +/** A module that contains the built-in commands. */ +public final class BazelBuiltinCommandModule extends BuiltinCommandModule { + public BazelBuiltinCommandModule() { + super(new RunCommand(StandaloneTestStrategy.DEFAULT_LOCAL_POLICY)); + } +} diff --git a/src/main/java/com/google/devtools/build/lib/exec/TestPolicy.java b/src/main/java/com/google/devtools/build/lib/exec/TestPolicy.java index e8bf2753ac..67df538507 100644 --- a/src/main/java/com/google/devtools/build/lib/exec/TestPolicy.java +++ b/src/main/java/com/google/devtools/build/lib/exec/TestPolicy.java @@ -40,6 +40,8 @@ public class TestPolicy { public static final String INHERITED = "${inherited}"; + public static final TestPolicy EMPTY_POLICY = new TestPolicy(ImmutableMap.of()); + private final ImmutableMap<String, String> envVariables; /** diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java index 04d08f3e79..f69b44ba98 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java @@ -1073,7 +1073,6 @@ public final class BlazeRuntime { LoggingUtil.installRemoteLogger(getTestCrashLogger()); } - runtimeBuilder.addBlazeModule(new BuiltinCommandModule()); // This module needs to be registered before any module providing a SpawnCache implementation. runtimeBuilder.addBlazeModule(new NoSpawnCacheModule()); runtimeBuilder.addBlazeModule(new CommandLogModule()); diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BuiltinCommandModule.java b/src/main/java/com/google/devtools/build/lib/runtime/BuiltinCommandModule.java index 499f54fdb8..e94f2f5be2 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/BuiltinCommandModule.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/BuiltinCommandModule.java @@ -34,7 +34,13 @@ import com.google.devtools.common.options.OptionsProvider; /** * Internal module for the built-in commands. */ -public final class BuiltinCommandModule extends BlazeModule { +public class BuiltinCommandModule extends BlazeModule { + private final RunCommand runCommand; + + protected BuiltinCommandModule(RunCommand runCommand) { + this.runCommand = runCommand; + } + @Override public void serverInit(OptionsProvider startupOptions, ServerBuilder builder) { builder.addCommands( @@ -48,7 +54,7 @@ public final class BuiltinCommandModule extends BlazeModule { new PrintActionCommand(), new ProfileCommand(), new QueryCommand(), - new RunCommand(), + runCommand, new ShutdownCommand(), new TestCommand(), new VersionCommand(), diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/RunCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/RunCommand.java index 4229374a1d..f9d566f1e7 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/RunCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/RunCommand.java @@ -41,8 +41,8 @@ import com.google.devtools.build.lib.buildtool.TargetValidator; import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.events.Reporter; import com.google.devtools.build.lib.exec.ExecutionOptions; -import com.google.devtools.build.lib.exec.StandaloneTestStrategy; import com.google.devtools.build.lib.exec.SymlinkTreeHelper; +import com.google.devtools.build.lib.exec.TestPolicy; import com.google.devtools.build.lib.exec.TestStrategy; import com.google.devtools.build.lib.packages.InputFile; import com.google.devtools.build.lib.packages.NoSuchPackageException; @@ -158,11 +158,18 @@ public class RunCommand implements BlazeCommand { "'run' only works with tests with one shard ('--test_sharding_strategy=disabled' is okay) " + "and without --runs_per_test"; + // The test policy to determine the environment variables from when running tests + private final TestPolicy testPolicy; + // Value of --run_under as of the most recent command invocation. private RunUnder currentRunUnder; private static final FileType RUNFILES_MANIFEST = FileType.of(".runfiles_manifest"); + public RunCommand(TestPolicy testPolicy) { + this.testPolicy = testPolicy; + } + @VisibleForTesting // productionVisibility = Visibility.PRIVATE protected BuildResult processRequest(final CommandEnvironment env, BuildRequest request) { return new BuildTool(env).processRequest(request, new TargetValidator() { @@ -465,9 +472,9 @@ public class RunCommand implements BlazeCommand { Path tmpDirRoot = TestStrategy.getTmpRoot( env.getWorkspace(), env.getExecRoot(), executionOptions); PathFragment relativeTmpDir = tmpDirRoot.relativeTo(env.getExecRoot()); - Duration timeout = - configuration.getTestTimeout().get(testAction.getTestProperties().getTimeout()); - runEnvironment.putAll(StandaloneTestStrategy.DEFAULT_LOCAL_POLICY.computeTestEnvironment( + Duration timeout = configuration.getTestTimeout().get( + testAction.getTestProperties().getTimeout()); + runEnvironment.putAll(testPolicy.computeTestEnvironment( testAction, env.getClientEnv(), timeout, |