Add --alternative-frontend flag to test.py

Bug: 117969690
Change-Id: Id4bcc48e7aae014f85bbf18bce5d34a31695acdd
diff --git a/build.gradle b/build.gradle
index ad28ff9..96853e6 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1709,6 +1709,12 @@
         assert project.hasProperty('HEAD_sha1')
         systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
     }
+
+    if (project.hasProperty('alternative_frontend')) {
+        println "NOTE: Running with alternative frontend"
+        systemProperty 'com.android.tools.r8.useAlternativeFrontend', true
+    }
+
     dependsOn getJarsFromSupportLibs
     // R8.jar is required for running bootstrap tests.
     dependsOn R8
diff --git a/src/main/java/com/android/tools/r8/utils/InternalOptions.java b/src/main/java/com/android/tools/r8/utils/InternalOptions.java
index bbe8fb3..7b4fcad 100644
--- a/src/main/java/com/android/tools/r8/utils/InternalOptions.java
+++ b/src/main/java/com/android/tools/r8/utils/InternalOptions.java
@@ -363,7 +363,15 @@
   public boolean disableAssertions = true;
   public boolean configurationDebugging = false;
   // Read input classes into CfCode format (instead of JarCode).
-  public boolean enableCfFrontend = false;
+  public final boolean defaultCfFrontend = false;
+  public boolean enableCfFrontend = flipIfAlternativeFrontendFlagIsSet(defaultCfFrontend);
+  private static boolean flipIfAlternativeFrontendFlagIsSet(boolean value) {
+    if (System.getProperty("com.android.tools.r8.useAlternativeFrontend") == null) {
+      return value;
+    }
+    return !value;
+  }
+
   // Don't convert Code objects to IRCode.
   public boolean skipIR = false;
 
diff --git a/tools/test.py b/tools/test.py
index be271f2..fda24ee 100755
--- a/tools/test.py
+++ b/tools/test.py
@@ -124,6 +124,9 @@
   result.add_option('--fail-fast', '--fail_fast',
       default=False, action='store_true',
       help='Stop on first failure. Passes --fail-fast to gradle test runner.')
+  result.add_option('--alternative-frontend', '--alternative_frontend',
+      default=False, action='store_true',
+      help='Use the alternative (eg, non-default) classfile frontend.')
   return result.parse_args()
 
 def archive_failures():
@@ -199,6 +202,8 @@
     if not os.path.exists(options.use_golden_files_in):
       os.makedirs(options.use_golden_files_in)
     gradle_args.append('-PHEAD_sha1=' + utils.get_HEAD_sha1())
+  if options.alternative_frontend:
+    gradle_args.append('-Palternative_frontend')
   if (not options.no_r8lib) and options.r8lib_no_deps:
     print('Cannot run tests on r8lib with and without deps. R8lib is now default target.')
     exit(1)