Merge remote-tracking branch 'FabricMC/dev/0.10' into dev/0.10.0

# Conflicts:
#	src/main/java/net/fabricmc/loom/configuration/providers/mappings/MappingsProviderImpl.java
#	src/test/groovy/net/fabricmc/loom/test/integration/FabricAPITest.groovy
This commit is contained in:
shedaniel
2021-11-13 00:40:44 +08:00
12 changed files with 73 additions and 70 deletions

View File

@@ -46,6 +46,7 @@ import org.gradle.api.artifacts.result.ComponentArtifactsResult;
import org.gradle.api.artifacts.result.ResolvedArtifactResult;
import org.gradle.api.file.FileCollection;
import org.gradle.api.logging.Logger;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.jvm.JvmLibrary;
import org.gradle.language.base.artifact.SourcesArtifact;
import org.jetbrains.annotations.Nullable;
@@ -160,6 +161,11 @@ public class ModCompileRemapper {
if (entry.replacedWith() != null && !modDependencies.isEmpty()) {
extension.getDeprecationHelper().replaceWithInLoom0_11(entry.sourceConfiguration(), entry.replacedWith());
}
// Export to other projects
if (entry.targetConfiguration().equals(JavaPlugin.API_CONFIGURATION_NAME)) {
project.getConfigurations().getByName(Constants.Configurations.NAMED_ELEMENTS).extendsFrom(remappedConfig);
}
});
}
}

View File

