Kotlin metadata annotation remapping (#573)

Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com>
This commit is contained in:
modmuss50
2022-01-16 23:48:36 +00:00
committed by GitHub
parent 421b41ebc7
commit d71af0cfd7
21 changed files with 984 additions and 46 deletions

View File

@@ -46,6 +46,7 @@ import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
import net.fabricmc.loom.configuration.RemappedConfigurationEntry;
import net.fabricmc.loom.configuration.processors.dependency.ModDependencyInfo;
import net.fabricmc.loom.configuration.providers.mappings.MappingsProviderImpl;
import net.fabricmc.loom.kotlin.remapping.KotlinMetadataTinyRemapperExtension;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.TinyRemapperHelper;
import net.fabricmc.loom.util.ZipUtils;
@@ -134,16 +135,22 @@ public class ModProcessor {
private void remapJars(List<ModDependencyInfo> remapList) throws IOException {
final LoomGradleExtension extension = LoomGradleExtension.get(project);
final MappingsProviderImpl mappingsProvider = extension.getMappingsProvider();
final boolean useKotlinExtension = project.getPluginManager().hasPlugin("org.jetbrains.kotlin.jvm");
Path[] mcDeps = project.getConfigurations().getByName(Constants.Configurations.LOADER_DEPENDENCIES).getFiles()
.stream().map(File::toPath).toArray(Path[]::new);
project.getLogger().lifecycle(":remapping " + remapList.size() + " mods (TinyRemapper, " + fromM + " -> " + toM + ")");
final TinyRemapper remapper = TinyRemapper.newRemapper()
TinyRemapper.Builder builder = TinyRemapper.newRemapper()
.withMappings(TinyRemapperHelper.create(mappingsProvider.getMappings(), fromM, toM, false))
.renameInvalidLocals(false)
.build();
.renameInvalidLocals(false);
if (useKotlinExtension) {
builder.extension(KotlinMetadataTinyRemapperExtension.INSTANCE);
}
final TinyRemapper remapper = builder.build();
for (Path minecraftJar : extension.getMinecraftJars(MappingsNamespace.INTERMEDIARY)) {
remapper.readClassPathAsync(minecraftJar);

View File

@@ -37,6 +37,7 @@ import java.util.Objects;
import org.gradle.api.Project;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.kotlin.remapping.KotlinMetadataTinyRemapperExtension;
import net.fabricmc.loom.task.AbstractRemapJarTask;
import net.fabricmc.loom.util.service.SharedService;
import net.fabricmc.loom.util.service.SharedServiceManager;
@@ -52,9 +53,10 @@ public class TinyRemapperService implements SharedService {
final LoomGradleExtension extension = LoomGradleExtension.get(project);
final SharedServiceManager sharedServiceManager = SharedServiceManager.get(project);
final boolean legacyMixin = extension.getMixin().getUseLegacyMixinAp().get();
final boolean useKotlinExtension = project.getPluginManager().hasPlugin("org.jetbrains.kotlin.jvm");
// Generates an id that is used to share the remapper across projects. This tasks in the remap jar task name to handle custom remap jar tasks separately.
final String id = extension.getMappingsProvider().getBuildServiceName("remapJarService", from, to) + ":" + remapJarTask.getName();
final String id = extension.getMappingsProvider().getBuildServiceName("remapJarService", from, to) + ":" + remapJarTask.getName() + (useKotlinExtension ? ":kotlin" : "");
TinyRemapperService service = sharedServiceManager.getOrCreateService(id, () -> {
List<IMappingProvider> mappings = new ArrayList<>();
@@ -64,7 +66,7 @@ public class TinyRemapperService implements SharedService {
mappings.add(MixinMappingsService.getService(SharedServiceManager.get(project)).getMappingProvider(from, to));
}
return new TinyRemapperService(mappings, !legacyMixin);
return new TinyRemapperService(mappings, !legacyMixin, useKotlinExtension);
});
service.readClasspath(remapJarTask.getClasspath().getFiles().stream().map(File::toPath).toList());
@@ -78,7 +80,7 @@ public class TinyRemapperService implements SharedService {
// Set to true once remapping has started, once set no inputs can be read.
private boolean isRemapping = false;
public TinyRemapperService(List<IMappingProvider> mappings, boolean useMixinExtension) {
public TinyRemapperService(List<IMappingProvider> mappings, boolean useMixinExtension, boolean useKotlinExtension) {
TinyRemapper.Builder builder = TinyRemapper.newRemapper();
for (IMappingProvider provider : mappings) {
@@ -89,6 +91,10 @@ public class TinyRemapperService implements SharedService {
builder.extension(new net.fabricmc.tinyremapper.extension.mixin.MixinExtension());
}
if (useKotlinExtension) {
builder.extension(KotlinMetadataTinyRemapperExtension.INSTANCE);
}
tinyRemapper = builder.build();
}