Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize the mappings file by removing superflous entries #13

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -781,13 +781,21 @@ subprojects {
}
}

def optimizeMappings = tasks.register('optimizeMappings', OptimizeJoinedSrg) {
input = file('joined.tsrg')
output = layout.buildDirectory.file('joined_stripped.tsrg')
}

task makeZip(type: Zip, dependsOn: [generateConfiguration]) {
archiveBaseName = rootProject.name
archiveVersion = project.version
destinationDirectory = file(PATH_BUILD + '/distributions')

from generateConfiguration
from(file('joined.tsrg')){ into 'config/' }
from(optimizeMappings.flatMap(OptimizeJoinedSrg::getOutput)){
into 'config/'
rename { "joined.tsrg" }
}

def patches = file('patches')
if (patches.exists()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package net.minecraftforge.mcpconfig.tasks

import net.neoforged.srgutils.IMappingBuilder
import net.neoforged.srgutils.IMappingFile
import org.gradle.api.DefaultTask
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction

/**
* Removes superflous entries from the mappings file.
* We only need method parameter mappings, so we can strip:
* - field mappings
* - methods without parameters
* - the SRG ID (for publication at least)
*/
abstract class OptimizeJoinedSrg extends DefaultTask {

@InputFile
abstract RegularFileProperty getInput()

@OutputFile
abstract RegularFileProperty getOutput()

@TaskAction
void optimize() {
var input = getInput().get().asFile
var output = getOutput().get().asFile

def srgInput = IMappingFile.load(input)

// Drop anything but parameter names
def srgOutput = IMappingBuilder.create("obf", "srg")
for (var srcClass : srgInput.classes) {
var dstClass = srgOutput.addClass(srcClass.original, "-")
for (var srcMethod : srcClass.methods) {
if (srcMethod.parameters.isEmpty()) {
continue // Skip methods with no parameters
}
var dstMethod = dstClass.method(srcMethod.descriptor, srcMethod.original, "-")
for (var srcParam in srcMethod.parameters) {
dstMethod.parameter(srcParam.index, "-", srcParam.mapped)
}
}
}
srgOutput.build().write(output.toPath(), IMappingFile.Format.TSRG2)
}

}
8 changes: 4 additions & 4 deletions versions/release/1.21.4/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
"args": ["--input", "{input}", "--output", "{output}", "--map", "{mappings}", "--cfg", "{libraries}", "--ann-fix", "--ids-fix", "--src-fix", "--record-fix", "--unfinal-params"]
},
"bundler_extract_jar": {
"version": "net.neoforged.installertools:installertools:2.1.2:fatjar",
"version": "net.neoforged.installertools:installertools:3.0.2:fatjar",
"args": ["--task", "bundler_extract", "--input", "{input}", "--output", "{output}", "--jar-only"]
},
"bundler_extract_libs": {
"version": "net.neoforged.installertools:installertools:2.1.2:fatjar",
"version": "net.neoforged.installertools:installertools:3.0.2:fatjar",
"args": ["--task", "bundler_extract", "--input", "{input}", "--output", "{output}", "--libraries"]
},
"mergemap": {
"version": "net.neoforged.installertools:installertools:2.1.2:fatjar",
"args": ["--task", "MERGE_MAPPING", "--left", "{mappings}", "--right", "{official}", "--right-names", "right,left", "--classes", "--fields", "--methods", "--output", "{output}"]
"version": "net.neoforged.installertools:installertools:3.0.2:fatjar",
"args": ["--task", "MERGE_MAPPING", "--base", "{official}", "--reverse-base", "--merge", "{mappings}", "--output", "{output}"]
},
"libraries": {
"client": ["com.google.code.findbugs:jsr305:3.0.2", "ca.weblite:java-objc-bridge:1.1", "org.jetbrains:annotations:26.0.1"],
Expand Down
Loading