Skip to content

Commit

Permalink
Use smarter detection for excluding Fabric deps; rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGlitch76 committed Jun 19, 2023
1 parent f0e73ca commit 3ae46b5
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 43 deletions.
Empty file modified gradlew
100755 → 100644
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This includes:
- Using the Quilt Loader system properties
- Use quilt loader in all tests
- Using `quilt_installer.json`
- Renaming the shared service manager

diff --git a/bootstrap/test-project/build.gradle b/bootstrap/test-project/build.gradle
index 561915428a80131439ea9e1d9f12804c491d399a..db648181f772520d1607ce2510a66be1d00167c2 100644
Expand Down Expand Up @@ -304,6 +305,19 @@ index 7fd5d15941dddd97c2631c26b243b7f320d9337f..7d7122b5403049714202a7ead9be65ce
}

public static Provider<Boolean> getBooleanPropertyProvider(Project project, String key) {
diff --git a/src/main/java/net/fabricmc/loom/util/service/BuildSharedServiceManager.java b/src/main/java/net/fabricmc/loom/util/service/BuildSharedServiceManager.java
index 6575611dea711ca1bb284a76132110404cdd95cb..b6f0ed542dc183f5782e300c57dce2c3ee3969b2 100644
--- a/src/main/java/net/fabricmc/loom/util/service/BuildSharedServiceManager.java
+++ b/src/main/java/net/fabricmc/loom/util/service/BuildSharedServiceManager.java
@@ -39,7 +39,7 @@ import org.slf4j.LoggerFactory;

public abstract class BuildSharedServiceManager implements BuildService<BuildServiceParameters.None> {
private static final Logger LOGGER = LoggerFactory.getLogger(BuildSharedServiceManager.class);
- private static final String NAME = "loom:sharedServiceManager";
+ private static final String NAME = "quilt-loom:sharedServiceManager";

private SharedServiceManager sharedServiceManager = new BuildSharedServiceManagerImpl();
private final AtomicInteger refCount = new AtomicInteger(0);
diff --git a/src/test/groovy/net/fabricmc/loom/test/integration/CustomManifestTest.groovy b/src/test/groovy/net/fabricmc/loom/test/integration/CustomManifestTest.groovy
index 8b4de3243a929eb4073318b68c94ea6adb300438..0051c810071cc95fe89072e2bb8e5ade00c0c27c 100644
--- a/src/test/groovy/net/fabricmc/loom/test/integration/CustomManifestTest.groovy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,10 +461,10 @@ index 4731422ca79b2b0032090034d71305749a579675..b23f0e55b906b06d6df4561e4006565c

for (Map.Entry<String, ModEnvironment> entry : modJson.getClassTweakers().entrySet()) {
diff --git a/src/main/java/net/fabricmc/loom/configuration/ifaceinject/InterfaceInjectionProcessor.java b/src/main/java/net/fabricmc/loom/configuration/ifaceinject/InterfaceInjectionProcessor.java
index 4a2cf669fea5fe1198660fa54b31e9056fe78b88..af80470079ae06ae09d04e797dd873bdd5099bb6 100644
index ea0a7327246fe1da86ad80a4342e3f2299988541..363ea0c70a83b67e253abb6073b82613a1bd2ce0 100644
--- a/src/main/java/net/fabricmc/loom/configuration/ifaceinject/InterfaceInjectionProcessor.java
+++ b/src/main/java/net/fabricmc/loom/configuration/ifaceinject/InterfaceInjectionProcessor.java
@@ -50,13 +50,13 @@ import org.slf4j.Logger;
@@ -48,13 +48,13 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
Expand All @@ -479,7 +479,7 @@ index 4a2cf669fea5fe1198660fa54b31e9056fe78b88..af80470079ae06ae09d04e797dd873bd
import net.fabricmc.mappingio.tree.MappingTree;
import net.fabricmc.mappingio.tree.MemoryMappingTree;

@@ -196,9 +196,9 @@ public abstract class InterfaceInjectionProcessor implements MinecraftJarProcess
@@ -189,9 +189,9 @@ public abstract class InterfaceInjectionProcessor implements MinecraftJarProcess
}

private record InjectedInterface(String modId, String className, String ifaceName) {
Expand All @@ -492,7 +492,7 @@ index 4a2cf669fea5fe1198660fa54b31e9056fe78b88..af80470079ae06ae09d04e797dd873bd

if (jsonElement == null) {
return Collections.emptyList();
@@ -219,8 +219,8 @@ public abstract class InterfaceInjectionProcessor implements MinecraftJarProcess
@@ -212,8 +212,8 @@ public abstract class InterfaceInjectionProcessor implements MinecraftJarProcess
return result;
}

Expand Down
177 changes: 159 additions & 18 deletions patches/0004-Exclude-Fabric-dependencies-replaced-by-Quilt.patch
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,172 @@ Date: Thu, 9 Jun 2022 23:40:54 -0500
Subject: [PATCH] Exclude Fabric dependencies replaced by Quilt


diff --git a/src/main/java/net/fabricmc/loom/LoomGradlePlugin.java b/src/main/java/net/fabricmc/loom/LoomGradlePlugin.java
index 9be58def9beba193114122b11f3467ccbd004253..e6be206f1684bb461a4094b8ddf9b092c69672cc 100644
--- a/src/main/java/net/fabricmc/loom/LoomGradlePlugin.java
+++ b/src/main/java/net/fabricmc/loom/LoomGradlePlugin.java
@@ -25,6 +25,7 @@
package net.fabricmc.loom;
diff --git a/src/main/java/net/fabricmc/loom/configuration/InstallerData.java b/src/main/java/net/fabricmc/loom/configuration/InstallerData.java
index 9496320b9c7f7c9374f208f5445ceb174a7837f2..4083a9cf3dc8c655743a9c1c58813b681a0aed1f 100644
--- a/src/main/java/net/fabricmc/loom/configuration/InstallerData.java
+++ b/src/main/java/net/fabricmc/loom/configuration/InstallerData.java
@@ -35,7 +35,7 @@ import net.fabricmc.loom.LoomRepositoryPlugin;
import net.fabricmc.loom.configuration.ide.idea.IdeaUtils;
import net.fabricmc.loom.util.Constants;

-public record InstallerData(String version, JsonObject installerJson) {
+public record InstallerData(String version, JsonObject installerJson, boolean isQuilt) {
public void applyToProject(Project project) {
LoomGradleExtension extension = LoomGradleExtension.get(project);

diff --git a/src/main/java/net/fabricmc/loom/configuration/mods/ArtifactMetadata.java b/src/main/java/net/fabricmc/loom/configuration/mods/ArtifactMetadata.java
index fc3d6484b1801197c93c8f4c77efea10016eb249..536f13bce74690e3a207bd33ec29853ab0480f23 100644
--- a/src/main/java/net/fabricmc/loom/configuration/mods/ArtifactMetadata.java
+++ b/src/main/java/net/fabricmc/loom/configuration/mods/ArtifactMetadata.java
@@ -68,14 +68,16 @@ public record ArtifactMetadata(boolean isFabricMod, RemapRequirements remapRequi
}

Path installerPath = fs.getPath(QUILT_INSTALLER_PATH);
+ boolean isQuilt = true;

if (!Files.exists(installerPath)) {
- installerPath = fs.getPath(FABRIC_INSTALLER_PATH);;
+ installerPath = fs.getPath(FABRIC_INSTALLER_PATH);
+ isQuilt = false;
}

if (isFabricMod && Files.exists(installerPath)) {
final JsonObject jsonObject = LoomGradlePlugin.GSON.fromJson(Files.readString(installerPath, StandardCharsets.UTF_8), JsonObject.class);
- installerData = new InstallerData(artifact.version(), jsonObject);
+ installerData = new InstallerData(artifact.version(), jsonObject, isQuilt);
}
}

diff --git a/src/main/java/net/fabricmc/loom/configuration/mods/ModConfigurationRemapper.java b/src/main/java/net/fabricmc/loom/configuration/mods/ModConfigurationRemapper.java
index 4aebf75b933724338385f9f8a9232ffcd1281a3b..4e08a78d4826f7744fa29cb49c8e3242115e1cb4 100644
--- a/src/main/java/net/fabricmc/loom/configuration/mods/ModConfigurationRemapper.java
+++ b/src/main/java/net/fabricmc/loom/configuration/mods/ModConfigurationRemapper.java
@@ -31,12 +31,20 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
import java.util.Objects;
import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;

import com.fasterxml.jackson.databind.DeserializationFeature;
@@ -96,5 +97,12 @@ public class LoomGradlePlugin implements BootstrappedPlugin {
import com.google.common.collect.ImmutableMap;
+
+import net.fabricmc.loom.configuration.InstallerData;
+
+import net.fabricmc.loom.configuration.mods.dependency.ModDependencyFactory;
+
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.FileCollectionDependency;
@@ -59,7 +67,6 @@ import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.api.RemapConfigurationSettings;
import net.fabricmc.loom.configuration.RemapConfigurations;
import net.fabricmc.loom.configuration.mods.dependency.ModDependency;
-import net.fabricmc.loom.configuration.mods.dependency.ModDependencyFactory;
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftSourceSets;
import net.fabricmc.loom.util.Checksum;
import net.fabricmc.loom.util.Constants;
@@ -120,19 +127,19 @@ public class ModConfigurationRemapper {
}

project.apply(ImmutableMap.of("plugin", "io.github.juuxel.loom-quiltflower"));
// Round 1: Discovery
- // Go through all the configs to find artifacts to remap and
- // the installer data. The installer data has to be added before
+ // Go through all the configs and find the installer data and QSL.
+ // The installer data has to be added before
// any mods are remapped since remapping needs the dependencies provided by that data.
+ // The presence of Quilt Loader/QSL will be used to exclude the Fabric equivalents if needed.
+
+ if (!"false".equalsIgnoreCase(System.getProperty("loom.excludeFabricReplacedDependencies"))) {
+ project.getConfigurations().all(a -> {
+ a.exclude(Map.of("group", "net.fabricmc", "module", "fabric-loader"));
+ a.exclude(Map.of("group", "net.fabricmc.fabric-api"));
+ });
final Map<Configuration, List<ModDependency>> dependenciesBySourceConfig = new HashMap<>();
+ final Map<Configuration, List<ArtifactRef>> artifactsBySourceConfig = new HashMap<>();
+ final Set<Configuration> sourceConfigsWithQsl = new HashSet<>();
+ AtomicReference<InstallerData> installer = new AtomicReference<>();
configsToRemap.forEach((sourceConfig, remappedConfig) -> {
- /*
- sourceConfig - The source configuration where the intermediary named artifacts come from. i.e "modApi"
- remappedConfig - The target configuration where the remapped artifacts go
- */
- final Configuration clientRemappedConfig = clientConfigsToRemap.get(sourceConfig);
- final List<ModDependency> modDependencies = new ArrayList<>();
+ List<ArtifactRef> artifacts = resolveArtifacts(project, sourceConfig);

- for (ArtifactRef artifact : resolveArtifacts(project, sourceConfig)) {
+ for (ArtifactRef artifact : artifacts) {
final ArtifactMetadata artifactMetadata;

try {
@@ -142,11 +149,13 @@ public class ModConfigurationRemapper {
}

if (artifactMetadata.installerData() != null) {
- if (extension.getInstallerData() != null) {
- project.getLogger().info("Found another installer JSON in ({}), ignoring", artifact.path());
+ if (installer.get() == null) {
+ installer.set(artifactMetadata.installerData());
+ } else if (!installer.get().isQuilt() && artifactMetadata.installerData().isQuilt()) {
+ // Prefer Quilt over Fabric loader
+ installer.set(artifactMetadata.installerData());
} else {
- project.getLogger().info("Applying installer data from {}", artifact.path());
- artifactMetadata.installerData().applyToProject(project);
+ project.getLogger().info("Found another installer JSON in ({}), ignoring", artifact.path());
}
}

@@ -157,6 +166,49 @@ public class ModConfigurationRemapper {
continue;
}

+ if (artifact.group().startsWith("org.quiltmc.qsl")) {
+ sourceConfigsWithQsl.add(sourceConfig);
+ }
+ }
+
+ artifactsBySourceConfig.put(sourceConfig, artifacts);
+ });
+
+ boolean quiltLoader;
+
+ // Apply the installer.
+ // We do this outside Round 1, unlike Fabric Loom, because we need to prioritize Quilt Loader over Fabric Loader.
+ if (installer.get() != null) {
+ project.getLogger().info("Applying installer data");
+
+ if (installer.get().isQuilt()) {
+ quiltLoader = true;
+ } else {
+ quiltLoader = false;
+ project.getLogger().lifecycle("Warning: Quilt Loader not detected. Using Fabric Loader.");
+ }
+
+ installer.get().applyToProject(project);
+ } else {
+ quiltLoader = false;
+ }
}
}
+
+ // Round 1.5: Proposal
+ // Propose everything to be remapped, excluding anything we want to hide.
+ configsToRemap.forEach((sourceConfig, remappedConfig) -> {
+ /*
+ sourceConfig - The source configuration where the intermediary named artifacts come from. i.e "modApi"
+ remappedConfig - The target configuration where the remapped artifacts go
+ */
+ final Configuration clientRemappedConfig = clientConfigsToRemap.get(sourceConfig);
+ final List<ModDependency> modDependencies = new ArrayList<>();
+
+ for (ArtifactRef artifact : artifactsBySourceConfig.get(sourceConfig)) {
+ if (quiltLoader && artifact.group().equals("net.fabricmc") && artifact.name().equals("fabric-loader")) {
+ continue;
+ } else if (sourceConfigsWithQsl.contains(sourceConfig) && artifact.group().equals("net.fabricmc.fabric-api")) {
+ continue;
+ }
final ModDependency modDependency = ModDependencyFactory.create(artifact, remappedConfig, clientRemappedConfig, mappingsSuffix, project);
scheduleSourcesRemapping(project, sourceRemapper, modDependency);
modDependencies.add(modDependency);
diff --git a/src/test/groovy/net/fabricmc/loom/test/integration/MavenProjectTest.groovy b/src/test/groovy/net/fabricmc/loom/test/integration/MavenProjectTest.groovy
index 1a546c22e8ee8d4c56f9dd346a89b319402bbb2c..b56f85b7a4674b652b5bfc2c9ddf8d2daeec3a1d 100644
--- a/src/test/groovy/net/fabricmc/loom/test/integration/MavenProjectTest.groovy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Subject: [PATCH] Fix interface injection of inner class interfaces


diff --git a/src/main/java/net/fabricmc/loom/configuration/ifaceinject/InterfaceInjectionProcessor.java b/src/main/java/net/fabricmc/loom/configuration/ifaceinject/InterfaceInjectionProcessor.java
index ea0a7327246fe1da86ad80a4342e3f2299988541..4a2cf669fea5fe1198660fa54b31e9056fe78b88 100644
index 363ea0c70a83b67e253abb6073b82613a1bd2ce0..af80470079ae06ae09d04e797dd873bdd5099bb6 100644
--- a/src/main/java/net/fabricmc/loom/configuration/ifaceinject/InterfaceInjectionProcessor.java
+++ b/src/main/java/net/fabricmc/loom/configuration/ifaceinject/InterfaceInjectionProcessor.java
@@ -28,6 +28,7 @@ import java.io.IOException;
Expand Down

This file was deleted.

0 comments on commit 3ae46b5

Please sign in to comment.