mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-04-02 05:27:43 -05:00
Merge branch 'dev/0.6-forge' into dev/0.7-forge
# Conflicts: # src/main/java/net/fabricmc/loom/configuration/CompileConfiguration.java # src/main/java/net/fabricmc/loom/task/RemapJarTask.java # src/main/java/net/fabricmc/loom/task/RemapSourcesJarTask.java # src/main/java/net/fabricmc/loom/util/SourceRemapper.java
This commit is contained in:
@@ -79,7 +79,7 @@ import net.fabricmc.loom.build.nesting.NestedJarProvider;
|
||||
import net.fabricmc.loom.configuration.accesswidener.AccessWidenerJarProcessor;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.MappingsProvider;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.LoggerFilter;
|
||||
import net.fabricmc.loom.util.SourceRemapper;
|
||||
import net.fabricmc.loom.util.TinyRemapperMappingsHelper;
|
||||
import net.fabricmc.loom.util.gradle.GradleSupport;
|
||||
import net.fabricmc.loom.util.ZipReprocessorUtil;
|
||||
@@ -114,7 +114,7 @@ public class RemapJarTask extends Jar {
|
||||
fromM = getProject().getObjects().property(String.class);
|
||||
toM = getProject().getObjects().property(String.class);
|
||||
fromM.set("named");
|
||||
toM.set("intermediary");
|
||||
toM.set(SourceRemapper.intermediary(getProject()));
|
||||
// false by default, I have no idea why I have to do it for this property and not the other one
|
||||
remapAccessWidener.set(false);
|
||||
addDefaultNestedDependencies.set(true);
|
||||
@@ -136,6 +136,72 @@ public class RemapJarTask extends Jar {
|
||||
}
|
||||
}
|
||||
|
||||
private ReferenceRemapper createReferenceRemapper(LoomGradleExtension extension, String fromM, String toM) throws IOException {
|
||||
TinyTree mappings = extension.shouldGenerateSrgTiny() ? extension.getMappingsProvider().getMappingsWithSrg() : extension.getMappingsProvider().getMappings();
|
||||
|
||||
return new SimpleReferenceRemapper(new SimpleReferenceRemapper.Remapper() {
|
||||
@Override
|
||||
@Nullable
|
||||
public String mapClass(String value) {
|
||||
return mappings.getClasses().stream()
|
||||
.filter(classDef -> Objects.equals(classDef.getName(fromM), value))
|
||||
.findFirst()
|
||||
.map(classDef -> classDef.getName(toM))
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String mapMethod(@Nullable String className, String methodName, String methodDescriptor) {
|
||||
if (className != null) {
|
||||
Optional<ClassDef> classDef = mappings.getClasses().stream()
|
||||
.filter(c -> Objects.equals(c.getName(fromM), className))
|
||||
.findFirst();
|
||||
|
||||
if (classDef.isPresent()) {
|
||||
for (MethodDef methodDef : classDef.get().getMethods()) {
|
||||
if (Objects.equals(methodDef.getName(fromM), methodName) && Objects.equals(methodDef.getDescriptor(fromM), methodDescriptor)) {
|
||||
return methodDef.getName(toM);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return mappings.getClasses().stream()
|
||||
.flatMap(classDef -> classDef.getMethods().stream())
|
||||
.filter(methodDef -> Objects.equals(methodDef.getName(fromM), methodName) && Objects.equals(methodDef.getDescriptor(fromM), methodDescriptor))
|
||||
.findFirst()
|
||||
.map(methodDef -> methodDef.getName(toM))
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String mapField(@Nullable String className, String fieldName, String fieldDescriptor) {
|
||||
if (className != null) {
|
||||
Optional<ClassDef> classDef = mappings.getClasses().stream()
|
||||
.filter(c -> Objects.equals(c.getName(fromM), className))
|
||||
.findFirst();
|
||||
|
||||
if (classDef.isPresent()) {
|
||||
for (FieldDef fieldDef : classDef.get().getFields()) {
|
||||
if (Objects.equals(fieldDef.getName(fromM), fieldName) && Objects.equals(fieldDef.getDescriptor(fromM), fieldDescriptor)) {
|
||||
return fieldDef.getName(toM);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return mappings.getClasses().stream()
|
||||
.flatMap(classDef -> classDef.getFields().stream())
|
||||
.filter(fieldDef -> Objects.equals(fieldDef.getName(fromM), fieldName) && Objects.equals(fieldDef.getDescriptor(fromM), fieldDescriptor))
|
||||
.findFirst()
|
||||
.map(fieldDef -> fieldDef.getName(toM))
|
||||
.orElse(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void scheduleRemap(boolean isMainRemapTask) throws Throwable {
|
||||
Project project = getProject();
|
||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
||||
@@ -154,19 +220,21 @@ public class RemapJarTask extends Jar {
|
||||
if (isMainRemapTask) {
|
||||
jarRemapper.addToClasspath(getRemapClasspath());
|
||||
|
||||
jarRemapper.addMappings(TinyRemapperMappingsHelper.create(extension.isForge() ? mappingsProvider.getMappingsWithSrg() : mappingsProvider.getMappings(), fromM, toM, false));
|
||||
jarRemapper.addMappings(TinyRemapperMappingsHelper.create(extension.shouldGenerateSrgTiny() ? mappingsProvider.getMappingsWithSrg() : mappingsProvider.getMappings(), fromM, toM, false));
|
||||
}
|
||||
|
||||
for (File mixinMapFile : extension.getAllMixinMappings()) {
|
||||
if (mixinMapFile.exists()) {
|
||||
IMappingProvider provider = TinyUtils.createTinyMappingProvider(mixinMapFile.toPath(), fromM, "intermediary");
|
||||
jarRemapper.addMappings(extension.isForge() ? remapToSrg(extension, provider) : provider);
|
||||
jarRemapper.addMappings(!toM.equals("intermediary") ? remapToSrg(extension, provider, fromM, toM) : provider);
|
||||
}
|
||||
}
|
||||
|
||||
// Add remap options to the jar remapper
|
||||
jarRemapper.addOptions(this.remapOptions);
|
||||
|
||||
project.getLogger().info(":scheduling remap " + input.getFileName() + " from " + fromM + " to " + toM);
|
||||
|
||||
NestedJarProvider nestedJarProvider = getNestedJarProvider();
|
||||
nestedJarProvider.prepare(getProject());
|
||||
|
||||
@@ -237,42 +305,42 @@ public class RemapJarTask extends Jar {
|
||||
);
|
||||
}
|
||||
|
||||
private IMappingProvider remapToSrg(LoomGradleExtension extension, IMappingProvider parent) throws IOException {
|
||||
TinyTree srg = extension.getMappingsProvider().getMappingsWithSrg();
|
||||
private IMappingProvider remapToSrg(LoomGradleExtension extension, IMappingProvider parent, String fromM, String toM) throws IOException {
|
||||
TinyTree mappings = extension.shouldGenerateSrgTiny() ? extension.getMappingsProvider().getMappingsWithSrg() : extension.getMappingsProvider().getMappings();
|
||||
|
||||
return sink -> {
|
||||
parent.load(new IMappingProvider.MappingAcceptor() {
|
||||
@Override
|
||||
public void acceptClass(String srcName, String dstName) {
|
||||
String srgName = srg.getClasses()
|
||||
String srgName = mappings.getClasses()
|
||||
.stream()
|
||||
.filter(it -> Objects.equals(it.getName("intermediary"), dstName))
|
||||
.filter(it -> Objects.equals(it.getName(fromM), dstName))
|
||||
.findFirst()
|
||||
.map(it -> it.getName("srg"))
|
||||
.map(it -> it.getName(toM))
|
||||
.orElse(dstName);
|
||||
sink.acceptClass(srcName, srgName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptMethod(IMappingProvider.Member method, String dstName) {
|
||||
String srgName = srg.getClasses()
|
||||
String srgName = mappings.getClasses()
|
||||
.stream()
|
||||
.flatMap(it -> it.getMethods().stream())
|
||||
.filter(it -> Objects.equals(it.getName("intermediary"), dstName))
|
||||
.filter(it -> Objects.equals(it.getName(fromM), dstName))
|
||||
.findFirst()
|
||||
.map(it -> it.getName("srg"))
|
||||
.map(it -> it.getName(toM))
|
||||
.orElse(dstName);
|
||||
sink.acceptMethod(method, srgName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptField(IMappingProvider.Member field, String dstName) {
|
||||
String srgName = srg.getClasses()
|
||||
String srgName = mappings.getClasses()
|
||||
.stream()
|
||||
.flatMap(it -> it.getFields().stream())
|
||||
.filter(it -> Objects.equals(it.getName("intermediary"), dstName))
|
||||
.filter(it -> Objects.equals(it.getName(fromM), dstName))
|
||||
.findFirst()
|
||||
.map(it -> it.getName("srg"))
|
||||
.map(it -> it.getName(toM))
|
||||
.orElse(dstName);
|
||||
sink.acceptField(field, srgName);
|
||||
}
|
||||
|
||||
@@ -37,18 +37,25 @@ import net.fabricmc.loom.util.SourceRemapper;
|
||||
public class RemapSourcesJarTask extends AbstractLoomTask {
|
||||
private Object input;
|
||||
private Object output;
|
||||
private String direction = "intermediary";
|
||||
private String from = "named";
|
||||
private String direction;
|
||||
private SourceRemapper sourceRemapper = null;
|
||||
private boolean preserveFileTimestamps = true;
|
||||
private boolean reproducibleFileOrder = false;
|
||||
|
||||
public RemapSourcesJarTask() {
|
||||
this.direction = SourceRemapper.intermediary(getProject());
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
public void remap() throws Exception {
|
||||
if (sourceRemapper == null) {
|
||||
SourceRemapper.remapSources(getProject(), getInput(), getOutput(), direction.equals("named"), reproducibleFileOrder, preserveFileTimestamps);
|
||||
if (from.equals(direction)) {
|
||||
SourceRemapper.remapSources(getProject(), getInput(), getOutput(),
|
||||
direction.equals("named") ? SourceRemapper.intermediary(getProject()) : "named", direction, reproducibleFileOrder, preserveFileTimestamps);
|
||||
} else {
|
||||
SourceRemapper.remapSources(getProject(), getInput(), getOutput(), from, direction, reproducibleFileOrder, preserveFileTimestamps);
|
||||
}
|
||||
} else {
|
||||
sourceRemapper.scheduleRemapSources(getInput(), getOutput(), reproducibleFileOrder, preserveFileTimestamps);
|
||||
}
|
||||
@@ -74,6 +81,11 @@ public class RemapSourcesJarTask extends AbstractLoomTask {
|
||||
return getProject().file(output == null ? input : output);
|
||||
}
|
||||
|
||||
@Input
|
||||
public String getSourceNamespace() {
|
||||
return from;
|
||||
}
|
||||
|
||||
@Input
|
||||
public String getTargetNamespace() {
|
||||
return direction;
|
||||
@@ -87,6 +99,10 @@ public class RemapSourcesJarTask extends AbstractLoomTask {
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
public void setSourceNamespace(String value) {
|
||||
this.from = value;
|
||||
}
|
||||
|
||||
public void setTargetNamespace(String value) {
|
||||
this.direction = value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user