Add R8 command-line flag to output the configuration.

Bug: b/227746536
Change-Id: I57885f9225e5c43a77adefa50a48053e4e070ef7
diff --git a/src/main/java/com/android/tools/r8/R8CommandParser.java b/src/main/java/com/android/tools/r8/R8CommandParser.java
index 56e2b97..c2bcaae 100644
--- a/src/main/java/com/android/tools/r8/R8CommandParser.java
+++ b/src/main/java/com/android/tools/r8/R8CommandParser.java
@@ -3,6 +3,7 @@
 // BSD-style license that can be found in the LICENSE file.
 package com.android.tools.r8;
 
+import com.android.tools.r8.StringConsumer.FileConsumer;
 import com.android.tools.r8.origin.Origin;
 import com.android.tools.r8.utils.AndroidApiLevel;
 import com.android.tools.r8.utils.FlagFile;
@@ -33,6 +34,7 @@
           "--feature",
           "--main-dex-list-output",
           "--pg-conf",
+          "--pg-conf-output",
           "--pg-map-output",
           "--desugared-lib",
           "--desugared-lib-pg-conf-output",
@@ -85,6 +87,7 @@
                       + ".",
                   "  --pg-compat             # Compile with R8 in Proguard compatibility mode.",
                   "  --pg-conf <file>        # Proguard configuration <file>.",
+                  "  --pg-conf-output <file> # Output the collective configuration to <file>.",
                   "  --pg-map-output <file>  # Output the resulting name and line mapping to"
                       + " <file>.",
                   "  --desugared-lib <file>  # Specify desugared library configuration.",
@@ -260,6 +263,9 @@
         builder.setOptimizeMultidexForLinearAlloc(true);
       } else if (arg.equals("--pg-conf")) {
         builder.addProguardConfigurationFiles(Paths.get(nextArg));
+      } else if (arg.equals("--pg-conf-output")) {
+        FileConsumer consumer = new FileConsumer(Paths.get(nextArg));
+        builder.setProguardConfigurationConsumer(consumer);
       } else if (arg.equals("--pg-map-output")) {
         builder.setProguardMapOutputPath(Paths.get(nextArg));
       } else if (arg.equals("--desugared-lib")) {
diff --git a/src/test/java/com/android/tools/r8/R8CommandTest.java b/src/test/java/com/android/tools/r8/R8CommandTest.java
index 1242d17..c5e961c 100644
--- a/src/test/java/com/android/tools/r8/R8CommandTest.java
+++ b/src/test/java/com/android/tools/r8/R8CommandTest.java
@@ -9,6 +9,7 @@
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
@@ -685,6 +686,14 @@
   }
 
   @Test
+  public void setPgConfOutputFlag() throws Throwable {
+    Path file = temp.newFolder().toPath().resolve("output.conf");
+    R8Command command = parse("--pg-conf-output", file.toString());
+    InternalOptions options = command.getInternalOptions();
+    assertNotNull(options.configurationConsumer);
+  }
+
+  @Test
   public void defaultDataResourcesOption() throws Throwable {
     Path dataResourceZip = writeZipWithDataResource("dataResource.zip");
     Path outputZip = temp.newFolder().toPath().resolve("output.zip");