Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use .turbine instead of .class as the file extension for repackaged transitive deps #333

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions java/com/google/turbine/binder/ClassPathBinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ public final class ClassPathBinder {
*/
public static final String TRANSITIVE_PREFIX = "META-INF/TRANSITIVE/";

/**
* The suffix for repackaged transitive dependencies; see {@link
* com.google.turbine.deps.Transitive}.
*/
public static final String TRANSITIVE_SUFFIX = ".turbine";

/** Creates an environment containing symbols in the given classpath. */
public static ClassPath bindClasspath(Collection<Path> paths) throws IOException {
// TODO(cushon): this is going to require an env eventually,
Expand Down Expand Up @@ -110,14 +116,14 @@ private static void bindJar(
// TODO(cushon): don't leak file descriptors
for (Zip.Entry ze : new Zip.ZipIterable(path)) {
String name = ze.name();
if (!name.endsWith(".class")) {
resources.put(name, toByteArrayOrDie(ze));
continue;
}
if (name.startsWith(TRANSITIVE_PREFIX)) {
if (!name.endsWith(TRANSITIVE_SUFFIX)) {
continue;
}
ClassSymbol sym =
new ClassSymbol(
name.substring(TRANSITIVE_PREFIX.length(), name.length() - ".class".length()));
name.substring(
TRANSITIVE_PREFIX.length(), name.length() - TRANSITIVE_SUFFIX.length()));
transitive.computeIfAbsent(
sym,
new Function<ClassSymbol, BytecodeBoundClass>() {
Expand All @@ -128,6 +134,10 @@ public BytecodeBoundClass apply(ClassSymbol sym) {
});
continue;
}
if (!name.endsWith(".class")) {
resources.put(name, toByteArrayOrDie(ze));
continue;
}
if (name.substring(name.lastIndexOf('/') + 1).equals("module-info.class")) {
ModuleInfo moduleInfo =
BytecodeBinder.bindModuleInfo(path.toString(), toByteArrayOrDie(ze));
Expand Down
4 changes: 3 additions & 1 deletion java/com/google/turbine/main/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,9 @@ private static void writeOutput(
}
for (Map.Entry<String, byte[]> entry : transitive.entrySet()) {
addEntry(
jos, ClassPathBinder.TRANSITIVE_PREFIX + entry.getKey() + ".class", entry.getValue());
jos,
ClassPathBinder.TRANSITIVE_PREFIX + entry.getKey() + ClassPathBinder.TRANSITIVE_SUFFIX,
entry.getValue());
}
for (Map.Entry<String, byte[]> entry : lowered.entrySet()) {
addEntry(jos, entry.getKey() + ".class", entry.getValue());
Expand Down
30 changes: 15 additions & 15 deletions javatests/com/google/turbine/deps/TransitiveTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ public void transitive() throws Exception {
.containsExactly(
"META-INF/",
"META-INF/MANIFEST.MF",
"META-INF/TRANSITIVE/a/A.class",
"META-INF/TRANSITIVE/a/A$Anno.class",
"META-INF/TRANSITIVE/a/A$Inner.class",
"META-INF/TRANSITIVE/a/A.turbine",
"META-INF/TRANSITIVE/a/A$Anno.turbine",
"META-INF/TRANSITIVE/a/A$Inner.turbine",
"b/B.class")
.inOrder();

ClassFile a = ClassReader.read(null, readJar(libb).get("META-INF/TRANSITIVE/a/A.class"));
ClassFile a = ClassReader.read(null, readJar(libb).get("META-INF/TRANSITIVE/a/A.turbine"));
// methods and non-constant fields are removed
assertThat(getOnlyElement(a.fields()).name()).isEqualTo("CONST");
assertThat(a.methods()).isEmpty();
Expand All @@ -142,7 +142,7 @@ public void transitive() throws Exception {

// annotation interface methods are preserved
assertThat(
ClassReader.read(null, readJar(libb).get("META-INF/TRANSITIVE/a/A$Anno.class"))
ClassReader.read(null, readJar(libb).get("META-INF/TRANSITIVE/a/A$Anno.turbine"))
.methods())
.hasSize(1);

Expand Down Expand Up @@ -186,10 +186,10 @@ public void transitive() throws Exception {
.containsExactly(
"META-INF/",
"META-INF/MANIFEST.MF",
"META-INF/TRANSITIVE/b/B.class",
"META-INF/TRANSITIVE/a/A.class",
"META-INF/TRANSITIVE/a/A$Anno.class",
"META-INF/TRANSITIVE/a/A$Inner.class",
"META-INF/TRANSITIVE/b/B.turbine",
"META-INF/TRANSITIVE/a/A.turbine",
"META-INF/TRANSITIVE/a/A$Anno.turbine",
"META-INF/TRANSITIVE/a/A$Inner.turbine",
"c/C.class")
.inOrder();

Expand Down Expand Up @@ -256,8 +256,8 @@ public void anonymous() throws Exception {
.containsExactly(
"META-INF/",
"META-INF/MANIFEST.MF",
"META-INF/TRANSITIVE/a/A.class",
"META-INF/TRANSITIVE/a/A$I.class",
"META-INF/TRANSITIVE/a/A.turbine",
"META-INF/TRANSITIVE/a/A$I.turbine",
"b/B.class")
.inOrder();
}
Expand Down Expand Up @@ -297,9 +297,9 @@ public void childClass() throws Exception {
.containsExactly(
"META-INF/",
"META-INF/MANIFEST.MF",
"META-INF/TRANSITIVE/a/A$I.class",
"META-INF/TRANSITIVE/a/S.class",
"META-INF/TRANSITIVE/a/A.class",
"META-INF/TRANSITIVE/a/A$I.turbine",
"META-INF/TRANSITIVE/a/S.turbine",
"META-INF/TRANSITIVE/a/A.turbine",
"b/B$I.class",
"b/B.class")
.inOrder();
Expand Down Expand Up @@ -338,7 +338,7 @@ public void packageInfo() throws Exception {
.containsExactly(
"META-INF/",
"META-INF/MANIFEST.MF",
"META-INF/TRANSITIVE/p/package-info.class",
"META-INF/TRANSITIVE/p/package-info.turbine",
"p/P.class")
.inOrder();
}
Expand Down
Loading