Skip to content

Commit

Permalink
Allow datagen tasks to be skipped when up to date.
Browse files Browse the repository at this point in the history
  • Loading branch information
modmuss50 committed Nov 28, 2024
1 parent c4e2679 commit a26f139
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ public void configureDataGeneration(Action<DataGenerationSettings> 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);
});
}
}

Expand Down
18 changes: 11 additions & 7 deletions src/main/java/net/fabricmc/loom/task/AbstractRunTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -100,6 +99,10 @@ public AbstractRunTask(Function<Project, RunConfig> 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() {
Expand Down Expand Up @@ -154,7 +157,8 @@ private List<String> 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) {
Expand Down

0 comments on commit a26f139

Please sign in to comment.