Change default dexer to D8

Summary: dx is being deprecated and D8 is required for using Java 8 features. This diff makes D8 the default dexer. Android apps can still fall back to dx by setting `dex_tool = "dx"` on `android_binary()`.

Reviewed By: styurin

shipit-source-id: 95c29a14c0
diff --git a/src/com/facebook/buck/android/AndroidGraphEnhancerArgs.java b/src/com/facebook/buck/android/AndroidGraphEnhancerArgs.java
index a6f65b4..ab7ae92 100644
--- a/src/com/facebook/buck/android/AndroidGraphEnhancerArgs.java
+++ b/src/com/facebook/buck/android/AndroidGraphEnhancerArgs.java
@@ -159,7 +159,7 @@
 
   @Value.Default
   default String getDexTool() {
-    return DxStep.DX;
+    return DxStep.D8;
   }
 
   Optional<SourcePath> getDexReorderToolFile();
diff --git a/src/com/facebook/buck/android/AndroidInstrumentationApkDescription.java b/src/com/facebook/buck/android/AndroidInstrumentationApkDescription.java
index 8ac6531..8fd28af 100644
--- a/src/com/facebook/buck/android/AndroidInstrumentationApkDescription.java
+++ b/src/com/facebook/buck/android/AndroidInstrumentationApkDescription.java
@@ -318,7 +318,7 @@
 
     @Value.Default
     default String getDexTool() {
-      return DxStep.DX;
+      return DxStep.D8;
     }
   }
 }
diff --git a/src/com/facebook/buck/android/DexProducedFromJavaLibrary.java b/src/com/facebook/buck/android/DexProducedFromJavaLibrary.java
index 8d4bdc3..916ca81 100644
--- a/src/com/facebook/buck/android/DexProducedFromJavaLibrary.java
+++ b/src/com/facebook/buck/android/DexProducedFromJavaLibrary.java
@@ -120,7 +120,7 @@
         ruleFinder,
         androidPlatformTarget,
         javaLibrary,
-        DxStep.DX,
+        DxStep.D8,
         1,
         ImmutableSortedSet.of());
   }
diff --git a/src/com/facebook/buck/android/DxStep.java b/src/com/facebook/buck/android/DxStep.java
index 261976f..db77bfb 100644
--- a/src/com/facebook/buck/android/DxStep.java
+++ b/src/com/facebook/buck/android/DxStep.java
@@ -123,7 +123,7 @@
         outputDexFile,
         filesToDex,
         EnumSet.noneOf(DxStep.Option.class),
