Remove DexFileMergerHelper
Bug: b/241063980
Change-Id: I4f9d0c78deda94dca39c7bf89eda1de1820a3e2a
diff --git a/src/main/java/com/android/tools/r8/DexFileMergerHelper.java b/src/main/java/com/android/tools/r8/DexFileMergerHelper.java
deleted file mode 100644
index b46e8f5..0000000
--- a/src/main/java/com/android/tools/r8/DexFileMergerHelper.java
+++ /dev/null
@@ -1,68 +0,0 @@
-// Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-package com.android.tools.r8;
-
-
-import com.android.tools.r8.graph.DexProgramClass;
-import com.android.tools.r8.utils.InternalOptions;
-import com.android.tools.r8.utils.InternalOptions.DesugarState;
-import java.util.Map;
-
-public class DexFileMergerHelper {
-
- private final Map<String, Integer> inputOrdering;
-
- private DexFileMergerHelper(Map<String, Integer> inputOrdering) {
- this.inputOrdering = inputOrdering;
- }
-
- private DexProgramClass keepFirstProgramClassConflictResolver(
- DexProgramClass a, DexProgramClass b) {
- String aPath = a.getOrigin().parent().part();
- String bPath = b.getOrigin().parent().part();
- Integer aIndex = inputOrdering.get(aPath);
- Integer bIndex = inputOrdering.get(bPath);
- if (aIndex == null || bIndex == null) {
- StringBuilder builder = new StringBuilder();
- builder.append("Class parent paths not found among input paths: ");
- if (aIndex == null) {
- builder.append(aPath);
- }
- if (bIndex == null) {
- if (aIndex == null) {
- builder.append(", ");
- }
- builder.append(bPath);
- }
- throw new RuntimeException(builder.toString());
- }
- return aIndex <= bIndex ? a.get() : b.get();
- }
-
- // NOTE: Don't change this signature! Reflectively accessed from bazel DexFileMerger.
- public static void run(
- D8Command command, Boolean minimalMainDex, Map<String, Integer> inputOrdering)
- throws CompilationFailedException {
- InternalOptions options = command.getInternalOptions();
-
- // TODO(b/241351268): Don't compile in intermediate mode as the output is a final "shard".
- options.intermediate = true;
-
- // TODO(b/241063980): Move this to D8Command.Builder.setDisableDesugaring(true) in bazel.
- options.desugarState = DesugarState.OFF;
-
- // TODO(b/241063980): Is this configuration needed?
- options.enableMainDexListCheck = false;
-
- // TODO(b/241063980): Is this configuration needed?
- options.minimalMainDex = minimalMainDex;
-
- // TODO(b/241063980): Add API to configure this in D8Command.Builder.
- options.programClassConflictResolver =
- new DexFileMergerHelper(inputOrdering)::keepFirstProgramClassConflictResolver;
-
- D8.runForTesting(command.getInputApp(), options);
- }
-}
diff --git a/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/MergingJ$Test.java b/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/MergingJ$Test.java
index 51fc891..8a7aecb 100644
--- a/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/MergingJ$Test.java
+++ b/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/MergingJ$Test.java
@@ -7,15 +7,10 @@
import static com.android.tools.r8.DiagnosticsMatcher.diagnosticType;
import static com.android.tools.r8.desugar.desugaredlibrary.jdktests.Jdk11TestLibraryDesugaringSpecification.EXTENSION_PATH;
import static com.android.tools.r8.desugar.desugaredlibrary.test.LibraryDesugaringSpecification.getJdk8Jdk11;
-import static junit.framework.TestCase.assertNotNull;
-import static junit.framework.TestCase.assertTrue;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.fail;
import com.android.tools.r8.CompilationFailedException;
-import com.android.tools.r8.D8Command;
-import com.android.tools.r8.DexFileMergerHelper;
import com.android.tools.r8.DiagnosticsMatcher;
import com.android.tools.r8.L8;
import com.android.tools.r8.L8Command;
@@ -27,9 +22,7 @@
import com.android.tools.r8.desugar.desugaredlibrary.test.LibraryDesugaringSpecification;
import com.android.tools.r8.errors.DuplicateTypesDiagnostic;
import com.android.tools.r8.utils.AndroidApiLevel;
-import com.android.tools.r8.utils.codeinspector.CodeInspector;
import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
import java.nio.file.Path;
import java.util.List;
import org.junit.Assume;
@@ -72,44 +65,6 @@
}));
}
- @Test
- public void testMergingJ$WithDexFileMergerHelper() throws Exception {
- Path mergerInputPart1 = buildSplitDesugaredLibraryPart1();
- Path mergerInputPart2 = buildSplitDesugaredLibraryPart2();
- Path merged = temp.newFolder().toPath().resolve("merged.jar");
- D8Command command =
- D8Command.builder()
- .addProgramFiles(mergerInputPart1, mergerInputPart2)
- .addLibraryFiles(libraryDesugaringSpecification.getLibraryFiles())
- .setOutput(merged, OutputMode.DexIndexed)
- .build();
- try {
- DexFileMergerHelper.run(
- command,
- true,
- ImmutableMap.<String, Integer>builder()
- .put(mergerInputPart1.toString(), 1)
- .put(mergerInputPart2.toString(), 2)
- .build());
- } catch (Exception e) {
- if (e.getCause().getMessage().contains("Merging dex file containing classes with prefix")) {
- // TODO(b/138278440): Forbid to merge j$ classes in a Google3 compliant way.
- // In Google 3 the Dex merger is used to merge the Bazel desugared core library.
- // The Dex merger has to be able to merge multiple classes with the prefix j$ for this case.
- // The following should therefore not raise:
- // "Merging dex file containing classes with prefix j$. is not allowed."
- fail();
- }
- throw e;
- }
- CodeInspector codeInspectorOutput = new CodeInspector(merged);
- CodeInspector codeInspectorSplit1 = new CodeInspector(mergerInputPart1);
- CodeInspector codeInspectorSplit2 = new CodeInspector(mergerInputPart2);
- assertNotNull(codeInspectorOutput);
- assertTrue(codeInspectorOutput.allClasses().size() > codeInspectorSplit1.allClasses().size());
- assertTrue(codeInspectorOutput.allClasses().size() > codeInspectorSplit2.allClasses().size());
- }
-
private Path buildSplitDesugaredLibraryPart1() throws Exception {
Path outputDex = temp.newFolder().toPath().resolve("merger-input-dex.zip");
L8.run(