Remove the --debug_print_action_contexts command line option.

The same information is now unconditionally logged to the logfile.

RELNOTES[INC]: The --debug_print_action_contexts command line option is not available anymore.

PiperOrigin-RevId: 568793876
Change-Id: I57466b3d9e77b1b763fa09cefae86665322d04e6
diff --git a/src/main/java/com/google/devtools/build/lib/exec/BUILD b/src/main/java/com/google/devtools/build/lib/exec/BUILD
index 895357e..2a27462 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/exec/BUILD
@@ -156,11 +156,11 @@
     srcs = ["ModuleActionContextRegistry.java"],
     deps = [
         "//src/main/java/com/google/devtools/build/lib/actions",
-        "//src/main/java/com/google/devtools/build/lib/events",
         "//src/main/java/com/google/devtools/build/lib/util:abrupt_exit_exception",
         "//src/main/java/com/google/devtools/build/lib/util:detailed_exit_code",
         "//src/main/protobuf:failure_details_java_proto",
         "//third_party:auto_value",
+        "//third_party:flogger",
         "//third_party:guava",
     ],
 )
diff --git a/src/main/java/com/google/devtools/build/lib/exec/BlazeExecutor.java b/src/main/java/com/google/devtools/build/lib/exec/BlazeExecutor.java
index 0c875f4..c02dae1 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/BlazeExecutor.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/BlazeExecutor.java
@@ -75,10 +75,8 @@
     this.options = options;
     this.actionContextRegistry = actionContextRegistry;
 
-    if (executionOptions.debugPrintActionContexts) {
-      spawnStrategyRegistry.writeSpawnStrategiesTo(reporter);
-      actionContextRegistry.writeActionContextsTo(reporter);
-    }
+    spawnStrategyRegistry.logSpawnStrategies();
+    actionContextRegistry.logActionContexts();
 
     actionContextRegistry.notifyUsed();
     spawnStrategyRegistry.notifyUsed(actionContextRegistry);
