mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-04-02 21:47:42 -05:00
Gradle 8 tests, perf/memory optimisations (#796)
* Add gradle 8 tests Reuse gradle home between tests Misc perf and mem optimisations * Fix build warning. * Added multi mc version test * Use server launcher in ServerRunner Co-authored-by: Luna <62033805+Luna5ama@users.noreply.github.com>
This commit is contained in:
@@ -26,10 +26,7 @@ package net.fabricmc.loom;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.cadixdev.lorenz.MappingSet;
|
||||
import org.cadixdev.mercury.Mercury;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.file.ConfigurableFileCollection;
|
||||
import org.gradle.api.file.FileCollection;
|
||||
@@ -54,10 +51,6 @@ public interface LoomGradleExtension extends LoomGradleExtensionAPI {
|
||||
|
||||
LoomFiles getFiles();
|
||||
|
||||
MappingSet getOrCreateSrcMappingCache(int id, Supplier<MappingSet> factory);
|
||||
|
||||
Mercury getOrCreateSrcMercuryCache(int id, Supplier<Mercury> factory);
|
||||
|
||||
ConfigurableFileCollection getUnmappedModCollection();
|
||||
|
||||
void setInstallerData(InstallerData data);
|
||||
|
||||
@@ -27,6 +27,7 @@ package net.fabricmc.loom.api.processor;
|
||||
import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftJarConfiguration;
|
||||
import net.fabricmc.loom.util.LazyCloseable;
|
||||
import net.fabricmc.mappingio.tree.MemoryMappingTree;
|
||||
import net.fabricmc.tinyremapper.TinyRemapper;
|
||||
|
||||
public interface ProcessorContext {
|
||||
@@ -39,4 +40,6 @@ public interface ProcessorContext {
|
||||
boolean includesServer();
|
||||
|
||||
LazyCloseable<TinyRemapper> createRemapper(MappingsNamespace from, MappingsNamespace to);
|
||||
|
||||
MemoryMappingTree getMappings();
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -43,7 +44,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.commons.Remapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -56,6 +56,7 @@ import net.fabricmc.loom.util.Pair;
|
||||
import net.fabricmc.loom.util.ZipUtils;
|
||||
import net.fabricmc.loom.util.fmj.FabricModJson;
|
||||
import net.fabricmc.mappingio.tree.MappingTree;
|
||||
import net.fabricmc.mappingio.tree.MemoryMappingTree;
|
||||
|
||||
public abstract class InterfaceInjectionProcessor implements MinecraftJarProcessor<InterfaceInjectionProcessor.Spec> {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(InterfaceInjectionProcessor.class);
|
||||
@@ -98,16 +99,13 @@ public abstract class InterfaceInjectionProcessor implements MinecraftJarProcess
|
||||
|
||||
@Override
|
||||
public void processJar(Path jar, Spec spec, ProcessorContext context) throws IOException {
|
||||
final List<InjectedInterface> remappedInjectedInterfaces;
|
||||
|
||||
// Remap from intermediary->named
|
||||
try (var tinyRemapper = context.createRemapper(MappingsNamespace.INTERMEDIARY, MappingsNamespace.NAMED)) {
|
||||
final Remapper remapper = tinyRemapper.get().getEnvironment().getRemapper();
|
||||
|
||||
remappedInjectedInterfaces = spec.injectedInterfaces().stream()
|
||||
.map(injectedInterface -> remap(injectedInterface, remapper))
|
||||
.toList();
|
||||
}
|
||||
final MemoryMappingTree mappings = context.getMappings();
|
||||
final int intermediaryIndex = mappings.getNamespaceId(MappingsNamespace.INTERMEDIARY.toString());
|
||||
final int namedIndex = mappings.getNamespaceId(MappingsNamespace.NAMED.toString());
|
||||
final List<InjectedInterface> remappedInjectedInterfaces = spec.injectedInterfaces().stream()
|
||||
.map(injectedInterface -> remap(injectedInterface, s -> mappings.mapClassName(s, intermediaryIndex, namedIndex)))
|
||||
.toList();
|
||||
|
||||
try {
|
||||
ZipUtils.transform(jar, getTransformers(remappedInjectedInterfaces));
|
||||
@@ -116,11 +114,11 @@ public abstract class InterfaceInjectionProcessor implements MinecraftJarProcess
|
||||
}
|
||||
}
|
||||
|
||||
private InjectedInterface remap(InjectedInterface in, Remapper remapper) {
|
||||
private InjectedInterface remap(InjectedInterface in, Function<String, String> remapper) {
|
||||
return new InjectedInterface(
|
||||
in.modId(),
|
||||
remapper.map(in.className()),
|
||||
remapper.map(in.ifaceName())
|
||||
remapper.apply(in.className()),
|
||||
remapper.apply(in.ifaceName())
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,12 +24,14 @@
|
||||
|
||||
package net.fabricmc.loom.configuration.processors;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
|
||||
import net.fabricmc.loom.api.processor.ProcessorContext;
|
||||
import net.fabricmc.loom.configuration.ConfigContext;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftJar;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftJarConfiguration;
|
||||
import net.fabricmc.loom.util.LazyCloseable;
|
||||
import net.fabricmc.mappingio.tree.MemoryMappingTree;
|
||||
import net.fabricmc.tinyremapper.TinyRemapper;
|
||||
|
||||
public record ProcessorContextImpl(ConfigContext configContext, MinecraftJar minecraftJar) implements ProcessorContext {
|
||||
@@ -57,4 +59,10 @@ public record ProcessorContextImpl(ConfigContext configContext, MinecraftJar min
|
||||
public LazyCloseable<TinyRemapper> createRemapper(MappingsNamespace from, MappingsNamespace to) {
|
||||
return ContextImplHelper.createRemapper(configContext, from, to);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MemoryMappingTree getMappings() {
|
||||
LoomGradleExtension extension = LoomGradleExtension.get(configContext().project());
|
||||
return extension.getMappingConfiguration().getMappingsService(configContext().serviceManager()).getMappingTree();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
|
||||
this.splitEnvironmentalSourceSet = project.getObjects().property(Boolean.class).convention(false);
|
||||
this.splitEnvironmentalSourceSet.finalizeValueOnRead();
|
||||
|
||||
// Add main source set by default
|
||||
// Enable dep iface injection by default
|
||||
interfaceInjection(interfaceInjection -> {
|
||||
interfaceInjection.getEnableDependencyInterfaceInjection().convention(true).finalizeValueOnRead();
|
||||
});
|
||||
|
||||
@@ -29,10 +29,7 @@ import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.cadixdev.lorenz.MappingSet;
|
||||
import org.cadixdev.mercury.Mercury;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.file.ConfigurableFileCollection;
|
||||
import org.gradle.api.file.FileCollection;
|
||||
@@ -60,8 +57,6 @@ public class LoomGradleExtensionImpl extends LoomGradleExtensionApiImpl implemen
|
||||
private final LoomFiles loomFiles;
|
||||
private final ConfigurableFileCollection unmappedMods;
|
||||
|
||||
private final MappingSet[] srcMappingCache = new MappingSet[2];
|
||||
private final Mercury[] srcMercuryCache = new Mercury[2];
|
||||
private final List<AccessWidenerFile> transitiveAccessWideners = new ArrayList<>();
|
||||
|
||||
private LoomDependencyManager dependencyManager;
|
||||
@@ -167,16 +162,6 @@ public class LoomGradleExtensionImpl extends LoomGradleExtensionApiImpl implemen
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MappingSet getOrCreateSrcMappingCache(int id, Supplier<MappingSet> factory) {
|
||||
return srcMappingCache[id] != null ? srcMappingCache[id] : (srcMappingCache[id] = factory.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mercury getOrCreateSrcMercuryCache(int id, Supplier<Mercury> factory) {
|
||||
return srcMercuryCache[id] != null ? srcMercuryCache[id] : (srcMercuryCache[id] = factory.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigurableFileCollection getUnmappedModCollection() {
|
||||
return unmappedMods;
|
||||
|
||||
@@ -57,14 +57,12 @@ public abstract class PrepareJarRemapTask extends AbstractLoomTask {
|
||||
getOutputs().upToDateWhen((o) -> false);
|
||||
|
||||
getProject().getGradle().allprojects(project -> {
|
||||
project.getTasks().configureEach(task -> {
|
||||
if (task instanceof PrepareJarRemapTask otherTask) {
|
||||
if (otherTask == this) return;
|
||||
project.getTasks().withType(PrepareJarRemapTask.class, otherTask -> {
|
||||
if (otherTask == this) return;
|
||||
|
||||
// Ensure that all other prepare tasks inputs have completed
|
||||
dependsOn(otherTask.getInputs());
|
||||
mustRunAfter(otherTask.getInputs());
|
||||
}
|
||||
// Ensure that all other prepare tasks inputs have completed
|
||||
dependsOn(otherTask.getInputs());
|
||||
mustRunAfter(otherTask.getInputs());
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -102,6 +100,6 @@ public abstract class PrepareJarRemapTask extends AbstractLoomTask {
|
||||
}
|
||||
|
||||
static void prepare(TinyRemapperService tinyRemapperService, Path inputFile) {
|
||||
tinyRemapperService.getTinyRemapperForInputs().readInputsAsync(tinyRemapperService.getOrCreateTag(inputFile), inputFile);
|
||||
tinyRemapperService.getTinyRemapperForInputs().readInputs(tinyRemapperService.getOrCreateTag(inputFile), inputFile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,13 +33,11 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.gradle.api.artifacts.Configuration;
|
||||
import org.gradle.api.file.ConfigurableFileCollection;
|
||||
@@ -90,13 +88,11 @@ public abstract class RemapJarTask extends AbstractRemapJarTask {
|
||||
public abstract Property<Boolean> getUseMixinAP();
|
||||
|
||||
private final Provider<BuildSharedServiceManager> serviceManagerProvider;
|
||||
private final Supplier<TinyRemapperService> tinyRemapperService;
|
||||
|
||||
@Inject
|
||||
public RemapJarTask() {
|
||||
super();
|
||||
serviceManagerProvider = BuildSharedServiceManager.createForTask(this, getBuildEventsListenerRegistry());
|
||||
tinyRemapperService = Suppliers.memoize(() -> TinyRemapperService.getOrCreate(serviceManagerProvider.get().get(), this));
|
||||
|
||||
getClasspath().from(getProject().getConfigurations().getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME));
|
||||
getAddNestedDependencies().convention(true).finalizeValueOnRead();
|
||||
@@ -134,7 +130,7 @@ public abstract class RemapJarTask extends AbstractRemapJarTask {
|
||||
params.getNestedJars().from(getNestedJars());
|
||||
}
|
||||
|
||||
params.getTinyRemapperBuildServiceUuid().set(UnsafeWorkQueueHelper.create(tinyRemapperService.get()));
|
||||
params.getTinyRemapperBuildServiceUuid().set(UnsafeWorkQueueHelper.create(getTinyRemapperService()));
|
||||
params.getRemapClasspath().from(getClasspath());
|
||||
params.getMultiProjectOptimisation().set(getLoomExtension().multiProjectOptimisation());
|
||||
|
||||
@@ -337,6 +333,6 @@ public abstract class RemapJarTask extends AbstractRemapJarTask {
|
||||
|
||||
@Internal
|
||||
public TinyRemapperService getTinyRemapperService() {
|
||||
return tinyRemapperService.get();
|
||||
return TinyRemapperService.getOrCreate(serviceManagerProvider.get().get(), this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2023 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.task.service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.cadixdev.lorenz.MappingSet;
|
||||
|
||||
import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.MappingConfiguration;
|
||||
import net.fabricmc.loom.util.service.SharedService;
|
||||
import net.fabricmc.loom.util.service.SharedServiceManager;
|
||||
import net.fabricmc.lorenztiny.TinyMappingsReader;
|
||||
import net.fabricmc.mappingio.tree.MemoryMappingTree;
|
||||
|
||||
public final class LorenzMappingService implements SharedService {
|
||||
private MappingSet mappings;
|
||||
|
||||
public LorenzMappingService(MappingSet mappings) {
|
||||
this.mappings = mappings;
|
||||
}
|
||||
|
||||
public static synchronized LorenzMappingService create(SharedServiceManager sharedServiceManager, MappingConfiguration mappingConfiguration, MappingsNamespace from, MappingsNamespace to) {
|
||||
return sharedServiceManager.getOrCreateService(mappingConfiguration.getBuildServiceName("LorenzMappingService", from.toString(), to.toString()), () -> {
|
||||
MemoryMappingTree m = mappingConfiguration.getMappingsService(sharedServiceManager).getMappingTree();
|
||||
|
||||
try {
|
||||
try (var reader = new TinyMappingsReader(m, from.toString(), to.toString())) {
|
||||
return new LorenzMappingService(reader.read());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException("Failed to read lorenz mappings", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
this.mappings = null;
|
||||
}
|
||||
|
||||
public MappingSet mappings() {
|
||||
return Objects.requireNonNull(mappings);
|
||||
}
|
||||
}
|
||||
@@ -181,12 +181,13 @@ public class TinyRemapperService implements SharedService {
|
||||
classpath.addAll(paths);
|
||||
}
|
||||
|
||||
tinyRemapper.readClassPathAsync(toRead.toArray(Path[]::new));
|
||||
tinyRemapper.readClassPath(toRead.toArray(Path[]::new));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
if (tinyRemapper != null) {
|
||||
tinyRemapper.getEnvironment();
|
||||
tinyRemapper.finish();
|
||||
tinyRemapper = null;
|
||||
}
|
||||
|
||||
@@ -50,9 +50,8 @@ import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.api.RemapConfigurationSettings;
|
||||
import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.MappingConfiguration;
|
||||
import net.fabricmc.loom.task.service.LorenzMappingService;
|
||||
import net.fabricmc.loom.util.service.SharedServiceManager;
|
||||
import net.fabricmc.lorenztiny.TinyMappingsReader;
|
||||
import net.fabricmc.mappingio.tree.MemoryMappingTree;
|
||||
|
||||
public class SourceRemapper {
|
||||
private final Project project;
|
||||
@@ -167,51 +166,43 @@ public class SourceRemapper {
|
||||
LoomGradleExtension extension = LoomGradleExtension.get(project);
|
||||
MappingConfiguration mappingConfiguration = extension.getMappingConfiguration();
|
||||
|
||||
MappingSet mappings = extension.getOrCreateSrcMappingCache(toNamed ? 1 : 0, () -> {
|
||||
try {
|
||||
MemoryMappingTree m = mappingConfiguration.getMappingsService(serviceManager).getMappingTree();
|
||||
project.getLogger().info(":loading " + (toNamed ? "intermediary -> named" : "named -> intermediary") + " source mappings");
|
||||
return new TinyMappingsReader(m, toNamed ? MappingsNamespace.INTERMEDIARY.toString() : MappingsNamespace.NAMED.toString(), toNamed ? MappingsNamespace.NAMED.toString() : MappingsNamespace.INTERMEDIARY.toString()).read();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
MappingSet mappings = LorenzMappingService.create(serviceManager,
|
||||
mappingConfiguration,
|
||||
toNamed ? MappingsNamespace.INTERMEDIARY : MappingsNamespace.NAMED,
|
||||
toNamed ? MappingsNamespace.NAMED : MappingsNamespace.INTERMEDIARY
|
||||
).mappings();
|
||||
|
||||
Mercury mercury = createMercuryWithClassPath(project, toNamed);
|
||||
mercury.setSourceCompatibilityFromRelease(getJavaCompileRelease(project));
|
||||
|
||||
for (File file : extension.getUnmappedModCollection()) {
|
||||
Path path = file.toPath();
|
||||
|
||||
if (Files.isRegularFile(path)) {
|
||||
mercury.getClassPath().add(path);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Mercury mercury = extension.getOrCreateSrcMercuryCache(toNamed ? 1 : 0, () -> {
|
||||
Mercury m = createMercuryWithClassPath(project, toNamed);
|
||||
m.setSourceCompatibilityFromRelease(getJavaCompileRelease(project));
|
||||
for (Path intermediaryJar : extension.getMinecraftJars(MappingsNamespace.INTERMEDIARY)) {
|
||||
mercury.getClassPath().add(intermediaryJar);
|
||||
}
|
||||
|
||||
for (File file : extension.getUnmappedModCollection()) {
|
||||
Path path = file.toPath();
|
||||
for (Path intermediaryJar : extension.getMinecraftJars(MappingsNamespace.NAMED)) {
|
||||
mercury.getClassPath().add(intermediaryJar);
|
||||
}
|
||||
|
||||
if (Files.isRegularFile(path)) {
|
||||
m.getClassPath().add(path);
|
||||
}
|
||||
}
|
||||
Set<File> files = project.getConfigurations()
|
||||
.detachedConfiguration(project.getDependencies().create(Constants.Dependencies.JETBRAINS_ANNOTATIONS + Constants.Dependencies.Versions.JETBRAINS_ANNOTATIONS))
|
||||
.resolve();
|
||||
|
||||
for (Path intermediaryJar : extension.getMinecraftJars(MappingsNamespace.INTERMEDIARY)) {
|
||||
m.getClassPath().add(intermediaryJar);
|
||||
}
|
||||
for (File file : files) {
|
||||
mercury.getClassPath().add(file.toPath());
|
||||
}
|
||||
|
||||
for (Path intermediaryJar : extension.getMinecraftJars(MappingsNamespace.NAMED)) {
|
||||
m.getClassPath().add(intermediaryJar);
|
||||
}
|
||||
|
||||
Set<File> files = project.getConfigurations()
|
||||
.detachedConfiguration(project.getDependencies().create(Constants.Dependencies.JETBRAINS_ANNOTATIONS + Constants.Dependencies.Versions.JETBRAINS_ANNOTATIONS))
|
||||
.resolve();
|
||||
|
||||
for (File file : files) {
|
||||
m.getClassPath().add(file.toPath());
|
||||
}
|
||||
|
||||
m.getProcessors().add(MercuryRemapper.create(mappings));
|
||||
|
||||
return m;
|
||||
});
|
||||
mercury.getProcessors().add(MercuryRemapper.create(mappings));
|
||||
|
||||
this.mercury = mercury;
|
||||
return mercury;
|
||||
return this.mercury;
|
||||
}
|
||||
|
||||
public static int getJavaCompileRelease(Project project) {
|
||||
|
||||
Reference in New Issue
Block a user