mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-04-02 13:37:45 -05:00
Allow the generation of tiny mappings with srg without being in a forge environment
This commit is contained in:
@@ -108,6 +108,13 @@ public class AbstractPlugin implements Plugin<Project> {
|
||||
Configuration minecraftConfig = project.getConfigurations().maybeCreate(Constants.Configurations.MINECRAFT);
|
||||
minecraftConfig.setTransitive(false);
|
||||
|
||||
project.afterEvaluate(project1 -> {
|
||||
if (project.getExtensions().getByType(LoomGradleExtension.class).shouldGenerateSrgTiny()) {
|
||||
Configuration srg = project.getConfigurations().maybeCreate(Constants.Configurations.SRG);
|
||||
srg.setTransitive(false);
|
||||
}
|
||||
});
|
||||
|
||||
if (project.getExtensions().getByType(LoomGradleExtension.class).isForge()) {
|
||||
Configuration forgeConfig = project.getConfigurations().maybeCreate(Constants.Configurations.FORGE);
|
||||
forgeConfig.setTransitive(false);
|
||||
@@ -236,15 +243,23 @@ public class AbstractPlugin implements Plugin<Project> {
|
||||
LoomDependencyManager dependencyManager = new LoomDependencyManager();
|
||||
extension.setDependencyManager(dependencyManager);
|
||||
|
||||
dependencyManager.addProvider(new MinecraftProvider(getProject()));
|
||||
|
||||
if (extension.isForge()) {
|
||||
dependencyManager.addProvider(new ForgeProvider(getProject()));
|
||||
dependencyManager.addProvider(new ForgeUserdevProvider(getProject()));
|
||||
}
|
||||
|
||||
if (extension.shouldGenerateSrgTiny()) {
|
||||
dependencyManager.addProvider(new SrgProvider(getProject()));
|
||||
}
|
||||
|
||||
if (extension.isForge()) {
|
||||
dependencyManager.addProvider(new McpConfigProvider(getProject()));
|
||||
dependencyManager.addProvider(new PatchProvider(getProject()));
|
||||
dependencyManager.addProvider(new ForgeUniversalProvider(getProject()));
|
||||
}
|
||||
|
||||
dependencyManager.addProvider(new MinecraftProvider(getProject()));
|
||||
|
||||
dependencyManager.addProvider(new MappingsProvider(getProject()));
|
||||
dependencyManager.addProvider(new LaunchProvider(getProject()));
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ import java.util.stream.Collectors;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.fabricmc.loom.providers.*;
|
||||
import org.cadixdev.lorenz.MappingSet;
|
||||
import org.cadixdev.mercury.Mercury;
|
||||
import org.gradle.api.Project;
|
||||
@@ -52,14 +53,6 @@ import org.gradle.api.plugins.BasePluginConvention;
|
||||
import net.fabricmc.loom.api.decompilers.LoomDecompiler;
|
||||
import net.fabricmc.loom.processors.JarProcessor;
|
||||
import net.fabricmc.loom.processors.JarProcessorManager;
|
||||
import net.fabricmc.loom.providers.ForgeProvider;
|
||||
import net.fabricmc.loom.providers.ForgeUniversalProvider;
|
||||
import net.fabricmc.loom.providers.ForgeUserdevProvider;
|
||||
import net.fabricmc.loom.providers.MappingsProvider;
|
||||
import net.fabricmc.loom.providers.MinecraftMappedProvider;
|
||||
import net.fabricmc.loom.providers.MinecraftProvider;
|
||||
import net.fabricmc.loom.providers.PatchProvider;
|
||||
import net.fabricmc.loom.providers.McpConfigProvider;
|
||||
import net.fabricmc.loom.util.function.LazyBool;
|
||||
import net.fabricmc.loom.util.LoomDependencyManager;
|
||||
import net.fabricmc.loom.util.mappings.MojangMappingsDependency;
|
||||
@@ -83,6 +76,8 @@ public class LoomGradleExtension {
|
||||
|
||||
final List<LoomDecompiler> decompilers = new ArrayList<>();
|
||||
private final List<JarProcessor> jarProcessors = new ArrayList<>();
|
||||
private boolean silentMojangMappingsLicense = false;
|
||||
public Boolean generateSrgTiny = null;
|
||||
|
||||
// Not to be set in the build.gradle
|
||||
private final Project project;
|
||||
@@ -94,7 +89,6 @@ public class LoomGradleExtension {
|
||||
private final LazyBool forge;
|
||||
private Set<File> mixinMappings = Collections.synchronizedSet(new HashSet<>());
|
||||
private final List<String> tasksBeforeRun = Collections.synchronizedList(new ArrayList<>());
|
||||
private boolean silentMojangMappingsLicense = false;
|
||||
|
||||
/**
|
||||
* Loom will generate a new genSources task (with a new name, based off of {@link LoomDecompiler#name()})
|
||||
@@ -397,6 +391,10 @@ public class LoomGradleExtension {
|
||||
public McpConfigProvider getMcpConfigProvider() {
|
||||
return getDependencyManager().getProvider(McpConfigProvider.class);
|
||||
}
|
||||
|
||||
public SrgProvider getSrgProvider() {
|
||||
return getDependencyManager().getProvider(SrgProvider.class);
|
||||
}
|
||||
|
||||
public ForgeUniversalProvider getForgeUniversalProvider() {
|
||||
return getDependencyManager().getProvider(ForgeUniversalProvider.class);
|
||||
@@ -428,7 +426,12 @@ public class LoomGradleExtension {
|
||||
|
||||
public String getRefmapName() {
|
||||
if (refmapName == null || refmapName.isEmpty()) {
|
||||
String defaultRefmapName = project.getConvention().getPlugin(BasePluginConvention.class).getArchivesBaseName() + "-refmap.json";
|
||||
String defaultRefmapName;
|
||||
if (isRootProject()) {
|
||||
defaultRefmapName = project.getConvention().getPlugin(BasePluginConvention.class).getArchivesBaseName() + "-refmap.json";
|
||||
} else {
|
||||
defaultRefmapName = project.getConvention().getPlugin(BasePluginConvention.class).getArchivesBaseName() + "-" + project.getPath().replaceFirst(":", "") + "-refmap.json";
|
||||
}
|
||||
project.getLogger().info("Could not find refmap definition, will be using default name: " + defaultRefmapName);
|
||||
refmapName = defaultRefmapName;
|
||||
}
|
||||
@@ -469,6 +472,14 @@ public class LoomGradleExtension {
|
||||
public boolean isForge() {
|
||||
return forge.getAsBoolean();
|
||||
}
|
||||
|
||||
public boolean shouldGenerateSrgTiny() {
|
||||
if (generateSrgTiny != null) {
|
||||
return generateSrgTiny;
|
||||
}
|
||||
|
||||
return isForge();
|
||||
}
|
||||
|
||||
// Creates a new file each time its called, this is then held onto later when remapping the output jar
|
||||
// Required as now when using parallel builds the old single file could be written by another sourceset compile task
|
||||
|
||||
@@ -75,6 +75,7 @@ public class ForgeUserdevProvider extends DependencyProvider {
|
||||
}
|
||||
|
||||
addDependency(json.get("mcp").getAsString(), Constants.Configurations.MCP_CONFIG);
|
||||
addDependency(json.get("mcp").getAsString(), Constants.Configurations.SRG);
|
||||
addDependency(json.get("universal").getAsString(), Constants.Configurations.FORGE_UNIVERSAL);
|
||||
|
||||
for (JsonElement lib : json.get("libraries").getAsJsonArray()) {
|
||||
|
||||
@@ -101,11 +101,11 @@ public class MappingsProvider extends DependencyProvider {
|
||||
}
|
||||
|
||||
public TinyTree getMappingsWithSrg() throws IOException {
|
||||
if (getExtension().isForge()) {
|
||||
if (getExtension().shouldGenerateSrgTiny()) {
|
||||
return MappingsCache.INSTANCE.get(tinyMappingsWithSrg);
|
||||
}
|
||||
|
||||
throw new UnsupportedOperationException("Not running with Forge support.");
|
||||
throw new UnsupportedOperationException("Not running with Forge support / Tiny srg support.");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -163,12 +163,18 @@ public class MappingsProvider extends DependencyProvider {
|
||||
if (!tinyMappingsJar.exists() || isRefreshDeps()) {
|
||||
ZipUtil.pack(new ZipEntrySource[] {new FileSource("mappings/mappings.tiny", tinyMappings)}, tinyMappingsJar);
|
||||
}
|
||||
|
||||
if (getExtension().isForge()) {
|
||||
|
||||
if (getExtension().shouldGenerateSrgTiny()) {
|
||||
if (Files.notExists(tinyMappingsWithSrg) || isRefreshDeps()) {
|
||||
SrgMerger.mergeSrg(getExtension().getMcpConfigProvider().getSrg().toPath(), tinyMappings.toPath(), tinyMappingsWithSrg, true);
|
||||
SrgMerger.mergeSrg(getExtension().getSrgProvider().getSrg().toPath(), tinyMappings.toPath(), tinyMappingsWithSrg, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (getExtension().isForge()) {
|
||||
if (!getExtension().shouldGenerateSrgTiny()) {
|
||||
throw new IllegalStateException("We have to generate srg tiny in a forge environment!");
|
||||
}
|
||||
|
||||
if (!mixinTinyMappingsWithSrg.exists() || isRefreshDeps()) {
|
||||
List<String> lines = new ArrayList<>(Files.readAllLines(tinyMappingsWithSrg));
|
||||
lines.set(0, lines.get(0).replace("intermediary", "yraidemretni").replace("srg", "intermediary"));
|
||||
|
||||
@@ -24,24 +24,18 @@
|
||||
|
||||
package net.fabricmc.loom.providers;
|
||||
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.DependencyProvider;
|
||||
import org.gradle.api.Project;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.nio.file.FileSystem;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.gradle.api.Project;
|
||||
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.DependencyProvider;
|
||||
|
||||
public class McpConfigProvider extends DependencyProvider {
|
||||
private File mcp;
|
||||
private File srg;
|
||||
|
||||
public McpConfigProvider(Project project) {
|
||||
super(project);
|
||||
@@ -51,7 +45,7 @@ public class McpConfigProvider extends DependencyProvider {
|
||||
public void provide(DependencyInfo dependency, Consumer<Runnable> postPopulationScheduler) throws Exception {
|
||||
init(dependency.getDependency().getVersion());
|
||||
|
||||
if (mcp.exists() && srg.exists() && !isRefreshDeps()) {
|
||||
if (mcp.exists() && !isRefreshDeps()) {
|
||||
return; // No work for us to do here
|
||||
}
|
||||
|
||||
@@ -60,27 +54,16 @@ public class McpConfigProvider extends DependencyProvider {
|
||||
if (!mcp.exists() || isRefreshDeps()) {
|
||||
Files.copy(mcpZip, mcp.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
|
||||
if (!srg.exists() || isRefreshDeps()) {
|
||||
try (FileSystem fs = FileSystems.newFileSystem(new URI("jar:" + mcpZip.toUri()), ImmutableMap.of("create", false))) {
|
||||
Files.copy(fs.getPath("config", "joined.tsrg"), srg.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void init(String version) {
|
||||
mcp = new File(getExtension().getUserCache(), "mcp-" + version + ".zip");
|
||||
srg = new File(getExtension().getUserCache(), "srg-" + version + ".tsrg");
|
||||
}
|
||||
|
||||
public File getMcp() {
|
||||
return mcp;
|
||||
}
|
||||
|
||||
public File getSrg() {
|
||||
return srg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTargetConfig() {
|
||||
return Constants.Configurations.MCP_CONFIG;
|
||||
|
||||
@@ -69,6 +69,10 @@ public class MinecraftProvider extends DependencyProvider {
|
||||
@Override
|
||||
public void provide(DependencyInfo dependency, Consumer<Runnable> postPopulationScheduler) throws Exception {
|
||||
minecraftVersion = dependency.getDependency().getVersion();
|
||||
|
||||
if (getExtension().shouldGenerateSrgTiny() && !getExtension().isForge()) {
|
||||
addDependency("de.oceanlabs.mcp:mcp_config:" + minecraftVersion, Constants.Configurations.SRG);
|
||||
}
|
||||
|
||||
boolean offline = getProject().getGradle().getStartParameter().isOffline();
|
||||
|
||||
|
||||
73
src/main/java/net/fabricmc/loom/providers/SrgProvider.java
Normal file
73
src/main/java/net/fabricmc/loom/providers/SrgProvider.java
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2016, 2017, 2018 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.providers;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.DependencyProvider;
|
||||
import org.gradle.api.Project;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.nio.file.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class SrgProvider extends DependencyProvider {
|
||||
private File srg;
|
||||
|
||||
public SrgProvider(Project project) {
|
||||
super(project);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void provide(DependencyInfo dependency, Consumer<Runnable> postPopulationScheduler) throws Exception {
|
||||
init(dependency.getDependency().getVersion());
|
||||
|
||||
if (srg.exists() && !isRefreshDeps()) {
|
||||
return; // No work for us to do here
|
||||
}
|
||||
|
||||
Path srgZip = dependency.resolveFile().orElseThrow(() -> new RuntimeException("Could not resolve srg")).toPath();
|
||||
|
||||
if (!srg.exists() || isRefreshDeps()) {
|
||||
try (FileSystem fs = FileSystems.newFileSystem(new URI("jar:" + srgZip.toUri()), ImmutableMap.of("create", false))) {
|
||||
Files.copy(fs.getPath("config", "joined.tsrg"), srg.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void init(String version) {
|
||||
srg = new File(getExtension().getUserCache(), "srg-" + version + ".tsrg");
|
||||
}
|
||||
|
||||
public File getSrg() {
|
||||
return srg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTargetConfig() {
|
||||
return Constants.Configurations.SRG;
|
||||
}
|
||||
}
|
||||
@@ -61,6 +61,7 @@ public class Constants {
|
||||
public static final String MINECRAFT_NAMED = "minecraftNamed";
|
||||
public static final String MAPPINGS = "mappings";
|
||||
public static final String MAPPINGS_FINAL = "mappingsFinal";
|
||||
public static final String SRG = "srg";
|
||||
public static final String MCP_CONFIG = "mcp";
|
||||
public static final String FORGE = "forge";
|
||||
public static final String FORGE_USERDEV = "forgeUserdev";
|
||||
|
||||
Reference in New Issue
Block a user