diff options
author | 2017-06-22 17:41:06 +0200 | |
---|---|---|
committer | 2017-06-26 18:30:02 +0200 | |
commit | 94225590d55749db00c9644b9e62b78ea302b64e (patch) | |
tree | a49a2185050373449cc199d4c7e5284505822837 /src/main/java/com/google/devtools/build/lib/runtime/commands/ProjectFileSupport.java | |
parent | b82e3d014b68e5bf220129aa3bbd59bbaa4afa7f (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/commands/ProjectFileSupport.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/runtime/commands/ProjectFileSupport.java | 33 |
1 files changed, 18 insertions, 15 deletions
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()); } |