aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/net/fabricmc/loom/build
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/net/fabricmc/loom/build')
-rw-r--r--src/main/java/net/fabricmc/loom/build/JarRemapper.java36
-rw-r--r--src/main/java/net/fabricmc/loom/build/MixinRefmapHelper.java2
-rw-r--r--src/main/java/net/fabricmc/loom/build/ModCompileRemapper.java33
-rw-r--r--src/main/java/net/fabricmc/loom/build/mixin/AnnotationProcessorInvoker.java8
-rw-r--r--src/main/java/net/fabricmc/loom/build/nesting/EmptyNestedJarProvider.java38
5 files changed, 100 insertions, 17 deletions
diff --git a/src/main/java/net/fabricmc/loom/build/JarRemapper.java b/src/main/java/net/fabricmc/loom/build/JarRemapper.java
index 47158bc0..5996401b 100644
--- a/src/main/java/net/fabricmc/loom/build/JarRemapper.java
+++ b/src/main/java/net/fabricmc/loom/build/JarRemapper.java
@@ -35,15 +35,17 @@ import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
+import dev.architectury.tinyremapper.IMappingProvider;
+import dev.architectury.tinyremapper.InputTag;
+import dev.architectury.tinyremapper.OutputConsumerPath;
+import dev.architectury.tinyremapper.TinyRemapper;
import org.gradle.api.Action;
+import org.gradle.api.Project;
import org.objectweb.asm.commons.Remapper;
import net.fabricmc.loom.util.CloseableList;
+import net.fabricmc.loom.util.LoggerFilter;
import net.fabricmc.stitch.util.Pair;
-import net.fabricmc.tinyremapper.IMappingProvider;
-import net.fabricmc.tinyremapper.InputTag;
-import net.fabricmc.tinyremapper.OutputConsumerPath;
-import net.fabricmc.tinyremapper.TinyRemapper;
public class JarRemapper {
private final List<IMappingProvider> mappingProviders = new ArrayList<>();
@@ -65,8 +67,11 @@ public class JarRemapper {
return data;
}
- public void remap() throws IOException {
+ public void remap(Project project) throws IOException {
+ LoggerFilter.replaceSystemOut();
TinyRemapper.Builder remapperBuilder = TinyRemapper.newRemapper();
+ remapperBuilder.logger(project.getLogger()::lifecycle);
+ remapperBuilder.logUnknownInvokeDynamic(false);
mappingProviders.forEach(remapperBuilder::withMappings);
if (remapOptions != null) {
@@ -79,7 +84,7 @@ public class JarRemapper {
Path[] remapClasspath = classPath.stream()
.filter(path ->
- remapData.stream().noneMatch(remapData -> remapData.input.equals(path))
+ remapData.stream().noneMatch(remapData -> remapData.input.toString().equals(path.toString()))
)
.toArray(Path[]::new);
@@ -88,13 +93,28 @@ public class JarRemapper {
for (RemapData data : remapData) {
InputTag tag = remapper.createInputTag();
data.tag = tag;
- remapper.readInputsAsync(tag, data.input);
+ project.getLogger().info(":remapper input -> " + data.input.getFileName().toString());
+
+ try {
+ remapper.readInputsAsync(tag, data.input);
+ } catch (Exception e) {
+ throw new RuntimeException("Failed to read remapper input " + data.input.getFileName().toString(), e);
+ }
}
//noinspection MismatchedQueryAndUpdateOfCollection
try (CloseableList<OutputConsumerPath> outputConsumers = new CloseableList<>()) {
for (RemapData data : remapData) {
- OutputConsumerPath outputConsumer = new OutputConsumerPath.Builder(data.output).build();
+ OutputConsumerPath outputConsumer;
+ project.getLogger().info(":remapper output -> " + data.output.getFileName().toString());
+
+ try {
+ Files.deleteIfExists(data.output);
+ outputConsumer = new OutputConsumerPath.Builder(data.output).build();
+ } catch (Exception e) {
+ throw new RuntimeException("Failed to create remapper output " + data.output.getFileName().toString(), e);
+ }
+
outputConsumers.add(outputConsumer);
outputConsumer.addNonClassFiles(data.input);
diff --git a/src/main/java/net/fabricmc/loom/build/MixinRefmapHelper.java b/src/main/java/net/fabricmc/loom/build/MixinRefmapHelper.java
index 4d1ba261..580d5659 100644
--- a/src/main/java/net/fabricmc/loom/build/MixinRefmapHelper.java
+++ b/src/main/java/net/fabricmc/loom/build/MixinRefmapHelper.java
@@ -60,7 +60,7 @@ public final class MixinRefmapHelper {
MixinExtension mixin = LoomGradleExtension.get(project).getMixin();
File output = outputPath.toFile();
- Collection<String> allMixinConfigs = getMixinConfigurationFiles(readFabricModJson(output));
+ Collection<String> allMixinConfigs = LoomGradleExtension.get(project).isForge() ? LoomGradleExtension.get(project).getForge().getMixinConfigs().get() : getMixinConfigurationFiles(readFabricModJson(output));
return mixin.getMixinSourceSetsStream().map(sourceSet -> {
MixinExtension.MixinInformationContainer container = Objects.requireNonNull(
diff --git a/src/main/java/net/fabricmc/loom/build/ModCompileRemapper.java b/src/main/java/net/fabricmc/loom/build/ModCompileRemapper.java
index 4b922cd6..ceccd3b2 100644
--- a/src/main/java/net/fabricmc/loom/build/ModCompileRemapper.java
+++ b/src/main/java/net/fabricmc/loom/build/ModCompileRemapper.java
@@ -31,6 +31,7 @@ import java.util.List;
import java.util.function.Supplier;
import java.util.zip.ZipFile;
+import com.google.common.base.Suppliers;
import com.google.common.io.Files;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
@@ -88,10 +89,12 @@ public class ModCompileRemapper {
for (ResolvedArtifact artifact : sourceConfig.getResolvedConfiguration().getResolvedArtifacts()) {
String group = replaceIfNullOrEmpty(artifact.getModuleVersion().getId().getGroup(), () -> MISSING_GROUP);
- String name = artifact.getModuleVersion().getId().getName();
- String version = replaceIfNullOrEmpty(artifact.getModuleVersion().getId().getVersion(), () -> Checksum.truncatedSha256(artifact.getFile()));
+ // Awful fix for https://github.com/architectury/architectury-loom/issues/42 for now
+ Supplier<String> checksum = Suppliers.memoize(() -> Checksum.truncatedSha256(artifact.getFile()));
+ String name = extension.isForgeAndOfficial() ? "B" + checksum.get() : artifact.getModuleVersion().getId().getName();
+ String version = extension.isForgeAndOfficial() ? "B" + checksum.get() : replaceIfNullOrEmpty(artifact.getModuleVersion().getId().getVersion(), () -> Checksum.truncatedSha256(artifact.getFile()));
- if (!isFabricMod(logger, artifact.getFile(), artifact.getId())) {
+ if (!shouldRemapMod(logger, artifact.getFile(), artifact.getId(), extension.isForge(), sourceConfig.getName())) {
addToRegularCompile(project, regularConfig, artifact);
continue;
}
@@ -118,7 +121,7 @@ public class ModCompileRemapper {
// Create a mod dependency for each file in the file collection
for (File artifact : files) {
- if (!isFabricMod(logger, artifact, artifact.getName())) {
+ if (!shouldRemapMod(logger, artifact, artifact.getName(), extension.isForge(), sourceConfig.getName())) {
dependencies.add(regularConfig.getName(), project.files(artifact));
continue;
}
@@ -150,6 +153,7 @@ public class ModCompileRemapper {
// Add all of the remapped mods onto the config
for (ModDependencyInfo info : modDependencies) {
+ project.getLogger().info(":adding " + info.toString() + " into " + info.targetConfig.getName());
project.getDependencies().add(info.targetConfig.getName(), info.getRemappedNotation());
}
@@ -169,13 +173,28 @@ public class ModCompileRemapper {
/**
* Checks if an artifact is a fabric mod, according to the presence of a fabric.mod.json.
*/
- private static boolean isFabricMod(Logger logger, File artifact, Object id) {
+ private static boolean shouldRemapMod(Logger logger, File artifact, Object id, boolean forge, String config) {
try (ZipFile zipFile = new ZipFile(artifact)) {
- if (zipFile.getEntry("fabric.mod.json") != null) {
- logger.info("Found Fabric mod in modCompile: {}", id);
+ if (zipFile.getEntry("architectury.common.marker") != null) {
+ logger.info("Found architectury common mod in " + config + ": {}", id);
return true;
}
+ if (forge) {
+ if (zipFile.getEntry("META-INF/mods.toml") != null) {
+ logger.info("Found Forge mod in " + config + ": {}", id);
+ return true;
+ }
+
+ logger.lifecycle(":could not find forge mod in " + config + " but forcing: {}", id);
+ return true;
+ } else {
+ if (zipFile.getEntry("fabric.mod.json") != null) {
+ logger.info("Found Fabric mod in " + config + ": {}", id);
+ return true;
+ }
+ }
+
return false;
} catch (IOException e) {
return false;
diff --git a/src/main/java/net/fabricmc/loom/build/mixin/AnnotationProcessorInvoker.java b/src/main/java/net/fabricmc/loom/build/mixin/AnnotationProcessorInvoker.java
index f87ccc21..33fec4e6 100644
--- a/src/main/java/net/fabricmc/loom/build/mixin/AnnotationProcessorInvoker.java
+++ b/src/main/java/net/fabricmc/loom/build/mixin/AnnotationProcessorInvoker.java
@@ -26,6 +26,7 @@ package net.fabricmc.loom.build.mixin;
import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@@ -81,8 +82,9 @@ public abstract class AnnotationProcessorInvoker<T extends Task> {
try {
LoomGradleExtension loom = LoomGradleExtension.get(project);
String refmapName = Objects.requireNonNull(MixinExtension.getMixinInformationContainer(sourceSet)).refmapNameProvider().get();
+ Path mappings = loom.isForge() ? loom.getMappingsProvider().mixinTinyMappingsWithSrg : loom.getMappingsProvider().tinyMappings;
Map<String, String> args = new HashMap<>() {{
- put(Constants.MixinArguments.IN_MAP_FILE_NAMED_INTERMEDIARY, loom.getMappingsProvider().tinyMappings.toFile().getCanonicalPath());
+ put(Constants.MixinArguments.IN_MAP_FILE_NAMED_INTERMEDIARY, mappings.toFile().getCanonicalPath());
put(Constants.MixinArguments.OUT_MAP_FILE_NAMED_INTERMEDIARY, loom.getNextMixinMappings().getCanonicalPath());
put(Constants.MixinArguments.OUT_REFMAP_FILE, getRefmapDestination(task, refmapName));
put(Constants.MixinArguments.DEFAULT_OBFUSCATION_ENV, "named:intermediary");
@@ -109,6 +111,10 @@ public abstract class AnnotationProcessorInvoker<T extends Task> {
configs.getByName(Constants.Configurations.MAPPINGS_FINAL)
);
+ if (extension.isForge()) {
+ processorConfig.extendsFrom(configs.getByName(Constants.Configurations.FORGE_NAMED));
+ }
+
// Add Mixin and mixin extensions (fabric-mixin-compile-extensions pulls mixin itself too)
project.getDependencies().add(processorConfig.getName(),
Constants.Dependencies.MIXIN_COMPILE_EXTENSIONS + Constants.Dependencies.Versions.MIXIN_COMPILE_EXTENSIONS);
diff --git a/src/main/java/net/fabricmc/loom/build/nesting/EmptyNestedJarProvider.java b/src/main/java/net/fabricmc/loom/build/nesting/EmptyNestedJarProvider.java
new file mode 100644
index 00000000..8a305d49
--- /dev/null
+++ b/src/main/java/net/fabricmc/loom/build/nesting/EmptyNestedJarProvider.java
@@ -0,0 +1,38 @@
+/*
+ * This file is part of fabric-loom, licensed under the MIT License (MIT).
+ *
+ * Copyright (c) 2021 FabricMC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package net.fabricmc.loom.build.nesting;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.Collections;
+
+public enum EmptyNestedJarProvider implements NestedJarProvider {
+ INSTANCE;
+
+ @Override
+ public Collection<File> provide() {
+ return Collections.emptyList();
+ }
+}