Very many debof fixes (#1430)

This commit is contained in:
modmuss
2025-11-08 09:04:40 +00:00
committed by GitHub
parent f9dbaae926
commit 03d4fd077b
12 changed files with 130 additions and 30 deletions

View File

@@ -48,11 +48,14 @@ public final class VineflowerDecompiler implements LoomInternalDecompiler {
IFernflowerPreferences.REMOVE_SYNTHETIC, "1",
IFernflowerPreferences.LOG_LEVEL, "trace",
IFernflowerPreferences.THREADS, String.valueOf(context.numberOfThreads()),
IFernflowerPreferences.INDENT_STRING, "\t",
IFabricJavadocProvider.PROPERTY_NAME, new TinyJavadocProvider(context.javaDocs().toFile())
IFernflowerPreferences.INDENT_STRING, "\t"
)
);
if (context.javaDocs() != null) {
options.put(IFabricJavadocProvider.PROPERTY_NAME, new TinyJavadocProvider(context.javaDocs().toFile()));
}
options.putAll(context.options());
IResultSaver saver = new ThreadSafeResultSaver(sourcesDestination::toFile, linemapDestination::toFile);

View File

@@ -63,6 +63,7 @@ import net.fabricmc.loom.configuration.accesswidener.AccessWidenerJarProcessor;
import net.fabricmc.loom.configuration.ifaceinject.InterfaceInjectionProcessor;
import net.fabricmc.loom.configuration.processors.MinecraftJarProcessorManager;
import net.fabricmc.loom.configuration.processors.ModJavadocProcessor;
import net.fabricmc.loom.configuration.processors.speccontext.DebofConfiguration;
import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingsFactory;
import net.fabricmc.loom.configuration.providers.mappings.MappingConfiguration;
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftMetadataProvider;
@@ -103,6 +104,10 @@ public abstract class CompileConfiguration implements Runnable {
afterEvaluationWithService((serviceFactory) -> {
final ConfigContext configContext = new ConfigContextImpl(getProject(), serviceFactory, extension);
if (extension.disableObfuscation()) {
DebofConfiguration.create(getProject());
}
MinecraftSourceSets.get(getProject()).afterEvaluate(getProject());
final boolean previousRefreshDeps = extension.refreshDeps();

View File

@@ -45,7 +45,6 @@ import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.provider.Provider;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.configuration.processors.speccontext.DebofConfiguration;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.LoomVersions;
import net.fabricmc.loom.util.gradle.SourceSetHelper;
@@ -162,10 +161,6 @@ public abstract class LoomConfigurations implements Runnable {
extendsFrom(Constants.Configurations.MINECRAFT_TEST_CLIENT_RUNTIME_LIBRARIES, Constants.Configurations.LOADER_DEPENDENCIES);
register(Constants.Configurations.PRODUCTION_RUNTIME_MODS, Role.RESOLVABLE);
if (extension.disableObfuscation()) {
DebofConfiguration.create(getProject());
}
}
private NamedDomainObjectProvider<Configuration> register(String name, Role role) {

View File

@@ -73,6 +73,11 @@ public final class RemapConfigurations {
public static void configureClientConfigurations(Project project, SourceSet clientSourceSet) {
final LoomGradleExtension extension = LoomGradleExtension.get(project);
if (extension.disableObfuscation()) {
return;
}
extension.createRemapConfigurations(clientSourceSet);
final NamedDomainObjectList<RemapConfigurationSettings> configurations = extension.getRemapConfigurations();

View File

@@ -76,7 +76,9 @@ abstract class FabricApiAbstractSourceSet {
mod.sourceSet(getSourceSetName());
});
extension.createRemapConfigurations(sourceSets.getByName(getSourceSetName()));
if (!extension.disableObfuscation()) {
extension.createRemapConfigurations(sourceSets.getByName(getSourceSetName()));
}
return sourceSet;
}

View File

@@ -87,7 +87,12 @@ public record DebofConfiguration(String name, List<Function<SourceSet, String>>
LoomConfigurations.Role.RESOLVABLE.apply(c);
for (Function<SourceSet, String> configProvider : configurationFunctions()) {
Configuration sourceConfig = configurations.getByName(configProvider.apply(sourceSet));
Configuration sourceConfig = configurations.findByName(configProvider.apply(sourceSet));
if (sourceConfig == null) {
continue;
}
c.extendsFrom(sourceConfig);
}
});

View File

@@ -25,12 +25,15 @@
package net.fabricmc.loom.configuration.processors.speccontext;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
@@ -101,7 +104,7 @@ public record DeobfSpecContext(List<FabricModJson> modDependencies,
for (File artifact : artifacts) {
futures.add(fmjCache.get(artifact.toPath().toAbsolutePath().toString(), () -> {
return FabricModJsonFactory.createFromZipOptional(artifact.toPath())
return getMod(artifact.toPath())
.map(List::of)
.orElseGet(List::of);
}));
@@ -125,7 +128,7 @@ public record DeobfSpecContext(List<FabricModJson> modDependencies,
for (File artifact : artifacts) {
futures.add(fmjCache.get(artifact.toPath().toAbsolutePath().toString(), () -> {
return FabricModJsonFactory.createFromZipOptional(artifact.toPath())
return getMod(artifact.toPath())
.map(List::of)
.orElseGet(List::of);
}));
@@ -136,6 +139,14 @@ public record DeobfSpecContext(List<FabricModJson> modDependencies,
.collect(HashSet::new, Set::add, Set::addAll);
}
private static Optional<FabricModJson> getMod(Path path) {
if (Files.isRegularFile(path)) {
return FabricModJsonFactory.createFromZipOptional(path);
}
return Optional.empty();
}
private static List<FabricModJson> getMods(Map<String, FabricModJson> mods, Set<String> ids) {
List<FabricModJson> result = new ArrayList<>();

View File

@@ -174,6 +174,7 @@ public abstract class LoomGradleExtensionImpl extends LoomGradleExtensionApiImpl
@Override
public MappingConfiguration getMappingConfiguration() {
if (disableObfuscation()) {
project.getLogger().lifecycle("help", new RuntimeException());
throw new UnsupportedOperationException("Cannot get mappings configuration in a non-obfuscated environment");
}

View File

@@ -70,6 +70,7 @@ import org.gradle.workers.internal.WorkerDaemonClientsManager;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.api.decompilers.DecompilationMetadata;
import net.fabricmc.loom.api.decompilers.DecompilerOptions;
import net.fabricmc.loom.api.decompilers.LoomDecompiler;
@@ -140,6 +141,7 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask {
// Internal inputs
@ApiStatus.Internal
@Nested
@Optional
protected abstract Property<SourceMappingsService.Options> getMappings();
// Internal outputs
@@ -221,15 +223,16 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask {
getUseCache().convention(true);
getResetCache().convention(getExtension().refreshDeps());
getMappings().set(SourceMappingsService.create(getProject()));
if (!LoomGradleExtension.get(getProject()).disableObfuscation()) {
getMappings().set(SourceMappingsService.create(getProject()));
getUnpickOptions().set(UnpickService.createOptions(this));
}
getMaxCachedFiles().set(GradleUtils.getIntegerPropertyProvider(getProject(), Constants.Properties.DECOMPILE_CACHE_MAX_FILES).orElse(50_000));
getMaxCacheFileAge().set(GradleUtils.getIntegerPropertyProvider(getProject(), Constants.Properties.DECOMPILE_CACHE_MAX_AGE).orElse(90));
getDaemonUtilsContext().set(getProject().getObjects().newInstance(DaemonUtils.Context.class, getProject()));
getUnpickOptions().set(UnpickService.createOptions(this));
mustRunAfter(getProject().getTasks().withType(AbstractRemapJarTask.class));
}
@@ -407,11 +410,13 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask {
sj.add(unpick.getUnpickCacheKey());
}
SourceMappingsService mappingsService = serviceFactory.get(getMappings());
String mappingsHash = mappingsService.getProcessorHash();
if (getMappings().isPresent()) {
SourceMappingsService mappingsService = serviceFactory.get(getMappings());
String mappingsHash = mappingsService.getProcessorHash();
if (mappingsHash != null) {
sj.add(mappingsHash);
if (mappingsHash != null) {
sj.add(mappingsHash);
}
}
getLogger().info("Decompile cache data: {}", sj);
@@ -484,7 +489,10 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask {
params.getInputJar().set(inputJar.toFile());
params.getOutputJar().set(outputJar.toFile());
params.getLinemapFile().set(linemapFile.toFile());
params.getMappings().set(getMappings());
if (getMappings().isPresent()) {
params.getMappings().set(getMappings());
}
if (ipcServer != null) {
params.getIPCPath().set(ipcServer.getPath().toFile());
@@ -587,11 +595,16 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask {
}
try (var serviceFactory = new ScopedServiceFactory()) {
final SourceMappingsService mappingsService = serviceFactory.get(getParameters().getMappings());
Path javaDocs = null;
if (getParameters().getMappings().isPresent()) {
final SourceMappingsService mappingsService = serviceFactory.get(getParameters().getMappings());
javaDocs = mappingsService.getMappingsFile();
}
final var metadata = new DecompilationMetadata(
decompilerOptions.maxThreads(),
mappingsService.getMappingsFile(),
javaDocs,
getLibraries(),
logger,
decompilerOptions.options()

View File

@@ -53,14 +53,14 @@ import net.fabricmc.loom.util.ZipUtils;
public class ManifestModificationAction implements Action<Task>, Serializable {
private final Provider<JarManifestService> manifestService;
private final String targetNamespace;
private final boolean areEnvironmentSourceSetsSplit;
private final List<String> clientOnlyEntries;
private final Provider<Boolean> areEnvironmentSourceSetsSplit;
private final Provider<List<String>> clientOnlyEntries;
public ManifestModificationAction(
Provider<JarManifestService> manifestService,
String targetNamespace,
boolean areEnvironmentSourceSetsSplit,
List<String> clientOnlyEntries) {
Provider<Boolean> areEnvironmentSourceSetsSplit,
Provider<List<String>> clientOnlyEntries) {
this.manifestService = manifestService;
this.targetNamespace = targetNamespace;
this.areEnvironmentSourceSetsSplit = areEnvironmentSourceSetsSplit;
@@ -86,13 +86,13 @@ public class ManifestModificationAction implements Action<Task>, Serializable {
manifestAttributes.put(Constants.Manifest.MAPPING_NAMESPACE, targetNamespace);
// Set split environment flag if source sets are split (even for common-only jars)
if (areEnvironmentSourceSetsSplit) {
if (areEnvironmentSourceSetsSplit.get()) {
manifestAttributes.put(Constants.Manifest.SPLIT_ENV, "true");
}
// Add client-only entries list if present
if (clientOnlyEntries != null && !clientOnlyEntries.isEmpty()) {
manifestAttributes.put(Constants.Manifest.CLIENT_ENTRIES, String.join(";", clientOnlyEntries));
if (clientOnlyEntries != null && !clientOnlyEntries.get().isEmpty()) {
manifestAttributes.put(Constants.Manifest.CLIENT_ENTRIES, String.join(";", clientOnlyEntries.get()));
}
int count = ZipUtils.transform(jarFile.toPath(), Map.of(Constants.Manifest.PATH, bytes -> {

View File

@@ -71,8 +71,8 @@ public class NonRemappedJarTaskConfiguration {
task.doLast(new ManifestModificationAction(
manifestServiceProvider,
"official",
extension.areEnvironmentSourceSetsSplit(),
getClientOnlyEntries()
project.provider(extension::areEnvironmentSourceSetsSplit),
project.provider(this::getClientOnlyEntries)
));
task.usesService(manifestServiceProvider);

View File

@@ -71,4 +71,64 @@ class SimpleDebofTest extends Specification implements GradleProjectTestTrait {
result.task(":build").outcome == SUCCESS
result.task(":configureClientLaunch").outcome == SUCCESS
}
@Unroll
def "split build"() {
setup:
def gradle = gradleProject(project: "minimalBaseNoRemap", version: PRE_RELEASE_GRADLE)
gradle.buildGradle << '''
loom {
splitEnvironmentSourceSets()
}
dependencies {
minecraft 'com.mojang:minecraft:25w45a_unobfuscated'
implementation "net.fabricmc:fabric-loader:0.17.3"
}
'''
def sourceFile = new File(gradle.projectDir, "src/main/java/example/Test.java")
sourceFile.parentFile.mkdirs()
@Language("JAVA") String src = """
package example;
import net.minecraft.resources.Identifier;
import org.spongepowered.asm.mixin.Mixin; // Make sure we applied loaders deps via the installer data
public class Test {
public static void main(String[] args) {
Identifier id = Identifier.fromNamespaceAndPath("loom", "test");
}
}
"""
sourceFile.text = src
when:
def result = gradle.run(task: "build")
then:
result.task(":build").outcome == SUCCESS
}
@Unroll
def "genSources split build"() {
setup:
def gradle = gradleProject(project: "minimalBaseNoRemap", version: PRE_RELEASE_GRADLE)
gradle.buildGradle << '''
loom {
splitEnvironmentSourceSets()
}
dependencies {
minecraft 'com.mojang:minecraft:25w45a_unobfuscated'
implementation "net.fabricmc:fabric-loader:0.17.3"
}
'''
when:
def result = gradle.run(task: "genSources")
then:
result.task(":genSources").outcome == SUCCESS
}
}