mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-03-30 13:05:27 -05:00
Fix mixin refmap generation on Forge
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2022 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.build;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
|
||||
|
||||
public final class IntermediaryNamespaces {
|
||||
/**
|
||||
* Returns the intermediary namespace of the project.
|
||||
*/
|
||||
public static String intermediary(Project project) {
|
||||
LoomGradleExtension extension = LoomGradleExtension.get(project);
|
||||
return extension.isForge() ? "srg" : "intermediary";
|
||||
}
|
||||
|
||||
/**
|
||||
* Potentially replaces the remapping target namespace for mixin refmaps.
|
||||
*
|
||||
* <p>All {@linkplain #intermediary(Project) intermediary-like namespaces} are replaced
|
||||
* by {@code intermediary} since fabric-mixin-compile-extensions only supports intermediary.
|
||||
* We transform the namespaces in the input mappings, e.g. {@code intermediary} -> {@code yraidemretni} and
|
||||
* {@code srg} -> {@code intermediary}.
|
||||
*
|
||||
* @param project the project
|
||||
* @param namespace the original namespace
|
||||
* @return the correct namespace to use
|
||||
*/
|
||||
public static String replaceMixinIntermediaryNamespace(Project project, String namespace) {
|
||||
return namespace.equals(intermediary(project)) ? MappingsNamespace.INTERMEDIARY.toString() : namespace;
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,7 @@ import org.gradle.api.artifacts.ConfigurationContainer;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.build.IntermediaryNamespaces;
|
||||
import net.fabricmc.loom.configuration.ide.idea.IdeaUtils;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftSourceSets;
|
||||
import net.fabricmc.loom.extension.MixinExtension;
|
||||
@@ -91,7 +92,7 @@ public abstract class AnnotationProcessorInvoker<T extends Task> {
|
||||
put(Constants.MixinArguments.IN_MAP_FILE_NAMED_INTERMEDIARY, mappings.toFile().getCanonicalPath());
|
||||
put(Constants.MixinArguments.OUT_MAP_FILE_NAMED_INTERMEDIARY, MixinMappingsService.getMixinMappingFile(project, sourceSet).getCanonicalPath());
|
||||
put(Constants.MixinArguments.OUT_REFMAP_FILE, getRefmapDestination(task, refmapName));
|
||||
put(Constants.MixinArguments.DEFAULT_OBFUSCATION_ENV, "named:" + loom.getMixin().getRefmapTargetNamespace().get());
|
||||
put(Constants.MixinArguments.DEFAULT_OBFUSCATION_ENV, "named:" + IntermediaryNamespaces.replaceMixinIntermediaryNamespace(project, loom.getMixin().getRefmapTargetNamespace().get()));
|
||||
put(Constants.MixinArguments.QUIET, "true");
|
||||
}};
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ import org.gradle.api.tasks.SourceSet;
|
||||
import org.gradle.api.tasks.util.PatternSet;
|
||||
|
||||
import net.fabricmc.loom.api.MixinExtensionAPI;
|
||||
import net.fabricmc.loom.util.SourceRemapper;
|
||||
import net.fabricmc.loom.build.IntermediaryNamespaces;
|
||||
|
||||
public abstract class MixinExtensionApiImpl implements MixinExtensionAPI {
|
||||
protected final Project project;
|
||||
@@ -50,7 +50,7 @@ public abstract class MixinExtensionApiImpl implements MixinExtensionAPI {
|
||||
.convention(true);
|
||||
|
||||
this.refmapTargetNamespace = project.getObjects().property(String.class)
|
||||
.convention(project.provider(() -> SourceRemapper.intermediary(project)));
|
||||
.convention(project.provider(() -> IntermediaryNamespaces.intermediary(project)));
|
||||
this.refmapTargetNamespace.finalizeValueOnRead();
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ import org.gradle.workers.WorkQueue;
|
||||
import org.gradle.workers.WorkerExecutor;
|
||||
|
||||
import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
|
||||
import net.fabricmc.loom.util.SourceRemapper;
|
||||
import net.fabricmc.loom.build.IntermediaryNamespaces;
|
||||
import net.fabricmc.loom.util.ZipReprocessorUtil;
|
||||
|
||||
public abstract class AbstractRemapJarTask extends Jar {
|
||||
@@ -71,7 +71,7 @@ public abstract class AbstractRemapJarTask extends Jar {
|
||||
@Inject
|
||||
public AbstractRemapJarTask() {
|
||||
getSourceNamespace().convention(MappingsNamespace.NAMED.toString()).finalizeValueOnRead();
|
||||
getTargetNamespace().convention(SourceRemapper.intermediary(getProject())).finalizeValueOnRead();
|
||||
getTargetNamespace().convention(IntermediaryNamespaces.intermediary(getProject())).finalizeValueOnRead();
|
||||
getRemapperIsolation().convention(true).finalizeValueOnRead();
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.gradle.api.Project;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.build.IntermediaryNamespaces;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.MappingsProviderImpl;
|
||||
import net.fabricmc.loom.util.service.SharedService;
|
||||
import net.fabricmc.loom.util.service.SharedServiceManager;
|
||||
@@ -57,12 +58,13 @@ public final class MixinMappingsService implements SharedService {
|
||||
return sharedServiceManager.getOrCreateService("MixinMappings-" + mappingsProvider.mappingsIdentifier(), () -> new MixinMappingsService(sharedServiceManager));
|
||||
}
|
||||
|
||||
IMappingProvider getMappingProvider(String from, String to) {
|
||||
IMappingProvider getMappingProvider(Project project, String from, String to) {
|
||||
return out -> {
|
||||
for (File mixinMapping : mixinMappings) {
|
||||
if (!mixinMapping.exists()) continue;
|
||||
|
||||
MappingsService service = MappingsService.create(sharedServiceManager, mixinMapping.getAbsolutePath(), mixinMapping.toPath(), from, to, false);
|
||||
String newTo = IntermediaryNamespaces.replaceMixinIntermediaryNamespace(project, to);
|
||||
MappingsService service = MappingsService.create(sharedServiceManager, mixinMapping.getAbsolutePath(), mixinMapping.toPath(), from, newTo, false);
|
||||
service.getMappingsProvider().load(out);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -83,7 +83,7 @@ public class TinyRemapperService implements SharedService {
|
||||
mappings.add(MappingsService.createDefault(project, from, to).getMappingsProvider());
|
||||
|
||||
if (legacyMixin) {
|
||||
mappings.add(MixinMappingsService.getService(SharedServiceManager.get(project), extension.getMappingsProvider()).getMappingProvider(from, to));
|
||||
mappings.add(MixinMappingsService.getService(SharedServiceManager.get(project), extension.getMappingsProvider()).getMappingProvider(project, from, to));
|
||||
}
|
||||
|
||||
return new TinyRemapperService(mappings, !legacyMixin, kotlinClasspathService);
|
||||
|
||||
@@ -41,6 +41,7 @@ import org.slf4j.Logger;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
|
||||
import net.fabricmc.loom.build.IntermediaryNamespaces;
|
||||
import net.fabricmc.loom.configuration.RemappedConfigurationEntry;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.MappingsProviderImpl;
|
||||
import net.fabricmc.loom.util.gradle.ProgressLoggerHelper;
|
||||
@@ -56,12 +57,7 @@ public class SourceRemapper {
|
||||
private Mercury mercury;
|
||||
|
||||
public SourceRemapper(Project project, boolean named) {
|
||||
this(project, named ? intermediary(project) : "named", !named ? intermediary(project) : "named");
|
||||
}
|
||||
|
||||
public static String intermediary(Project project) {
|
||||
LoomGradleExtension extension = LoomGradleExtension.get(project);
|
||||
return extension.isForge() ? "srg" : "intermediary";
|
||||
this(project, named ? IntermediaryNamespaces.intermediary(project) : "named", !named ? IntermediaryNamespaces.intermediary(project) : "named");
|
||||
}
|
||||
|
||||
public SourceRemapper(Project project, String from, String to) {
|
||||
|
||||
Reference in New Issue
Block a user