Skip to content

Commit

Permalink
[Fix] LCP writer not properly de-duplicating dependencies (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
marchermans authored Sep 22, 2024
1 parent 28e9828 commit 89bae0f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.BiFunction;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand All @@ -63,8 +61,8 @@ private RunsUtil() {
throw new IllegalStateException("Tried to create utility class!");
}

public static String createTaskName(final String prefix, final Run run) {
return createTaskName(prefix, run.getName());
public static String createNameFor(final String prefix, final Run run) {
return createNameFor(prefix, run.getName());
}

public static void configure(Project project, Run run, boolean isInternal) {
Expand All @@ -91,7 +89,7 @@ public static void registerPostSyncTasks(Project project, Run run) {
public static void createTasks(Project project, Run run) {
if (!run.getIsJUnit().get()) {
//Create run exec tasks for all non-unit test runs
project.getTasks().register(createTaskName(run.getName()), JavaExec.class, runExec -> {
project.getTasks().register(createNameFor(run.getName()), JavaExec.class, runExec -> {
runExec.setDescription("Runs the " + run.getName() + " run.");
runExec.setGroup("NeoGradle/Runs");

Expand Down Expand Up @@ -220,7 +218,7 @@ public static void setupRenderDocSupport(Project project, Run run) {
throw new InvalidUserDataException("RenderDoc can only be enabled for client runs.");

final RenderDocTools renderDocTools = project.getExtensions().getByType(Subsystems.class).getTools().getRenderDoc();
final TaskProvider<RenderDocDownloaderTask> setupRenderDoc = project.getTasks().register(RunsUtil.createTaskName("setupRenderDoc", run), RenderDocDownloaderTask.class, renderDoc -> {
final TaskProvider<RenderDocDownloaderTask> setupRenderDoc = project.getTasks().register(RunsUtil.createNameFor("setupRenderDoc", run), RenderDocDownloaderTask.class, renderDoc -> {
renderDoc.getRenderDocVersion().set(renderDocTools.getRenderDocVersion());
renderDoc.getRenderDocOutputDirectory().set(renderDocTools.getRenderDocPath().dir("download"));
renderDoc.getRenderDocInstallationDirectory().set(renderDocTools.getRenderDocPath().dir("installation"));
Expand Down Expand Up @@ -347,7 +345,7 @@ private static void createOrReuseTestTask(Project project, String name, Run run)

private static void createNewTestTask(Project project, String name, Run run) {
//Create a test task for unit tests
TaskProvider<Test> newTestTask = project.getTasks().register(createTaskName("test", name), Test.class);
TaskProvider<Test> newTestTask = project.getTasks().register(createNameFor("test", name), Test.class);
configureTestTask(project, newTestTask, run);
project.getTasks().named("check", check -> check.dependsOn(newTestTask));
}
Expand Down Expand Up @@ -663,11 +661,11 @@ public static Provider<String> buildModClasses(final Provider<Multimap<String, S
.collect(Collectors.joining(File.pathSeparator)));
}

private static String createTaskName(final String runName) {
return createTaskName("run", runName);
private static String createNameFor(final String runName) {
return createNameFor("run", runName);
}

private static String createTaskName(final String prefix, final String runName) {
private static String createNameFor(final String prefix, final String runName) {
final String conventionTaskName = runName.replaceAll("[^a-zA-Z0-9\\-_]", "");
if (conventionTaskName.startsWith("run")) {
return conventionTaskName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import net.neoforged.gradle.common.runtime.tasks.ExtractNatives;
import net.neoforged.gradle.common.util.ConfigurationUtils;
import net.neoforged.gradle.common.util.run.RunsUtil;
import net.neoforged.gradle.dsl.common.runs.run.DependencyHandler;
import net.neoforged.gradle.dsl.common.runtime.definition.Definition;
import net.neoforged.gradle.dsl.common.tasks.WithOutput;
import net.neoforged.gradle.dsl.userdev.configurations.UserdevProfile;
Expand Down Expand Up @@ -127,14 +126,26 @@ protected void buildRunInterpolationData(RunImpl run, @NotNull MapProperty<Strin
}

final TaskProvider<ClasspathSerializer> minecraftClasspathSerializer = getSpecification().getProject().getTasks().register(
RunsUtil.createTaskName("writeMinecraftClasspath", run),
RunsUtil.createNameFor("writeMinecraftClasspath", run),
ClasspathSerializer.class,
task -> {
this.additionalUserDevDependencies.getExtendsFrom().forEach(task.getInputFiles()::from);
task.getInputFiles().from(this.additionalUserDevDependencies);
task.getInputFiles().from(neoformRuntimeDefinition.getMinecraftDependenciesConfiguration());
final Configuration lcpConfiguration = ConfigurationUtils.temporaryConfiguration(getSpecification().getProject(),
RunsUtil.createNameFor("lcp", run));

lcpConfiguration.extendsFrom(neoformRuntimeDefinition.getMinecraftDependenciesConfiguration());
lcpConfiguration.extendsFrom(this.additionalUserDevDependencies);
lcpConfiguration.extendsFrom(run.getDependencies().getRuntimeConfiguration());

//We depend on the configuration, this ensures that if we have dependencies with different versions in the
//dependency tree they are resolved to one version and are not added with different versions to the ConfigurableFileCollection
//on the input files.
//Additionally, we need to directly depend on the output file of the userdevClasspathElementProducer, we can not convert
//this to a dependency because it would be a transform of a configurable file collection that holds the output of the task
//which requires running that task, which would be a cyclic dependency.
//This is a workaround to ensure that the path to the userdev classpath element is resolved correctly.
//And added to the LCP, as we are now not transforming the CFC created from the output (we are not even creating a CFC)
task.getInputFiles().from(lcpConfiguration);
task.getInputFiles().from(this.userdevClasspathElementProducer.flatMap(WithOutput::getOutput));
task.getInputFiles().from(run.getDependencies().getRuntimeConfiguration());
}
);
configureAssociatedTask(minecraftClasspathSerializer);
Expand Down

0 comments on commit 89bae0f

Please sign in to comment.