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

Implement ATs with JST and enable incremental compilation #147

Merged
merged 7 commits into from
May 13, 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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import static net.neoforged.gradle.dsl.common.util.Constants.DEFAULT_PARCHMENT_ARTIFACT_PREFIX;
import static net.neoforged.gradle.dsl.common.util.Constants.DEFAULT_PARCHMENT_GROUP;
import static net.neoforged.gradle.dsl.common.util.Constants.DEFAULT_PARCHMENT_MAVEN_URL;
import static net.neoforged.gradle.dsl.common.util.Constants.DEFAULT_PARCHMENT_TOOL_ARTIFACT;
import static net.neoforged.gradle.dsl.common.util.Constants.JST_TOOL_ARTIFACT;
import static net.neoforged.gradle.dsl.common.util.Constants.DEFAULT_RECOMPILER_MAX_MEMORY;
import static net.neoforged.gradle.dsl.common.util.Constants.SUBSYSTEM_PROPERTY_PREFIX;

Expand Down Expand Up @@ -82,7 +82,7 @@ private void configureParchmentDefaults() {
getStringProperty("parchment.mappingsVersion")
);
parchment.getToolArtifact().convention(
getStringProperty("parchment.toolArtifact").orElse(DEFAULT_PARCHMENT_TOOL_ARTIFACT)
getStringProperty("parchment.toolArtifact").orElse(JST_TOOL_ARTIFACT)
);
parchment.getAddRepository().convention(
getBooleanProperty("parchment.addRepository").orElse(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
import org.gradle.api.tasks.InputFiles;
import org.gradle.api.tasks.PathSensitive;
import org.gradle.api.tasks.PathSensitivity;
import org.gradle.api.tasks.SkipWhenEmpty;
import org.gradle.jvm.toolchain.JavaLanguageVersion;

import java.io.File;
import java.util.Collections;
import java.util.List;

@CacheableTask
Expand All @@ -23,34 +24,43 @@ public AccessTransformer() {

setDescription("Runs the access transformer on the decompiled sources.");

getExecutingJar().set(ToolUtilities.resolveTool(getProject(), Constants.ACCESSTRANSFORMER));
getExecutingJar().set(ToolUtilities.resolveTool(getProject(), Constants.JST_TOOL_ARTIFACT));
getRuntimeProgramArguments().convention(
getInputFile().map(inputFile -> {
final List<String> args = Lists.newArrayList();
final File outputFile = ensureFileWorkspaceReady(getOutput());

args.add("--inJar");
args.add(inputFile.getAsFile().getAbsolutePath());
args.add("--outJar");
args.add(outputFile.getAbsolutePath());
args.add("--enable-accesstransformers");
getTransformers().forEach(f -> {
args.add("--atFile");
args.add("--access-transformer");
args.add(f.getAbsolutePath());
});

args.add("--libraries-list=" + getLibraries().get().getAsFile().getAbsolutePath());

args.add(inputFile.getAsFile().getAbsolutePath());
args.add(outputFile.getAbsolutePath());

return args;
}
)
);

getJavaVersion().set(JavaLanguageVersion.of(17));

getTransformers().finalizeValueOnRead();
}

@InputFile
@PathSensitive(PathSensitivity.NONE)
public abstract RegularFileProperty getInputFile();

@InputFile
@PathSensitive(PathSensitivity.NONE)
public abstract RegularFileProperty getLibraries();

@InputFiles
@SkipWhenEmpty
@PathSensitive(PathSensitivity.NONE)
public abstract ConfigurableFileCollection getTransformers();
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ public void run() throws IOException {

// Write the list
PrintWriter writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(output), StandardCharsets.UTF_8));
for (File file : libraries) {
writer.println("-e=" + file.getAbsolutePath());
Iterator<File> itr = libraries.stream().sorted(Comparator.naturalOrder()).iterator();
while (itr.hasNext()) {
writer.println("-e=" + itr.next().getAbsolutePath());
}
writer.flush();
writer.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,14 @@
import net.neoforged.gradle.common.runtime.tasks.AccessTransformerFileGenerator;
import net.neoforged.gradle.dsl.common.runtime.definition.Definition;
import net.neoforged.gradle.dsl.common.runtime.tasks.Runtime;
import net.neoforged.gradle.dsl.common.tasks.ArtifactProvider;
import net.neoforged.gradle.dsl.common.tasks.WithOutput;
import net.neoforged.gradle.dsl.common.util.CommonRuntimeUtils;
import net.neoforged.gradle.dsl.common.util.GameArtifact;
import net.neoforged.gradle.util.StringCapitalizationUtils;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.EmptyFileVisitor;
import org.gradle.api.file.FileTree;
import org.gradle.api.file.FileVisitDetails;
import org.gradle.api.tasks.TaskProvider;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.util.*;
import java.util.Collection;
import java.util.function.Consumer;

public final class CommonRuntimeTaskUtils {
Expand All @@ -26,7 +20,7 @@ private CommonRuntimeTaskUtils() {
throw new IllegalStateException("Can not instantiate an instance of: CommonRuntimeTaskUtils. This is a utility class");
}

public static TaskProvider<? extends AccessTransformer> createAccessTransformer(Definition<?> definition, String namePreFix, File workspaceDirectory, Consumer<TaskProvider<? extends Runtime>> dependentTaskConfigurationHandler, FileTree files, Collection<String> data) {
public static TaskProvider<? extends AccessTransformer> createAccessTransformer(Definition<?> definition, String namePreFix, File workspaceDirectory, Consumer<TaskProvider<? extends Runtime>> dependentTaskConfigurationHandler, FileTree files, Collection<String> data, TaskProvider<? extends WithOutput> listLibs) {
final TaskProvider<AccessTransformerFileGenerator> generator;
if (!data.isEmpty()) {
generator = definition.getSpecification().getProject().getTasks().register(CommonRuntimeUtils.buildTaskName(definition.getSpecification(), namePreFix + "AccessTransformerGenerator"), AccessTransformerFileGenerator.class, task -> {
Expand All @@ -44,6 +38,8 @@ public static TaskProvider<? extends AccessTransformer> createAccessTransformer(
task.getTransformers().from(generator.flatMap(WithOutput::getOutput));
task.dependsOn(generator);
}
task.dependsOn(listLibs);
task.getLibraries().set(listLibs.flatMap(WithOutput::getOutput));
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ interface ExecuteSpecification extends ProjectSpecification, OutputSpecification
*
* @return The path to the console log file.
*/
@OutputFile
@Internal
@DSLProperty
RegularFileProperty getConsoleLogFile();

Expand All @@ -61,7 +61,7 @@ interface ExecuteSpecification extends ProjectSpecification, OutputSpecification
*
* @return The path to the program log file.
*/
@OutputFile
@Internal
@DSLProperty
RegularFileProperty getLogFile();

Expand Down Expand Up @@ -114,4 +114,4 @@ interface ExecuteSpecification extends ProjectSpecification, OutputSpecification
*/
@Internal
MapProperty<String, Provider<List<String>>> getMultiRuntimeArguments();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ class Constants {
public static final String BINPATCHER_VERSION_INTERPOLATION = "net.minecraftforge:binarypatcher:%s:fatjar";
public static final String BINPATCHER = String.format(BINPATCHER_VERSION_INTERPOLATION, BINPATCHER_VERSION);
public static final String ACCESSTRANSFORMER_VERSION = "10.0.+";
public static final String ACCESSTRANSFORMER_VERSION_INTERPOLATION = "net.neoforged.accesstransformers:at-cli:%s:fatjar";
public static final String ACCESSTRANSFORMER = String.format(ACCESSTRANSFORMER_VERSION_INTERPOLATION, ACCESSTRANSFORMER_VERSION);
public static final String SPECIALSOURCE = "net.md-5:SpecialSource:1.11.0:shaded";
public static final String FART_VERSION = "1.0.13";
public static final String FART_VERSION = "2.0.3";
public static final String FART_ARTIFACT_INTERPOLATION = "net.neoforged:AutoRenamingTool:%s:all";
public static final String FART = String.format(FART_ARTIFACT_INTERPOLATION, FART_VERSION);
public static final String INSTALLERTOOLS_VERSION = '2.1.2'
Expand All @@ -27,7 +25,7 @@ class Constants {
public static final String DEFAULT_PARCHMENT_GROUP = "org.parchmentmc.data"
public static final String DEFAULT_PARCHMENT_ARTIFACT_PREFIX = "parchment-"
public static final String DEFAULT_PARCHMENT_MAVEN_URL = "https://maven.parchmentmc.org/"
public static final String DEFAULT_PARCHMENT_TOOL_ARTIFACT = "net.neoforged.jst:jst-cli-bundle:1.0.31"
public static final String JST_TOOL_ARTIFACT = "net.neoforged.jst:jst-cli-bundle:1.0.35"

public static final String DEFAULT_RECOMPILER_MAX_MEMORY = "1g"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,24 @@
import net.neoforged.gradle.dsl.neoform.configuration.NeoFormConfigConfigurationSpecV2;
import net.neoforged.gradle.neoform.runtime.definition.NeoFormRuntimeDefinition;
import net.neoforged.gradle.neoform.runtime.specification.NeoFormRuntimeSpecification;
import net.neoforged.gradle.neoform.runtime.tasks.*;
import net.neoforged.gradle.neoform.runtime.tasks.InjectFromFileTreeSource;
import net.neoforged.gradle.neoform.runtime.tasks.InjectZipContent;
import net.neoforged.gradle.neoform.runtime.tasks.PackZip;
import net.neoforged.gradle.neoform.runtime.tasks.Patch;
import net.neoforged.gradle.neoform.runtime.tasks.RecompileSourceJar;
import net.neoforged.gradle.neoform.runtime.tasks.StripJar;
import net.neoforged.gradle.neoform.runtime.tasks.UnpackJavaSources;
import net.neoforged.gradle.neoform.util.NeoFormRuntimeConstants;
import net.neoforged.gradle.neoform.util.NeoFormRuntimeUtils;
import net.neoforged.gradle.util.CopyingFileTreeVisitor;
import org.apache.commons.lang3.StringUtils;
import org.gradle.api.GradleException;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.file.FileCollection;
import org.gradle.api.file.FileTree;
import org.gradle.api.file.RegularFile;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.api.tasks.compile.AbstractCompile;
import org.gradle.api.tasks.compile.ForkOptions;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -407,8 +412,9 @@ protected void bakeDefinition(NeoFormRuntimeDefinition definition) {
}
});

final String taskName = neoFormRuntimeTaskProvider.getName();
if (!spec.getPostTypeAdapters().containsKey(step.getName())) {
taskOutputs.put(neoFormRuntimeTaskProvider.getName(), neoFormRuntimeTaskProvider);
taskOutputs.put(taskName, neoFormRuntimeTaskProvider);
} else {
for (TaskTreeAdapter taskTreeAdapter : spec.getPostTypeAdapters().get(step.getName())) {
final TaskProvider<? extends Runtime> taskProvider = taskTreeAdapter.adapt(definition, neoFormRuntimeTaskProvider, neoFormDirectory, definition.getGameArtifactProvidingTasks(), definition.getMappingVersionData(), dependentTaskProvider -> dependentTaskProvider.configure(task -> configureMcpRuntimeTaskWithDefaults(spec, neoFormDirectory, symbolicDataSources, task)));
Expand All @@ -418,6 +424,8 @@ protected void bakeDefinition(NeoFormRuntimeDefinition definition) {
}
}

// We consider the output of the final post adapter the output of step
taskOutputs.put(taskName, neoFormRuntimeTaskProvider);
taskOutputs.put(neoFormRuntimeTaskProvider.getName(), neoFormRuntimeTaskProvider);
}
}
Expand All @@ -441,9 +449,14 @@ protected void bakeDefinition(NeoFormRuntimeDefinition definition) {
);

final FileCollection recompileDependencies = spec.getAdditionalRecompileDependencies().plus(spec.getProject().files(definition.getMinecraftDependenciesConfiguration()));
final TaskProvider<? extends Runtime> recompileTask = spec.getProject()
final TaskProvider<UnpackJavaSources> unpackSources = spec.getProject().getTasks().register(CommonRuntimeUtils.buildTaskName(spec, "unzipSources"), UnpackJavaSources.class, task -> {
task.getInputZip().set(recompileInput);
});
unpackSources.configure(neoFormRuntimeTask -> configureMcpRuntimeTaskWithDefaults(spec, neoFormDirectory, symbolicDataSources, neoFormRuntimeTask));

final TaskProvider<RecompileSourceJar> recompileTask = spec.getProject()
.getTasks().register(CommonRuntimeUtils.buildTaskName(spec, "recompile"), RecompileSourceJar.class, task -> {
task.getInputJar().set(recompileInput);
task.setSource(unpackSources.flatMap(UnpackJavaSources::getUnpackingTarget));
task.getCompileClasspath().setFrom(recompileDependencies);
task.getStepName().set("recompile");

Expand All @@ -455,17 +468,27 @@ protected void bakeDefinition(NeoFormRuntimeDefinition definition) {
forkOptions.setJvmArgs(settings.getJvmArgs().get());
task.getOptions().getCompilerArgumentProviders().add(settings.getArgs()::get);
});

recompileTask.configure(neoFormRuntimeTask -> configureMcpRuntimeTaskWithDefaults(spec, neoFormDirectory, symbolicDataSources, neoFormRuntimeTask));

taskOutputs.put(recompileTask.getName(), recompileTask);
final TaskProvider<PackZip> packTask = spec.getProject()
.getTasks().register(CommonRuntimeUtils.buildTaskName(spec, "packRecomp"), PackZip.class, task -> {
task.getInputFiles().from(recompileTask.flatMap(AbstractCompile::getDestinationDirectory));
task.getInputFiles().from(getProject().fileTree(recompileInput)
.matching(sp -> sp.exclude("**/*.java")));
});

packTask.configure(neoFormRuntimeTask -> configureMcpRuntimeTaskWithDefaults(spec, neoFormDirectory, symbolicDataSources, neoFormRuntimeTask));

taskOutputs.put(recompileTask.getName(), packTask);

definition.getSourceJarTask().configure(task -> {
task.getInputFiles().from(recompileInput);
task.dependsOn(remapTask);
});
definition.getRawJarTask().configure(task -> {
task.getInputFiles().from(recompileTask.flatMap(WithOutput::getOutput));
task.dependsOn(recompileTask);
task.getInputFiles().from(packTask.flatMap(WithOutput::getOutput));
task.dependsOn(packTask);
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.neoforged.gradle.platform.runtime.runtime.tasks;
package net.neoforged.gradle.neoform.runtime.tasks;

import net.neoforged.gradle.common.runtime.tasks.DefaultRuntime;
import net.neoforged.gradle.util.ZipBuildingFileTreeVisitor;
Expand Down
Loading
Loading