broken-refmap-remapping

This commit is contained in:
moehreag 2024-10-28 14:15:43 +01:00
parent 54fb5fe91e
commit cbdfac65fc
5 changed files with 88 additions and 55 deletions

View file

@ -7,7 +7,6 @@ import java.io.IOException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
import dev.frogmc.thyroxine.api.data.MappingBundle; import dev.frogmc.thyroxine.api.data.MappingBundle;
import dev.frogmc.thyroxine.api.data.MappingData; import dev.frogmc.thyroxine.api.data.MappingData;
@ -21,23 +20,32 @@ public class FrogMappingProvider extends MappingProvider {
private final Map<MappingMethod, MappingMethod> methodMap = getMap("methodMap"); private final Map<MappingMethod, MappingMethod> methodMap = getMap("methodMap");
private final Map<MappingField, MappingField> fieldMap = getMap("fieldMap"); private final Map<MappingField, MappingField> fieldMap = getMap("fieldMap");
private final Map<String, String> classMap = getMap("classMap"); private final Map<String, String> classMap = getMap("classMap");
public FrogMappingProvider(Messager messager, Filer filer) { public FrogMappingProvider(Messager messager, Filer filer, String from, String to) {
super(messager, filer); super(messager, filer);
} }
@Override @Override
public void read(File input) throws IOException { public void read(File input) throws IOException {
if (!input.getName().endsWith(".tiny")) {
return;
}
MappingBundle bundle = TinyV2Parser.parse(Files.readString(input.toPath())); MappingBundle bundle = TinyV2Parser.parse(Files.readString(input.toPath()));
MappingData data = bundle.data().getFirst(); MappingData data = bundle.data().getFirst();
classMap.putAll(data.classes()); classMap.putAll(data.classes());
fieldMap.putAll(data.fields().entrySet().stream().collect(Collectors.toMap( data.fields().forEach((key, value) -> {
e -> new MappingField(e.getKey().owner(), e.getKey().name(), e.getKey().descriptor()), fieldMap.put(
e -> new MappingField(e.getKey().owner(), e.getKey().name())))); new MappingField(key.owner(), key.name(), key.descriptor()),
methodMap.putAll(data.methods().entrySet().stream().collect(Collectors.toMap( new MappingField(classMap.get(key.owner()), value, key.descriptor())
e -> new MappingMethod(e.getKey().owner(), e.getKey().name(), e.getKey().descriptor()), );
e -> new MappingMethod(e.getKey().owner(), e.getKey().name())))); });
data.methods().forEach((key, value) -> {
methodMap.put(
new MappingMethod(key.owner(), key.name(), key.descriptor()),
new MappingMethod(classMap.get(key.owner()), value, key.descriptor())
);
});
} }
// Mixin has guava shadowed which means the actual type is not something we can import // Mixin has guava shadowed which means the actual type is not something we can import

View file

@ -15,7 +15,8 @@ public class FrogObfuscationEnvironment extends ObfuscationEnvironment {
@Override @Override
protected IMappingProvider getMappingProvider(Messager messager, Filer filer) { protected IMappingProvider getMappingProvider(Messager messager, Filer filer) {
return new FrogMappingProvider(messager, filer); String[] key = type.getKey().split(":");
return new FrogMappingProvider(messager, filer, key[0], key[1]);
} }
@Override @Override

View file

@ -25,6 +25,7 @@ import dev.frogmc.thyroxine.writer.tiny.TinyV2Writer
import net.fabricmc.fernflower.api.IFabricJavadocProvider import net.fabricmc.fernflower.api.IFabricJavadocProvider
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.logging.LogLevel
import org.gradle.api.plugins.JavaBasePlugin import org.gradle.api.plugins.JavaBasePlugin
import org.gradle.api.plugins.JavaPlugin import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.tasks.Delete import org.gradle.api.tasks.Delete
@ -142,7 +143,7 @@ class PhytotelmaPlugin : Plugin<Project> {
projectData.remappedGameJarPath!!.resolveSibling( projectData.remappedGameJarPath!!.resolveSibling(
fileName.substring( fileName.substring(
0, 0,
fileName.lastIndexOf("-") fileName.lastIndexOf(".")
) + "-sources.jar" ) + "-sources.jar"
) )
if (output.exists()) { if (output.exists()) {
@ -150,7 +151,7 @@ class PhytotelmaPlugin : Plugin<Project> {
output.deleteExisting() output.deleteExisting()
} }
val options = mutableMapOf<String, Any>() val options = mutableMapOf<String, Any>()
println("Preparing Parchment...") println("Preparing javadocs...")
val javadocs = ProjectStorage.get(project).mappings!! val javadocs = ProjectStorage.get(project).mappings!!
options[IFabricJavadocProvider.PROPERTY_NAME] = options[IFabricJavadocProvider.PROPERTY_NAME] =
FrogJavadocProvider(javadocs.get(ProjectStorage.get(project).targetNamespace)) FrogJavadocProvider(javadocs.get(ProjectStorage.get(project).targetNamespace))

View file

@ -6,6 +6,8 @@ import dev.frogmc.phytotelma.ProjectStorage
import dev.frogmc.phytotelma.VersionChecker import dev.frogmc.phytotelma.VersionChecker
import dev.frogmc.phytotelma.accesswidener.AccessWidener import dev.frogmc.phytotelma.accesswidener.AccessWidener
import dev.frogmc.phytotelma.ext.datagen.DatagenExtension import dev.frogmc.phytotelma.ext.datagen.DatagenExtension
import dev.frogmc.phytotelma.mappings.renameDstNamespace
import dev.frogmc.phytotelma.mappings.renameNamespaces
import dev.frogmc.phytotelma.run.AssetDownloader import dev.frogmc.phytotelma.run.AssetDownloader
import dev.frogmc.phytotelma.run.RunConfigGenerator import dev.frogmc.phytotelma.run.RunConfigGenerator
import dev.frogmc.phytotelma.run.RuntimeAccessFixVisitor import dev.frogmc.phytotelma.run.RuntimeAccessFixVisitor
@ -13,7 +15,9 @@ import dev.frogmc.phytotelma.run.datagen.DatagenConfigGenerator
import dev.frogmc.phytotelma.run.datagen.DatagenTask import dev.frogmc.phytotelma.run.datagen.DatagenTask
import dev.frogmc.thyroxine.RemappingStep import dev.frogmc.thyroxine.RemappingStep
import dev.frogmc.thyroxine.Thyroxine import dev.frogmc.thyroxine.Thyroxine
import dev.frogmc.thyroxine.api.data.MappingBundle
import dev.frogmc.thyroxine.api.data.MappingData import dev.frogmc.thyroxine.api.data.MappingData
import dev.frogmc.thyroxine.provider.MojmapProvider
import dev.frogmc.thyroxine.writer.tiny.TinyV2Writer import dev.frogmc.thyroxine.writer.tiny.TinyV2Writer
import org.gradle.api.Action import org.gradle.api.Action
import org.gradle.api.Project import org.gradle.api.Project
@ -108,10 +112,21 @@ abstract class PhytotelmaGradleExtensionImpl @Inject constructor(
VersionChecker.saveMergedPomFile(version, mergedJar.parent) VersionChecker.saveMergedPomFile(version, mergedJar.parent)
println("Writing mappings...") println("Writing mappings...")
if (projectData.intermediaryNs != Constants.MOJMAP_NAMESPACE) {
TinyV2Writer.write( TinyV2Writer.write(
mappings, MappingBundle(mappings.forNamespaces(mcConf.targetNamespace, projectData.intermediaryNs))
.renameNamespaces("dev", projectData.intermediaryNs!!),
ProjectStorage.get(project).localCacheDir?.resolve("mappings.tiny")?.writer() ProjectStorage.get(project).localCacheDir?.resolve("mappings.tiny")?.writer()
) )
} else {
TinyV2Writer.write(
MappingBundle.merge(
mappings.reverse(),
mcConf.mojmap().get().reverse().renameDstNamespace("moj")
),
ProjectStorage.get(project).localCacheDir?.resolve("mappings.tiny")?.writer()
)
}
projectData.targetNamespace = mcConf.targetNamespace projectData.targetNamespace = mcConf.targetNamespace
@ -168,27 +183,30 @@ abstract class PhytotelmaGradleExtensionImpl @Inject constructor(
error("No loader version provided!") error("No loader version provided!")
} }
project.dependencies.add(Constants.MINECRAFT_CONFIGURATION, "dev.frogmc:frogloader:${conf.version.get()}") project.dependencies.add(Constants.MINECRAFT_CONFIGURATION, "dev.frogmc:frogloader:${conf.version.get()}")
project.afterEvaluate {
project.logger.warn("doing ap stuff")
project.configurations.getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME) project.configurations.getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME)
.dependencies.find { it.group.equals("net.fabricmc") && it.name.equals("sponge-mixin") } .resolvedConfiguration.resolvedArtifacts.map { it.moduleVersion.id }
.find { it.group.equals("net.fabricmc") && it.name.equals("sponge-mixin") }
?.let { mixinDep -> ?.let { mixinDep ->
project.dependencies.add(
JavaPlugin.ANNOTATION_PROCESSOR_CONFIGURATION_NAME,
mixinDep.group + ":" + mixinDep.name + ":" + mixinDep.version
)
project.dependencies.add( project.dependencies.add(
JavaPlugin.ANNOTATION_PROCESSOR_CONFIGURATION_NAME, JavaPlugin.ANNOTATION_PROCESSOR_CONFIGURATION_NAME,
"dev.frogmc.phytotelma:frog-mixin-obfuscation:" + PhytotelmaPlugin::class.java.`package`.implementationVersion "dev.frogmc.phytotelma:frog-mixin-obfuscation:" + PhytotelmaPlugin::class.java.`package`.implementationVersion
) )
project.dependencies.add(
JavaPlugin.ANNOTATION_PROCESSOR_CONFIGURATION_NAME,
mixinDep.group + ":" + mixinDep.name + ":" + mixinDep.version
)
val options = mapOf( val options = mapOf(
"defaultObfuscationEnv" to "dev:" + ProjectStorage.get(project).targetNamespace, "defaultObfuscationEnv" to "dev:" + ProjectStorage.get(project).intermediaryNs,
"quiet" to "true", "quiet" to "true",
"inMapFileDevMoj" to ProjectStorage.get(project).localCacheDir!!.resolve("mappings.tiny"), "inMapFileDevMoj" to ProjectStorage.get(project).localCacheDir!!.resolve("mappings.tiny"),
"outMapFileDevMoj" to project.layout.buildDirectory.file( "outMapFileDevMoj" to project.layout.buildDirectory.file(
"mixin-out-" + ProjectStorage.get(project).mappingsName + "_" + "mixin-out-" + (ProjectStorage.get(project).mappingsName + "_" +
project.extensions.getByType(JavaPluginExtension::class.java).sourceSets.getByName( project.extensions.getByType(JavaPluginExtension::class.java).sourceSets.getByName(
SourceSet.MAIN_SOURCE_SET_NAME SourceSet.MAIN_SOURCE_SET_NAME
) ).name
) ).replace("[(). +,]".toRegex(), ""))
.get().asFile, .get().asFile,
"inMapExtraFilesDevMoj" to ProjectStorage.get(project).remappedGameJarPath, "inMapExtraFilesDevMoj" to ProjectStorage.get(project).remappedGameJarPath,
) )
@ -202,13 +220,14 @@ abstract class PhytotelmaGradleExtensionImpl @Inject constructor(
task.options.compilerArgs.addAll(options task.options.compilerArgs.addAll(options
.map { "-A" + it.key + "=" + it.value } .map { "-A" + it.key + "=" + it.value }
.plus( .plus(
"-AoutRefmapFile=" + task.destinationDirectory.asFile.get() "-AoutRefMapFile=" + task.destinationDirectory.asFile.get()
.resolve(project.name + "-refmap.json") .resolve(project.name + "-refmap.json")
)) ))
} }
} }
} }
} }
}
override fun froglib(action: Action<VersionConfiguration>) { override fun froglib(action: Action<VersionConfiguration>) {
val conf = objects.newInstance(VersionConfiguration::class.java) val conf = objects.newInstance(VersionConfiguration::class.java)

View file

@ -12,17 +12,21 @@ class FrogJavadocProvider(data: DocumentationData) : IFabricJavadocProvider {
private val classMap = data.classes.stream().collect(Collectors.toMap({ it.name() }, { it })) private val classMap = data.classes.stream().collect(Collectors.toMap({ it.name() }, { it }))
override fun getClassDoc(structClass: StructClass): String? { override fun getClassDoc(structClass: StructClass): String? {
return classMap[structClass.qualifiedName]?.javadoc?.joinToString("\n") if (structClass.qualifiedName.contains("package-info")) {
println(structClass)
}
println(structClass)
return classMap[structClass.qualifiedName]?.javadoc?.takeUnless { it.isEmpty() }?.joinToString("\n")
} }
override fun getFieldDoc(structClass: StructClass, structField: StructField): String? { override fun getFieldDoc(structClass: StructClass, structField: StructField): String? {
return classMap[structClass.qualifiedName] return classMap[structClass.qualifiedName]
?.getField(structField.name, structField.descriptor) ?.getField(structField.name, structField.descriptor)
?.orElse(null)?.javadoc?.joinToString("\n") ?.orElse(null)?.javadoc?.takeUnless { it.isEmpty() }?.joinToString("\n")
} }
override fun getMethodDoc(structClass: StructClass, structMethod: StructMethod): String? { override fun getMethodDoc(structClass: StructClass, structMethod: StructMethod): String? {
return classMap[structClass.qualifiedName]?.getMethod(structMethod.name, structMethod.descriptor) return classMap[structClass.qualifiedName]?.getMethod(structMethod.name, structMethod.descriptor)
?.orElse(null)?.javadoc?.joinToString("\n") ?.orElse(null)?.javadoc?.takeUnless { it.isEmpty() }?.joinToString("\n")
} }
} }