diff --git a/src/main/java/com/google/devtools/build/lib/exec/ExecutionOptions.java b/src/main/java/com/google/devtools/build/lib/exec/ExecutionOptions.java
index 8732f66..d3cf3c1 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/ExecutionOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/ExecutionOptions.java
@@ -367,14 +367,6 @@
   public boolean prioritizeLocalActions;
 
   @Option(
-      name = "debug_print_action_contexts",
-      defaultValue = "false",
-      documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
-      effectTags = {OptionEffectTag.UNKNOWN},
-      help = "Print the contents of the SpawnActionContext and ContextProviders maps.")
-  public boolean debugPrintActionContexts;
-
-  @Option(
       name = "cache_computed_file_digests",
       defaultValue = "50000",
       documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
diff --git a/src/main/java/com/google/devtools/build/lib/exec/ModuleActionContextRegistry.java b/src/main/java/com/google/devtools/build/lib/exec/ModuleActionContextRegistry.java
index 3c22484..8b8478f 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/ModuleActionContextRegistry.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/ModuleActionContextRegistry.java
@@ -21,9 +21,8 @@
 import com.google.common.collect.Multimap;
 import com.google.common.collect.MutableClassToInstanceMap;
 import com.google.common.collect.Sets;
+import com.google.common.flogger.GoogleLogger;
 import com.google.devtools.build.lib.actions.ActionContext;
-import com.google.devtools.build.lib.events.Event;
-import com.google.devtools.build.lib.events.Reporter;
 import com.google.devtools.build.lib.server.FailureDetails;
 import com.google.devtools.build.lib.server.FailureDetails.ExecutionOptions.Code;
 import com.google.devtools.build.lib.server.FailureDetails.FailureDetail;
@@ -53,6 +52,8 @@
 public final class ModuleActionContextRegistry
     implements ActionContext, ActionContext.ActionContextRegistry {
 
+  private static final GoogleLogger logger = GoogleLogger.forEnclosingClass();
+
   private final ImmutableClassToInstanceMap<ActionContext> identifyingTypeToContext;
 
   private ModuleActionContextRegistry(
@@ -79,17 +80,14 @@
    * Records the list of all contexts that can be {@linkplain #getContext returned by this registry}
    * to the given reporter.
    */
-  void writeActionContextsTo(Reporter reporter) {
+  void logActionContexts() {
     for (Map.Entry<Class<? extends ActionContext>, ActionContext> typeToContext :
         identifyingTypeToContext.entrySet()) {
-      reporter.handle(
-          Event.info(
-              String.format(
-                  "IdentifyingTypeToContext: \"%s\" = [%s]",
-                  typeToContext.getKey(), typeToContext.getValue().getClass().getSimpleName())));
+      logger.atInfo().log(
+          "IdentifyingTypeToContext: \"%s\" = [%s]",
+          typeToContext.getKey(), typeToContext.getValue().getClass().getSimpleName());
     }
   }
-
   /**
    * Returns a new {@link Builder} suitable for creating instances of ModuleActionContextRegistry.
    */
diff --git a/src/main/java/com/google/devtools/build/lib/exec/SpawnStrategyRegistry.java b/src/main/java/com/google/devtools/build/lib/exec/SpawnStrategyRegistry.java
index 5567512..5226916 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/SpawnStrategyRegistry.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/SpawnStrategyRegistry.java
@@ -185,55 +185,43 @@
    * Records the list of all spawn strategies that can be returned by the various query methods of
    * this registry to the given reporter.
    */
-  void writeSpawnStrategiesTo(Reporter reporter) {
+  void logSpawnStrategies() {
     for (Map.Entry<String, Collection<SpawnStrategy>> entry :
         mnemonicToStrategies.asMap().entrySet()) {
-      reporter.handle(
-          Event.info(
-              String.format(
-                  "MnemonicToStrategyImplementations: \"%s\" = [%s]",
-                  entry.getKey(), toImplementationNames(entry.getValue()))));
+      logger.atInfo().log(
+          "MnemonicToStrategyImplementations: \"%s\" = [%s]",
+          entry.getKey(), toImplementationNames(entry.getValue()));
     }
 
     for (Map.Entry<RegexFilter, Collection<SpawnStrategy>> entry :
         filterToStrategies.asMap().entrySet()) {
       Collection<SpawnStrategy> value = entry.getValue();
-      reporter.handle(
-          Event.info(
-              String.format(
-                  "FilterToStrategyImplementations: \"%s\" = [%s]",
-                  entry.getKey(), toImplementationNames(value))));
+      logger.atInfo().log(
+          "FilterToStrategyImplementations: \"%s\" = [%s]",
+          entry.getKey(), toImplementationNames(value));
     }
 
-    reporter.handle(
-        Event.info(
-            String.format(
-                "DefaultStrategyImplementations: [%s]", toImplementationNames(defaultStrategies))));
+    logger.atInfo().log(
+        "DefaultStrategyImplementations: [%s]", toImplementationNames(defaultStrategies));
 
     if (remoteLocalFallbackStrategy != null) {
-      reporter.handle(
-          Event.info(
-              String.format(
-                  "RemoteLocalFallbackImplementation: [%s]",
-                  remoteLocalFallbackStrategy.getClass().getSimpleName())));
+      logger.atInfo().log(
+          "RemoteLocalFallbackImplementation: [%s]",
+          remoteLocalFallbackStrategy.getClass().getSimpleName());
     }
 
     for (Map.Entry<String, Collection<SandboxedSpawnStrategy>> entry :
         mnemonicToRemoteDynamicStrategies.asMap().entrySet()) {
-      reporter.handle(
-          Event.info(
-              String.format(
-                  "MnemonicToRemoteDynamicStrategyImplementations: \"%s\" = [%s]",
-                  entry.getKey(), toImplementationNames(entry.getValue()))));
+      logger.atInfo().log(
+          "MnemonicToRemoteDynamicStrategyImplementations: \"%s\" = [%s]",
+          entry.getKey(), toImplementationNames(entry.getValue()));
     }
 
     for (Map.Entry<String, Collection<SandboxedSpawnStrategy>> entry :
         mnemonicToLocalDynamicStrategies.asMap().entrySet()) {
-      reporter.handle(
-          Event.info(
-              String.format(
-                  "MnemonicToLocalDynamicStrategyImplementations: \"%s\" = [%s]",
-                  entry.getKey(), toImplementationNames(entry.getValue()))));
+      logger.atInfo().log(
+          "MnemonicToLocalDynamicStrategyImplementations: \"%s\" = [%s]",
+          entry.getKey(), toImplementationNames(entry.getValue()));
     }
   }
 
diff --git a/src/test/java/com/google/devtools/build/lib/exec/BlazeExecutorTest.java b/src/test/java/com/google/devtools/build/lib/exec/BlazeExecutorTest.java
deleted file mode 100644
index b973d53..0000000
--- a/src/test/java/com/google/devtools/build/lib/exec/BlazeExecutorTest.java
+++ /dev/null
@@ -1,102 +0,0 @@
-// Copyright 2016 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.exec;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-import com.google.common.eventbus.EventBus;
-import com.google.devtools.build.lib.actions.ActionContext;
-import com.google.devtools.build.lib.actions.ActionExecutionContext;
-import com.google.devtools.build.lib.actions.Spawn;
-import com.google.devtools.build.lib.actions.SpawnResult;
-import com.google.devtools.build.lib.actions.SpawnStrategy;
-import com.google.devtools.build.lib.analysis.BlazeDirectories;
-import com.google.devtools.build.lib.analysis.ServerDirectories;
-import com.google.devtools.build.lib.events.Event;
-import com.google.devtools.build.lib.events.Reporter;
-import com.google.devtools.build.lib.events.StoredEventHandler;
-import com.google.devtools.build.lib.exec.util.TestExecutorBuilder;
-import com.google.devtools.build.lib.vfs.DigestHashFunction;
-import com.google.devtools.build.lib.vfs.FileSystem;
-import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem;
-import com.google.devtools.common.options.OptionsParser;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/** Tests for {@link BlazeExecutor}. */
-@RunWith(JUnit4.class)
-public class BlazeExecutorTest {
-  private FileSystem fileSystem;
-  private BlazeDirectories directories;
-  private BinTools binTools;
-
-  @Before
-  public final void setUpDirectoriesAndTools() throws Exception {
-    fileSystem = new InMemoryFileSystem(DigestHashFunction.SHA256);
-    directories =
-        new BlazeDirectories(
-            new ServerDirectories(
-                fileSystem.getPath("/install"),
-                fileSystem.getPath("/base"),
-                fileSystem.getPath("/root")),
-            fileSystem.getPath("/workspace"),
-            /* defaultSystemJavabase= */ null,
-            "mock-product-name");
-    binTools = BinTools.empty(directories);
-  }
-
-  @Test
-  public void testDebugPrintActionContexts() throws Exception {
-    OptionsParser parser =
-        OptionsParser.builder().optionsClasses(TestExecutorBuilder.DEFAULT_OPTIONS).build();
-    parser.parse("--debug_print_action_contexts");
-
-    Reporter reporter = new Reporter(new EventBus());
-    StoredEventHandler storedEventHandler = new StoredEventHandler();
-    reporter.addHandler(storedEventHandler);
-
-    FakeSpawnStrategy strategy = new FakeSpawnStrategy();
-
-    new TestExecutorBuilder(fileSystem, directories, binTools)
-        .setReporter(reporter)
-        .setOptionsParser(parser)
-        .setExecution("fake", "fake")
-        .addStrategy(new FakeSpawnStrategy(), "fake")
-        .build();
-
-    Event event =
-        Iterables.find(storedEventHandler.getEvents(), e -> e.getMessage().contains("\"fake\" = "));
-    assertThat(event).isNotNull();
-    assertThat(event.getMessage())
-        .contains("\"fake\" = [" + strategy.getClass().getSimpleName() + "]");
-  }
-
-  private static class FakeSpawnStrategy implements SpawnStrategy {
-
-    @Override
-    public ImmutableList<SpawnResult> exec(
-        Spawn spawn, ActionExecutionContext actionExecutionContext) {
-      throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public boolean canExec(Spawn spawn, ActionContext.ActionContextRegistry actionContextRegistry) {
-      return false;
-    }
-  }
-}
diff --git a/src/test/shell/integration/bazel_worker_multiplexer_test.sh b/src/test/shell/integration/bazel_worker_multiplexer_test.sh
index 1225cf0..215bbeff 100755
--- a/src/test/shell/integration/bazel_worker_multiplexer_test.sh
+++ b/src/test/shell/integration/bazel_worker_multiplexer_test.sh
@@ -35,7 +35,6 @@
 add_to_bazelrc "build -s"
 add_to_bazelrc "build --spawn_strategy=worker,standalone"
 add_to_bazelrc "build --worker_verbose --worker_max_instances=3"
-add_to_bazelrc "build --debug_print_action_contexts"
 add_to_bazelrc "build --worker_multiplex"
 add_to_bazelrc "build ${ADDITIONAL_BUILD_FLAGS}"
 
diff --git a/src/test/shell/integration/bazel_worker_test.sh b/src/test/shell/integration/bazel_worker_test.sh
index 857aa9b..e77ea6a 100755
--- a/src/test/shell/integration/bazel_worker_test.sh
+++ b/src/test/shell/integration/bazel_worker_test.sh
@@ -36,7 +36,6 @@
 add_to_bazelrc "build -s"
 add_to_bazelrc "build --spawn_strategy=worker,standalone"
 add_to_bazelrc "build --worker_verbose --worker_max_instances=1"
-add_to_bazelrc "build --debug_print_action_contexts"
 add_to_bazelrc "build --noworker_multiplex"
 add_to_bazelrc "build ${ADDITIONAL_BUILD_FLAGS}"
 
diff --git a/src/test/shell/integration/execution_strategies_test.sh b/src/test/shell/integration/execution_strategies_test.sh
index 624191d..94109cb 100755
--- a/src/test/shell/integration/execution_strategies_test.sh
+++ b/src/test/shell/integration/execution_strategies_test.sh
@@ -60,37 +60,38 @@
 
 # Tests that you can set the spawn strategy flags to a list of strategies.
 function test_multiple_strategies() {
-  bazel build --spawn_strategy=worker,local --debug_print_action_contexts &> $TEST_log || fail
+  SERVER_LOG=$(bazel info server_log)
+  bazel build --spawn_strategy=worker,local || fail
   # Can't test for exact strategy names here, because they differ between platforms and products.
-  expect_log "DefaultStrategyImplementations: \[.*, .*\]"
+  assert_contains "DefaultStrategyImplementations: \[.*, .*\]" "$SERVER_LOG"
 }
 
 # Tests that the hardcoded Worker strategies are not introduced with the new
 # strategy selection
 function test_no_worker_defaults() {
-  bazel build --debug_print_action_contexts &> $TEST_log || fail
+  SERVER_LOG=$(bazel info server_log)
+  bazel build || fail
   # Can't test for exact strategy names here, because they differ between platforms and products.
-  expect_not_log "\"Closure\""
-  expect_not_log "\"DexBuilder\""
-  expect_not_log "\"Javac\""
+  assert_not_contains "\"Closure\"" "$SERVER_LOG"
+  assert_not_contains "\"DexBuilder\"" "$SERVER_LOG"
+  assert_not_contains "\"Javac\"" "$SERVER_LOG"
 }
 
 # Tests that Bazel catches an invalid strategy list that has an empty string as an element.
 function test_empty_strategy_in_list_is_forbidden() {
-  bazel build --spawn_strategy=worker,,local --debug_print_action_contexts &> $TEST_log || true
+  bazel build --spawn_strategy=worker,,local &> $TEST_log || true
   expect_log "--spawn_strategy=worker,,local: Empty values are not allowed as part of this comma-separated list of options"
 }
 
 # Test that when you set a strategy to the empty string, it gets removed from the map of strategies
 # and thus results in the default strategy being used (the one set via --spawn_strategy=).
 function test_empty_strategy_means_default() {
-  bazel build --spawn_strategy=worker,local --strategy=FooBar=local \
-      --debug_print_action_contexts &> $TEST_log || fail
-  expect_log "\"FooBar\" = "
+  SERVER_LOG=$(bazel info server_log)
+  bazel build --spawn_strategy=worker,local --strategy=FooBar=local || fail
+  assert_contains "\"FooBar\" = " "$SERVER_LOG"
 
-  bazel build --spawn_strategy=worker,local --strategy=FooBar=local --strategy=FooBar= \
-      --debug_print_action_contexts &> $TEST_log || fail
-  expect_not_log "\"FooBar\" = "
+  bazel build --spawn_strategy=worker,local --strategy=FooBar=local --strategy=FooBar= || fail
+  assert_contains "\"FooBar\" = " "$SERVER_LOG"
 }
 
 # Runs a build, waits for the given dir and file to appear, and then kills