mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-04-02 21:47:42 -05:00
Start on improved mappings service
This commit is contained in:
@@ -39,7 +39,7 @@ import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
|
||||
import net.fabricmc.loom.configuration.InstallerData;
|
||||
import net.fabricmc.loom.configuration.LoomDependencyManager;
|
||||
import net.fabricmc.loom.configuration.accesswidener.AccessWidenerFile;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.MappingsProviderImpl;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.MappingConfiguration;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftProvider;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.mapped.IntermediaryMinecraftProvider;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.mapped.NamedMinecraftProvider;
|
||||
@@ -72,9 +72,9 @@ public interface LoomGradleExtension extends LoomGradleExtensionAPI {
|
||||
|
||||
void setMinecraftProvider(MinecraftProvider minecraftProvider);
|
||||
|
||||
MappingsProviderImpl getMappingsProvider();
|
||||
MappingConfiguration getMappingConfiguration();
|
||||
|
||||
void setMappingsProvider(MappingsProviderImpl mappingsProvider);
|
||||
void setMappingConfiguration(MappingConfiguration mappingConfiguration);
|
||||
|
||||
NamedMinecraftProvider<?> getNamedMinecraftProvider();
|
||||
|
||||
|
||||
@@ -32,6 +32,8 @@ import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.fabricmc.loom.configuration.providers.mappings.MappingConfiguration;
|
||||
|
||||
import org.gradle.api.NamedDomainObjectProvider;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.artifacts.Configuration;
|
||||
@@ -52,7 +54,6 @@ import net.fabricmc.loom.configuration.accesswidener.TransitiveAccessWidenerJarP
|
||||
import net.fabricmc.loom.configuration.ifaceinject.InterfaceInjectionProcessor;
|
||||
import net.fabricmc.loom.configuration.processors.MinecraftJarProcessorManager;
|
||||
import net.fabricmc.loom.configuration.processors.ModJavadocProcessor;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.MappingsProviderImpl;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftJarConfiguration;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftProvider;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftSourceSets;
|
||||
@@ -191,9 +192,9 @@ public final class CompileConfiguration {
|
||||
minecraftProvider.provide();
|
||||
|
||||
final DependencyInfo mappingsDep = DependencyInfo.create(project, Constants.Configurations.MAPPINGS);
|
||||
final MappingsProviderImpl mappingsProvider = MappingsProviderImpl.getInstance(serviceManager, project, mappingsDep, minecraftProvider);
|
||||
extension.setMappingsProvider(mappingsProvider);
|
||||
mappingsProvider.applyToProject(project, mappingsDep);
|
||||
final MappingConfiguration mappingConfiguration = MappingConfiguration.create(project, serviceManager, mappingsDep, minecraftProvider);
|
||||
extension.setMappingConfiguration(mappingConfiguration);
|
||||
mappingConfiguration.applyToProject(project, mappingsDep);
|
||||
|
||||
// Provide the remapped mc jars
|
||||
final IntermediaryMinecraftProvider<?> intermediaryMinecraftProvider = jarConfiguration.getIntermediaryMinecraftProviderBiFunction().apply(project, minecraftProvider);
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package net.fabricmc.loom.configuration;
|
||||
|
||||
import net.fabricmc.loom.util.service.SharedServiceManager;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
|
||||
public interface ConfigContext {
|
||||
Project project();
|
||||
SharedServiceManager serviceManager();
|
||||
}
|
||||
@@ -76,8 +76,8 @@ public class LoomDependencyManager {
|
||||
}
|
||||
}
|
||||
|
||||
SourceRemapper sourceRemapper = new SourceRemapper(project, true);
|
||||
String mappingsIdentifier = extension.getMappingsProvider().mappingsIdentifier();
|
||||
SourceRemapper sourceRemapper = new SourceRemapper(project, serviceManager, true);
|
||||
String mappingsIdentifier = extension.getMappingConfiguration().mappingsIdentifier();
|
||||
|
||||
ModConfigurationRemapper.supplyModConfigurations(project, serviceManager, mappingsIdentifier, extension, sourceRemapper);
|
||||
|
||||
|
||||
@@ -26,11 +26,12 @@ package net.fabricmc.loom.configuration.decompile;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import net.fabricmc.loom.configuration.providers.mappings.MappingConfiguration;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.tasks.TaskProvider;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.MappingsProviderImpl;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.mapped.MappedMinecraftProvider;
|
||||
import net.fabricmc.loom.task.UnpickJarTask;
|
||||
|
||||
@@ -38,20 +39,20 @@ public abstract class DecompileConfiguration<T extends MappedMinecraftProvider>
|
||||
protected final Project project;
|
||||
protected final T minecraftProvider;
|
||||
protected final LoomGradleExtension extension;
|
||||
protected final MappingsProviderImpl mappingsProvider;
|
||||
protected final MappingConfiguration mappingConfiguration;
|
||||
|
||||
public DecompileConfiguration(Project project, T minecraftProvider) {
|
||||
this.project = project;
|
||||
this.minecraftProvider = minecraftProvider;
|
||||
this.extension = LoomGradleExtension.get(project);
|
||||
this.mappingsProvider = extension.getMappingsProvider();
|
||||
this.mappingConfiguration = extension.getMappingConfiguration();
|
||||
}
|
||||
|
||||
public abstract void afterEvaluation();
|
||||
|
||||
protected final TaskProvider<UnpickJarTask> createUnpickJarTask(String name, File inputJar, File outputJar) {
|
||||
return project.getTasks().register(name, UnpickJarTask.class, unpickJarTask -> {
|
||||
unpickJarTask.getUnpickDefinitions().set(mappingsProvider.getUnpickDefinitionsFile());
|
||||
unpickJarTask.getUnpickDefinitions().set(mappingConfiguration.getUnpickDefinitionsFile());
|
||||
unpickJarTask.getInputJar().set(inputJar);
|
||||
unpickJarTask.getOutputJar().set(outputJar);
|
||||
});
|
||||
|
||||
@@ -49,8 +49,8 @@ public class SingleJarDecompileConfiguration extends DecompileConfiguration<Mapp
|
||||
|
||||
File mappedJar = namedJar;
|
||||
|
||||
if (mappingsProvider.hasUnpickDefinitions()) {
|
||||
File outputJar = new File(extension.getMappingsProvider().mappingsWorkingDir().toFile(), "minecraft-unpicked.jar");
|
||||
if (mappingConfiguration.hasUnpickDefinitions()) {
|
||||
File outputJar = new File(extension.getMappingConfiguration().mappingsWorkingDir().toFile(), "minecraft-unpicked.jar");
|
||||
createUnpickJarTask("unpickJar", namedJar, outputJar);
|
||||
|
||||
mappedJar = outputJar;
|
||||
@@ -70,7 +70,7 @@ public class SingleJarDecompileConfiguration extends DecompileConfiguration<Mapp
|
||||
task.setDescription("Decompile minecraft using %s.".formatted(decompilerName));
|
||||
task.setGroup(Constants.TaskGroup.FABRIC);
|
||||
|
||||
if (mappingsProvider.hasUnpickDefinitions()) {
|
||||
if (mappingConfiguration.hasUnpickDefinitions()) {
|
||||
task.dependsOn(project.getTasks().named("unpickJar"));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -50,9 +50,9 @@ public final class SplitDecompileConfiguration extends DecompileConfiguration<Ma
|
||||
TaskProvider<UnpickJarTask> unpickCommonJar = null;
|
||||
TaskProvider<UnpickJarTask> unpickClientOnlyJar = null;
|
||||
|
||||
if (mappingsProvider.hasUnpickDefinitions()) {
|
||||
commonJarToDecompile = new File(extension.getMappingsProvider().mappingsWorkingDir().toFile(), "minecraft-common-unpicked.jar");
|
||||
clientOnlyJarToDecompile = new File(extension.getMappingsProvider().mappingsWorkingDir().toFile(), "minecraft-clientonly-unpicked.jar");
|
||||
if (mappingConfiguration.hasUnpickDefinitions()) {
|
||||
commonJarToDecompile = new File(extension.getMappingConfiguration().mappingsWorkingDir().toFile(), "minecraft-common-unpicked.jar");
|
||||
clientOnlyJarToDecompile = new File(extension.getMappingConfiguration().mappingsWorkingDir().toFile(), "minecraft-clientonly-unpicked.jar");
|
||||
|
||||
unpickCommonJar = createUnpickJarTask("unpickCommonJar", minecraftProvider.getCommonJar().toFile(), commonJarToDecompile);
|
||||
unpickClientOnlyJar = createUnpickJarTask("unpickClientOnlyJar", minecraftProvider.getClientOnlyJar().toFile(), clientOnlyJarToDecompile);
|
||||
|
||||
@@ -45,7 +45,7 @@ import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.api.RemapConfigurationSettings;
|
||||
import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
|
||||
import net.fabricmc.loom.configuration.mods.dependency.ModDependency;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.MappingsProviderImpl;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.MappingConfiguration;
|
||||
import net.fabricmc.loom.task.RemapJarTask;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.Pair;
|
||||
@@ -96,12 +96,12 @@ public class ModProcessor {
|
||||
|
||||
private void remapJars(List<ModDependency> remapList) throws IOException {
|
||||
final LoomGradleExtension extension = LoomGradleExtension.get(project);
|
||||
final MappingsProviderImpl mappingsProvider = extension.getMappingsProvider();
|
||||
final MappingConfiguration mappingConfiguration = extension.getMappingConfiguration();
|
||||
Path[] mcDeps = project.getConfigurations().getByName(Constants.Configurations.LOADER_DEPENDENCIES).getFiles()
|
||||
.stream().map(File::toPath).toArray(Path[]::new);
|
||||
|
||||
TinyRemapper.Builder builder = TinyRemapper.newRemapper()
|
||||
.withMappings(TinyRemapperHelper.create(mappingsProvider.getMappings(), fromM, toM, false))
|
||||
.withMappings(TinyRemapperHelper.create(mappingConfiguration.getMappingsService(serviceManager).getMappingTree(), fromM, toM, false))
|
||||
.renameInvalidLocals(false);
|
||||
|
||||
final KotlinClasspathService kotlinClasspathService = KotlinClasspathService.getOrCreateIfRequired(serviceManager, project);
|
||||
|
||||
@@ -63,7 +63,7 @@ public abstract class IntermediaryMappingsProvider extends IntermediateMappingsP
|
||||
.defaultCache()
|
||||
.downloadPath(intermediaryJarPath);
|
||||
|
||||
MappingsProviderImpl.extractMappings(intermediaryJarPath, tinyMappings);
|
||||
MappingConfiguration.extractMappings(intermediaryJarPath, tinyMappings);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -38,9 +38,7 @@ import java.nio.file.StandardCopyOption;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.apache.tools.ant.util.StringUtils;
|
||||
import org.gradle.api.Project;
|
||||
@@ -58,18 +56,15 @@ import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.DeletingFileVisitor;
|
||||
import net.fabricmc.loom.util.FileSystemUtil;
|
||||
import net.fabricmc.loom.util.ZipUtils;
|
||||
import net.fabricmc.loom.util.service.SharedService;
|
||||
import net.fabricmc.loom.util.service.SharedServiceManager;
|
||||
import net.fabricmc.mappingio.MappingReader;
|
||||
import net.fabricmc.mappingio.format.MappingFormat;
|
||||
import net.fabricmc.mappingio.tree.MemoryMappingTree;
|
||||
import net.fabricmc.stitch.Command;
|
||||
import net.fabricmc.stitch.commands.CommandProposeFieldNames;
|
||||
|
||||
public class MappingsProviderImpl implements MappingsProvider, SharedService {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(MappingsProviderImpl.class);
|
||||
public class MappingConfiguration {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(MappingConfiguration.class);
|
||||
|
||||
private Supplier<MemoryMappingTree> mappingTree;
|
||||
public final String mappingsIdentifier;
|
||||
|
||||
private final Path mappingsWorkingDir;
|
||||
@@ -84,9 +79,7 @@ public class MappingsProviderImpl implements MappingsProvider, SharedService {
|
||||
private UnpickMetadata unpickMetadata;
|
||||
private Map<String, String> signatureFixes;
|
||||
|
||||
private final Supplier<IntermediateMappingsService> intermediaryService;
|
||||
|
||||
private MappingsProviderImpl(String mappingsIdentifier, Path mappingsWorkingDir, Supplier<IntermediateMappingsService> intermediaryService) {
|
||||
private MappingConfiguration(String mappingsIdentifier, Path mappingsWorkingDir) {
|
||||
this.mappingsIdentifier = mappingsIdentifier;
|
||||
|
||||
this.mappingsWorkingDir = mappingsWorkingDir;
|
||||
@@ -94,22 +87,9 @@ public class MappingsProviderImpl implements MappingsProvider, SharedService {
|
||||
this.tinyMappings = mappingsWorkingDir.resolve("mappings.tiny");
|
||||
this.tinyMappingsJar = mappingsWorkingDir.resolve("mappings.jar");
|
||||
this.unpickDefinitions = mappingsWorkingDir.resolve("mappings.unpick");
|
||||
|
||||
this.intermediaryService = intermediaryService;
|
||||
}
|
||||
|
||||
public static synchronized MappingsProviderImpl getInstance(SharedServiceManager sharedServiceManager, Project project, DependencyInfo dependency, MinecraftProvider minecraftProvider) {
|
||||
return sharedServiceManager.getOrCreateService("MappingsProvider:%s:%s".formatted(dependency.getDepString(), minecraftProvider.minecraftVersion()), () -> {
|
||||
Supplier<IntermediateMappingsService> intermediaryService = Suppliers.memoize(() -> IntermediateMappingsService.getInstance(sharedServiceManager, project, minecraftProvider));
|
||||
return create(dependency, minecraftProvider, intermediaryService);
|
||||
});
|
||||
}
|
||||
|
||||
public MemoryMappingTree getMappings() throws IOException {
|
||||
return Objects.requireNonNull(mappingTree, "Cannot get mappings before they have been read").get();
|
||||
}
|
||||
|
||||
private static MappingsProviderImpl create(DependencyInfo dependency, MinecraftProvider minecraftProvider, Supplier<IntermediateMappingsService> intermediaryService) {
|
||||
public static MappingConfiguration create(Project project, SharedServiceManager serviceManager, DependencyInfo dependency, MinecraftProvider minecraftProvider) {
|
||||
final String version = dependency.getResolvedVersion();
|
||||
final Path inputJar = dependency.resolveFile().orElseThrow(() -> new RuntimeException("Could not resolve mappings: " + dependency)).toPath();
|
||||
final String mappingsName = StringUtils.removeSuffix(dependency.getDependency().getGroup() + "." + dependency.getDependency().getName(), "-unmerged");
|
||||
@@ -124,10 +104,10 @@ public class MappingsProviderImpl implements MappingsProvider, SharedService {
|
||||
final String mappingsIdentifier = createMappingsIdentifier(mappingsName, version, getMappingsClassifier(dependency, jarInfo.v2()), minecraftProvider.minecraftVersion());
|
||||
final Path workingDir = minecraftProvider.dir(mappingsIdentifier).toPath();
|
||||
|
||||
var mappingProvider = new MappingsProviderImpl(mappingsIdentifier, workingDir, intermediaryService);
|
||||
var mappingProvider = new MappingConfiguration(mappingsIdentifier, workingDir);
|
||||
|
||||
try {
|
||||
mappingProvider.setup(minecraftProvider, inputJar);
|
||||
mappingProvider.setup(project, serviceManager, minecraftProvider, inputJar);
|
||||
} catch (IOException e) {
|
||||
cleanWorkingDirectory(workingDir);
|
||||
throw new UncheckedIOException("Failed to setup mappings: " + dependency.getDepString(), e);
|
||||
@@ -136,13 +116,17 @@ public class MappingsProviderImpl implements MappingsProvider, SharedService {
|
||||
return mappingProvider;
|
||||
}
|
||||
|
||||
private void setup(MinecraftProvider minecraftProvider, Path inputJar) throws IOException {
|
||||
public MappingsService getMappingsService(SharedServiceManager serviceManager) {
|
||||
return MappingsService.create(serviceManager, Objects.requireNonNull(tinyMappings));
|
||||
}
|
||||
|
||||
private void setup(Project project, SharedServiceManager serviceManager, MinecraftProvider minecraftProvider, Path inputJar) throws IOException {
|
||||
if (minecraftProvider.refreshDeps()) {
|
||||
cleanWorkingDirectory(mappingsWorkingDir);
|
||||
}
|
||||
|
||||
if (Files.notExists(tinyMappings) || minecraftProvider.refreshDeps()) {
|
||||
storeMappings(minecraftProvider, inputJar);
|
||||
storeMappings(project, serviceManager, minecraftProvider, inputJar);
|
||||
} else {
|
||||
try (FileSystem fileSystem = FileSystems.newFileSystem(inputJar, (ClassLoader) null)) {
|
||||
extractExtras(fileSystem);
|
||||
@@ -153,8 +137,6 @@ public class MappingsProviderImpl implements MappingsProvider, SharedService {
|
||||
Files.deleteIfExists(tinyMappingsJar);
|
||||
ZipUtils.add(tinyMappingsJar, "mappings/mappings.tiny", Files.readAllBytes(tinyMappings));
|
||||
}
|
||||
|
||||
mappingTree = Suppliers.memoize(this::readMappings);
|
||||
}
|
||||
|
||||
public void applyToProject(Project project, DependencyInfo dependency) {
|
||||
@@ -182,7 +164,7 @@ public class MappingsProviderImpl implements MappingsProvider, SharedService {
|
||||
return isV2 ? "-v2" : "";
|
||||
}
|
||||
|
||||
private void storeMappings(MinecraftProvider minecraftProvider, Path inputJar) throws IOException {
|
||||
private void storeMappings(Project project, SharedServiceManager serviceManager, MinecraftProvider minecraftProvider, Path inputJar) throws IOException {
|
||||
LOGGER.info(":extracting " + inputJar.getFileName());
|
||||
|
||||
try (FileSystemUtil.Delegate delegate = FileSystemUtil.getJarFileSystem(inputJar)) {
|
||||
@@ -192,7 +174,9 @@ public class MappingsProviderImpl implements MappingsProvider, SharedService {
|
||||
|
||||
if (areMappingsV2(baseTinyMappings)) {
|
||||
// These are unmerged v2 mappings
|
||||
MappingsMerger.mergeAndSaveMappings(baseTinyMappings, tinyMappings, intermediaryService.get());
|
||||
IntermediateMappingsService intermediateMappingsService = IntermediateMappingsService.getInstance(serviceManager, project, minecraftProvider);
|
||||
|
||||
MappingsMerger.mergeAndSaveMappings(baseTinyMappings, tinyMappings, intermediateMappingsService);
|
||||
} else {
|
||||
final List<Path> minecraftJars = minecraftProvider.getMinecraftJars();
|
||||
|
||||
@@ -207,16 +191,6 @@ public class MappingsProviderImpl implements MappingsProvider, SharedService {
|
||||
}
|
||||
}
|
||||
|
||||
private MemoryMappingTree readMappings() {
|
||||
try {
|
||||
MemoryMappingTree mappingTree = new MemoryMappingTree();
|
||||
MappingReader.read(tinyMappings, mappingTree);
|
||||
return mappingTree;
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException("Failed to read mappings", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean areMappingsV2(Path path) throws IOException {
|
||||
try (BufferedReader reader = Files.newBufferedReader(path)) {
|
||||
return MappingReader.detectFormat(reader) == MappingFormat.TINY_2;
|
||||
@@ -326,16 +300,10 @@ public class MappingsProviderImpl implements MappingsProvider, SharedService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path mappingsWorkingDir() {
|
||||
return mappingsWorkingDir;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File intermediaryTinyFile() {
|
||||
return intermediaryService.get().getIntermediaryTiny().toFile();
|
||||
}
|
||||
|
||||
private static String createMappingsIdentifier(String mappingsName, String version, String classifier, String minecraftVersion) {
|
||||
// mappingsName . mcVersion . version classifier
|
||||
// Example: net.fabricmc.yarn . 1_16_5 . 1.16.5+build.5 -v2
|
||||
@@ -365,9 +333,4 @@ public class MappingsProviderImpl implements MappingsProvider, SharedService {
|
||||
|
||||
public record UnpickMetadata(String unpickGroup, String unpickVersion) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
mappingTree = null;
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2016-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.configuration.providers.mappings;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public interface MappingsProvider {
|
||||
Path mappingsWorkingDir();
|
||||
|
||||
File intermediaryTinyFile();
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package net.fabricmc.loom.configuration.providers.mappings;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import net.fabricmc.loom.util.service.SharedService;
|
||||
import net.fabricmc.loom.util.service.SharedServiceManager;
|
||||
import net.fabricmc.mappingio.MappingReader;
|
||||
import net.fabricmc.mappingio.tree.MemoryMappingTree;
|
||||
|
||||
public final class MappingsService implements SharedService {
|
||||
private final MemoryMappingTree mappingTree;
|
||||
|
||||
public MappingsService(Path tinyMappings) {
|
||||
try {
|
||||
this.mappingTree = new MemoryMappingTree();
|
||||
MappingReader.read(tinyMappings, mappingTree);
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException("Failed to read mappings", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized MappingsService create(SharedServiceManager serviceManager, Path tinyMappings) {
|
||||
return serviceManager.getOrCreateService("MappingsService:" + tinyMappings.toAbsolutePath(), () -> new MappingsService(tinyMappings));
|
||||
}
|
||||
|
||||
public MemoryMappingTree getMappingTree() {
|
||||
return mappingTree;
|
||||
}
|
||||
}
|
||||
@@ -29,12 +29,13 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.fabricmc.loom.configuration.providers.mappings.MappingConfiguration;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import org.objectweb.asm.commons.Remapper;
|
||||
|
||||
import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.MappingsProviderImpl;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.TinyRemapperHelper;
|
||||
import net.fabricmc.tinyremapper.TinyRemapper;
|
||||
@@ -55,15 +56,15 @@ public record SignatureFixerApplyVisitor(Map<String, String> signatureFixes) imp
|
||||
};
|
||||
}
|
||||
|
||||
public static Map<String, String> getRemappedSignatures(boolean toIntermediary, MappingsProviderImpl mappingsProvider, Project project, String targetNamespace) throws IOException {
|
||||
if (mappingsProvider.getSignatureFixes() == null) {
|
||||
public static Map<String, String> getRemappedSignatures(boolean toIntermediary, MappingConfiguration mappingConfiguration, Project project, String targetNamespace) throws IOException {
|
||||
if (mappingConfiguration.getSignatureFixes() == null) {
|
||||
// No fixes
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
if (toIntermediary) {
|
||||
// No need to remap, as these are already intermediary
|
||||
return mappingsProvider.getSignatureFixes();
|
||||
return mappingConfiguration.getSignatureFixes();
|
||||
}
|
||||
|
||||
// Remap the sig fixes from intermediary to the target namespace
|
||||
@@ -72,7 +73,7 @@ public record SignatureFixerApplyVisitor(Map<String, String> signatureFixes) imp
|
||||
final Remapper sigAsmRemapper = sigTinyRemapper.getEnvironment().getRemapper();
|
||||
|
||||
// Remap the class names and the signatures using a new tiny remapper instance.
|
||||
for (Map.Entry<String, String> entry : mappingsProvider.getSignatureFixes().entrySet()) {
|
||||
for (Map.Entry<String, String> entry : mappingConfiguration.getSignatureFixes().entrySet()) {
|
||||
remapped.put(
|
||||
sigAsmRemapper.map(entry.getKey()),
|
||||
sigAsmRemapper.mapSignature(entry.getValue(), false)
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.gradle.api.Project;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.MappingsProviderImpl;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.MappingConfiguration;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftProvider;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftSourceSets;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.SignatureFixerApplyVisitor;
|
||||
@@ -102,7 +102,7 @@ public abstract class AbstractMappedMinecraftProvider<M extends MinecraftProvide
|
||||
}
|
||||
|
||||
protected String getDependencyNotation(String name) {
|
||||
return "net.minecraft:%s:%s/%s".formatted(getName(name), extension.getMinecraftProvider().minecraftVersion(), extension.getMappingsProvider().mappingsIdentifier());
|
||||
return "net.minecraft:%s:%s/%s".formatted(getName(name), extension.getMinecraftProvider().minecraftVersion(), extension.getMappingConfiguration().mappingsIdentifier());
|
||||
}
|
||||
|
||||
private boolean areOutputsValid(List<RemappedJars> remappedJars) {
|
||||
@@ -124,13 +124,13 @@ public abstract class AbstractMappedMinecraftProvider<M extends MinecraftProvide
|
||||
}
|
||||
|
||||
private void remapJar(RemappedJars remappedJars) throws IOException {
|
||||
final MappingsProviderImpl mappingsProvider = extension.getMappingsProvider();
|
||||
final MappingConfiguration mappingConfiguration = extension.getMappingConfiguration();
|
||||
final String fromM = remappedJars.sourceNamespace().toString();
|
||||
final String toM = getTargetNamespace().toString();
|
||||
|
||||
Files.deleteIfExists(remappedJars.outputJar());
|
||||
|
||||
final Map<String, String> remappedSignatures = SignatureFixerApplyVisitor.getRemappedSignatures(getTargetNamespace() == MappingsNamespace.INTERMEDIARY, mappingsProvider, project, toM);
|
||||
final Map<String, String> remappedSignatures = SignatureFixerApplyVisitor.getRemappedSignatures(getTargetNamespace() == MappingsNamespace.INTERMEDIARY, mappingConfiguration, project, toM);
|
||||
TinyRemapper remapper = TinyRemapperHelper.getTinyRemapper(project, fromM, toM, true, (builder) -> {
|
||||
builder.extraPostApplyVisitor(new SignatureFixerApplyVisitor(remappedSignatures));
|
||||
configureRemapper(remappedJars, builder);
|
||||
@@ -147,7 +147,7 @@ public abstract class AbstractMappedMinecraftProvider<M extends MinecraftProvide
|
||||
remapper.readInputs(remappedJars.inputJar());
|
||||
remapper.apply(outputConsumer);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Failed to remap JAR " + remappedJars.inputJar() + " with mappings from " + mappingsProvider.tinyMappings, e);
|
||||
throw new RuntimeException("Failed to remap JAR " + remappedJars.inputJar() + " with mappings from " + mappingConfiguration.tinyMappings, e);
|
||||
} finally {
|
||||
remapper.finish();
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public abstract class NamedMinecraftProvider<M extends MinecraftProvider> extend
|
||||
|
||||
@Override
|
||||
protected Path getDirectory() {
|
||||
return extension.getMappingsProvider().mappingsWorkingDir();
|
||||
return extension.getMappingConfiguration().mappingsWorkingDir();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -59,7 +59,7 @@ public abstract class ProcessedNamedMinecraftProvider<M extends MinecraftProvide
|
||||
final LoomGradleExtension extension = LoomGradleExtension.get(getProject());
|
||||
this.projectMappedDir = extension.getFiles().getRootProjectPersistentCache().toPath()
|
||||
.resolve(getMinecraftProvider().minecraftVersion())
|
||||
.resolve(extension.getMappingsProvider().mappingsIdentifier());
|
||||
.resolve(extension.getMappingConfiguration().mappingsIdentifier());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -275,7 +275,7 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
|
||||
|
||||
@Override
|
||||
public File getMappingsFile() {
|
||||
return LoomGradleExtension.get(getProject()).getMappingsProvider().tinyMappings.toFile();
|
||||
return LoomGradleExtension.get(getProject()).getMappingConfiguration().tinyMappings.toFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -44,7 +44,7 @@ import net.fabricmc.loom.configuration.InstallerData;
|
||||
import net.fabricmc.loom.configuration.LoomDependencyManager;
|
||||
import net.fabricmc.loom.configuration.accesswidener.AccessWidenerFile;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.IntermediaryMappingsProvider;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.MappingsProviderImpl;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.MappingConfiguration;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftProvider;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.mapped.IntermediaryMinecraftProvider;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.mapped.NamedMinecraftProvider;
|
||||
@@ -63,7 +63,7 @@ public class LoomGradleExtensionImpl extends LoomGradleExtensionApiImpl implemen
|
||||
|
||||
private LoomDependencyManager dependencyManager;
|
||||
private MinecraftProvider minecraftProvider;
|
||||
private MappingsProviderImpl mappingsProvider;
|
||||
private MappingConfiguration mappingConfiguration;
|
||||
private NamedMinecraftProvider<?> namedMinecraftProvider;
|
||||
private IntermediaryMinecraftProvider<?> intermediaryMinecraftProvider;
|
||||
private InstallerData installerData;
|
||||
@@ -124,13 +124,13 @@ public class LoomGradleExtensionImpl extends LoomGradleExtensionApiImpl implemen
|
||||
}
|
||||
|
||||
@Override
|
||||
public MappingsProviderImpl getMappingsProvider() {
|
||||
return Objects.requireNonNull(mappingsProvider, "Cannot get MappingsProvider before it has been setup");
|
||||
public MappingConfiguration getMappingConfiguration() {
|
||||
return Objects.requireNonNull(mappingConfiguration, "Cannot get MappingsProvider before it has been setup");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMappingsProvider(MappingsProviderImpl mappingsProvider) {
|
||||
this.mappingsProvider = mappingsProvider;
|
||||
public void setMappingConfiguration(MappingConfiguration mappingConfiguration) {
|
||||
this.mappingConfiguration = mappingConfiguration;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -319,7 +319,7 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask {
|
||||
}
|
||||
|
||||
private Path getMappings() {
|
||||
Path inputMappings = getExtension().getMappingsProvider().tinyMappings;
|
||||
Path inputMappings = getExtension().getMappingConfiguration().tinyMappings;
|
||||
|
||||
MemoryMappingTree mappingTree = new MemoryMappingTree();
|
||||
|
||||
|
||||
@@ -52,9 +52,10 @@ import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
|
||||
import net.fabricmc.loom.api.mappings.layered.spec.LayeredMappingSpecBuilder;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingsDependency;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.MappingsProviderImpl;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.MappingConfiguration;
|
||||
import net.fabricmc.loom.util.FileSystemUtil;
|
||||
import net.fabricmc.loom.util.SourceRemapper;
|
||||
import net.fabricmc.loom.util.service.ScopedSharedServiceManager;
|
||||
import net.fabricmc.lorenztiny.TinyMappingsJoiner;
|
||||
import net.fabricmc.mappingio.MappingReader;
|
||||
import net.fabricmc.mappingio.tree.MemoryMappingTree;
|
||||
@@ -105,10 +106,10 @@ public abstract class MigrateMappingsTask extends AbstractLoomTask {
|
||||
Files.createDirectories(outputDir);
|
||||
|
||||
File mappings = loadMappings();
|
||||
MappingsProviderImpl mappingsProvider = extension.getMappingsProvider();
|
||||
MappingConfiguration mappingConfiguration = extension.getMappingConfiguration();
|
||||
|
||||
try {
|
||||
MemoryMappingTree currentMappings = mappingsProvider.getMappings();
|
||||
try (var serviceManager = new ScopedSharedServiceManager()) {
|
||||
MemoryMappingTree currentMappings = mappingConfiguration.getMappingsService(serviceManager).getMappingTree();
|
||||
MemoryMappingTree targetMappings = getMappings(mappings);
|
||||
migrateMappings(project, extension, inputDir, outputDir, currentMappings, targetMappings);
|
||||
project.getLogger().lifecycle(":remapped project written to " + outputDir.toAbsolutePath());
|
||||
|
||||
@@ -31,7 +31,7 @@ import java.nio.file.Path;
|
||||
import org.gradle.api.Project;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.MappingsProviderImpl;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.MappingConfiguration;
|
||||
import net.fabricmc.loom.util.TinyRemapperHelper;
|
||||
import net.fabricmc.loom.util.service.SharedService;
|
||||
import net.fabricmc.loom.util.service.SharedServiceManager;
|
||||
@@ -49,10 +49,10 @@ public final class MappingsService implements SharedService {
|
||||
}
|
||||
|
||||
public static MappingsService createDefault(Project project, SharedServiceManager serviceManager, String from, String to) {
|
||||
final MappingsProviderImpl mappingsProvider = LoomGradleExtension.get(project).getMappingsProvider();
|
||||
final MappingConfiguration mappingConfiguration = LoomGradleExtension.get(project).getMappingConfiguration();
|
||||
|
||||
final String name = mappingsProvider.getBuildServiceName("mappingsProvider", from, to);
|
||||
return MappingsService.create(serviceManager, name, mappingsProvider.tinyMappings, from, to, false);
|
||||
final String name = mappingConfiguration.getBuildServiceName("mappingsProvider", from, to);
|
||||
return MappingsService.create(serviceManager, name, mappingConfiguration.tinyMappings, from, to, false);
|
||||
}
|
||||
|
||||
private final Options options;
|
||||
|
||||
@@ -33,6 +33,10 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.fabricmc.loom.configuration.providers.mappings.MappingConfiguration;
|
||||
|
||||
import net.fabricmc.loom.util.service.SharedServiceManager;
|
||||
|
||||
import org.cadixdev.lorenz.MappingSet;
|
||||
import org.cadixdev.mercury.Mercury;
|
||||
import org.cadixdev.mercury.remapper.MercuryRemapper;
|
||||
@@ -45,19 +49,20 @@ import org.slf4j.Logger;
|
||||
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.MappingsProviderImpl;
|
||||
import net.fabricmc.lorenztiny.TinyMappingsReader;
|
||||
import net.fabricmc.mappingio.tree.MemoryMappingTree;
|
||||
|
||||
public class SourceRemapper {
|
||||
private final Project project;
|
||||
private final SharedServiceManager serviceManager;
|
||||
private final boolean toNamed;
|
||||
private final List<Consumer<ProgressLogger>> remapTasks = new ArrayList<>();
|
||||
|
||||
private Mercury mercury;
|
||||
|
||||
public SourceRemapper(Project project, boolean toNamed) {
|
||||
public SourceRemapper(Project project, SharedServiceManager serviceManager, boolean toNamed) {
|
||||
this.project = project;
|
||||
this.serviceManager = serviceManager;
|
||||
this.toNamed = toNamed;
|
||||
}
|
||||
|
||||
@@ -158,11 +163,11 @@ public class SourceRemapper {
|
||||
}
|
||||
|
||||
LoomGradleExtension extension = LoomGradleExtension.get(project);
|
||||
MappingsProviderImpl mappingsProvider = extension.getMappingsProvider();
|
||||
MappingConfiguration mappingConfiguration = extension.getMappingConfiguration();
|
||||
|
||||
MappingSet mappings = extension.getOrCreateSrcMappingCache(toNamed ? 1 : 0, () -> {
|
||||
try {
|
||||
MemoryMappingTree m = mappingsProvider.getMappings();
|
||||
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) {
|
||||
|
||||
@@ -32,6 +32,9 @@ import java.util.function.Consumer;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import net.fabricmc.loom.util.service.SharedServiceManager;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
@@ -60,13 +63,13 @@ public final class TinyRemapperHelper {
|
||||
private TinyRemapperHelper() {
|
||||
}
|
||||
|
||||
public static TinyRemapper getTinyRemapper(Project project, String fromM, String toM) throws IOException {
|
||||
return getTinyRemapper(project, fromM, toM, false, (builder) -> { });
|
||||
public static TinyRemapper getTinyRemapper(Project project, SharedServiceManager serviceManager, String fromM, String toM) throws IOException {
|
||||
return getTinyRemapper(project, serviceManager, fromM, toM, false, (builder) -> { });
|
||||
}
|
||||
|
||||
public static TinyRemapper getTinyRemapper(Project project, String fromM, String toM, boolean fixRecords, Consumer<TinyRemapper.Builder> builderConsumer) throws IOException {
|
||||
public static TinyRemapper getTinyRemapper(Project project, SharedServiceManager serviceManager, String fromM, String toM, boolean fixRecords, Consumer<TinyRemapper.Builder> builderConsumer) throws IOException {
|
||||
LoomGradleExtension extension = LoomGradleExtension.get(project);
|
||||
MemoryMappingTree mappingTree = extension.getMappingsProvider().getMappings();
|
||||
MemoryMappingTree mappingTree = extension.getMappingConfiguration().getMappingsService(serviceManager).getMappingTree();
|
||||
|
||||
if (fixRecords && !mappingTree.getSrcNamespace().equals(fromM)) {
|
||||
throw new IllegalStateException("Mappings src namespace must match remap src namespace");
|
||||
|
||||
Reference in New Issue
Block a user