mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-03-28 04:07:01 -05:00
Dont allow gradle to run game/genSources tasks in parallel (#901)
* Dont allow gradle to run game/genSources tasks in parallel * Fix build
This commit is contained in:
@@ -38,18 +38,25 @@ import java.util.stream.Collectors;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.file.ConfigurableFileCollection;
|
||||
import org.gradle.api.file.FileCollection;
|
||||
import org.gradle.api.provider.Property;
|
||||
import org.gradle.api.services.ServiceReference;
|
||||
import org.gradle.api.specs.Spec;
|
||||
import org.gradle.api.tasks.JavaExec;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
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 final RunConfig config;
|
||||
// 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
|
||||
private final ConfigurableFileCollection classpath = getProject().getObjects().fileCollection();
|
||||
|
||||
// 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);
|
||||
|
||||
@@ -48,6 +48,7 @@ import javax.inject.Inject;
|
||||
import org.gradle.api.file.ConfigurableFileCollection;
|
||||
import org.gradle.api.file.RegularFileProperty;
|
||||
import org.gradle.api.provider.Property;
|
||||
import org.gradle.api.services.ServiceReference;
|
||||
import org.gradle.api.tasks.InputFile;
|
||||
import org.gradle.api.tasks.InputFiles;
|
||||
import org.gradle.api.tasks.OutputFile;
|
||||
@@ -72,6 +73,7 @@ import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.FileSystemUtil;
|
||||
import net.fabricmc.loom.util.IOStringConsumer;
|
||||
import net.fabricmc.loom.util.Platform;
|
||||
import net.fabricmc.loom.util.gradle.SyncTaskBuildService;
|
||||
import net.fabricmc.loom.util.gradle.ThreadedProgressLoggerConsumer;
|
||||
import net.fabricmc.loom.util.gradle.ThreadedSimpleProgressLogger;
|
||||
import net.fabricmc.loom.util.gradle.WorkerDaemonClientsManagerHelper;
|
||||
@@ -111,6 +113,10 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask {
|
||||
@Inject
|
||||
public abstract WorkerDaemonClientsManager getWorkerDaemonClientsManager();
|
||||
|
||||
// Prevent Gradle from running two gen sources tasks in parallel
|
||||
@ServiceReference(SyncTaskBuildService.NAME)
|
||||
abstract Property<SyncTaskBuildService> getSyncTask();
|
||||
|
||||
@Inject
|
||||
public GenerateSourcesTask(DecompilerOptions decompilerOptions) {
|
||||
this.decompilerOptions = decompilerOptions;
|
||||
|
||||
@@ -44,6 +44,7 @@ import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.gradle.GradleUtils;
|
||||
import net.fabricmc.loom.util.gradle.SourceSetHelper;
|
||||
import net.fabricmc.loom.util.gradle.SyncTaskBuildService;
|
||||
|
||||
public abstract class RemapTaskConfiguration implements Runnable {
|
||||
public static final String REMAP_JAR_TASK_NAME = "remapJar";
|
||||
@@ -64,6 +65,8 @@ public abstract class RemapTaskConfiguration implements Runnable {
|
||||
public void run() {
|
||||
final LoomGradleExtension extension = LoomGradleExtension.get(getProject());
|
||||
|
||||
SyncTaskBuildService.register(getProject());
|
||||
|
||||
if (GradleUtils.getBooleanProperty(getProject(), Constants.Properties.DONT_REMAP)) {
|
||||
extension.getUnmappedModCollection().from(getTasks().getByName(JavaPlugin.JAR_TASK_NAME));
|
||||
return;
|
||||
|
||||
@@ -29,7 +29,7 @@ import javax.inject.Inject;
|
||||
import net.fabricmc.loom.configuration.ide.RunConfig;
|
||||
import net.fabricmc.loom.configuration.ide.RunConfigSettings;
|
||||
|
||||
public class RunGameTask extends AbstractRunTask {
|
||||
public abstract class RunGameTask extends AbstractRunTask {
|
||||
@Inject
|
||||
public RunGameTask(RunConfigSettings settings) {
|
||||
super(proj -> RunConfig.runConfig(proj, settings));
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018-2021 FabricMC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package net.fabricmc.loom.util.gradle;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.services.BuildService;
|
||||
import org.gradle.api.services.BuildServiceParameters;
|
||||
|
||||
/**
|
||||
* Add the following snippet to task to prevent tasks running asynchronously with any other task with the same build service.
|
||||
*
|
||||
* <pre>{@code
|
||||
* @ServiceReference(SyncTaskBuildService.NAME)
|
||||
* abstract Property<SyncTaskBuildService> getSyncTask();
|
||||
* }</pre>
|
||||
*/
|
||||
public abstract class SyncTaskBuildService implements BuildService<SyncTaskBuildService.Params> {
|
||||
public static final String NAME = "loomSyncTask";
|
||||
|
||||
public static void register(Project project) {
|
||||
project.getGradle().getSharedServices().registerIfAbsent(
|
||||
NAME,
|
||||
SyncTaskBuildService.class,
|
||||
spec -> spec.getMaxParallelUsages().set(1)
|
||||
);
|
||||
}
|
||||
|
||||
public interface Params extends BuildServiceParameters {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user