Pass in the command options to BlazeModule.getCoverageReportFactory.

This allows us to make the coverage module stateless if it depends on options.

--
MOS_MIGRATED_REVID=129852270
diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/BuildTool.java b/src/main/java/com/google/devtools/build/lib/buildtool/BuildTool.java
index 802079b..9ce8770 100644
--- a/src/main/java/com/google/devtools/build/lib/buildtool/BuildTool.java
+++ b/src/main/java/com/google/devtools/build/lib/buildtool/BuildTool.java
@@ -447,7 +447,7 @@
     Profiler.instance().markPhase(ProfilePhase.ANALYZE);
 
     BuildView view = new BuildView(env.getDirectories(), runtime.getRuleClassProvider(),
-        env.getSkyframeExecutor(), runtime.getCoverageReportActionFactory());
+        env.getSkyframeExecutor(), runtime.getCoverageReportActionFactory(request));
     AnalysisResult analysisResult =
         view.update(
             loadingResult,
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeModule.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeModule.java
index 077cf5c..08e827b 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeModule.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeModule.java
@@ -40,12 +40,11 @@
 import com.google.devtools.build.lib.vfs.Path;
 import com.google.devtools.build.lib.vfs.PathFragment;
 import com.google.devtools.common.options.OptionsBase;
+import com.google.devtools.common.options.OptionsClassProvider;
 import com.google.devtools.common.options.OptionsProvider;
-
 import java.io.IOException;
 import java.util.Map;
 import java.util.UUID;
-
 import javax.annotation.Nullable;
 
 /**
@@ -320,10 +319,15 @@
   }
 
   /**
-   * Optionally returns a factory to create coverage report actions.
+   * Optionally returns a factory to create coverage report actions; this is called once per build,
+   * such that it can be affected by command options. 
+   *
+   * <p>It is an error if multiple modules return non-null values.
+   *
+   * @param commandOptions the options for the current command
    */
   @Nullable
-  public CoverageReportActionFactory getCoverageReportFactory() {
+  public CoverageReportActionFactory getCoverageReportFactory(OptionsClassProvider commandOptions) {
     return null;
   }
 }
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 acc7e6a..ea29c42 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
@@ -183,10 +183,11 @@
         this, packageFactory, ruleClassProvider, getProductName(), eventBusExceptionHandler);
   }
 
-  @Nullable public CoverageReportActionFactory getCoverageReportActionFactory() {
+  @Nullable public CoverageReportActionFactory getCoverageReportActionFactory(
+      OptionsClassProvider commandOptions) {
     CoverageReportActionFactory firstFactory = null;
     for (BlazeModule module : blazeModules) {
-      CoverageReportActionFactory factory = module.getCoverageReportFactory();
+      CoverageReportActionFactory factory = module.getCoverageReportFactory(commandOptions);
       if (factory != null) {
         Preconditions.checkState(firstFactory == null,
             "only one Blaze Module can have a Coverage Report Factory");