-        DX);
+        D8);
   }
 
   /**
diff --git a/test/com/facebook/buck/android/AndroidBinaryCrossCellIntegrationTest.java b/test/com/facebook/buck/android/AndroidBinaryCrossCellIntegrationTest.java
index a6317b1..26b1c1c 100644
--- a/test/com/facebook/buck/android/AndroidBinaryCrossCellIntegrationTest.java
+++ b/test/com/facebook/buck/android/AndroidBinaryCrossCellIntegrationTest.java
@@ -73,8 +73,6 @@
     workspace.runBuckCommand("build", "other_repo//:app_with_mainlib").assertSuccess();
     workspace.runBuckCommand("clean", "--keep-cache").assertSuccess();
     workspace.runBuckCommand("build", "//:app_with_main_lib").assertSuccess();
-    workspace
-        .getBuildLog()
-        .assertTargetWasFetchedFromCache("//java/com/sample/mainlib:mainlib#dex");
+    workspace.getBuildLog().assertTargetWasFetchedFromCache("//java/com/sample/mainlib:mainlib#d8");
   }
 }
diff --git a/test/com/facebook/buck/android/AndroidBinaryGraphEnhancerTest.java b/test/com/facebook/buck/android/AndroidBinaryGraphEnhancerTest.java
index 2142a43..3e44da7 100644
--- a/test/com/facebook/buck/android/AndroidBinaryGraphEnhancerTest.java
+++ b/test/com/facebook/buck/android/AndroidBinaryGraphEnhancerTest.java
@@ -581,7 +581,7 @@
             CxxPlatformUtils.DEFAULT_CONFIG,
             new APKModuleGraph(TargetGraph.EMPTY, apkTarget, Optional.empty()),
             new DxConfig(FakeBuckConfig.builder().build()),
-            DxStep.DX,
+            DxStep.D8,
             Optional.empty(),
             defaultNonPredexedArgs(),
             ImmutableSortedSet::of,
@@ -622,19 +622,19 @@
 
     BuildRule preDexMergeRule = graphEnhancer.createPreDexMergeRule(preDexedLibraries);
     BuildTarget dexMergeTarget =
-        BuildTargetFactory.newInstance("//java/com/example:apk#dex,dex_merge");
+        BuildTargetFactory.newInstance("//java/com/example:apk#d8,dex_merge");
     BuildRule dexMergeRule = graphBuilder.getRule(dexMergeTarget);
 
     assertEquals(dexMergeRule, preDexMergeRule);
 
     BuildTarget javaDep1DexBuildTarget =
-        javaDep1BuildTarget.withAppendedFlavors(AndroidBinaryGraphEnhancer.DEX_FLAVOR);
+        javaDep1BuildTarget.withAppendedFlavors(AndroidBinaryGraphEnhancer.D8_FLAVOR);
     BuildTarget javaDep2DexBuildTarget =
-        javaDep2BuildTarget.withAppendedFlavors(AndroidBinaryGraphEnhancer.DEX_FLAVOR);
+        javaDep2BuildTarget.withAppendedFlavors(AndroidBinaryGraphEnhancer.D8_FLAVOR);
     BuildTarget javaLibDexBuildTarget =
-        javaLibBuildTarget.withAppendedFlavors(AndroidBinaryGraphEnhancer.DEX_FLAVOR);
+        javaLibBuildTarget.withAppendedFlavors(AndroidBinaryGraphEnhancer.D8_FLAVOR);
     assertThat(
-        "There should be a #dex rule for dep1 and lib, but not dep2 because it is in the no_dx "
+        "There should be a #d8 rule for dep1 and lib, but not dep2 because it is in the no_dx "
             + "list.  And we should depend on uber_r_dot_java",
         Iterables.transform(dexMergeRule.getBuildDeps(), BuildRule::getBuildTarget),
         allOf(
@@ -733,7 +733,7 @@
             CxxPlatformUtils.DEFAULT_CONFIG,
             new APKModuleGraph(TargetGraph.EMPTY, apkTarget, Optional.empty()),
             new DxConfig(FakeBuckConfig.builder().build()),
-            DxStep.DX,
+            DxStep.D8,
             Optional.empty(),
             defaultNonPredexedArgs(),
             ImmutableSortedSet::of,
@@ -869,7 +869,7 @@
             CxxPlatformUtils.DEFAULT_CONFIG,
             new APKModuleGraph(TargetGraph.EMPTY, target, Optional.empty()),
             new DxConfig(FakeBuckConfig.builder().build()),
-            DxStep.DX,
+            DxStep.D8,
             Optional.empty(),
             defaultNonPredexedArgs(),
             ImmutableSortedSet::of,
@@ -952,7 +952,7 @@
             CxxPlatformUtils.DEFAULT_CONFIG,
             new APKModuleGraph(TargetGraph.EMPTY, target, Optional.empty()),
             new DxConfig(FakeBuckConfig.builder().build()),
-            DxStep.DX,
+            DxStep.D8,
             Optional.empty(),
             defaultNonPredexedArgs(),
             ImmutableSortedSet::of,
@@ -1063,7 +1063,7 @@
             CxxPlatformUtils.DEFAULT_CONFIG,
             new APKModuleGraph(TargetGraph.EMPTY, target, Optional.empty()),
             new DxConfig(FakeBuckConfig.builder().build()),
-            DxStep.DX,
+            DxStep.D8,
             Optional.empty(),
             defaultNonPredexedArgs(),
             ImmutableSortedSet::of,
diff --git a/test/com/facebook/buck/android/AndroidBinaryIntegrationTest.java b/test/com/facebook/buck/android/AndroidBinaryIntegrationTest.java
index 781be6c..8859388 100644
--- a/test/com/facebook/buck/android/AndroidBinaryIntegrationTest.java
+++ b/test/com/facebook/buck/android/AndroidBinaryIntegrationTest.java
@@ -320,7 +320,7 @@
   @Test
   public void testDxFindsReferencedResources() {
     workspace.runBuckBuild(SIMPLE_TARGET).assertSuccess();
-    BuildTarget dexTarget = BuildTargetFactory.newInstance("//java/com/sample/lib:lib#dex");
+    BuildTarget dexTarget = BuildTargetFactory.newInstance("//java/com/sample/lib:lib#d8");
     ProjectFilesystem filesystem =
         TestProjectFilesystems.createProjectFilesystem(tmpFolder.getRoot());
     Optional<String> resourcesFromMetadata =
@@ -346,20 +346,20 @@
     workspace.runBuckBuild(SIMPLE_TARGET).assertSuccess();
 
     BuckBuildLog buildLog = workspace.getBuildLog();
-    buildLog.assertTargetBuiltLocally("//java/com/sample/lib:lib#dex");
+    buildLog.assertTargetBuiltLocally("//java/com/sample/lib:lib#d8");
 
     workspace.replaceFileContents(
         "java/com/sample/lib/Sample.java", "import", "import /* no output change */");
     workspace.runBuckBuild(SIMPLE_TARGET).assertSuccess();
     buildLog = workspace.getBuildLog();
