Skip to content

Commit

Permalink
Remove Classic Desugar Dependency from r8/desugar DesugarBasicTest
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 404257264
  • Loading branch information
Googler authored and copybara-github committed Oct 19, 2021
1 parent 6c21d27 commit d5d095f
Showing 1 changed file with 0 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package com.google.devtools.build.android.r8.desugar;

import static com.google.common.truth.Truth.assertThat;
import static com.google.devtools.build.android.r8.R8Utils.DESUGAR_INTERFACE_COMPANION_SUFFIX;
import static com.google.devtools.build.android.r8.R8Utils.INTERFACE_COMPANION_SUFFIX;
import static org.objectweb.asm.Opcodes.V1_7;

Expand Down Expand Up @@ -56,12 +55,9 @@ public class DesugarBasicTest {
private Path desugared;
private Path desugaredClasspath;
private Path desugaredWithDependencyMetadata;
private Path desugaredWithDependencyMetadataWithDesugar;
private Path doubleDesugaredWithDependencyMetadata;
private Path desugaredClasspathWithDependencyMetadata;
private Path desugaredClasspathWithDependencyMetadataWithDesugar;
private Path desugaredWithDependencyMetadataMissingInterface;
private Path desugaredWithDependencyMetadataMissingInterfaceWithDesugar;

@Before
public void setup() {
Expand All @@ -79,11 +75,6 @@ public void setup() {
Paths.get(
System.getProperty(
"DesugarBasicTest.testdata_basic_desugared_with_dependency_metadata"));
// Same as above compiled with desugar.
desugaredWithDependencyMetadataWithDesugar =
Paths.get(
System.getProperty(
"DesugarBasicTest.testdata_basic_desugared_with_dependency_metadata_with_desugar"));
// Same as testdata_basic_desugared_with_dependency_metadata, but where the input is instead the
// already desugared code (i.e., testdata_basic_desugared)
doubleDesugaredWithDependencyMetadata =
Expand All @@ -96,22 +87,12 @@ public void setup() {
Paths.get(
System.getProperty(
"DesugarBasicTest.testdata_basic_desugared_classpath_with_dependency_metadata"));
// Same as above compiled with desugar.
desugaredClasspathWithDependencyMetadataWithDesugar =
Paths.get(
System.getProperty(
"DesugarBasicTest.testdata_basic_desugared_classpath_with_dependency_metadata_with_desugar"));
// Jar file with the compiled Java code in the sub-package basic after desugaring with missing
// interface.
desugaredWithDependencyMetadataMissingInterface =
Paths.get(
System.getProperty(
"DesugarBasicTest.testdata_basic_desugared_with_dependency_metadata_missing_interface"));
// Same as above compiled with desugar.
desugaredWithDependencyMetadataMissingInterfaceWithDesugar =
Paths.get(
System.getProperty(
"DesugarBasicTest.testdata_basic_desugared_with_dependency_metadata_missing_interface_with_desugar"));
}

@Test
Expand Down Expand Up @@ -174,34 +155,6 @@ private static DesugarDepsInfo extractDesugarDeps(Path jar) throws Exception {
}
}

private static DesugarDepsInfo mapD8Info(DesugarDepsInfo info) {
// Rebuild the D8 dependency information with the same naming scheme for companion classes
// as desugar use.
DesugarDepsInfo.Builder builder = info.newBuilderForType();
info.getAssumePresentList()
.forEach(
assumePresent ->
builder.addAssumePresent(
assumePresent
.newBuilderForType()
.setOrigin(assumePresent.getOrigin())
.setTarget(
assumePresent
.getTarget()
.newBuilderForType()
.setBinaryName(
assumePresent
.getTarget()
.getBinaryName()
.replace(
INTERFACE_COMPANION_SUFFIX,
DESUGAR_INTERFACE_COMPANION_SUFFIX)))));
info.getInterfaceWithCompanionList().forEach(builder::addInterfaceWithCompanion);
info.getInterfaceWithSupertypesList().forEach(builder::addInterfaceWithSupertypes);
info.getMissingInterfaceList().forEach(builder::addMissingInterface);
return builder.build();
}

private static DesugarDeps.Type classToType(Class<?> clazz) {
return DesugarDeps.Type.newBuilder()
.setBinaryName(DescriptorUtils.classToBinaryName(clazz))
Expand Down Expand Up @@ -254,10 +207,6 @@ public void checkDependencyMetadata() throws Exception {
.addExtendedInterface(classToType(I.class))
.build());
assertThat(info.getMissingInterfaceCount()).isEqualTo(0);

// Compare metadata with desugar metadata.
assertThat(mapD8Info(info))
.isEqualTo(extractDesugarDeps(desugaredWithDependencyMetadataWithDesugar));
}

@Test
Expand All @@ -282,10 +231,6 @@ public void checkDependencyMetadataClasspath() throws Exception {
assertThat(info.getInterfaceWithCompanionCount()).isEqualTo(0);
assertThat(info.getInterfaceWithSupertypesCount()).isEqualTo(0);
assertThat(info.getMissingInterfaceCount()).isEqualTo(0);

// Compare metadata with desugar metadata.
assertThat(mapD8Info(info))
.isEqualTo(extractDesugarDeps(desugaredClasspathWithDependencyMetadataWithDesugar));
}

@Test
Expand Down Expand Up @@ -325,10 +270,6 @@ public void checkDependencyMetadataMissingInterface() throws Exception {
.setOrigin(classToType(C.class))
.setTarget(classToType(K.class))
.build());

// Compare metadata with desugar metadata.
assertThat(mapD8Info(info))
.isEqualTo(extractDesugarDeps(desugaredWithDependencyMetadataMissingInterfaceWithDesugar));
}

private static void forAllClasses(Path jar, ClassVisitor classVisitor) throws Exception {
Expand Down

0 comments on commit d5d095f

Please sign in to comment.