From 91d08b3d1efa561dcd439a8e57b836c129311238 Mon Sep 17 00:00:00 2001 From: MiniDigger | Martin Date: Sat, 14 Dec 2024 15:25:45 +0100 Subject: [PATCH] feat: allow configuring hypo-parallelism --- codebook-cli/build.gradle.kts | 3 +++ .../main/java/io/papermc/codebook/cli/Main.java | 15 +++++++++++++++ src/main/java/io/papermc/codebook/CodeBook.java | 8 ++++++++ .../papermc/codebook/config/CodeBookContext.java | 4 +++- .../io/papermc/codebook/pages/CodeBookPage.java | 2 ++ .../io/papermc/codebook/pages/InspectJarPage.java | 7 ++++++- 6 files changed, 37 insertions(+), 2 deletions(-) diff --git a/codebook-cli/build.gradle.kts b/codebook-cli/build.gradle.kts index ba1bff9..42bdcc0 100644 --- a/codebook-cli/build.gradle.kts +++ b/codebook-cli/build.gradle.kts @@ -12,6 +12,9 @@ plugins { dependencies { implementation(projects.codebook) + implementation(platform(libs.hypo.platform)) + implementation(libs.bundles.hypo.full) + implementation(libs.picocli) implementation(libs.slf4j) implementation(libs.slf4j.jul) diff --git a/codebook-cli/src/main/java/io/papermc/codebook/cli/Main.java b/codebook-cli/src/main/java/io/papermc/codebook/cli/Main.java index 70c6219..c3e0530 100644 --- a/codebook-cli/src/main/java/io/papermc/codebook/cli/Main.java +++ b/codebook-cli/src/main/java/io/papermc/codebook/cli/Main.java @@ -22,6 +22,7 @@ package io.papermc.codebook.cli; +import dev.denwav.hypo.core.HypoConfig; import io.papermc.codebook.CodeBook; import io.papermc.codebook.config.CodeBookContext; import io.papermc.codebook.config.CodeBookCoordsResource; @@ -316,6 +317,13 @@ static class InputFileOptions { description = "The temp dir to work in.") private @Nullable Path tempDir; + @CommandLine.Option( + names = {"--hypo-parallelism"}, + paramLabel = "", + defaultValue = "-1", + description = "The parallelism level to use for Hypo executions.") + private int hypoConcurrency; + public Main() {} public static void main(final String[] args) { @@ -468,6 +476,12 @@ private CodeBookContext createContext() { reports = new Reports(this.reports.reportsDir, reportsToGenerate); } + @Nullable HypoConfig hypoConfig = null; + if (this.hypoConcurrency != -1) { + hypoConfig = + HypoConfig.builder().withParallelism(this.hypoConcurrency).build(); + } + return CodeBookContext.builder() .tempDir(this.tempDir) .remapperJar(remapper) @@ -479,6 +493,7 @@ private CodeBookContext createContext() { .overwrite(this.forceWrite) .input(input) .reports(reports) + .hypoConfig(hypoConfig) .build(); } diff --git a/src/main/java/io/papermc/codebook/CodeBook.java b/src/main/java/io/papermc/codebook/CodeBook.java index 29baa70..873be47 100644 --- a/src/main/java/io/papermc/codebook/CodeBook.java +++ b/src/main/java/io/papermc/codebook/CodeBook.java @@ -28,6 +28,7 @@ import com.google.inject.Module; import com.google.inject.util.Providers; import dev.denwav.hypo.asm.AsmOutputWriter; +import dev.denwav.hypo.core.HypoConfig; import dev.denwav.hypo.core.HypoContext; import io.papermc.codebook.config.CodeBookClasspathResource; import io.papermc.codebook.config.CodeBookContext; @@ -189,6 +190,13 @@ protected void configure() { this.bind(CodeBookPage.Report.KEY).toInstance(Reports.NOOP); this.install(Reports.NOOP); } + + if (CodeBook.this.ctx.hypoConfig() != null) { + this.bind(CodeBookPage.Hypo.CONFIG_KEY).toInstance(CodeBook.this.ctx.hypoConfig()); + } else { + this.bind(CodeBookPage.Hypo.CONFIG_KEY) + .toInstance(HypoConfig.builder().build()); + } } }; } diff --git a/src/main/java/io/papermc/codebook/config/CodeBookContext.java b/src/main/java/io/papermc/codebook/config/CodeBookContext.java index d20ecdb..0ef96bb 100644 --- a/src/main/java/io/papermc/codebook/config/CodeBookContext.java +++ b/src/main/java/io/papermc/codebook/config/CodeBookContext.java @@ -22,6 +22,7 @@ package io.papermc.codebook.config; +import dev.denwav.hypo.core.HypoConfig; import io.papermc.codebook.report.Reports; import io.soabase.recordbuilder.core.RecordBuilder; import java.nio.file.Path; @@ -42,7 +43,8 @@ public record CodeBookContext( @NotNull Path outputJar, boolean overwrite, @NotNull CodeBookInput input, - @Nullable @org.jetbrains.annotations.Nullable Reports reports) { + @Nullable @org.jetbrains.annotations.Nullable Reports reports, + @Nullable @org.jetbrains.annotations.Nullable HypoConfig hypoConfig) { public static CodeBookContextBuilder builder() { return CodeBookContextBuilder.builder(); diff --git a/src/main/java/io/papermc/codebook/pages/CodeBookPage.java b/src/main/java/io/papermc/codebook/pages/CodeBookPage.java index c921b93..07a7010 100644 --- a/src/main/java/io/papermc/codebook/pages/CodeBookPage.java +++ b/src/main/java/io/papermc/codebook/pages/CodeBookPage.java @@ -29,6 +29,7 @@ import com.google.inject.binder.LinkedBindingBuilder; import com.google.inject.util.Modules; import com.google.inject.util.Providers; +import dev.denwav.hypo.core.HypoConfig; import dev.denwav.hypo.core.HypoContext; import io.papermc.codebook.config.CodeBookContext; import io.papermc.codebook.report.Reports; @@ -156,6 +157,7 @@ public void to(final @Nullable T value) { @Retention(RetentionPolicy.RUNTIME) public @interface Hypo { Key KEY = Key.get(HypoContext.class, Hypo.class); + Key CONFIG_KEY = Key.get(HypoConfig.class, Hypo.class); } @Qualifier diff --git a/src/main/java/io/papermc/codebook/pages/InspectJarPage.java b/src/main/java/io/papermc/codebook/pages/InspectJarPage.java index 296c07c..328ccb9 100644 --- a/src/main/java/io/papermc/codebook/pages/InspectJarPage.java +++ b/src/main/java/io/papermc/codebook/pages/InspectJarPage.java @@ -33,6 +33,7 @@ import dev.denwav.hypo.asm.hydrate.LambdaCallHydrator; import dev.denwav.hypo.asm.hydrate.LocalClassHydrator; import dev.denwav.hypo.asm.hydrate.SuperConstructorHydrator; +import dev.denwav.hypo.core.HypoConfig; import dev.denwav.hypo.core.HypoContext; import dev.denwav.hypo.hydrate.HydrationManager; import dev.denwav.hypo.mappings.ChangeChain; @@ -65,15 +66,18 @@ public final class InspectJarPage extends CodeBookPage { private final Path inputJar; private final List classpathJars; private final @Nullable Path paramMappings; + private final HypoConfig config; @Inject public InspectJarPage( @InputJar final Path inputJar, @ClasspathJars final List classpathJars, - @ParamMappings @Nullable final Path paramMappings) { + @ParamMappings @Nullable final Path paramMappings, + @Hypo final HypoConfig config) { this.inputJar = inputJar; this.classpathJars = classpathJars; this.paramMappings = paramMappings; + this.config = config; } @Override @@ -87,6 +91,7 @@ public void exec() { .withProvider(AsmClassDataProvider.of(fromJar(this.inputJar))) .withContextProvider(AsmClassDataProvider.of(fromJars(this.classpathJars.toArray(new Path[0])))) .withContextProvider(AsmClassDataProvider.of(ofJdk())) + .withConfig(this.config) .build(); } catch (final IOException e) { throw new UnexpectedException("Failed to open jar files", e);