Skip to content

Commit

Permalink
Add a basic logger interface
Browse files Browse the repository at this point in the history
  • Loading branch information
modmuss50 committed Oct 15, 2024
1 parent 6736d5f commit dfb17c3
Show file tree
Hide file tree
Showing 18 changed files with 209 additions and 150 deletions.
5 changes: 2 additions & 3 deletions src/main/java/net/fabricmc/tinyremapper/AsmClassRemapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,14 @@ public void visitInvokeDynamicInsn(String name, String descriptor, Handle bootst
bootstrapMethodArguments);
}

private static Handle getLambdaImplementedMethod(String name, String desc, Handle bsm, Set<String> knownIndyBsm, Object... bsmArgs) {
private Handle getLambdaImplementedMethod(String name, String desc, Handle bsm, Set<String> knownIndyBsm, Object... bsmArgs) {
if (isJavaLambdaMetafactory(bsm)) {
assert desc.endsWith(";");
return new Handle(Opcodes.H_INVOKEINTERFACE, desc.substring(desc.lastIndexOf(')') + 2, desc.length() - 1), name, ((Type) bsmArgs[0]).getDescriptor(), true);
} else if (knownIndyBsm.contains(bsm.getOwner())) {
return null;
} else {
System.out.printf("unknown invokedynamic bsm: %s/%s%s (tag=%d iif=%b)%n", bsm.getOwner(), bsm.getName(), bsm.getDesc(), bsm.getTag(), bsm.isInterface());

tr.getEnvironment().getLogger().warn("unknown invokedynamic bsm: %s/%s%s (tag=%d iif=%b)", bsm.getOwner(), bsm.getName(), bsm.getDesc(), bsm.getTag(), bsm.isInterface());
return null;
}
}
Expand Down
40 changes: 40 additions & 0 deletions src/main/java/net/fabricmc/tinyremapper/ConsoleLogger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2016, 2018, Player, asie
* Copyright (c) 2019, 2022, FabricMC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package net.fabricmc.tinyremapper;

import net.fabricmc.tinyremapper.api.TrLogger;

public final class ConsoleLogger implements TrLogger {
private final TrLogger.Level level;

public ConsoleLogger(TrLogger.Level level) {
this.level = level;
}

public ConsoleLogger() {
this(TrLogger.Level.INFO);
}

@Override
public void log(Level level, String message) {
if (this.level.compareTo(level) <= 0) {
System.out.println("[" + level + "] " + message);
}
}
}
27 changes: 15 additions & 12 deletions src/main/java/net/fabricmc/tinyremapper/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.regex.Pattern;

import net.fabricmc.tinyremapper.TinyRemapper.LinkedMethodPropagation;
import net.fabricmc.tinyremapper.api.TrLogger;
import net.fabricmc.tinyremapper.extension.mixin.MixinExtension;

public class Main {
Expand All @@ -61,6 +62,8 @@ public static void main(String[] rawArgs) {
int threads = -1;
boolean enableMixin = false;

final TrLogger logger = new ConsoleLogger();

for (String arg : rawArgs) {
if (arg.startsWith("--")) {
int valueSepPos = arg.indexOf('=');
Expand All @@ -86,7 +89,7 @@ public static void main(String[] rawArgs) {
case "enabled": propagateBridges = LinkedMethodPropagation.ENABLED; break;
case "compatible": propagateBridges = LinkedMethodPropagation.COMPATIBLE; break;
default:
System.out.println("invalid propagateBridges: "+arg.substring(valueSepPos + 1));
logger.error("invalid propagateBridges: "+arg.substring(valueSepPos + 1));
System.exit(1);
}

Expand Down Expand Up @@ -124,7 +127,7 @@ public static void main(String[] rawArgs) {
case "fixmeta": ncCopyMode = NonClassCopyMode.FIX_META_INF; break;
case "skipmeta": ncCopyMode = NonClassCopyMode.SKIP_META_INF; break;
default:
System.out.println("invalid nonClassCopyMode: "+arg.substring(valueSepPos + 1));
logger.error("invalid nonClassCopyMode: "+arg.substring(valueSepPos + 1));
System.exit(1);
}

Expand All @@ -133,7 +136,7 @@ public static void main(String[] rawArgs) {
threads = Integer.parseInt(arg.substring(valueSepPos + 1));

if (threads <= 0) {
System.out.println("Thread count must be > 0");
logger.error("Thread count must be > 0");
System.exit(1);
}

Expand All @@ -142,7 +145,7 @@ public static void main(String[] rawArgs) {
enableMixin = true;
break;
default:
System.out.println("invalid argument: "+arg+".");
logger.error("invalid argument: "+arg+".");
System.exit(1);
}
} else {
Expand All @@ -151,22 +154,22 @@ public static void main(String[] rawArgs) {
}

if (args.size() < 5) {
System.out.println("usage: <input> <output> <mappings> <from> <to> [<classpath>]... [--reverse] [--forcePropagation=<file>] [--propagatePrivate] [--ignoreConflicts]");
logger.error("usage: <input> <output> <mappings> <from> <to> [<classpath>]... [--reverse] [--forcePropagation=<file>] [--propagatePrivate] [--ignoreConflicts]");
System.exit(1);
}

Path input = Paths.get(args.get(0));

if (!Files.isReadable(input)) {
System.out.println("Can't read input file "+input+".");
logger.error("Can't read input file "+input+".");
System.exit(1);
}

Path output = Paths.get(args.get(1));
Path mappings = Paths.get(args.get(2));

if (!Files.isReadable(mappings) || Files.isDirectory(mappings)) {
System.out.println("Can't read mappings file "+mappings+".");
logger.error("Can't read mappings file "+mappings+".");
System.exit(1);
}

Expand All @@ -179,7 +182,7 @@ public static void main(String[] rawArgs) {
classpath[i] = Paths.get(args.get(i + 5));

if (!Files.isReadable(classpath[i])) {
System.out.println("Can't read classpath file "+i+": "+classpath[i]+".");
logger.error("Can't read classpath file "+i+": "+classpath[i]+".");
System.exit(1);
}
}
Expand All @@ -188,7 +191,7 @@ public static void main(String[] rawArgs) {
forcePropagation = new HashSet<>();

if (!forcePropagationFile.canRead()) {
System.out.println("Can't read forcePropagation file "+forcePropagationFile+".");
logger.error("Can't read forcePropagation file "+forcePropagationFile+".");
System.exit(1);
}

Expand All @@ -210,7 +213,7 @@ public static void main(String[] rawArgs) {

if (knownIndyBsmFile != null) {
if (!knownIndyBsmFile.canRead()) {
System.out.println("Can't read knownIndyBsm file "+knownIndyBsmFile+".");
logger.error("Can't read knownIndyBsm file "+knownIndyBsmFile+".");
System.exit(1);
}

Expand All @@ -232,7 +235,7 @@ public static void main(String[] rawArgs) {

long startTime = System.nanoTime();

TinyRemapper.Builder builder = TinyRemapper.newRemapper()
TinyRemapper.Builder builder = TinyRemapper.newRemapper(logger)
.withMappings(TinyUtils.createTinyMappingProvider(mappings, fromM, toM))
.ignoreFieldDesc(ignoreFieldDesc)
.withForcedPropagation(forcePropagation)
Expand Down Expand Up @@ -269,6 +272,6 @@ public static void main(String[] rawArgs) {
remapper.finish();
}

System.out.printf("Finished after %.2f ms.\n", (System.nanoTime() - startTime) / 1e6);
logger.info("Finished after %.2f ms.", (System.nanoTime() - startTime) / 1e6);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static void checkClass(String accessingClass, String targetClass, String
// target class is not public and in a different package
// -> invalid access detected, needs to be public

System.out.printf("Invalid access from %s in %s to package-private class %s after remapping.%n",
remapper.tr.getLogger().warn("Invalid access from %s in %s to package-private class %s after remapping.%n",
source,
mappedAccessor,
mappedTarget);
Expand Down Expand Up @@ -211,7 +211,7 @@ public static void checkMember(String accessingOwner, String owner, String name,
}
}

System.out.printf("Invalid access from %s in %s to %s after remapping.%n",
remapper.tr.getLogger().warn("Invalid access from %s in %s to %s after remapping.%n",
source,
mappedAccessor,
inaccessible);
Expand Down
Loading

0 comments on commit dfb17c3

Please sign in to comment.