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

Fix getKnownIndyBsms storing a set in a list without sorting #1225

Merged
merged 2 commits into from
Nov 29, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ public String getJarHash() {
return Checksum.sha1Hex(getCacheValue().getBytes(StandardCharsets.UTF_8)).substring(0, 10);
}

public String getSourceMappingsHash() {
return Checksum.sha1Hex(getCacheValue().getBytes(StandardCharsets.UTF_8));
}

public boolean requiresProcessingJar(Path jar) {
Objects.requireNonNull(jar);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

import org.gradle.api.Project;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.InputFiles;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
Expand All @@ -56,6 +56,7 @@

public class SourceMappingsService extends Service<SourceMappingsService.Options> {
public static final ServiceType<Options, SourceMappingsService> TYPE = new ServiceType<>(Options.class, SourceMappingsService.class);
private static final Logger LOGGER = LoggerFactory.getLogger(SourceMappingsService.class);

public interface Options extends Service.Options {
@InputFiles
Expand All @@ -71,64 +72,63 @@ public static Provider<Options> create(Project project) {
}

private static Path getMappings(Project project) {
LoomGradleExtension extension = LoomGradleExtension.get(project);
Path inputMappings = extension.getMappingConfiguration().tinyMappings;

MemoryMappingTree mappingTree = new MemoryMappingTree();
final LoomGradleExtension extension = LoomGradleExtension.get(project);
final MinecraftJarProcessorManager jarProcessor = MinecraftJarProcessorManager.create(project);

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);
if (jarProcessor == null) {
LOGGER.info("No jar processor found, not creating source mappings, using project mappings");
return extension.getMappingConfiguration().tinyMappings;
}

final List<GenerateSourcesTask.MappingsProcessor> mappingsProcessors = new ArrayList<>();
final Path dir = extension.getFiles().getProjectPersistentCache().toPath().resolve("source_mappings");
final Path path = dir.resolve(jarProcessor.getSourceMappingsHash() + ".tiny");

MinecraftJarProcessorManager minecraftJarProcessorManager = MinecraftJarProcessorManager.create(project);

if (minecraftJarProcessorManager != null) {
mappingsProcessors.add(mappings -> {
try (var serviceFactory = new ScopedServiceFactory()) {
final var configContext = new ConfigContextImpl(project, serviceFactory, extension);
return minecraftJarProcessorManager.processMappings(mappings, new MappingProcessorContextImpl(configContext));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
});
if (Files.exists(path) && !extension.refreshDeps()) {
LOGGER.debug("Using cached source mappings");
return path;
}

if (mappingsProcessors.isEmpty()) {
return inputMappings;
LOGGER.info("Creating source mappings for hash {}", jarProcessor.getSourceMappingsHash());

try {
Files.createDirectories(dir);
Files.deleteIfExists(path);
createMappings(project, jarProcessor, path);
} catch (IOException e) {
throw new UncheckedIOException("Failed to create source mappings", e);
}

boolean transformed = false;
return path;
}

for (GenerateSourcesTask.MappingsProcessor mappingsProcessor : mappingsProcessors) {
if (mappingsProcessor.transform(mappingTree)) {
transformed = true;
}
}
private static void createMappings(Project project, MinecraftJarProcessorManager jarProcessor, Path outputMappings) throws IOException {
LoomGradleExtension extension = LoomGradleExtension.get(project);
Path inputMappings = extension.getMappingConfiguration().tinyMappings;
MemoryMappingTree mappingTree = new MemoryMappingTree();

if (!transformed) {
return inputMappings;
try (Reader reader = Files.newBufferedReader(inputMappings, StandardCharsets.UTF_8)) {
MappingReader.read(reader, new MappingSourceNsSwitch(mappingTree, MappingsNamespace.INTERMEDIARY.toString()));
}

final Path outputMappings;
GenerateSourcesTask.MappingsProcessor mappingsProcessor = mappings -> {
try (var serviceFactory = new ScopedServiceFactory()) {
final var configContext = new ConfigContextImpl(project, serviceFactory, extension);
return jarProcessor.processMappings(mappings, new MappingProcessorContextImpl(configContext));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
};

try {
outputMappings = Files.createTempFile("loom-transitive-mappings", ".tiny");
} catch (IOException e) {
throw new RuntimeException("Failed to create temp file", e);
boolean transformed = mappingsProcessor.transform(mappingTree);

if (!transformed) {
LOGGER.info("No mappings processors transformed the mappings");
}

try (Writer writer = Files.newBufferedWriter(outputMappings, StandardCharsets.UTF_8)) {
var tiny2Writer = new Tiny2FileWriter(writer, false);
mappingTree.accept(new MappingSourceNsSwitch(tiny2Writer, MappingsNamespace.NAMED.toString()));
} catch (IOException e) {
throw new RuntimeException("Failed to write mappings", e);
}

return outputMappings;
}

public SourceMappingsService(Options options, ServiceFactory serviceFactory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static Provider<Options> createOptions(AbstractRemapJarTask remapJarTask)
options.getUselegacyMixinAP().set(legacyMixin);
options.getKotlinClasspathService().set(KotlinClasspathService.createOptions(project));
options.getClasspath().from(classpath);
options.getKnownIndyBsms().set(extension.getKnownIndyBsms());
options.getKnownIndyBsms().set(extension.getKnownIndyBsms().get().stream().sorted().toList());
options.getRemapperExtensions().set(extension.getRemapperExtensions());
});
}
Expand Down
Loading