diff options
Diffstat (limited to 'src/main')
7 files changed, 44 insertions, 29 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); diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeWorkspace.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeWorkspace.java index d5b05da5e9..47b0cddc9e 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeWorkspace.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeWorkspace.java @@ -91,6 +91,10 @@ public final class BlazeWorkspace { this.outputBaseFilesystemTypeName = FileSystemUtils.getFileSystem(getOutputBase()); } + public BlazeRuntime getRuntime() { + return runtime; + } + /** * Returns the Blaze directories object for this runtime. */ diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/BuildCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/BuildCommand.java index 13f3f21891..fb7b4d2f2e 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/BuildCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/BuildCommand.java @@ -59,7 +59,7 @@ public final class BuildCommand implements BlazeCommand { @Override public ExitCode exec(CommandEnvironment env, OptionsProvider options) { BlazeRuntime runtime = env.getRuntime(); - List<String> targets = ProjectFileSupport.getTargets(runtime, options); + List<String> targets = ProjectFileSupport.getTargets(runtime.getProjectFileProvider(), options); BuildRequest request = BuildRequest.create( getClass().getAnnotation(Command.class).name(), options, diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/GotProjectFileEvent.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/GotProjectFileEvent.java index 36830e0136..4b6c58f803 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/GotProjectFileEvent.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/GotProjectFileEvent.java @@ -13,10 +13,12 @@ // limitations under the License. package com.google.devtools.build.lib.runtime.commands; +import com.google.devtools.build.lib.events.ExtendedEventHandler.Postable; + /** * An event describing a project file which has been parsed. */ -public class GotProjectFileEvent { +public class GotProjectFileEvent implements Postable { private final String projectFile; /** diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/ProjectFileSupport.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/ProjectFileSupport.java index 4f738c7a46..69b00fddc5 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/ProjectFileSupport.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/ProjectFileSupport.java @@ -13,12 +13,12 @@ // limitations under the License. package com.google.devtools.build.lib.runtime.commands; +import com.google.common.eventbus.EventBus; import com.google.devtools.build.lib.events.Event; +import com.google.devtools.build.lib.events.EventHandler; import com.google.devtools.build.lib.pkgcache.PackageCacheOptions; import com.google.devtools.build.lib.pkgcache.PathPackageLocator; import com.google.devtools.build.lib.runtime.BlazeCommand; -import com.google.devtools.build.lib.runtime.BlazeRuntime; -import com.google.devtools.build.lib.runtime.CommandEnvironment; import com.google.devtools.build.lib.runtime.CommonCommandOptions; import com.google.devtools.build.lib.runtime.ProjectFile; import com.google.devtools.build.lib.vfs.Path; @@ -42,11 +42,11 @@ public final class ProjectFileSupport { * accordingly. If project files cannot be read or if they contain unparsable options, or if they * are not enabled, then it throws an exception instead. */ - public static void handleProjectFiles(CommandEnvironment env, OptionsParser optionsParser, - String command) throws OptionsParsingException { - BlazeRuntime runtime = env.getRuntime(); + public static void handleProjectFiles( + EventHandler eventHandler, EventBus eventBus, ProjectFile.Provider projectFileProvider, + Path workspaceDir, Path workingDir, OptionsParser optionsParser, String command) + throws OptionsParsingException { List<String> targets = optionsParser.getResidue(); - ProjectFile.Provider projectFileProvider = runtime.getProjectFileProvider(); if (projectFileProvider != null && !targets.isEmpty() && targets.get(0).startsWith(PROJECT_FILE_PREFIX)) { if (targets.size() > 1) { @@ -60,18 +60,20 @@ public final class ProjectFileSupport { // relative to the cwd instead. PathFragment projectFilePath = PathFragment.create(targets.get(0).substring(1)); List<Path> packagePath = PathPackageLocator.create( - env.getOutputBase(), + // We only need a non-null outputBase for the PathPackageLocator if we support external + // repositories, which we don't for project files. + null, optionsParser.getOptions(PackageCacheOptions.class).packagePath, - env.getReporter(), - env.getWorkspace(), - env.getWorkingDirectory()).getPathEntries(); + eventHandler, + workspaceDir, + workingDir).getPathEntries(); ProjectFile projectFile = projectFileProvider.getProjectFile( - env.getWorkingDirectory(), packagePath, projectFilePath); - env.getReporter().handle(Event.info("Using " + projectFile.getName())); + workingDir, packagePath, projectFilePath); + eventHandler.handle(Event.info("Using " + projectFile.getName())); optionsParser.parse( OptionPriority.RC_FILE, projectFile.getName(), projectFile.getCommandLineFor(command)); - env.getEventBus().post(new GotProjectFileEvent(projectFile.getName())); + eventBus.post(new GotProjectFileEvent(projectFile.getName())); } } @@ -80,9 +82,10 @@ public final class ProjectFileSupport { * argument, it will be ignored, on the assumption that handleProjectFiles() has been called to * process it. */ - public static List<String> getTargets(BlazeRuntime runtime, OptionsProvider options) { + public static List<String> getTargets( + ProjectFile.Provider projectFileProvider, OptionsProvider options) { List<String> targets = options.getResidue(); - if (runtime.getProjectFileProvider() != null && !targets.isEmpty() + if (projectFileProvider != null && !targets.isEmpty() && targets.get(0).startsWith(PROJECT_FILE_PREFIX)) { return targets.subList(1, targets.size()); } diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/TestCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/TestCommand.java index de5f75feeb..02e7a7a9b9 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/TestCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/TestCommand.java @@ -109,7 +109,7 @@ public class TestCommand implements BlazeCommand { AggregatingTestListener testListener) { BlazeRuntime runtime = env.getRuntime(); // Run simultaneous build and test. - List<String> targets = ProjectFileSupport.getTargets(runtime, options); + List<String> targets = ProjectFileSupport.getTargets(runtime.getProjectFileProvider(), options); BuildRequest request = BuildRequest.create( getClass().getAnnotation(Command.class).name(), options, runtime.getStartupOptionsProvider(), targets, diff --git a/src/main/java/com/google/devtools/build/lib/runtime/mobileinstall/MobileInstallCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/mobileinstall/MobileInstallCommand.java index b424fd00ba..ed9329ed27 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/mobileinstall/MobileInstallCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/mobileinstall/MobileInstallCommand.java @@ -156,7 +156,8 @@ public class MobileInstallCommand implements BlazeCommand { env.getReporter().handle(Event.warn( "Warm start is enabled, but will have no effect on a non-incremental build")); } - List<String> targets = ProjectFileSupport.getTargets(env.getRuntime(), options); + List<String> targets = + ProjectFileSupport.getTargets(env.getRuntime().getProjectFileProvider(), options); BuildRequest request = BuildRequest.create( this.getClass().getAnnotation(Command.class).name(), |