diff options
Diffstat (limited to 'java/com/google/turbine/deps')
-rw-r--r-- | java/com/google/turbine/deps/Dependencies.java | 4 | ||||
-rw-r--r-- | java/com/google/turbine/deps/Transitive.java | 19 |
2 files changed, 18 insertions, 5 deletions
diff --git a/java/com/google/turbine/deps/Dependencies.java b/java/com/google/turbine/deps/Dependencies.java index 92193e8..ef1eea9 100644 --- a/java/com/google/turbine/deps/Dependencies.java +++ b/java/com/google/turbine/deps/Dependencies.java @@ -51,7 +51,7 @@ import java.util.Optional; import java.util.Set; /** Support for Bazel jdeps dependency output. */ -public class Dependencies { +public final class Dependencies { /** Creates a jdeps proto for the current compilation. */ public static DepsProto.Dependencies collectDeps( Optional<String> targetLabel, ClassPath bootclasspath, BindingResult bound, Lowered lowered) { @@ -219,4 +219,6 @@ public class Dependencies { // preserve the order of entries in the transitive classpath return Collections2.filter(transitiveClasspath, Predicates.in(reduced)); } + + private Dependencies() {} } diff --git a/java/com/google/turbine/deps/Transitive.java b/java/com/google/turbine/deps/Transitive.java index 8b0d44d..75d23f6 100644 --- a/java/com/google/turbine/deps/Transitive.java +++ b/java/com/google/turbine/deps/Transitive.java @@ -33,13 +33,14 @@ import com.google.turbine.bytecode.ClassWriter; import com.google.turbine.model.TurbineFlag; import java.util.LinkedHashSet; import java.util.Set; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Collects the minimal compile-time API for symbols in the supertype closure of compiled classes. * This allows header compilations to be performed against a classpath containing only direct * dependencies and no transitive dependencies. */ -public class Transitive { +public final class Transitive { public static ImmutableMap<String, byte[]> collectDeps( ClassPath bootClassPath, BindingResult bound) { @@ -54,7 +55,8 @@ public class Transitive { // don't export symbols loaded from the bootclasspath continue; } - transitive.put(sym.binaryName(), ClassWriter.writeClass(trimClass(info.classFile()))); + transitive.put( + sym.binaryName(), ClassWriter.writeClass(trimClass(info.classFile(), info.jarFile()))); } return transitive.build(); } @@ -62,7 +64,7 @@ public class Transitive { /** * Removes information from repackaged classes that will not be needed by upstream compilations. */ - public static ClassFile trimClass(ClassFile cf) { + public static ClassFile trimClass(ClassFile cf, @Nullable String jarFile) { // drop non-constant fields ImmutableList.Builder<FieldInfo> fields = ImmutableList.builder(); for (FieldInfo f : cf.fields()) { @@ -80,6 +82,12 @@ public class Transitive { innerClasses.add(i); } } + // Include the original jar file name when repackaging transitive deps. If the same transitive + // dep is repackaged more than once, keep the original name. + String transitiveJar = cf.transitiveJar(); + if (transitiveJar == null) { + transitiveJar = jarFile; + } return new ClassFile( cf.access(), cf.name(), @@ -96,7 +104,8 @@ public class Transitive { cf.annotations(), innerClasses.build(), cf.typeAnnotations(), - /* module= */ null); + /* module= */ null, + /* transitiveJar = */ transitiveJar); } private static Set<ClassSymbol> superClosure(BindingResult bound) { @@ -134,4 +143,6 @@ public class Transitive { addSuperTypes(closure, env, i); } } + + private Transitive() {} } |