Cleanup and fix dep remapping, also add better log output to source remapping.

dev/0.11
modmuss50 2020-06-01 12:17:58 +01:00
parent 0265a756c4
commit f673579da8
5 changed files with 89 additions and 65 deletions

View File

@ -32,6 +32,7 @@ import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import com.google.gson.JsonObject;
import org.gradle.api.artifacts.Configuration;
import net.fabricmc.loom.util.ModProcessor;
@ -41,15 +42,19 @@ public class ModDependencyInfo {
public final String version;
public final String classifier;
public final File inputFile;
public final File sourcesFile;
public final Configuration targetConfig;
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.name = name;
this.version = version;
this.classifier = classifier;
this.inputFile = inputFile;
this.sourcesFile = sourcesFile;
this.targetConfig = targetConfig;
this.remapData = remapData;
}

View File

@ -117,14 +117,9 @@ public class LoomDependencyManager {
}
SourceRemapper sourceRemapper = new SourceRemapper(project, true);
{
String mappingsKey = mappingsProvider.mappingsName + "." + mappingsProvider.minecraftVersion.replace(' ', '_').replace('.', '_').replace('-', '_') + "." + mappingsProvider.mappingsVersion;
for (RemappedConfigurationEntry entry : Constants.MOD_COMPILE_ENTRIES) {
ModCompileRemapper.remapDependencies(project, mappingsKey, extension, project.getConfigurations().getByName(entry.getSourceConfiguration()), project.getConfigurations().getByName(entry.getRemappedConfiguration()), project.getConfigurations().getByName(entry.getTargetConfiguration(project.getConfigurations())), sourceRemapper);
}
}
ModCompileRemapper.remapDependencies(project, mappingsKey, extension, sourceRemapper);
if (extension.getInstallerJson() == null) {
//If we've not found the installer JSON we've probably skipped remapping Fabric loader, let's go looking

View File

@ -28,7 +28,6 @@ import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.zip.ZipFile;
import org.gradle.api.Project;
@ -51,16 +50,21 @@ import net.fabricmc.loom.processors.dependency.ModDependencyInfo;
import net.fabricmc.loom.processors.dependency.RemapData;
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();
DependencyHandler dependencies = project.getDependencies();
final File modStore = extension.getRemappedModCache();
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 name;
String version;
@ -79,37 +83,33 @@ public class ModCompileRemapper {
final String notation = group + ":" + name + ":" + version + classifierSuffix;
if (!isFabricMod(project, logger, artifact, notation)) {
addToRegularCompile(project, regularCompile, notation);
addToRegularCompile(project, regularConfig, notation);
continue;
}
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);
String remappedLog = group + ":" + name + ":" + version + classifierSuffix + " (" + mappingsSuffix + ")";
String remappedFilename = String.format("%s-%s@%s", name, version, mappingsSuffix + classifierSuffix.replace(':', '-'));
project.getLogger().info(":providing " + remappedLog);
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 {
ModProcessor.processMods(project, processList);
ModProcessor.processMods(project, modDependencies);
} catch (IOException e) {
throw new RuntimeException("Failed to remap mods", e);
}
// Add all of the remapped mods onto the config
for (ModDependencyInfo modDependency : modDependencies) {
project.getDependencies().add(modCompileRemapped.getName(), project.getDependencies().module(modDependency.getRemappedNotation()));
for (ModDependencyInfo info : modDependencies) {
project.getDependencies().add(info.targetConfig.getName(), project.getDependencies().module(info.getRemappedNotation()));
}
}
}

View File

@ -37,6 +37,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.jar.JarFile;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import com.google.gson.Gson;
@ -63,12 +64,12 @@ public class ModProcessor {
public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
public static void processMods(Project project, List<ModDependencyInfo> processList) throws IOException {
if (processList.isEmpty()) {
if (processList.stream().noneMatch(ModDependencyInfo::requiresRemapping)) {
return;
}
for (ModDependencyInfo info : processList) {
if (info.getRemappedOutput().exists()) {
if (info.requiresRemapping() && info.getRemappedOutput().exists()) {
info.getRemappedOutput().delete();
}
}
@ -80,9 +81,11 @@ public class ModProcessor {
throw new RuntimeException("Failed to remap mod" + info);
}
if (info.requiresRemapping()) {
stripNestedJars(info.getRemappedOutput());
}
}
}
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.
@ -124,7 +127,9 @@ public class ModProcessor {
Path mc = mappedProvider.getIntermediaryJar().toPath();
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()
.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, 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();
project.getLogger().info("Adding " + info.getInputFile() + " as a remap input");
remapper.readInputsAsync(tag, info.getInputFile().toPath());
tagMap.put(info, tag);
}
// 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();
outputConsumer.addNonClassFiles(info.getInputFile().toPath());
outputConsumerMap.put(info, outputConsumer);
@ -160,7 +175,7 @@ public class ModProcessor {
remapper.finish();
for (ModDependencyInfo info : processList) {
for (ModDependencyInfo info : remapList) {
outputConsumerMap.get(info).close();
byte[] accessWidener = accessWidenerMap.get(info);

View File

@ -30,6 +30,7 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import org.cadixdev.lorenz.MappingSet;
import org.cadixdev.mercury.Mercury;
@ -39,6 +40,7 @@ import org.zeroturnaround.zip.ZipUtil;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.providers.MappingsProvider;
import net.fabricmc.loom.util.progress.ProgressLogger;
import net.fabricmc.lorenztiny.TinyMappingsReader;
import net.fabricmc.mapping.tree.TinyTree;
import net.fabricmc.stitch.util.StitchUtil;
@ -46,7 +48,7 @@ import net.fabricmc.stitch.util.StitchUtil;
public class SourceRemapper {
private final Project project;
private final boolean toNamed;
private final List<Runnable> remapTasks = new ArrayList<>();
private final List<Consumer<ProgressLogger>> remapTasks = new ArrayList<>();
private Mercury mercury;
@ -62,8 +64,9 @@ public class SourceRemapper {
}
public void scheduleRemapSources(File source, File destination) throws Exception {
remapTasks.add(() -> {
remapTasks.add((logger) -> {
try {
logger.progress("remapping sources - " + source.getName());
remapSourcesInner(source, destination);
} catch (Exception e) {
throw new RuntimeException("Failed to remap sources for " + source, e);
@ -76,7 +79,13 @@ public class SourceRemapper {
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
System.gc();
}