Skip to content

Commit 82d81c9

Browse files
committed
feat: allow configuring hypo-parallelism
1 parent f25c643 commit 82d81c9

File tree

6 files changed

+36
-2
lines changed

6 files changed

+36
-2
lines changed

codebook-cli/build.gradle.kts

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ plugins {
1212
dependencies {
1313
implementation(projects.codebook)
1414

15+
implementation(platform(libs.hypo.platform))
16+
implementation(libs.bundles.hypo.full)
17+
1518
implementation(libs.picocli)
1619
implementation(libs.slf4j)
1720
implementation(libs.slf4j.jul)

codebook-cli/src/main/java/io/papermc/codebook/cli/Main.java

+14
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
package io.papermc.codebook.cli;
2424

25+
import dev.denwav.hypo.core.HypoConfig;
2526
import io.papermc.codebook.CodeBook;
2627
import io.papermc.codebook.config.CodeBookContext;
2728
import io.papermc.codebook.config.CodeBookCoordsResource;
@@ -316,6 +317,13 @@ static class InputFileOptions {
316317
description = "The temp dir to work in.")
317318
private @Nullable Path tempDir;
318319

320+
@CommandLine.Option(
321+
names = {"--hypo-parallelism"},
322+
paramLabel = "<parallelism-level>",
323+
defaultValue = "-1",
324+
description = "The parallelism level to use for Hypo executions.")
325+
private int hypoConcurrency;
326+
319327
public Main() {}
320328

321329
public static void main(final String[] args) {
@@ -468,6 +476,11 @@ private CodeBookContext createContext() {
468476
reports = new Reports(this.reports.reportsDir, reportsToGenerate);
469477
}
470478

479+
@Nullable HypoConfig hypoConfig = null;
480+
if (this.hypoConcurrency != -1) {
481+
hypoConfig = HypoConfig.builder().withParallelism(this.hypoConcurrency).build();
482+
}
483+
471484
return CodeBookContext.builder()
472485
.tempDir(this.tempDir)
473486
.remapperJar(remapper)
@@ -479,6 +492,7 @@ private CodeBookContext createContext() {
479492
.overwrite(this.forceWrite)
480493
.input(input)
481494
.reports(reports)
495+
.hypoConfig(hypoConfig)
482496
.build();
483497
}
484498

src/main/java/io/papermc/codebook/CodeBook.java

+8
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.google.inject.Module;
2929
import com.google.inject.util.Providers;
3030
import dev.denwav.hypo.asm.AsmOutputWriter;
31+
import dev.denwav.hypo.core.HypoConfig;
3132
import dev.denwav.hypo.core.HypoContext;
3233
import io.papermc.codebook.config.CodeBookClasspathResource;
3334
import io.papermc.codebook.config.CodeBookContext;
@@ -189,6 +190,13 @@ protected void configure() {
189190
this.bind(CodeBookPage.Report.KEY).toInstance(Reports.NOOP);
190191
this.install(Reports.NOOP);
191192
}
193+
194+
if (CodeBook.this.ctx.hypoConfig() != null) {
195+
this.bind(CodeBookPage.Hypo.CONFIG_KEY).toInstance(CodeBook.this.ctx.hypoConfig());
196+
} else {
197+
this.bind(CodeBookPage.Hypo.CONFIG_KEY)
198+
.toInstance(HypoConfig.builder().build());
199+
}
192200
}
193201
};
194202
}

src/main/java/io/papermc/codebook/config/CodeBookContext.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
package io.papermc.codebook.config;
2424

25+
import dev.denwav.hypo.core.HypoConfig;
2526
import io.papermc.codebook.report.Reports;
2627
import io.soabase.recordbuilder.core.RecordBuilder;
2728
import java.nio.file.Path;
@@ -42,7 +43,8 @@ public record CodeBookContext(
4243
@NotNull Path outputJar,
4344
boolean overwrite,
4445
@NotNull CodeBookInput input,
45-
@Nullable @org.jetbrains.annotations.Nullable Reports reports) {
46+
@Nullable @org.jetbrains.annotations.Nullable Reports reports,
47+
@Nullable @org.jetbrains.annotations.Nullable HypoConfig hypoConfig) {
4648

4749
public static CodeBookContextBuilder builder() {
4850
return CodeBookContextBuilder.builder();

src/main/java/io/papermc/codebook/pages/CodeBookPage.java

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.google.inject.binder.LinkedBindingBuilder;
3030
import com.google.inject.util.Modules;
3131
import com.google.inject.util.Providers;
32+
import dev.denwav.hypo.core.HypoConfig;
3233
import dev.denwav.hypo.core.HypoContext;
3334
import io.papermc.codebook.config.CodeBookContext;
3435
import io.papermc.codebook.report.Reports;
@@ -156,6 +157,7 @@ public void to(final @Nullable T value) {
156157
@Retention(RetentionPolicy.RUNTIME)
157158
public @interface Hypo {
158159
Key<HypoContext> KEY = Key.get(HypoContext.class, Hypo.class);
160+
Key<HypoConfig> CONFIG_KEY = Key.get(HypoConfig.class, Hypo.class);
159161
}
160162

161163
@Qualifier

src/main/java/io/papermc/codebook/pages/InspectJarPage.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import dev.denwav.hypo.asm.hydrate.LambdaCallHydrator;
3434
import dev.denwav.hypo.asm.hydrate.LocalClassHydrator;
3535
import dev.denwav.hypo.asm.hydrate.SuperConstructorHydrator;
36+
import dev.denwav.hypo.core.HypoConfig;
3637
import dev.denwav.hypo.core.HypoContext;
3738
import dev.denwav.hypo.hydrate.HydrationManager;
3839
import dev.denwav.hypo.mappings.ChangeChain;
@@ -65,15 +66,18 @@ public final class InspectJarPage extends CodeBookPage {
6566
private final Path inputJar;
6667
private final List<Path> classpathJars;
6768
private final @Nullable Path paramMappings;
69+
private final HypoConfig config;
6870

6971
@Inject
7072
public InspectJarPage(
7173
@InputJar final Path inputJar,
7274
@ClasspathJars final List<Path> classpathJars,
73-
@ParamMappings @Nullable final Path paramMappings) {
75+
@ParamMappings @Nullable final Path paramMappings,
76+
@Hypo final HypoConfig config) {
7477
this.inputJar = inputJar;
7578
this.classpathJars = classpathJars;
7679
this.paramMappings = paramMappings;
80+
this.config = config;
7781
}
7882

7983
@Override
@@ -87,6 +91,7 @@ public void exec() {
8791
.withProvider(AsmClassDataProvider.of(fromJar(this.inputJar)))
8892
.withContextProvider(AsmClassDataProvider.of(fromJars(this.classpathJars.toArray(new Path[0]))))
8993
.withContextProvider(AsmClassDataProvider.of(ofJdk()))
94+
.withConfig(this.config)
9095
.build();
9196
} catch (final IOException e) {
9297
throw new UnexpectedException("Failed to open jar files", e);

0 commit comments

Comments
 (0)