Make 'srg' the target namespace of remapJar when Forge is enabled

This commit is contained in:
Juuxel
2020-07-30 16:15:23 +03:00
parent ed331990e7
commit bee5b389c4
4 changed files with 33 additions and 110 deletions

View File

@@ -61,7 +61,6 @@ import net.fabricmc.loom.task.AbstractLoomTask;
import net.fabricmc.loom.task.RemapAllSourcesTask;
import net.fabricmc.loom.task.RemapJarTask;
import net.fabricmc.loom.task.RemapSourcesJarTask;
import net.fabricmc.loom.task.SrgRemapJarTask;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.DownloadUtil;
import net.fabricmc.loom.util.FabricApiExtension;
@@ -273,22 +272,16 @@ public class AbstractPlugin implements Plugin<Project> {
if (extension.remapMod) {
AbstractArchiveTask jarTask = (AbstractArchiveTask) project1.getTasks().getByName("jar");
RemapJarTask remapJarTask = (RemapJarTask) project1.getTasks().findByName("remapJar");
SrgRemapJarTask srgRemapJarTask = (SrgRemapJarTask) project1.getTasks().findByName("srgRemapJar");
assert remapJarTask != null;
assert srgRemapJarTask != null;
if (!remapJarTask.getInput().isPresent()) {
jarTask.setClassifier("dev");
remapJarTask.setClassifier("");
if (extension.isForge()) {
remapJarTask.setClassifier("official");
remapJarTask.getInput().set(jarTask.getArchivePath());
srgRemapJarTask.setClassifier("");
srgRemapJarTask.getInput().set(remapJarTask.getArchivePath());
srgRemapJarTask.getMappings().set(extension.getMcpConfigProvider().getSrg());
} else {
remapJarTask.setClassifier("");
remapJarTask.getToM().set("srg");
}
}
@@ -297,10 +290,8 @@ public class AbstractPlugin implements Plugin<Project> {
remapJarTask.getRemapAccessWidener().set(true);
project1.getArtifacts().add("archives", remapJarTask);
project1.getArtifacts().add("archives", srgRemapJarTask);
remapJarTask.dependsOn(jarTask);
project1.getTasks().getByName("build").dependsOn(remapJarTask);
project1.getTasks().getByName("build").dependsOn(srgRemapJarTask);
Map<Project, Set<Task>> taskMap = project.getAllTasks(true);

View File

@@ -47,7 +47,6 @@ import net.fabricmc.loom.task.RemapJarTask;
import net.fabricmc.loom.task.RemapSourcesJarTask;
import net.fabricmc.loom.task.RunClientTask;
import net.fabricmc.loom.task.RunServerTask;
import net.fabricmc.loom.task.SrgRemapJarTask;
public class LoomGradlePlugin extends AbstractPlugin {
public static File getMappedByproduct(Project project, String suffix) {
@@ -89,12 +88,6 @@ public class LoomGradlePlugin extends AbstractPlugin {
t.setGroup("fabric");
});
tasks.register("srgRemapJar", SrgRemapJarTask.class, t -> {
t.setDescription("Remaps the built project jar to intermediary mappings.");
t.setGroup("fabric");
t.dependsOn("remapJar");
});
tasks.register("downloadAssets", DownloadAssetsTask.class, t -> t.setDescription("Downloads required assets for Fabric."));
tasks.register("genIdeaWorkspace", GenIdeaProjectTask.class, t -> {

View File

@@ -58,6 +58,8 @@ public class RemapJarTask extends Jar {
private final RegularFileProperty input;
private final Property<Boolean> addNestedDependencies;
private final Property<Boolean> remapAccessWidener;
private final Property<String> fromM;
private final Property<String> toM;
public JarRemapper jarRemapper;
public RemapJarTask() {
@@ -65,6 +67,10 @@ public class RemapJarTask extends Jar {
input = GradleSupport.getfileProperty(getProject());
addNestedDependencies = getProject().getObjects().property(Boolean.class);
remapAccessWidener = getProject().getObjects().property(Boolean.class);
fromM = getProject().getObjects().property(String.class);
toM = getProject().getObjects().property(String.class);
fromM.set("named");
toM.set("intermediary");
// false by default, I have no idea why I have to do it for this property and not the other one
remapAccessWidener.set(false);
}
@@ -90,12 +96,11 @@ public class RemapJarTask extends Jar {
MappingsProvider mappingsProvider = extension.getMappingsProvider();
String fromM = "named";
String toM = "official";
// ^ This is passed to SrgRemapJarTask.
String fromM = this.fromM.get();
String toM = this.toM.get();
Set<File> classpathFiles = new LinkedHashSet<>(
project.getConfigurations().getByName("compileClasspath").getFiles()
project.getConfigurations().getByName("compileClasspath").getFiles()
);
Path[] classpath = classpathFiles.stream().map(File::toPath).filter((p) -> !input.equals(p) && Files.exists(p)).toArray(Path[]::new);
@@ -104,14 +109,14 @@ public class RemapJarTask extends Jar {
TinyRemapper.Builder remapperBuilder = TinyRemapper.newRemapper();
remapperBuilder = remapperBuilder.withMappings(TinyRemapperMappingsHelper.create(mappingsProvider.getMappings(), fromM, toM, false));
remapperBuilder = remapperBuilder.withMappings(TinyRemapperMappingsHelper.create(extension.isForge() ? mappingsProvider.getMappingsWithSrg() : mappingsProvider.getMappings(), fromM, toM, false));
// FIXME: The mixin map is named->intermediary, but I think we need named->srg?
if (mixinMapFile.exists()) {
project.getLogger().error("Mixins in Forge projects are currently not supported.");
if (false) {
if ("intermediary".equals(toM)) {
remapperBuilder = remapperBuilder.withMappings(TinyUtils.createTinyMappingProvider(mixinMapPath, fromM, toM));
} else {
project.getLogger().error("Mixins in Forge projects are currently not supported.");
}
}
@@ -181,8 +186,8 @@ public class RemapJarTask extends Jar {
MappingsProvider mappingsProvider = extension.getMappingsProvider();
String fromM = "named";
String toM = "intermediary";
String fromM = this.fromM.get();
String toM = this.toM.get();
if (extension.isRootProject()) {
Set<File> classpathFiles = new LinkedHashSet<>(
@@ -196,14 +201,18 @@ public class RemapJarTask extends Jar {
jarRemapper.addToClasspath(classpath);
jarRemapper.addMappings(TinyRemapperMappingsHelper.create(mappingsProvider.getMappings(), fromM, toM, false));
jarRemapper.addMappings(TinyRemapperMappingsHelper.create(extension.isForge() ? mappingsProvider.getMappingsWithSrg() : mappingsProvider.getMappings(), fromM, toM, false));
}
File mixinMapFile = mappingsProvider.mappingsMixinExport;
Path mixinMapPath = mixinMapFile.toPath();
if (mixinMapFile.exists()) {
jarRemapper.addMappings(TinyUtils.createTinyMappingProvider(mixinMapPath, fromM, toM));
if ("intermediary".equals(toM)) {
jarRemapper.addMappings(TinyUtils.createTinyMappingProvider(mixinMapPath, fromM, toM));
} else {
project.getLogger().error("Mixins in Forge projects are currently not supported.");
}
}
jarRemapper.scheduleRemap(input, output)
@@ -258,4 +267,14 @@ public class RemapJarTask extends Jar {
public Property<Boolean> getRemapAccessWidener() {
return remapAccessWidener;
}
@Input
public Property<String> getFromM() {
return fromM;
}
@Input
public Property<String> getToM() {
return toM;
}
}

View File

@@ -1,80 +0,0 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2016, 2017, 2018 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;
import java.io.File;
import java.io.FileReader;
import org.cadixdev.atlas.Atlas;
import org.cadixdev.bombe.asm.jar.JarEntryRemappingTransformer;
import org.cadixdev.lorenz.MappingSet;
import org.cadixdev.lorenz.asm.LorenzRemapper;
import org.cadixdev.lorenz.io.srg.tsrg.TSrgReader;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.tasks.InputFile;
import org.gradle.api.tasks.TaskAction;
import org.gradle.jvm.tasks.Jar;
import net.fabricmc.loom.util.GradleSupport;
@SuppressWarnings("UnstableApiUsage")
public class SrgRemapJarTask extends Jar {
private final RegularFileProperty input;
private final RegularFileProperty mappings;
public SrgRemapJarTask() {
super();
input = GradleSupport.getfileProperty(getProject());
mappings = GradleSupport.getfileProperty(getProject());
}
@TaskAction
public void doTask() throws Throwable {
try (TSrgReader reader = new TSrgReader(new FileReader(mappings.getAsFile().get()));
Atlas atlas = new Atlas()) {
MappingSet mappings = reader.read();
atlas.install(ctx -> new JarEntryRemappingTransformer(
new LorenzRemapper(mappings, ctx.inheritanceProvider())
));
for (File file : getProject().getConfigurations().getByName("runtimeClasspath")) {
atlas.use(file.toPath());
}
atlas.run(input.getAsFile().get().toPath(), getArchivePath().toPath());
}
}
@InputFile
public RegularFileProperty getInput() {
return input;
}
@InputFile
public RegularFileProperty getMappings() {
return mappings;
}
}