Allow datagen tasks to be skipped when up to date. (#1226)

Fixes #1135
This commit is contained in:
modmuss
2024-11-29 09:50:14 +00:00
committed by GitHub
parent e5ad4e186c
commit 7cc7cb0c15
2 changed files with 16 additions and 7 deletions

View File

@@ -205,6 +205,11 @@ public abstract class FabricApiExtension {
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);
});
}
}

View File

@@ -31,6 +31,7 @@ import java.nio.charset.CharsetEncoder;
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.ListProperty;
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.jetbrains.annotations.NotNull;
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<Boolean> getUseArgFile();
@Input
protected abstract Property<String> 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<String> 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<SyncTaskBuildService> getSyncTask();
public AbstractRunTask(Function<Project, RunConfig> configProvider) {
super();
setGroup(Constants.TaskGroup.FABRIC);
@@ -100,6 +99,10 @@ public abstract class AbstractRunTask extends JavaExec {
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 @@ public abstract class AbstractRunTask extends JavaExec {
.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) {