Improve setup speed. (#208)

* Improve access widener remapper, now uses tiny remapper

* First pass on using the new tiny remapper

* Optimise source remapping
This commit is contained in:
modmuss50
2020-05-13 19:44:45 +01:00
committed by GitHub
parent bf6fb4a95e
commit 3eff7d0fdb
13 changed files with 420 additions and 362 deletions

View File

@@ -26,7 +26,9 @@ package net.fabricmc.loom.util;
import java.io.File;
import java.io.IOException;
import java.util.function.Consumer;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.zip.ZipFile;
import org.gradle.api.Project;
@@ -45,12 +47,19 @@ import org.gradle.jvm.JvmLibrary;
import org.gradle.language.base.artifact.SourcesArtifact;
import net.fabricmc.loom.LoomGradleExtension;
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, Consumer<Runnable> postPopulationScheduler) {
public static void remapDependencies(Project project, String mappingsSuffix, LoomGradleExtension extension, Configuration modCompile, Configuration modCompileRemapped, Configuration regularCompile, 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 (ResolvedArtifact artifact : modCompile.getResolvedConfiguration().getResolvedArtifacts()) {
String group;
String name;
@@ -76,21 +85,32 @@ public class ModCompileRemapper {
File sources = findSources(dependencies, artifact);
ModDependencyInfo info = new ModDependencyInfo(group, name, version, classifierSuffix, artifact.getFile(), remapData);
modDependencies.add(info);
String remappedLog = group + ":" + name + ":" + version + classifierSuffix + " (" + mappingsSuffix + ")";
String remappedNotation = String.format("%s:%s:%s@%s%s", group, name, version, mappingsSuffix, classifierSuffix);
String remappedFilename = String.format("%s-%s@%s", name, version, mappingsSuffix + classifierSuffix.replace(':', '-'));
project.getLogger().info(":providing " + remappedLog);
File modStore = extension.getRemappedModCache();
remapArtifact(project, modCompileRemapped, artifact, remappedFilename, modStore);
project.getDependencies().add(modCompileRemapped.getName(), project.getDependencies().module(remappedNotation));
if (sources != null) {
scheduleSourcesRemapping(project, postPopulationScheduler, sources, remappedLog, remappedFilename, modStore);
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()));
}
}
/**
@@ -123,28 +143,6 @@ public class ModCompileRemapper {
dependencies.add(regularCompile.getName(), dep);
}
private static void remapArtifact(Project project, Configuration config, ResolvedArtifact artifact, String remappedFilename, File modStore) {
File input = artifact.getFile();
File output = new File(modStore, remappedFilename + ".jar");
if (!output.exists() || input.lastModified() <= 0 || input.lastModified() > output.lastModified()) {
//If the output doesn't exist, or appears to be outdated compared to the input we'll remap it
try {
ModProcessor.processMod(input, output, project, config, artifact);
} catch (IOException e) {
throw new RuntimeException("Failed to remap mod", e);
}
if (!output.exists()) {
throw new RuntimeException("Failed to remap mod");
}
output.setLastModified(input.lastModified());
} else {
project.getLogger().info(output.getName() + " is up to date with " + input.getName());
}
}
public static File findSources(DependencyHandler dependencies, ResolvedArtifact artifact) {
@SuppressWarnings("unchecked") ArtifactResolutionQuery query = dependencies.createArtifactResolutionQuery()//
.forComponents(artifact.getId().getComponentIdentifier())//
@@ -161,23 +159,21 @@ public class ModCompileRemapper {
return null;
}
private static void scheduleSourcesRemapping(Project project, Consumer<Runnable> postPopulationScheduler, File sources, String remappedLog, String remappedFilename, File modStore) {
postPopulationScheduler.accept(() -> {
project.getLogger().info(":providing " + remappedLog + " sources");
File remappedSources = new File(modStore, remappedFilename + "-sources.jar");
private static void scheduleSourcesRemapping(Project project, SourceRemapper sourceRemapper, File sources, String remappedLog, String remappedFilename, File modStore) {
project.getLogger().info(":providing " + remappedLog + " sources");
File remappedSources = new File(modStore, remappedFilename + "-sources.jar");
if (!remappedSources.exists() || sources.lastModified() <= 0 || sources.lastModified() > remappedSources.lastModified()) {
try {
SourceRemapper.remapSources(project, sources, remappedSources, true);
if (!remappedSources.exists() || sources.lastModified() <= 0 || sources.lastModified() > remappedSources.lastModified()) {
try {
sourceRemapper.scheduleRemapSources(sources, remappedSources);
//Set the remapped sources creation date to match the sources if we're likely succeeded in making it
remappedSources.setLastModified(sources.lastModified());
} catch (Exception e) {
e.printStackTrace();
}
} else {
project.getLogger().info(remappedSources.getName() + " is up to date with " + sources.getName());
//Set the remapped sources creation date to match the sources if we're likely succeeded in making it
remappedSources.setLastModified(sources.lastModified());
} catch (Exception e) {
e.printStackTrace();
}
});
} else {
project.getLogger().info(remappedSources.getName() + " is up to date with " + sources.getName());
}
}
}