summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2024-03-06 12:47:12 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-03-06 12:47:12 +0000
commit4d5685ae8c635219ac9bd27af7e6602e88eb078d (patch)
tree4527676937be79cc70943b5e5b82d05521d572c9
parentd814b1d701859ce4f48dd2cea393d8de9656f1f6 (diff)
parent32b1b355a107188852042c8aff8102996f1cd25b (diff)
Merge "Use deterministic hash for generate ProtoLogImpl postfix" into main
-rw-r--r--tools/protologtool/src/com/android/protolog/tool/ProtoLogTool.kt9
1 files changed, 6 insertions, 3 deletions
diff --git a/tools/protologtool/src/com/android/protolog/tool/ProtoLogTool.kt b/tools/protologtool/src/com/android/protolog/tool/ProtoLogTool.kt
index 1381847c258f..ea2c8dacff50 100644
--- a/tools/protologtool/src/com/android/protolog/tool/ProtoLogTool.kt
+++ b/tools/protologtool/src/com/android/protolog/tool/ProtoLogTool.kt
@@ -39,8 +39,7 @@ import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
import java.util.jar.JarOutputStream
import java.util.zip.ZipEntry
-import kotlin.math.abs
-import kotlin.random.Random
+import kotlin.math.absoluteValue
import kotlin.system.exitProcess
object ProtoLogTool {
@@ -72,7 +71,11 @@ object ProtoLogTool {
}
private fun processClasses(command: CommandOptions) {
- val generationHash = abs(Random.nextInt())
+ // A deterministic hash based on the group jar path and the source files we are processing.
+ // The hash is required to make sure different ProtoLogImpls don't conflict.
+ val generationHash = (command.javaSourceArgs.toTypedArray() + command.protoLogGroupsJarArg)
+ .contentHashCode().absoluteValue
+
// Need to generate a new impl class to inject static constants into the class.
val generatedProtoLogImplClass =
"com.android.internal.protolog.ProtoLogImpl_$generationHash"