-    buildLog.assertNotTargetBuiltLocally("//java/com/sample/lib:lib#dex");
-    buildLog.assertTargetHadMatchingInputRuleKey("//java/com/sample/lib:lib#dex");
+    buildLog.assertNotTargetBuiltLocally("//java/com/sample/lib:lib#d8");
+    buildLog.assertTargetHadMatchingInputRuleKey("//java/com/sample/lib:lib#d8");
 
     workspace.replaceFileContents(
         "java/com/sample/lib/Sample.java", "import", "import /* \n some output change */");
     workspace.runBuckBuild(SIMPLE_TARGET).assertSuccess();
     buildLog = workspace.getBuildLog();
-    buildLog.assertTargetBuiltLocally("//java/com/sample/lib:lib#dex");
+    buildLog.assertTargetBuiltLocally("//java/com/sample/lib:lib#d8");
   }
 
   @Test
diff --git a/test/com/facebook/buck/android/AndroidBinaryRDotJavaIntegrationTest.java b/test/com/facebook/buck/android/AndroidBinaryRDotJavaIntegrationTest.java
index 05a1eca..7404a39 100644
--- a/test/com/facebook/buck/android/AndroidBinaryRDotJavaIntegrationTest.java
+++ b/test/com/facebook/buck/android/AndroidBinaryRDotJavaIntegrationTest.java
@@ -130,7 +130,7 @@
     BuckBuildLog buildLog = workspace.getBuildLog();
     buildLog.assertTargetBuiltLocally("//apps/multidex:app#compile_uber_r_dot_java");
     buildLog.assertTargetBuiltLocally(
-        "//apps/multidex:app#dex,dexing,rtype__primarydex,split_uber_r_dot_java_jar");
+        "//apps/multidex:app#d8,dexing,rtype__primarydex,split_uber_r_dot_java_jar");
     verifyTrimmedRDotJava(ImmutableSet.of("title"));
 
     // Turn off trimming and turn on exopackage, and rebuilt.
@@ -172,7 +172,7 @@
     BuckBuildLog buildLog = workspace.getBuildLog();
     buildLog.assertTargetBuiltLocally("//apps/multidex:app#compile_uber_r_dot_java");
     buildLog.assertTargetBuiltLocally(
-        "//apps/multidex:app#dex,dexing,rtype__primarydex,split_uber_r_dot_java_jar");
+        "//apps/multidex:app#d8,dexing,rtype__primarydex,split_uber_r_dot_java_jar");
     verifyTrimmedRDotJava(ImmutableSet.of("app_icon", "app_name", "title"));
   }
 
