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 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;
} }

View File

@ -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;
{ ModCompileRemapper.remapDependencies(project, mappingsKey, extension, sourceRemapper);
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);
}
}
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

View File

@ -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,66 +50,67 @@ 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<>();
String group;
String name;
String version;
String classifierSuffix = artifact.getClassifier() == null ? "" : (":" + artifact.getClassifier());
if (artifact.getId().getComponentIdentifier() instanceof ModuleComponentIdentifier) { for (ResolvedArtifact artifact : sourceConfig.getResolvedConfiguration().getResolvedArtifacts()) {
group = ((ModuleComponentIdentifier) artifact.getId().getComponentIdentifier()).getGroup(); String group;
name = ((ModuleComponentIdentifier) artifact.getId().getComponentIdentifier()).getModule(); String name;
version = ((ModuleComponentIdentifier) artifact.getId().getComponentIdentifier()).getVersion(); String version;
} else { String classifierSuffix = artifact.getClassifier() == null ? "" : (":" + artifact.getClassifier());
group = "net.fabricmc.synthetic";
name = artifact.getId().getComponentIdentifier().getDisplayName().replace('.', '-').replace(" :", "-"); if (artifact.getId().getComponentIdentifier() instanceof ModuleComponentIdentifier) {
version = "0.1.0"; group = ((ModuleComponentIdentifier) artifact.getId().getComponentIdentifier()).getGroup();
name = ((ModuleComponentIdentifier) artifact.getId().getComponentIdentifier()).getModule();
version = ((ModuleComponentIdentifier) artifact.getId().getComponentIdentifier()).getVersion();
} else {
group = "net.fabricmc.synthetic";
name = artifact.getId().getComponentIdentifier().getDisplayName().replace('.', '-').replace(" :", "-");
version = "0.1.0";
}
final String notation = group + ":" + name + ":" + version + classifierSuffix;
if (!isFabricMod(project, logger, artifact, notation)) {
addToRegularCompile(project, regularConfig, notation);
continue;
}
File sources = findSources(dependencies, artifact);
ModDependencyInfo info = new ModDependencyInfo(group, name, version, classifierSuffix, artifact.getFile(), sources, remappedConfig, remapData);
modDependencies.add(info);
String remappedLog = group + ":" + name + ":" + version + classifierSuffix + " (" + mappingsSuffix + ")";
project.getLogger().info(":providing " + remappedLog);
if (sources != null) {
scheduleSourcesRemapping(project, sourceRemapper, info.sourcesFile, info.getRemappedNotation(), info.getRemappedFilename(), modStore);
}
} }
final String notation = group + ":" + name + ":" + version + classifierSuffix; try {
ModProcessor.processMods(project, modDependencies);
if (!isFabricMod(project, logger, artifact, notation)) { } catch (IOException e) {
addToRegularCompile(project, regularCompile, notation); throw new RuntimeException("Failed to remap mods", e);
continue;
} }
File sources = findSources(dependencies, artifact); // Add all of the remapped mods onto the config
for (ModDependencyInfo info : modDependencies) {
ModDependencyInfo info = new ModDependencyInfo(group, name, version, classifierSuffix, artifact.getFile(), remapData); project.getDependencies().add(info.targetConfig.getName(), project.getDependencies().module(info.getRemappedNotation()));
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);
} }
} }
List<ModDependencyInfo> processList = modDependencies.stream()
.filter(ModDependencyInfo::requiresRemapping)
.collect(Collectors.toList());
try {
ModProcessor.processMods(project, processList);
} 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()));
}
} }
/** /**

View File

@ -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,7 +81,9 @@ public class ModProcessor {
throw new RuntimeException("Failed to remap mod" + info); throw new RuntimeException("Failed to remap mod" + info);
} }
stripNestedJars(info.getRemappedOutput()); if (info.requiresRemapping()) {
stripNestedJars(info.getRemappedOutput());
}
} }
} }
@ -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);

View File

@ -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();
} }