Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4d5685ae authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Use deterministic hash for generate ProtoLogImpl postfix" into main

parents d814b1d7 32b1b355
Loading
Loading
Loading
Loading
+6 −3
Original line number Original line Diff line number Diff line
@@ -39,8 +39,7 @@ import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
import java.util.concurrent.Executors
import java.util.jar.JarOutputStream
import java.util.jar.JarOutputStream
import java.util.zip.ZipEntry
import java.util.zip.ZipEntry
import kotlin.math.abs
import kotlin.math.absoluteValue
import kotlin.random.Random
import kotlin.system.exitProcess
import kotlin.system.exitProcess


object ProtoLogTool {
object ProtoLogTool {
@@ -72,7 +71,11 @@ object ProtoLogTool {
    }
    }


    private fun processClasses(command: CommandOptions) {
    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.
        // Need to generate a new impl class to inject static constants into the class.
        val generatedProtoLogImplClass =
        val generatedProtoLogImplClass =
            "com.android.internal.protolog.ProtoLogImpl_$generationHash"
            "com.android.internal.protolog.ProtoLogImpl_$generationHash"