Interface for api for partitioning mapping files
Bug: 211603371
Bug: 201666766
Change-Id: I8b7215f1e29e74de0977dd74626a31617b0c91da
diff --git a/src/main/java/com/android/tools/r8/retrace/MappingPartition.java b/src/main/java/com/android/tools/r8/retrace/MappingPartition.java
new file mode 100644
index 0000000..a925cc3
--- /dev/null
+++ b/src/main/java/com/android/tools/r8/retrace/MappingPartition.java
@@ -0,0 +1,15 @@
+// Copyright (c) 2022, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+package com.android.tools.r8.retrace;
+
+import com.android.tools.r8.Keep;
+
+@Keep
+public interface MappingPartition {
+
+ String getKey();
+
+ byte[] getPayload();
+}
diff --git a/src/main/java/com/android/tools/r8/retrace/MappingPartitionKeyInfo.java b/src/main/java/com/android/tools/r8/retrace/MappingPartitionKeyInfo.java
new file mode 100644
index 0000000..56f20b1
--- /dev/null
+++ b/src/main/java/com/android/tools/r8/retrace/MappingPartitionKeyInfo.java
@@ -0,0 +1,31 @@
+// Copyright (c) 2022, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+package com.android.tools.r8.retrace;
+
+import com.android.tools.r8.Keep;
+import com.android.tools.r8.references.ClassReference;
+import com.android.tools.r8.references.FieldReference;
+import com.android.tools.r8.references.MethodReference;
+import com.android.tools.r8.references.TypeReference;
+import java.util.function.Consumer;
+
+@Keep
+public interface MappingPartitionKeyInfo {
+
+ void getKeysForClass(ClassReference reference, Consumer<String> keyConsumer);
+
+ void getKeysForClassAndMethodName(
+ ClassReference reference, String methodName, Consumer<String> keyConsumer);
+
+ void getKeysForMethod(MethodReference reference, Consumer<String> keyConsumer);
+
+ void getKeysForField(FieldReference fieldReference, Consumer<String> keyConsumer);
+
+ void getKeysForType(TypeReference typeReference, Consumer<String> keyConsumer);
+
+ static MappingPartitionKeyInfo getDefault(byte[] metadata) {
+ return null;
+ }
+}
diff --git a/src/main/java/com/android/tools/r8/retrace/MappingPartitioner.java b/src/main/java/com/android/tools/r8/retrace/MappingPartitioner.java
new file mode 100644
index 0000000..10c641a
--- /dev/null
+++ b/src/main/java/com/android/tools/r8/retrace/MappingPartitioner.java
@@ -0,0 +1,13 @@
+// Copyright (c) 2022, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+package com.android.tools.r8.retrace;
+
+import com.android.tools.r8.Keep;
+
+@Keep
+public interface MappingPartitioner {
+
+ MappingPartitions partition(ProguardMapProducer mapProducer);
+}
diff --git a/src/main/java/com/android/tools/r8/retrace/MappingPartitions.java b/src/main/java/com/android/tools/r8/retrace/MappingPartitions.java
new file mode 100644
index 0000000..9bb9eb7
--- /dev/null
+++ b/src/main/java/com/android/tools/r8/retrace/MappingPartitions.java
@@ -0,0 +1,16 @@
+// Copyright (c) 2022, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+package com.android.tools.r8.retrace;
+
+import com.android.tools.r8.Keep;
+import java.util.function.Consumer;
+
+@Keep
+public interface MappingPartitions {
+
+ byte[] getMetadata();
+
+ void visitPartitions(Consumer<MappingPartition> consumer);
+}
diff --git a/src/main/java/com/android/tools/r8/retrace/ProguardMapProducer.java b/src/main/java/com/android/tools/r8/retrace/ProguardMapProducer.java
index 81b7f30..c3f94be 100644
--- a/src/main/java/com/android/tools/r8/retrace/ProguardMapProducer.java
+++ b/src/main/java/com/android/tools/r8/retrace/ProguardMapProducer.java
@@ -5,6 +5,7 @@
package com.android.tools.r8.retrace;
import com.android.tools.r8.Keep;
+import com.google.common.primitives.Bytes;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
@@ -25,4 +26,8 @@
static ProguardMapProducer fromPath(Path path) {
return () -> Files.newBufferedReader(path, StandardCharsets.UTF_8);
}
+
+ static ProguardMapProducer fromBytes(byte[]... partitions) {
+ return fromString(new String(Bytes.concat(partitions), StandardCharsets.UTF_8));
+ }
}