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

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

Merged
merged 1 commit into from
Nov 29, 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 @@ -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