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

Auto skip remap by default for Mojang-mapped NeoForge projects #176

Open
wants to merge 2 commits into
base: exp/1.5
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
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,15 @@ public final class FieldMigratedMappingConfiguration extends MappingConfiguratio
private Path rawTinyMappings;
private Path rawTinyMappingsWithSrg;
private Path rawTinyMappingsWithMojang;
private final boolean mojangMappedProject;

public FieldMigratedMappingConfiguration(String mappingsIdentifier, Path mappingsWorkingDir) {
public FieldMigratedMappingConfiguration(String mappingsIdentifier, Path mappingsWorkingDir, boolean mojangMappedProject) {
super(mappingsIdentifier, mappingsWorkingDir);
this.mojangMappedProject = mojangMappedProject;
}

public boolean isMojangMappedProject() {
return this.mojangMappedProject;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
import net.fabricmc.loom.api.mappings.layered.MappingLayer;
import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
import net.fabricmc.loom.configuration.providers.mappings.extras.unpick.UnpickLayer;
import net.fabricmc.loom.configuration.providers.mappings.mojmap.MojangMappingsSpec;
import net.fabricmc.loom.configuration.providers.mappings.parchment.ParchmentMappingsSpec;
import net.fabricmc.loom.configuration.providers.mappings.utils.AddConstructorMappingVisitor;
import net.fabricmc.loom.util.ZipUtils;
import net.fabricmc.mappingio.adapter.MappingDstNsReorder;
Expand Down Expand Up @@ -186,4 +188,10 @@ public void because(String s) {
public FileCollection getFiles() {
return project.files(resolve());
}

public boolean isMojangMappings() {
return this.layeredMappingSpec.layers().stream()
.skip(1) // see LayeredMappingSpecBuilderImpl
.allMatch(spec -> spec instanceof MojangMappingsSpec || spec instanceof ParchmentMappingsSpec);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,15 @@ public static MappingConfiguration create(Project project, SharedServiceManager
MappingConfiguration mappingConfiguration;

if (extension.isForgeLike()) {
mappingConfiguration = new FieldMigratedMappingConfiguration(mappingsIdentifier, workingDir);
final boolean mojmap;

if (dependency.getDependency() instanceof LayeredMappingsDependency layered) {
mojmap = layered.isMojangMappings();
} else {
mojmap = false;
}

mappingConfiguration = new FieldMigratedMappingConfiguration(mappingsIdentifier, workingDir, mojmap);
} else {
mappingConfiguration = new MappingConfiguration(mappingsIdentifier, workingDir);
}
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/net/fabricmc/loom/task/AbstractRemapJarTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
import net.fabricmc.loom.build.IntermediaryNamespaces;
import net.fabricmc.loom.configuration.providers.forge.FieldMigratedMappingConfiguration;
import net.fabricmc.loom.task.service.JarManifestService;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.ZipReprocessorUtil;
Expand Down Expand Up @@ -111,6 +112,11 @@ public abstract class AbstractRemapJarTask extends Jar {
@ApiStatus.Internal
public abstract Property<String> getJarType();

@ApiStatus.Experimental
@Input
@Optional
public abstract Property<Boolean> getAutoSkipRemap();

private final Provider<JarManifestService> jarManifestServiceProvider;

@Inject
Expand All @@ -125,6 +131,20 @@ public AbstractRemapJarTask() {
usesService(jarManifestServiceProvider);
}

protected final <P extends AbstractRemapParams> void autoSkipRemap(LoomGradleExtension extension, P params) {
if (getAutoSkipRemap().getOrElse(true) && shouldSkipRemap(extension)) {
params.getSourceNamespace().set(getTargetNamespace());
}
}

private boolean shouldSkipRemap(LoomGradleExtension extension) {
return extension.isNeoForge()
&& extension.getMappingConfiguration() instanceof FieldMigratedMappingConfiguration c
&& c.isMojangMappedProject()
&& MappingsNamespace.of(this.getSourceNamespace().get()) == MappingsNamespace.NAMED
&& MappingsNamespace.of(this.getTargetNamespace().get()) == MappingsNamespace.MOJANG;
}

public final <P extends AbstractRemapParams> void submitWork(Class<? extends AbstractRemapAction<P>> workAction, Action<P> action) {
final WorkQueue workQueue = getWorkerExecutor().noIsolation();

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/fabricmc/loom/task/RemapJarTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ public void run() {
final LoomGradleExtension extension = LoomGradleExtension.get(getProject());

submitWork(RemapAction.class, params -> {
autoSkipRemap(extension, params);

if (getAddNestedDependencies().get()) {
params.getNestedJars().from(getNestedJars());

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/net/fabricmc/loom/task/RemapSourcesJarTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.task.service.SourceRemapperService;
import net.fabricmc.loom.util.service.BuildSharedServiceManager;
import net.fabricmc.loom.util.service.UnsafeWorkQueueHelper;
Expand All @@ -58,7 +59,11 @@ public RemapSourcesJarTask() {

@TaskAction
public void run() {
final LoomGradleExtension extension = LoomGradleExtension.get(getProject());

submitWork(RemapSourcesAction.class, params -> {
autoSkipRemap(extension, params);

if (!params.namespacesMatch()) {
params.getSourcesRemapperServiceUuid().set(UnsafeWorkQueueHelper.create(SourceRemapperService.create(serviceManagerProvider.get().get(), this)));
}
Expand Down