Cleanup and fix dep remapping, also add better log output to source remapping.
parent
0265a756c4
commit
f673579da8
|
@ -32,6 +32,7 @@ import java.util.jar.JarEntry;
|
||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
import org.gradle.api.artifacts.Configuration;
|
||||||
|
|
||||||
import net.fabricmc.loom.util.ModProcessor;
|
import net.fabricmc.loom.util.ModProcessor;
|
||||||
|
|
||||||
|
@ -41,15 +42,19 @@ public class ModDependencyInfo {
|
||||||
public final String version;
|
public final String version;
|
||||||
public final String classifier;
|
public final String classifier;
|
||||||
public final File inputFile;
|
public final File inputFile;
|
||||||
|
public final File sourcesFile;
|
||||||
|
public final Configuration targetConfig;
|
||||||
|
|
||||||
public final RemapData remapData;
|
public final RemapData remapData;
|
||||||
|
|
||||||
public ModDependencyInfo(String group, String name, String version, String classifier, File inputFile, RemapData remapData) {
|
public ModDependencyInfo(String group, String name, String version, String classifier, File inputFile, File sourcesFile, Configuration targetConfig, RemapData remapData) {
|
||||||
this.group = group;
|
this.group = group;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.version = version;
|
this.version = version;
|
||||||
this.classifier = classifier;
|
this.classifier = classifier;
|
||||||
this.inputFile = inputFile;
|
this.inputFile = inputFile;
|
||||||
|
this.sourcesFile = sourcesFile;
|
||||||
|
this.targetConfig = targetConfig;
|
||||||
this.remapData = remapData;
|
this.remapData = remapData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -117,14 +117,9 @@ public class LoomDependencyManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
SourceRemapper sourceRemapper = new SourceRemapper(project, true);
|
SourceRemapper sourceRemapper = new SourceRemapper(project, true);
|
||||||
|
|
||||||
{
|
|
||||||
String mappingsKey = mappingsProvider.mappingsName + "." + mappingsProvider.minecraftVersion.replace(' ', '_').replace('.', '_').replace('-', '_') + "." + mappingsProvider.mappingsVersion;
|
String mappingsKey = mappingsProvider.mappingsName + "." + mappingsProvider.minecraftVersion.replace(' ', '_').replace('.', '_').replace('-', '_') + "." + mappingsProvider.mappingsVersion;
|
||||||
|
|
||||||
for (RemappedConfigurationEntry entry : Constants.MOD_COMPILE_ENTRIES) {
|
ModCompileRemapper.remapDependencies(project, mappingsKey, extension, sourceRemapper);
|
||||||
ModCompileRemapper.remapDependencies(project, mappingsKey, extension, project.getConfigurations().getByName(entry.getSourceConfiguration()), project.getConfigurations().getByName(entry.getRemappedConfiguration()), project.getConfigurations().getByName(entry.getTargetConfiguration(project.getConfigurations())), sourceRemapper);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (extension.getInstallerJson() == null) {
|
if (extension.getInstallerJson() == null) {
|
||||||
//If we've not found the installer JSON we've probably skipped remapping Fabric loader, let's go looking
|
//If we've not found the installer JSON we've probably skipped remapping Fabric loader, let's go looking
|
||||||
|
|
|
@ -28,7 +28,6 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.zip.ZipFile;
|
import java.util.zip.ZipFile;
|
||||||
|
|
||||||
import org.gradle.api.Project;
|
import org.gradle.api.Project;
|
||||||
|
@ -51,16 +50,21 @@ import net.fabricmc.loom.processors.dependency.ModDependencyInfo;
|
||||||
import net.fabricmc.loom.processors.dependency.RemapData;
|
import net.fabricmc.loom.processors.dependency.RemapData;
|
||||||
|
|
||||||
public class ModCompileRemapper {
|
public class ModCompileRemapper {
|
||||||
public static void remapDependencies(Project project, String mappingsSuffix, LoomGradleExtension extension, Configuration modCompile, Configuration modCompileRemapped, Configuration regularCompile, SourceRemapper sourceRemapper) {
|
public static void remapDependencies(Project project, String mappingsSuffix, LoomGradleExtension extension, SourceRemapper sourceRemapper) {
|
||||||
Logger logger = project.getLogger();
|
Logger logger = project.getLogger();
|
||||||
DependencyHandler dependencies = project.getDependencies();
|
DependencyHandler dependencies = project.getDependencies();
|
||||||
|
|
||||||
final File modStore = extension.getRemappedModCache();
|
final File modStore = extension.getRemappedModCache();
|
||||||
final RemapData remapData = new RemapData(mappingsSuffix, modStore);
|
final RemapData remapData = new RemapData(mappingsSuffix, modStore);
|
||||||
|
|
||||||
final List<ModDependencyInfo> modDependencies = new ArrayList<>();
|
for (RemappedConfigurationEntry entry : Constants.MOD_COMPILE_ENTRIES) {
|
||||||
|
Configuration sourceConfig = project.getConfigurations().getByName(entry.getSourceConfiguration());
|
||||||
|
Configuration remappedConfig = project.getConfigurations().getByName(entry.getRemappedConfiguration());
|
||||||
|
Configuration regularConfig = project.getConfigurations().getByName(entry.getTargetConfiguration(project.getConfigurations()));
|
||||||
|
|
||||||
for (ResolvedArtifact artifact : modCompile.getResolvedConfiguration().getResolvedArtifacts()) {
|
List<ModDependencyInfo> modDependencies = new ArrayList<>();
|
||||||
|
|
||||||
|
for (ResolvedArtifact artifact : sourceConfig.getResolvedConfiguration().getResolvedArtifacts()) {
|
||||||
String group;
|
String group;
|
||||||
String name;
|
String name;
|
||||||
String version;
|
String version;
|
||||||
|
@ -79,37 +83,33 @@ public class ModCompileRemapper {
|
||||||
final String notation = group + ":" + name + ":" + version + classifierSuffix;
|
final String notation = group + ":" + name + ":" + version + classifierSuffix;
|
||||||
|
|
||||||
if (!isFabricMod(project, logger, artifact, notation)) {
|
if (!isFabricMod(project, logger, artifact, notation)) {
|
||||||
addToRegularCompile(project, regularCompile, notation);
|
addToRegularCompile(project, regularConfig, notation);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
File sources = findSources(dependencies, artifact);
|
File sources = findSources(dependencies, artifact);
|
||||||
|
|
||||||
ModDependencyInfo info = new ModDependencyInfo(group, name, version, classifierSuffix, artifact.getFile(), remapData);
|
ModDependencyInfo info = new ModDependencyInfo(group, name, version, classifierSuffix, artifact.getFile(), sources, remappedConfig, remapData);
|
||||||
modDependencies.add(info);
|
modDependencies.add(info);
|
||||||
|
|
||||||
String remappedLog = group + ":" + name + ":" + version + classifierSuffix + " (" + mappingsSuffix + ")";
|
String remappedLog = group + ":" + name + ":" + version + classifierSuffix + " (" + mappingsSuffix + ")";
|
||||||
String remappedFilename = String.format("%s-%s@%s", name, version, mappingsSuffix + classifierSuffix.replace(':', '-'));
|
|
||||||
project.getLogger().info(":providing " + remappedLog);
|
project.getLogger().info(":providing " + remappedLog);
|
||||||
|
|
||||||
if (sources != null) {
|
if (sources != null) {
|
||||||
scheduleSourcesRemapping(project, sourceRemapper, sources, remappedLog, remappedFilename, modStore);
|
scheduleSourcesRemapping(project, sourceRemapper, info.sourcesFile, info.getRemappedNotation(), info.getRemappedFilename(), modStore);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ModDependencyInfo> processList = modDependencies.stream()
|
|
||||||
.filter(ModDependencyInfo::requiresRemapping)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ModProcessor.processMods(project, processList);
|
ModProcessor.processMods(project, modDependencies);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException("Failed to remap mods", e);
|
throw new RuntimeException("Failed to remap mods", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add all of the remapped mods onto the config
|
// Add all of the remapped mods onto the config
|
||||||
for (ModDependencyInfo modDependency : modDependencies) {
|
for (ModDependencyInfo info : modDependencies) {
|
||||||
project.getDependencies().add(modCompileRemapped.getName(), project.getDependencies().module(modDependency.getRemappedNotation()));
|
project.getDependencies().add(info.targetConfig.getName(), project.getDependencies().module(info.getRemappedNotation()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
@ -63,12 +64,12 @@ public class ModProcessor {
|
||||||
public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
||||||
|
|
||||||
public static void processMods(Project project, List<ModDependencyInfo> processList) throws IOException {
|
public static void processMods(Project project, List<ModDependencyInfo> processList) throws IOException {
|
||||||
if (processList.isEmpty()) {
|
if (processList.stream().noneMatch(ModDependencyInfo::requiresRemapping)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ModDependencyInfo info : processList) {
|
for (ModDependencyInfo info : processList) {
|
||||||
if (info.getRemappedOutput().exists()) {
|
if (info.requiresRemapping() && info.getRemappedOutput().exists()) {
|
||||||
info.getRemappedOutput().delete();
|
info.getRemappedOutput().delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,9 +81,11 @@ public class ModProcessor {
|
||||||
throw new RuntimeException("Failed to remap mod" + info);
|
throw new RuntimeException("Failed to remap mod" + info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (info.requiresRemapping()) {
|
||||||
stripNestedJars(info.getRemappedOutput());
|
stripNestedJars(info.getRemappedOutput());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void stripNestedJars(File file) {
|
private static void stripNestedJars(File file) {
|
||||||
//Strip out all contained jar info as we dont want loader to try and load the jars contained in dev.
|
//Strip out all contained jar info as we dont want loader to try and load the jars contained in dev.
|
||||||
|
@ -124,7 +127,9 @@ public class ModProcessor {
|
||||||
Path mc = mappedProvider.getIntermediaryJar().toPath();
|
Path mc = mappedProvider.getIntermediaryJar().toPath();
|
||||||
Path[] mcDeps = mappedProvider.getMapperPaths().stream().map(File::toPath).toArray(Path[]::new);
|
Path[] mcDeps = mappedProvider.getMapperPaths().stream().map(File::toPath).toArray(Path[]::new);
|
||||||
|
|
||||||
project.getLogger().lifecycle(":remapping " + processList.size() + " mods (TinyRemapper, " + fromM + " -> " + toM + ")");
|
List<ModDependencyInfo> remapList = processList.stream().filter(ModDependencyInfo::requiresRemapping).collect(Collectors.toList());
|
||||||
|
|
||||||
|
project.getLogger().lifecycle(":remapping " + remapList.size() + " mods (TinyRemapper, " + fromM + " -> " + toM + ")");
|
||||||
|
|
||||||
TinyRemapper remapper = TinyRemapper.newRemapper()
|
TinyRemapper remapper = TinyRemapper.newRemapper()
|
||||||
.withMappings(TinyRemapperMappingsHelper.create(mappingsProvider.getMappings(), fromM, toM, false))
|
.withMappings(TinyRemapperMappingsHelper.create(mappingsProvider.getMappings(), fromM, toM, false))
|
||||||
|
@ -138,14 +143,24 @@ public class ModProcessor {
|
||||||
final Map<ModDependencyInfo, OutputConsumerPath> outputConsumerMap = new HashMap<>();
|
final Map<ModDependencyInfo, OutputConsumerPath> outputConsumerMap = new HashMap<>();
|
||||||
final Map<ModDependencyInfo, byte[]> accessWidenerMap = new HashMap<>();
|
final Map<ModDependencyInfo, byte[]> accessWidenerMap = new HashMap<>();
|
||||||
|
|
||||||
for (ModDependencyInfo info : processList) {
|
for (RemappedConfigurationEntry entry : Constants.MOD_COMPILE_ENTRIES) {
|
||||||
|
for (File inputFile : project.getConfigurations().getByName(entry.getSourceConfiguration()).getFiles()) {
|
||||||
|
if (remapList.stream().noneMatch(info -> info.getInputFile().equals(inputFile))) {
|
||||||
|
project.getLogger().info("Adding " + inputFile + " onto the remap classpath");
|
||||||
|
remapper.readClassPathAsync(inputFile.toPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (ModDependencyInfo info : remapList) {
|
||||||
InputTag tag = remapper.createInputTag();
|
InputTag tag = remapper.createInputTag();
|
||||||
|
project.getLogger().info("Adding " + info.getInputFile() + " as a remap input");
|
||||||
remapper.readInputsAsync(tag, info.getInputFile().toPath());
|
remapper.readInputsAsync(tag, info.getInputFile().toPath());
|
||||||
tagMap.put(info, tag);
|
tagMap.put(info, tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply this in a second loop as we need to ensure all the inputs are on the classpath before remapping.
|
// Apply this in a second loop as we need to ensure all the inputs are on the classpath before remapping.
|
||||||
for (ModDependencyInfo info : processList) {
|
for (ModDependencyInfo info : remapList) {
|
||||||
OutputConsumerPath outputConsumer = new OutputConsumerPath.Builder(info.getRemappedOutput().toPath()).build();
|
OutputConsumerPath outputConsumer = new OutputConsumerPath.Builder(info.getRemappedOutput().toPath()).build();
|
||||||
outputConsumer.addNonClassFiles(info.getInputFile().toPath());
|
outputConsumer.addNonClassFiles(info.getInputFile().toPath());
|
||||||
outputConsumerMap.put(info, outputConsumer);
|
outputConsumerMap.put(info, outputConsumer);
|
||||||
|
@ -160,7 +175,7 @@ public class ModProcessor {
|
||||||
|
|
||||||
remapper.finish();
|
remapper.finish();
|
||||||
|
|
||||||
for (ModDependencyInfo info : processList) {
|
for (ModDependencyInfo info : remapList) {
|
||||||
outputConsumerMap.get(info).close();
|
outputConsumerMap.get(info).close();
|
||||||
byte[] accessWidener = accessWidenerMap.get(info);
|
byte[] accessWidener = accessWidenerMap.get(info);
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import org.cadixdev.lorenz.MappingSet;
|
import org.cadixdev.lorenz.MappingSet;
|
||||||
import org.cadixdev.mercury.Mercury;
|
import org.cadixdev.mercury.Mercury;
|
||||||
|
@ -39,6 +40,7 @@ import org.zeroturnaround.zip.ZipUtil;
|
||||||
|
|
||||||
import net.fabricmc.loom.LoomGradleExtension;
|
import net.fabricmc.loom.LoomGradleExtension;
|
||||||
import net.fabricmc.loom.providers.MappingsProvider;
|
import net.fabricmc.loom.providers.MappingsProvider;
|
||||||
|
import net.fabricmc.loom.util.progress.ProgressLogger;
|
||||||
import net.fabricmc.lorenztiny.TinyMappingsReader;
|
import net.fabricmc.lorenztiny.TinyMappingsReader;
|
||||||
import net.fabricmc.mapping.tree.TinyTree;
|
import net.fabricmc.mapping.tree.TinyTree;
|
||||||
import net.fabricmc.stitch.util.StitchUtil;
|
import net.fabricmc.stitch.util.StitchUtil;
|
||||||
|
@ -46,7 +48,7 @@ import net.fabricmc.stitch.util.StitchUtil;
|
||||||
public class SourceRemapper {
|
public class SourceRemapper {
|
||||||
private final Project project;
|
private final Project project;
|
||||||
private final boolean toNamed;
|
private final boolean toNamed;
|
||||||
private final List<Runnable> remapTasks = new ArrayList<>();
|
private final List<Consumer<ProgressLogger>> remapTasks = new ArrayList<>();
|
||||||
|
|
||||||
private Mercury mercury;
|
private Mercury mercury;
|
||||||
|
|
||||||
|
@ -62,8 +64,9 @@ public class SourceRemapper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void scheduleRemapSources(File source, File destination) throws Exception {
|
public void scheduleRemapSources(File source, File destination) throws Exception {
|
||||||
remapTasks.add(() -> {
|
remapTasks.add((logger) -> {
|
||||||
try {
|
try {
|
||||||
|
logger.progress("remapping sources - " + source.getName());
|
||||||
remapSourcesInner(source, destination);
|
remapSourcesInner(source, destination);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("Failed to remap sources for " + source, e);
|
throw new RuntimeException("Failed to remap sources for " + source, e);
|
||||||
|
@ -76,7 +79,13 @@ public class SourceRemapper {
|
||||||
project.getLogger().lifecycle(":remapping sources");
|
project.getLogger().lifecycle(":remapping sources");
|
||||||
}
|
}
|
||||||
|
|
||||||
remapTasks.forEach(Runnable::run);
|
ProgressLogger progressLogger = ProgressLogger.getProgressFactory(project, SourceRemapper.class.getName());
|
||||||
|
progressLogger.start("Remapping dependency sources", "sources");
|
||||||
|
|
||||||
|
remapTasks.forEach(consumer -> consumer.accept(progressLogger));
|
||||||
|
|
||||||
|
progressLogger.completed();
|
||||||
|
|
||||||
// TODO: FIXME - WORKAROUND https://github.com/FabricMC/fabric-loom/issues/45
|
// TODO: FIXME - WORKAROUND https://github.com/FabricMC/fabric-loom/issues/45
|
||||||
System.gc();
|
System.gc();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue