Skip to content
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
3 changes: 3 additions & 0 deletions codebook-cli/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions codebook-cli/src/main/java/io/papermc/codebook/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -316,6 +317,13 @@ static class InputFileOptions {
description = "The temp dir to work in.")
private @Nullable Path tempDir;

@CommandLine.Option(
names = {"--hypo-parallelism"},
paramLabel = "<parallelism-level>",
defaultValue = "-1",
description = "The parallelism level to use for Hypo executions.")
private int hypoConcurrency;

public Main() {}

public static void main(final String[] args) {
Expand Down Expand Up @@ -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)
Expand All @@ -479,6 +493,7 @@ private CodeBookContext createContext() {
.overwrite(this.forceWrite)
.input(input)
.reports(reports)
.hypoConfig(hypoConfig)
.build();
}

Expand Down
8 changes: 8 additions & 0 deletions src/main/java/io/papermc/codebook/CodeBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/io/papermc/codebook/pages/CodeBookPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -156,6 +157,7 @@ public void to(final @Nullable T value) {
@Retention(RetentionPolicy.RUNTIME)
public @interface Hypo {
Key<HypoContext> KEY = Key.get(HypoContext.class, Hypo.class);
Key<HypoConfig> CONFIG_KEY = Key.get(HypoConfig.class, Hypo.class);
}

@Qualifier
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/io/papermc/codebook/pages/InspectJarPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -65,15 +66,18 @@ public final class InspectJarPage extends CodeBookPage {
private final Path inputJar;
private final List<Path> classpathJars;
private final @Nullable Path paramMappings;
private final HypoConfig config;

@Inject
public InspectJarPage(
@InputJar final Path inputJar,
@ClasspathJars final List<Path> 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
Expand All @@ -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);
Expand Down