@@ -24,10 +24,14 @@
package net.fabricmc.loom.configuration;
import java.nio.charset.StandardCharsets;
import org.gradle.api.Project;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.plugins.JavaPluginConvention;
import org.gradle.api.tasks.AbstractCopyTask;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.compile.JavaCompile;
import org.gradle.api.tasks.javadoc.Javadoc;
import org.gradle.jvm.tasks.Jar;
@@ -106,6 +110,7 @@ public final class CompileConfiguration {
extension.createLazyConfiguration(Constants.Configurations.NAMED_ELEMENTS).configure(configuration -> {
configuration.setCanBeConsumed(true);
configuration.setCanBeResolved(false);
configuration.extendsFrom(project.getConfigurations().getByName(JavaPlugin.API_CONFIGURATION_NAME));
});
extendsFrom(JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME, Constants.Configurations.MAPPING_CONSTANTS, project);
@@ -219,6 +224,12 @@ public final class CompileConfiguration {
// Add the "dev" jar to the "namedElements" configuration
p.artifacts(artifactHandler -> artifactHandler.add(Constants.Configurations.NAMED_ELEMENTS, p.getTasks().getByName("jar")));
// Ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
p.getTasks().withType(AbstractCopyTask.class).configureEach(abstractCopyTask -> abstractCopyTask.setFilteringCharset(StandardCharsets.UTF_8.name()));
p.getTasks().withType(JavaCompile.class).configureEach(javaCompile -> javaCompile.getOptions().setEncoding(StandardCharsets.UTF_8.name()));
if (p.getPluginManager().hasPlugin("org.jetbrains.kotlin.kapt")) {
// If loom is applied after kapt, then kapt will use the AP arguments too early for loom to pass the arguments we need for mixin.
throw new IllegalArgumentException("fabric-loom must be applied BEFORE kapt in the plugins { } block.");

View File

@@ -78,7 +78,15 @@ public class RemapConfiguration {
return;
}
PublishArtifact artifact = artifacts.add(JavaPlugin.SOURCES_ELEMENTS_CONFIGURATION_NAME, task.getOutput());
PublishArtifact artifact = artifacts.add(JavaPlugin.SOURCES_ELEMENTS_CONFIGURATION_NAME, task.getOutput(), configurablePublishArtifact -> {
Task remapJarTask = task;
if (extension.getShareRemapCaches().get()) {
remapJarTask = project.getRootProject().getTasks().getByName(DEFAULT_REMAP_ALL_JARS_TASK_NAME);
}
configurablePublishArtifact.builtBy(remapJarTask);
});
// Remove the existing artifact that does not run remapSourcesJar.
// It doesn't seem to hurt, but I'm not sure if the file-level duplicates cause issues.

View File

@@ -298,8 +298,13 @@ public class MinecraftProviderImpl extends DependencyProvider implements Minecra
}
String jarPath = null;
String[] versions = versionsList.split("\n");
for (String version : versionsList.split("\n")) {
if (versions.length != 1) {
throw new UnsupportedOperationException("Expected only 1 version in META-INF/versions.list, but got %d".formatted(versions.length));
}
for (String version : versions) {
if (version.isBlank()) continue;
String[] split = version.split("\t");
@@ -310,10 +315,9 @@ public class MinecraftProviderImpl extends DependencyProvider implements Minecra
final String id = split[1];
final String path = split[2];
if (minecraftVersion().equals(id)) {
jarPath = path;
break;
}
// Take the first (only) version we find.
jarPath = path;
break;
}
Objects.requireNonNull(jarPath, "Could not find minecraft server jar for " + minecraftVersion());

View File

@@ -83,8 +83,6 @@ import net.fabricmc.mappingio.tree.MappingTree;
import net.fabricmc.mappingio.tree.MemoryMappingTree;
import net.fabricmc.stitch.Command;
import net.fabricmc.stitch.commands.CommandProposeFieldNames;
import net.fabricmc.stitch.commands.tinyv2.CommandMergeTinyV2;
import net.fabricmc.stitch.commands.tinyv2.CommandReorderTinyV2;
import net.fabricmc.stitch.commands.tinyv2.TinyFile;
import net.fabricmc.stitch.commands.tinyv2.TinyV2Writer;
@@ -225,7 +223,7 @@ public class MappingsProviderImpl extends DependencyProvider implements Mappings
if (processorManager.active() || (extension.isForge() && patchedProvider.usesProjectCache())) {
mappedProvider = new MinecraftProcessedProvider(getProject(), processorManager);
getProject().getLogger().lifecycle("Using project based jar storage");
getProject().getLogger().info("Using project based jar storage");
} else {
mappedProvider = new MinecraftMappedProvider(getProject());
}
@@ -447,18 +445,22 @@ public class MappingsProviderImpl extends DependencyProvider implements Mappings
Stopwatch stopwatch = Stopwatch.createStarted();
project.getLogger().info(":merging mappings");
MemoryMappingTree tree = new MemoryMappingTree();
MappingSourceNsSwitch sourceNsSwitch = new MappingSourceNsSwitch(tree, MappingsNamespace.OFFICIAL.toString());
readIntermediaryTree().accept(sourceNsSwitch);
MemoryMappingTree intermediaryTree = new MemoryMappingTree();
readIntermediaryTree().accept(new MappingSourceNsSwitch(intermediaryTree, MappingsNamespace.INTERMEDIARY.toString()));
try (BufferedReader reader = Files.newBufferedReader(from, StandardCharsets.UTF_8)) {
Tiny2Reader.read(reader, tree);
Tiny2Reader.read(reader, intermediaryTree);
}
inheritMappedNamesOfEnclosingClasses(tree);
MemoryMappingTree officialTree = new MemoryMappingTree();
MappingNsCompleter nsCompleter = new MappingNsCompleter(officialTree, Map.of(MappingsNamespace.OFFICIAL.toString(), MappingsNamespace.INTERMEDIARY.toString()));
MappingSourceNsSwitch nsSwitch = new MappingSourceNsSwitch(nsCompleter, MappingsNamespace.OFFICIAL.toString());
intermediaryTree.accept(nsSwitch);
inheritMappedNamesOfEnclosingClasses(officialTree);
try (Tiny2Writer writer = new Tiny2Writer(Files.newBufferedWriter(out, StandardCharsets.UTF_8), false)) {
tree.accept(writer);
officialTree.accept(writer);
}
project.getLogger().info(":merged mappings in " + stopwatch.stop());
@@ -509,28 +511,6 @@ public class MappingsProviderImpl extends DependencyProvider implements Mappings
return tree;
}
private void reorderMappings(Path oldMappings, Path newMappings, String... newOrder) {
Command command = new CommandReorderTinyV2();
String[] args = new String[2 + newOrder.length];
args[0] = oldMappings.toAbsolutePath().toString();
args[1] = newMappings.toAbsolutePath().toString();
System.arraycopy(newOrder, 0, args, 2, newOrder.length);
runCommand(command, args);
}
private void mergeMappings(Path intermediaryMappings, Path yarnMappings, Path newMergedMappings) {
try {
Command command = new CommandMergeTinyV2();
runCommand(command, intermediaryMappings.toAbsolutePath().toString(),
yarnMappings.toAbsolutePath().toString(),
newMergedMappings.toAbsolutePath().toString(),
MappingsNamespace.INTERMEDIARY.toString(), MappingsNamespace.OFFICIAL.toString());
} catch (Exception e) {
throw new RuntimeException("Could not merge mappings from " + intermediaryMappings.toString()
+ " with mappings from " + yarnMappings, e);
}
}
private void suggestFieldNames(MinecraftProviderImpl minecraftProvider, Path oldMappings, Path newMappings) {
Command command = new CommandProposeFieldNames();
runCommand(command, minecraftProvider.getMergedJar().getAbsolutePath(),

View File

@@ -24,6 +24,8 @@
package net.fabricmc.loom.util;
import java.util.Objects;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.RecordComponentVisitor;
@@ -60,7 +62,7 @@ public class RecordComponentFixVisitor extends ClassVisitor {
@Override
public FieldVisitor visitField(int access, String name, String descriptor, String signature, Object value) {
String intermediaryName = mappings.getField(owner, name, descriptor).getName(intermediaryNsId);
String intermediaryName = Objects.requireNonNull(mappings.getField(owner, name, descriptor), "Could not get field for %s:%s%s".formatted(owner, name, descriptor)).getName(intermediaryNsId);
if (!hasExistingComponents && intermediaryName != null && intermediaryName.startsWith("comp_")) {
super.visitRecordComponent(name, descriptor, signature);