Skip to content

Commit

Permalink
Exclude the none root MC jars from the remap classpath when using MPO
Browse files Browse the repository at this point in the history
  • Loading branch information
modmuss50 committed Dec 21, 2023
1 parent f2591ed commit 1a2cb87
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle/test.libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ java-debug = "0.49.0"
mixin = "0.11.4+mixin.0.8.5"

gradle-nightly = "8.6-20231219002119+0000"
fabric-loader = "0.14.24"
fabric-loader = "0.15.3"
fabric-installer = "0.11.1"

[libraries]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,18 @@
import java.util.Objects;
import java.util.Set;
import java.util.StringJoiner;
import java.util.concurrent.CompletableFuture;

import org.gradle.api.Project;
import org.gradle.api.artifacts.ConfigurationContainer;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.invocation.Gradle;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.tasks.SourceSet;
import org.jetbrains.annotations.Nullable;

import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
import net.fabricmc.loom.build.mixin.AnnotationProcessorInvoker;
import net.fabricmc.loom.extension.RemapperExtensionHolder;
import net.fabricmc.loom.task.AbstractRemapJarTask;
Expand All @@ -70,6 +73,7 @@ public static synchronized TinyRemapperService getOrCreate(SharedServiceManager
final LoomGradleExtension extension = LoomGradleExtension.get(project);
final boolean legacyMixin = extension.getMixin().getUseLegacyMixinAp().get();
final @Nullable KotlinClasspathService kotlinClasspathService = KotlinClasspathService.getOrCreateIfRequired(serviceManager, project);
boolean multiProjectOptimisation = extension.multiProjectOptimisation();

// Generates an id that is used to share the remapper across projects. This tasks in the remap jar task name to handle custom remap jar tasks separately.
final var joiner = new StringJoiner(":");
Expand All @@ -80,7 +84,7 @@ public static synchronized TinyRemapperService getOrCreate(SharedServiceManager
joiner.add("kotlin-" + kotlinClasspathService.version());
}

if (remapJarTask.getRemapperIsolation().get() || !extension.multiProjectOptimisation()) {
if (remapJarTask.getRemapperIsolation().get() || !multiProjectOptimisation) {
joiner.add(project.getPath());
}

Expand All @@ -100,10 +104,26 @@ public static synchronized TinyRemapperService getOrCreate(SharedServiceManager
});

final ConfigurationContainer configurations = project.getConfigurations();
ConfigurableFileCollection excludedMinecraftJars = project.files();

// Exclude none root minecraft jars.
if (multiProjectOptimisation && !extension.isRootProject()) {
MappingsNamespace mappingsNamespace = MappingsNamespace.of(from);

if (mappingsNamespace != null) {
for (Path minecraftJar : extension.getMinecraftJars(mappingsNamespace)) {
excludedMinecraftJars.from(minecraftJar.toFile());
}
} else {
// None fatal as this is a performance optimisation.
project.getLogger().warn("Unable to find minecraft jar for namespace {}", from);
}
}

List<Path> classPath = remapJarTask.getClasspath()
.minus(configurations.getByName(Constants.Configurations.MINECRAFT_COMPILE_LIBRARIES))
.minus(configurations.getByName(Constants.Configurations.MINECRAFT_RUNTIME_LIBRARIES))
.minus(excludedMinecraftJars)
.getFiles()
.stream()
.map(File::toPath)
Expand Down Expand Up @@ -225,6 +245,8 @@ void readClasspath(List<Path> paths) {
return;
}

List<CompletableFuture<?>> futures = new ArrayList<>();

for (Path path : toRead) {
final InputTag tag = getOrCreateTagInternal(path);
final RemapClasspathEntry classpathEntry = RemapClasspathEntry.create(path);
Expand All @@ -233,8 +255,10 @@ void readClasspath(List<Path> paths) {
staticMixinTagMap.add(tag);
}

tinyRemapper.readClassPathAsync(tag, path);
futures.add(tinyRemapper.readClassPathAsync(tag, path));
}

CompletableFuture.allOf(futures.toArray(CompletableFuture[]::new)).join();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class FabricAPITest extends Specification implements GradleProjectTestTrait {
setup:
def gradle = gradleProject(
repo: "https://github.com/FabricMC/fabric.git",
commit: "23e8616e7457d7d4a65119b93952d134607ffc5c",
commit: "efa5891941a32589207dc58c2e77183d599465b8",
version: version,
patch: "fabric_api"
)
Expand All @@ -60,7 +60,7 @@ class FabricAPITest extends Specification implements GradleProjectTestTrait {
""".stripIndent()
}

def minecraftVersion = "23w45a"
def minecraftVersion = "23w51b"
def server = ServerRunner.create(gradle.projectDir, minecraftVersion)
.withMod(gradle.getOutputFile("fabric-api-999.0.0.jar"))

Expand Down

0 comments on commit 1a2cb87

Please sign in to comment.