diff --git a/test/com/facebook/buck/android/AndroidExopackageBinaryIntegrationTest.java b/test/com/facebook/buck/android/AndroidExopackageBinaryIntegrationTest.java
index 54bfe75..60b62c4 100644
--- a/test/com/facebook/buck/android/AndroidExopackageBinaryIntegrationTest.java
+++ b/test/com/facebook/buck/android/AndroidExopackageBinaryIntegrationTest.java
@@ -98,7 +98,7 @@
             BuildTargetPaths.getScratchPath(
                 filesystem,
                 BuildTargetFactory.newInstance(DEX_EXOPACKAGE_TARGET)
-                    .withFlavors(InternalFlavor.of("dex"), InternalFlavor.of("dex_merge")),
+                    .withFlavors(InternalFlavor.of("d8"), InternalFlavor.of("dex_merge")),
                 "%s_output/secondary/jarfiles/assets/secondary-program-dex-jars"));
 
     try (DirectoryStream<Path> stream = Files.newDirectoryStream(secondaryDir)) {
diff --git a/test/com/facebook/buck/android/DexWithClassesTest.java b/test/com/facebook/buck/android/DexWithClassesTest.java
index 25c6ab4..7b0f906 100644
--- a/test/com/facebook/buck/android/DexWithClassesTest.java
+++ b/test/com/facebook/buck/android/DexWithClassesTest.java
@@ -41,7 +41,7 @@
     BuildTarget javaLibraryTarget = BuildTargetFactory.newInstance("//java/com/example:lib");
     JavaLibrary javaLibrary = new FakeJavaLibrary(javaLibraryTarget);
 
-    BuildTarget buildTarget = BuildTargetFactory.newInstance("//java/com/example:lib#dex");
+    BuildTarget buildTarget = BuildTargetFactory.newInstance("//java/com/example:lib#d8");
     DexProducedFromJavaLibrary dexFromJavaLibrary =
         new DexProducedFromJavaLibrary(
             buildTarget,
@@ -74,7 +74,7 @@
     BuildTarget javaLibraryTarget = BuildTargetFactory.newInstance("//java/com/example:lib");
     JavaLibrary javaLibrary = new FakeJavaLibrary(javaLibraryTarget);
 
-    BuildTarget buildTarget = BuildTargetFactory.newInstance("//java/com/example:lib#dex");
+    BuildTarget buildTarget = BuildTargetFactory.newInstance("//java/com/example:lib#d8");
     DexProducedFromJavaLibrary dexFromJavaLibrary =
         new DexProducedFromJavaLibrary(
             buildTarget,
diff --git a/test/com/facebook/buck/android/DxStepTest.java b/test/com/facebook/buck/android/DxStepTest.java
index 9556fcd..5cedfa0 100644
--- a/test/com/facebook/buck/android/DxStepTest.java
+++ b/test/com/facebook/buck/android/DxStepTest.java
@@ -90,7 +90,7 @@
               SAMPLE_OUTPUT_PATH,
               SAMPLE_FILES_TO_DEX,
               EnumSet.of(Option.NO_OPTIMIZE),
-              DxStep.DX);
+              DxStep.D8);
 
       String expected =
           String.format(
@@ -142,7 +142,7 @@
               SAMPLE_OUTPUT_PATH,
               SAMPLE_FILES_TO_DEX,
               EnumSet.of(DxStep.Option.NO_OPTIMIZE, DxStep.Option.FORCE_JUMBO),
-              DxStep.DX);
+              DxStep.D8);
 
       String expected =
           String.format(
@@ -229,7 +229,7 @@
               SAMPLE_FILES_TO_DEX,
               EnumSet.noneOf(DxStep.Option.class),
               Optional.of("2g"),
-              DxStep.DX,
+              DxStep.D8,
               false);
 
       String expected =
