Skip to content

Commit

Permalink
feat: skip merging mappings on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus8448 committed Jul 6, 2024
1 parent 2a55392 commit a2a6356
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 19 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ plugin.group=dev.galacticraft
plugin.name=Mojarn
plugin.id=mojarn
plugin.description=Mixes official and yarn mappings for better argument names
plugin.version=0.3.0
plugin.version=0.4.0

loom.version=1.7.1
loom.version=1.7.2
mapping-io.version=0.6.1
junit.version=5.10.2
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,42 @@
public interface MojarnMappingsSpecBuilder {
/**
* Whether to remap arguments with class types.
* @param remapArguments Whether to map arguments with class types
* @return This builder
* @param remapArguments whether to map arguments with class types
* @return this builder
*/
MojarnMappingsSpecBuilder remapArguments(boolean remapArguments);

/**
* Whether to remap partial argument matches with class types.
* @param partialMatch Whether to remap partial argument matches with class types
* @return This builder
* @param partialMatch whether to remap partial argument matches with class types
* @return this builder
*/
MojarnMappingsSpecBuilder partialMatch(boolean partialMatch);

/**
* Disable mapping when the class name is different.
* @param skipDifferent Whether to skip mapping when the class name is different
* @return This builder
* @param skipDifferent whether to skip mapping when the class name is different
* @return this builder
*/
MojarnMappingsSpecBuilder skipDifferent(boolean skipDifferent);

/**
* Whether to map variables.
* @param mapVariables Whether to map variables
* @return This builder
* @param mapVariables whether to map variables
* @return this builder
*/
MojarnMappingsSpecBuilder mapVariables(boolean mapVariables);

/**
* Whether to disable mojarn when in a CI environment.
* @param skipCI whether to disable mojarn when in a CI environment
* @return this builder
*/
MojarnMappingsSpecBuilder skipCI(boolean skipCI);

/**
* Whether the mapping file is an Enigma mappings file (forwarded to file mapping builder).
* @return This builder
* @return this builder
* @see FileMappingsSpecBuilder#enigmaMappings()
*/
MojarnMappingsSpecBuilder fileIsEnigma();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ public Dependency mappings(Object file, Action<? super MojarnMappingsSpecBuilder
FileMappingsSpec fileSpec = fileBuilder.build();
MojangMappingsSpec mojangSpec = MojangMappingsSpecBuilderImpl.builder().build();

return loom.layered(b -> b.addLayer(new MojarnMappingsSpec(new IntermediaryMappingsSpec(), mojangSpec, fileSpec, builder.remapArguments, builder.partialMatch, builder.skipDifferent, builder.mapVariables)));
return loom.layered(b -> b.addLayer(new MojarnMappingsSpec(new IntermediaryMappingsSpec(), mojangSpec, fileSpec, builder.remapArguments, builder.partialMatch, builder.skipDifferent, builder.skipCI, builder.mapVariables)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,17 @@ public class MojarnMappingsLayer implements MappingLayer {
private final boolean partialMatch;
private final boolean skipDifferent;
private final boolean mapVariables;
private final boolean skipCI;

public MojarnMappingsLayer(@NotNull MappingLayer intermediary, @NotNull MappingLayer mojang, @NotNull MappingLayer yarn, boolean remapArguments, boolean partialMatch, boolean skipDifferent, boolean mapVariables) {
public MojarnMappingsLayer(@NotNull MappingLayer intermediary, @NotNull MappingLayer mojang, @NotNull MappingLayer yarn, boolean remapArguments, boolean partialMatch, boolean skipDifferent, boolean mapVariables, boolean skipCI) {
this.intermediary = intermediary;
this.mojang = mojang;
this.yarn = yarn;
this.remapArguments = remapArguments;
this.partialMatch = partialMatch;
this.skipDifferent = skipDifferent;
this.mapVariables = mapVariables;
this.skipCI = skipCI;
}

@Override
Expand All @@ -64,6 +66,11 @@ public void visit(MappingVisitor mappingVisitor) throws IOException {

this.mojang.visit(mappingVisitor);

if (MojarnPlugin.isCI && this.skipCI) {
MojarnPlugin.LOGGER.info("Skipping mapping layer generation for CI build.");
return;
}

// generate a tree of official mappings
MemoryMappingTree officialTree = new MemoryMappingTree();
this.intermediary.visit(officialTree);
Expand Down Expand Up @@ -124,9 +131,8 @@ public void visit(MappingVisitor mappingVisitor) throws IOException {
if (desc[i] == 'L') {
// parse class types
StringBuilder sb = new StringBuilder();
while (desc[i] != ';') {
while (desc[++i] != ';') {
sb.append(desc[i]);
i++;
}
descriptor.add(sb.toString());
} else if (desc[i] == ')') {
Expand All @@ -148,15 +154,15 @@ public void visit(MappingVisitor mappingVisitor) throws IOException {
// check if the argument is a class
if (descriptor.get(i) != null) {
// get the class mapping of the argument type
MappingTree.ClassMapping typeClass = yarnTree.getClass(descriptor.get(i));
MappingTree.ClassMapping typeClass = yarnTree.getClass(descriptor.get(i), named);
// if there is a mapping for this type, try to remap it.
if (typeClass != null) {
// skip if class remapping is disabled
if (!this.remapArguments) {
continue;
}

String typeName = typeClass.getDstName(named);
String typeName = getClassName(descriptor.get(i));

if (typeName != null) {
// check if class ends in numeric suffix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
import net.fabricmc.loom.api.mappings.layered.spec.MappingsSpec;
import org.jetbrains.annotations.NotNull;

public record MojarnMappingsSpec(@NotNull MappingsSpec<?> intermediary, @NotNull MappingsSpec<?> mojang, @NotNull MappingsSpec<?> yarn, boolean remapArguments, boolean partialMatch, boolean skipDifferent, boolean matchVariables) implements MappingsSpec<MojarnMappingsLayer> {
import java.util.Objects;

public record MojarnMappingsSpec(@NotNull MappingsSpec<?> intermediary, @NotNull MappingsSpec<?> mojang, @NotNull MappingsSpec<?> yarn, boolean remapArguments, boolean partialMatch, boolean skipDifferent, boolean skipCI, boolean matchVariables) implements MappingsSpec<MojarnMappingsLayer> {
@Override
public MojarnMappingsLayer createLayer(MappingContext context) {
return new MojarnMappingsLayer(this.intermediary.createLayer(context), this.mojang.createLayer(context), this.yarn.createLayer(context), this.remapArguments, this.partialMatch, this.skipDifferent, this.matchVariables);
return new MojarnMappingsLayer(this.intermediary.createLayer(context), this.mojang.createLayer(context), this.yarn.createLayer(context), this.remapArguments, this.partialMatch, this.skipDifferent, this.skipCI, this.matchVariables);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class MojarnMappingsSpecBuilderImpl implements MojarnMappingsSpecBuilder
boolean partialMatch = false;
boolean skipDifferent = false;
boolean mapVariables = true;
boolean skipCI = true;
boolean fileIsEnigma = false;

@Override
Expand All @@ -55,6 +56,12 @@ public MojarnMappingsSpecBuilder mapVariables(boolean mapVariables) {
return this;
}

@Override
public MojarnMappingsSpecBuilder skipCI(boolean skipCI) {
this.skipCI = skipCI;
return this;
}

@Override
public MojarnMappingsSpecBuilder fileIsEnigma() {
this.fileIsEnigma = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
*/
public final class MojarnPlugin implements Plugin<Project> {
public static final Logger LOGGER = LoggerFactory.getLogger("Mojarn");
public static final boolean isCI = System.getenv("CI") != null;

@Override
public void apply(Project project) {
Expand Down

0 comments on commit a2a6356

Please sign in to comment.