mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-03-28 12:17:00 -05:00
Merge remote-tracking branch 'upstream/dev/0.11' into dev/0.11.0
# Conflicts: # src/main/java/net/fabricmc/loom/configuration/ifaceinject/InterfaceInjectionProcessor.java # src/main/java/net/fabricmc/loom/extension/LoomGradleExtensionApiImpl.java # src/main/java/net/fabricmc/loom/task/GenerateSourcesTask.java
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2016-2021 FabricMC
|
||||
* Copyright (c) 2016-2022 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
|
||||
@@ -26,12 +26,16 @@ package net.fabricmc.loom.task;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.io.Writer;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@@ -47,6 +51,7 @@ import org.gradle.api.file.FileCollection;
|
||||
import org.gradle.api.file.RegularFileProperty;
|
||||
import org.gradle.api.provider.Property;
|
||||
import org.gradle.api.tasks.InputFile;
|
||||
import org.gradle.api.tasks.InputFiles;
|
||||
import org.gradle.api.tasks.TaskAction;
|
||||
import org.gradle.workers.WorkAction;
|
||||
import org.gradle.workers.WorkParameters;
|
||||
@@ -59,8 +64,9 @@ import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.api.decompilers.DecompilationMetadata;
|
||||
import net.fabricmc.loom.api.decompilers.DecompilerOptions;
|
||||
import net.fabricmc.loom.api.decompilers.LoomDecompiler;
|
||||
import net.fabricmc.loom.configuration.accesswidener.AccessWidenerFile;
|
||||
import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
|
||||
import net.fabricmc.loom.configuration.accesswidener.TransitiveAccessWidenerMappingsProcessor;
|
||||
import net.fabricmc.loom.configuration.ifaceinject.InterfaceInjectionProcessor;
|
||||
import net.fabricmc.loom.decompilers.LineNumberRemapper;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.FileSystemUtil;
|
||||
@@ -71,6 +77,10 @@ import net.fabricmc.loom.util.gradle.ThreadedSimpleProgressLogger;
|
||||
import net.fabricmc.loom.util.gradle.WorkerDaemonClientsManagerHelper;
|
||||
import net.fabricmc.loom.util.ipc.IPCClient;
|
||||
import net.fabricmc.loom.util.ipc.IPCServer;
|
||||
import net.fabricmc.mappingio.MappingReader;
|
||||
import net.fabricmc.mappingio.adapter.MappingSourceNsSwitch;
|
||||
import net.fabricmc.mappingio.format.Tiny2Writer;
|
||||
import net.fabricmc.mappingio.tree.MemoryMappingTree;
|
||||
|
||||
public abstract class GenerateSourcesTask extends AbstractLoomTask implements DecompilationTask {
|
||||
private final DecompilerOptions decompilerOptions;
|
||||
@@ -89,6 +99,9 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask implements De
|
||||
@InputFile
|
||||
public abstract RegularFileProperty getRuntimeJar();
|
||||
|
||||
@InputFiles
|
||||
public abstract ConfigurableFileCollection getClasspath();
|
||||
|
||||
@Inject
|
||||
public abstract WorkerExecutor getWorkerExecutor();
|
||||
|
||||
@@ -100,6 +113,8 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask implements De
|
||||
this.decompilerOptions = decompilerOptions;
|
||||
|
||||
getOutputs().upToDateWhen((o) -> false);
|
||||
getClasspath().from(decompilerOptions.getClasspath()).finalizeValueOnRead();
|
||||
dependsOn(decompilerOptions.getClasspath().getBuiltBy());
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
@@ -165,15 +180,17 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask implements De
|
||||
|
||||
private WorkQueue createWorkQueue(String jvmMarkerValue) {
|
||||
if (!useProcessIsolation()) {
|
||||
return getWorkerExecutor().noIsolation();
|
||||
return getWorkerExecutor().classLoaderIsolation(spec -> {
|
||||
spec.getClasspath().from(getClasspath());
|
||||
});
|
||||
}
|
||||
|
||||
return getWorkerExecutor().processIsolation(spec -> {
|
||||
spec.forkOptions(forkOptions -> {
|
||||
forkOptions.setMaxHeapSize("%dm".formatted(decompilerOptions.getMemory().get()));
|
||||
forkOptions.systemProperty(WorkerDaemonClientsManagerHelper.MARKER_PROP, jvmMarkerValue);
|
||||
forkOptions.bootstrapClasspath(decompilerOptions.getClasspath());
|
||||
});
|
||||
spec.getClasspath().from(getClasspath());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -309,37 +326,72 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask implements De
|
||||
}
|
||||
|
||||
static Path getMappings(Project project, LoomGradleExtension extension) {
|
||||
Path baseMappings = extension.isForge() ? extension.getMappingsProvider().tinyMappingsWithSrg : extension.getMappingsProvider().tinyMappings;
|
||||
Path inputMappings = extension.isForge() ? extension.getMappingsProvider().tinyMappingsWithSrg : extension.getMappingsProvider().tinyMappings;
|
||||
|
||||
if (extension.getEnableTransitiveAccessWideners().get()) {
|
||||
List<AccessWidenerFile> accessWideners = extension.getTransitiveAccessWideners();
|
||||
MemoryMappingTree mappingTree = new MemoryMappingTree();
|
||||
|
||||
if (accessWideners.isEmpty()) {
|
||||
return baseMappings;
|
||||
}
|
||||
|
||||
Path outputMappings;
|
||||
|
||||
try {
|
||||
outputMappings = Files.createTempFile("loom-transitive-mappings", ".tiny");
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to create temp file", e);
|
||||
}
|
||||
|
||||
TransitiveAccessWidenerMappingsProcessor.process(baseMappings, outputMappings, accessWideners, project.getLogger());
|
||||
|
||||
return outputMappings;
|
||||
try (Reader reader = Files.newBufferedReader(inputMappings, StandardCharsets.UTF_8)) {
|
||||
MappingReader.read(reader, new MappingSourceNsSwitch(mappingTree, MappingsNamespace.INTERMEDIARY.toString()));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to read mappings", e);
|
||||
}
|
||||
|
||||
return baseMappings;
|
||||
final List<MappingsProcessor> mappingsProcessors = new ArrayList<>();
|
||||
|
||||
if (getExtension().getEnableTransitiveAccessWideners().get()) {
|
||||
mappingsProcessors.add(new TransitiveAccessWidenerMappingsProcessor(getProject()));
|
||||
}
|
||||
|
||||
if (getExtension().getInterfaceInjection().isEnabled()) {
|
||||
mappingsProcessors.add(new InterfaceInjectionProcessor(getProject()));
|
||||
}
|
||||
|
||||
if (mappingsProcessors.isEmpty()) {
|
||||
return inputMappings;
|
||||
}
|
||||
|
||||
boolean transformed = false;
|
||||
|
||||
for (MappingsProcessor mappingsProcessor : mappingsProcessors) {
|
||||
if (mappingsProcessor.transform(mappingTree)) {
|
||||
transformed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!transformed) {
|
||||
return inputMappings;
|
||||
}
|
||||
|
||||
final Path outputMappings;
|
||||
|
||||
try {
|
||||
outputMappings = Files.createTempFile("loom-transitive-mappings", ".tiny");
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to create temp file", e);
|
||||
}
|
||||
|
||||
try (Writer writer = Files.newBufferedWriter(outputMappings, StandardCharsets.UTF_8)) {
|
||||
Tiny2Writer tiny2Writer = new Tiny2Writer(writer, false);
|
||||
mappingTree.accept(new MappingSourceNsSwitch(tiny2Writer, MappingsNamespace.NAMED.toString()));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to write mappings", e);
|
||||
}
|
||||
|
||||
return outputMappings;
|
||||
}
|
||||
|
||||
public interface MappingsProcessor {
|
||||
boolean transform(MemoryMappingTree mappings);
|
||||
}
|
||||
|
||||
private static Constructor<LoomDecompiler> getDecompilerConstructor(String clazz) {
|
||||
try {
|
||||
//noinspection unchecked
|
||||
return (Constructor<LoomDecompiler>) Class.forName(clazz).getConstructor();
|
||||
} catch (NoSuchMethodException | ClassNotFoundException e) {
|
||||
} catch (NoSuchMethodException e) {
|
||||
return null;
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user