From a26f1397f103264e6decaf225e90994065470992 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Thu, 28 Nov 2024 22:08:20 +0000 Subject: [PATCH] Allow datagen tasks to be skipped when up to date. Fixes #1135 --- .../loom/configuration/FabricApiExtension.java | 5 +++++ .../fabricmc/loom/task/AbstractRunTask.java | 18 +++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/fabricmc/loom/configuration/FabricApiExtension.java b/src/main/java/net/fabricmc/loom/configuration/FabricApiExtension.java index a1eefff4d..3fea88beb 100644 --- a/src/main/java/net/fabricmc/loom/configuration/FabricApiExtension.java +++ b/src/main/java/net/fabricmc/loom/configuration/FabricApiExtension.java @@ -205,6 +205,11 @@ public void configureDataGeneration(Action action) { run.source(DATAGEN_SOURCESET_NAME); } }); + + // Add the output directory as an output allowing the task to be skipped. + getProject().getTasks().named("runDatagen", task -> { + task.getOutputs().file(outputDirectory); + }); } } diff --git a/src/main/java/net/fabricmc/loom/task/AbstractRunTask.java b/src/main/java/net/fabricmc/loom/task/AbstractRunTask.java index 67191ff5b..8a0a4b72d 100644 --- a/src/main/java/net/fabricmc/loom/task/AbstractRunTask.java +++ b/src/main/java/net/fabricmc/loom/task/AbstractRunTask.java @@ -31,6 +31,7 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.function.Function; @@ -43,7 +44,6 @@ import org.gradle.api.provider.MapProperty; import org.gradle.api.provider.Property; import org.gradle.api.provider.Provider; -import org.gradle.api.services.ServiceReference; import org.gradle.api.specs.Spec; import org.gradle.api.tasks.Input; import org.gradle.api.tasks.InputFiles; @@ -52,9 +52,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.configuration.ide.RunConfig; import net.fabricmc.loom.util.Constants; -import net.fabricmc.loom.util.gradle.SyncTaskBuildService; public abstract class AbstractRunTask extends JavaExec { private static final CharsetEncoder ASCII_ENCODER = StandardCharsets.US_ASCII.newEncoder(); @@ -70,15 +70,14 @@ public abstract class AbstractRunTask extends JavaExec { protected abstract Property getUseArgFile(); @Input protected abstract Property getProjectDir(); + @Input + // We use a string here, as it's technically an output, but we don't want to cache runs of this task by default. + protected abstract Property getArgFilePath(); // We control the classpath, as we use a ArgFile to pass it over the command line: https://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html#commandlineargfile @InputFiles protected abstract ConfigurableFileCollection getInternalClasspath(); - // Prevent Gradle from running two run tasks in parallel - @ServiceReference(SyncTaskBuildService.NAME) - abstract Property getSyncTask(); - public AbstractRunTask(Function configProvider) { super(); setGroup(Constants.TaskGroup.FABRIC); @@ -100,6 +99,10 @@ public AbstractRunTask(Function configProvider) { getInternalJvmArgs().set(config.map(runConfig -> runConfig.vmArgs)); getUseArgFile().set(getProject().provider(this::canUseArgFile)); getProjectDir().set(getProject().getProjectDir().getAbsolutePath()); + + File buildCache = LoomGradleExtension.get(getProject()).getFiles().getProjectBuildCache(); + File argFile = new File(buildCache, "argFiles/" + getName()); + getArgFilePath().set(argFile.getAbsolutePath()); } private boolean canUseArgFile() { @@ -154,7 +157,8 @@ private List getGameJvmArgs() { .collect(Collectors.joining(File.pathSeparator)); try { - final Path argsFile = Files.createTempFile("loom-classpath", ".args"); + final Path argsFile = Paths.get(getArgFilePath().get()); + Files.createDirectories(argsFile.getParent()); Files.writeString(argsFile, content, StandardCharsets.UTF_8); args.add("@" + argsFile.toAbsolutePath()); } catch (IOException e) {