diff --git a/test/com/facebook/buck/android/SmartDexingStepTest.java b/test/com/facebook/buck/android/SmartDexingStepTest.java
index d42d2e5..a2829c3 100644
--- a/test/com/facebook/buck/android/SmartDexingStepTest.java
+++ b/test/com/facebook/buck/android/SmartDexingStepTest.java
@@ -88,7 +88,7 @@
             EnumSet.of(DxStep.Option.NO_OPTIMIZE),
             XzStep.DEFAULT_COMPRESSION_LEVEL,
             Optional.empty(),
-            DxStep.DX,
+            DxStep.D8,
             null,
             false);
     assertFalse("'dummy' is not a matching input hash", rule.checkIsCached());
@@ -122,7 +122,7 @@
         dxOptions,
         XzStep.DEFAULT_COMPRESSION_LEVEL,
         Optional.empty(),
-        DxStep.DX,
+        DxStep.D8,
         null,
         false);
 
@@ -166,7 +166,7 @@
         dxOptions,
         9,
         Optional.empty(),
-        DxStep.DX,
+        DxStep.D8,
         null,
         false);
 
@@ -210,7 +210,7 @@
         dxOptions,
         XzStep.DEFAULT_COMPRESSION_LEVEL,
         Optional.empty(),
-        DxStep.DX,
+        DxStep.D8,
         null,
         false);
 
@@ -248,7 +248,7 @@
         dxOptions,
         XzStep.DEFAULT_COMPRESSION_LEVEL,
         Optional.empty(),
-        DxStep.DX,
+        DxStep.D8,
         null,
         false);
 
@@ -290,7 +290,7 @@
         dxOptions,
         XzStep.DEFAULT_COMPRESSION_LEVEL,
         Optional.empty(),
-        DxStep.DX,
+        DxStep.D8,
         null,
         false);
   }
diff --git a/test/com/facebook/buck/core/model/BuildTargetTest.java b/test/com/facebook/buck/core/model/BuildTargetTest.java
index 187488b..8ae777f 100644
--- a/test/com/facebook/buck/core/model/BuildTargetTest.java
+++ b/test/com/facebook/buck/core/model/BuildTargetTest.java
@@ -87,9 +87,9 @@
   @Test
   public void testBuildTargetWithFlavor() {
     BuildTarget target =
-        BuildTargetFactory.newInstance(ROOT, "//foo/bar", "baz", InternalFlavor.of("dex"));
-    assertEquals("baz#dex", target.getShortNameAndFlavorPostfix());
-    assertEquals(ImmutableSortedSet.of(InternalFlavor.of("dex")), target.getFlavors());
+        BuildTargetFactory.newInstance(ROOT, "//foo/bar", "baz", InternalFlavor.of("d8"));
+    assertEquals("baz#d8", target.getShortNameAndFlavorPostfix());
+    assertEquals(ImmutableSortedSet.of(InternalFlavor.of("d8")), target.getFlavors());
     assertTrue(target.isFlavored());
   }
 
@@ -114,17 +114,17 @@
   @Test
   public void testShortNameCannotContainHashWhenFlavorSet() {
     try {
-      BuildTargetFactory.newInstance(ROOT, "//foo/bar", "baz#dex", InternalFlavor.of("src-jar"));
+      BuildTargetFactory.newInstance(ROOT, "//foo/bar", "baz#d8", InternalFlavor.of("src-jar"));
       fail("Should have thrown IllegalArgumentException.");
     } catch (IllegalArgumentException e) {
-      assertEquals("Build target name cannot contain '#' but was: baz#dex.", e.getMessage());
+      assertEquals("Build target name cannot contain '#' but was: baz#d8.", e.getMessage());
     }
   }
 
   @Test(expected = IllegalArgumentException.class)
   public void testShortNamesMustNotContainTheFlavorSeparator() {
     @SuppressWarnings("unused")
-    BuildTarget unused = BuildTargetFactory.newInstance(ROOT, "//foo/bar", "baz#dex");
+    BuildTarget unused = BuildTargetFactory.newInstance(ROOT, "//foo/bar", "baz#d8");
   }
 
   @Test