aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java
diff options
context:
space:
mode:
authorGravatar ulfjack <ulfjack@google.com>2017-06-22 17:41:06 +0200
committerGravatar Marcel Hlopko <hlopko@google.com>2017-06-26 18:30:02 +0200
commit94225590d55749db00c9644b9e62b78ea302b64e (patch)
treea49a2185050373449cc199d4c7e5284505822837 /src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java
parentb82e3d014b68e5bf220129aa3bbd59bbaa4afa7f (diff)
Refactor ProjectFileSupport to work without a CommandEnvironment
Reading project files happens very early in the command initialization, and my plan is to change it so CommandEnvironment is created after we did that; the reason for that is that it makes the options final upon CommandEnvironment creation, which in turn allows simplifying the BlazeModule API. Since we no longer need a CommandEnvironment, or a BlazeWorkspace, or a BlazeRuntime, make the ProjectFileSupportTest a unit test. PiperOrigin-RevId: 159830404
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java
index e15d202866..58a2b87b82 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java
@@ -158,22 +158,22 @@ public class BlazeCommandDispatcher {
* Only some commands work if cwd != workspaceSuffix in Blaze. In that case, also check if Blaze
* was called from the output directory and fail if it was.
*/
- private ExitCode checkCwdInWorkspace(CommandEnvironment env, Command commandAnnotation,
+ private ExitCode checkCwdInWorkspace(BlazeWorkspace workspace, Command commandAnnotation,
String commandName, EventHandler eventHandler) {
if (!commandAnnotation.mustRunInWorkspace()) {
return ExitCode.SUCCESS;
}
- if (!env.inWorkspace()) {
+ if (!workspace.getDirectories().inWorkspace()) {
eventHandler.handle(
Event.error(
"The '" + commandName + "' command is only supported from within a workspace."));
return ExitCode.COMMAND_LINE_ERROR;
}
- Path workspace = env.getWorkspace();
+ Path workspacePath = workspace.getWorkspace();
// TODO(kchodorow): Remove this once spaces are supported.
- if (workspace.getPathString().contains(" ")) {
+ if (workspacePath.getPathString().contains(" ")) {
eventHandler.handle(
Event.error(
runtime.getProductName() + " does not currently work properly from paths "
@@ -181,7 +181,7 @@ public class BlazeCommandDispatcher {
return ExitCode.LOCAL_ENVIRONMENTAL_ERROR;
}
- Path doNotBuild = workspace.getParentDirectory().getRelative(
+ Path doNotBuild = workspacePath.getParentDirectory().getRelative(
BlazeWorkspace.DO_NOT_BUILD_FILE_NAME);
if (doNotBuild.exists()) {
@@ -228,7 +228,9 @@ public class BlazeCommandDispatcher {
parseOptionsForCommand(rcfileNotes, commandAnnotation, optionsParser, optionsMap, null, null);
if (commandAnnotation.builds()) {
- ProjectFileSupport.handleProjectFiles(env, optionsParser, commandAnnotation.name());
+ ProjectFileSupport.handleProjectFiles(
+ eventHandler, env.getEventBus(), runtime.getProjectFileProvider(), env.getWorkspace(),
+ env.getWorkingDirectory(), optionsParser, commandAnnotation.name());
}
// Fix-point iteration until all configs are loaded.
@@ -357,7 +359,8 @@ public class BlazeCommandDispatcher {
long execStartTimeNanos = runtime.getClock().nanoTime();
// The initCommand call also records the start time for the timestamp granularity monitor.
- CommandEnvironment env = runtime.getWorkspace().initCommand(commandAnnotation);
+ BlazeWorkspace workspace = runtime.getWorkspace();
+ CommandEnvironment env = workspace.initCommand(commandAnnotation);
// Record the command's starting time for use by the commands themselves.
env.recordCommandStartTime(firstContactTime);
@@ -388,7 +391,7 @@ public class BlazeCommandDispatcher {
}
try {
- Path commandLog = getCommandLogPath(env.getOutputBase());
+ Path commandLog = getCommandLogPath(workspace.getOutputBase());
// Unlink old command log from previous build, if present, so scripts
// reading it don't conflate it with the command log we're about to write.
@@ -396,7 +399,7 @@ public class BlazeCommandDispatcher {
logOutputStream = null;
commandLog.delete();
- if (env.getRuntime().writeCommandLog() && commandAnnotation.writeCommandLog()) {
+ if (workspace.getRuntime().writeCommandLog() && commandAnnotation.writeCommandLog()) {
logOutputStream = commandLog.getOutputStream();
outErr = tee(outErr, OutErr.create(logOutputStream, logOutputStream));
}
@@ -405,7 +408,7 @@ public class BlazeCommandDispatcher {
}
EventHandler eventHandler = new PrintingEventHandler(outErr, EventKind.ALL_EVENTS);
- ExitCode result = checkCwdInWorkspace(env, commandAnnotation, commandName, eventHandler);
+ ExitCode result = checkCwdInWorkspace(workspace, commandAnnotation, commandName, eventHandler);
if (!result.equals(ExitCode.SUCCESS)) {
return result.getNumericExitCode();
}
@@ -422,6 +425,8 @@ public class BlazeCommandDispatcher {
return ExitCode.BLAZE_INTERNAL_ERROR.getNumericExitCode();
}
try {
+ // TODO(ulfjack): parseArgsAndConfigs calls env.getWorkingDirectory, which isn't set correctly
+ // at this point in the code - it's initialized to the workspace root, which usually works.
ExitCode parseResult =
parseArgsAndConfigs(
env, optionsParser, commandAnnotation, args, rcfileNotes, eventHandler);