diff options
3 files changed, 27 insertions, 14 deletions
diff --git a/tools/protologtool/src/com/android/protolog/tool/ProtoLogTool.kt b/tools/protologtool/src/com/android/protolog/tool/ProtoLogTool.kt index 629f720314b2..dda13118bb21 100644 --- a/tools/protologtool/src/com/android/protolog/tool/ProtoLogTool.kt +++ b/tools/protologtool/src/com/android/protolog/tool/ProtoLogTool.kt @@ -60,7 +60,7 @@ object ProtoLogTool { val outSrc = try { val code = tryParse(text, path) if (containsProtoLogText(text, command.protoLogClassNameArg)) { - transformer.processClass(text, path, code) + transformer.processClass(text, path, packagePath(file, code), code) } else { text } @@ -157,10 +157,7 @@ ${updates.replaceIndent(" ")} if (containsProtoLogText(text, command.protoLogClassNameArg)) { try { val code = tryParse(text, path) - val pack = if (code.packageDeclaration.isPresent) code.packageDeclaration - .get().nameAsString else "" - val newPath = pack.replace('.', '/') + '/' + file.name - builder.findLogCalls(code, newPath) + builder.findLogCalls(code, path, packagePath(file, code)) } catch (ex: ParsingException) { // If we cannot parse this file, skip it (and log why). Compilation will fail // in a subsequent build step. @@ -182,6 +179,13 @@ ${updates.replaceIndent(" ")} out.close() } + private fun packagePath(file: File, code: CompilationUnit): String { + val pack = if (code.packageDeclaration.isPresent) code.packageDeclaration + .get().nameAsString else "" + val packagePath = pack.replace('.', '/') + '/' + file.name + return packagePath + } + private fun read(command: CommandOptions) { LogParser(ViewerConfigParser()) .parse(FileInputStream(command.logProtofileArg), diff --git a/tools/protologtool/src/com/android/protolog/tool/SourceTransformer.kt b/tools/protologtool/src/com/android/protolog/tool/SourceTransformer.kt index 0ad8091f97a2..36ea41129450 100644 --- a/tools/protologtool/src/com/android/protolog/tool/SourceTransformer.kt +++ b/tools/protologtool/src/com/android/protolog/tool/SourceTransformer.kt @@ -72,7 +72,7 @@ class SourceTransformer( } val ifStmt: IfStmt if (group.enabled) { - val hash = CodeUtils.hash(fileName, messageString, level, group) + val hash = CodeUtils.hash(packagePath, messageString, level, group) val newCall = call.clone() if (!group.textEnabled) { // Remove message string if text logging is not enabled by default. @@ -97,7 +97,7 @@ class SourceTransformer( if (argTypes.size != call.arguments.size - 2) { throw InvalidProtoLogCallException( "Number of arguments (${argTypes.size} does not mach format" + - " string in: $call", ParsingContext(fileName, call)) + " string in: $call", ParsingContext(path, call)) } val blockStmt = BlockStmt() if (argTypes.isNotEmpty()) { @@ -214,18 +214,23 @@ class SourceTransformer( StaticJavaParser.parseExpression<FieldAccessExpr>(protoLogCacheClassName) private var processedCode: MutableList<String> = mutableListOf() private var offsets: IntArray = IntArray(0) - private var fileName: String = "" + /** The path of the file being processed, relative to $ANDROID_BUILD_TOP */ + private var path: String = "" + /** The path of the file being processed, relative to the root package */ + private var packagePath: String = "" fun processClass( code: String, path: String, + packagePath: String, compilationUnit: CompilationUnit = StaticJavaParser.parse(code) ): String { - fileName = path + this.path = path + this.packagePath = packagePath processedCode = code.split('\n').toMutableList() offsets = IntArray(processedCode.size) - protoLogCallProcessor.process(compilationUnit, this, fileName) + protoLogCallProcessor.process(compilationUnit, this, path) return processedCode.joinToString("\n") } } diff --git a/tools/protologtool/src/com/android/protolog/tool/ViewerConfigBuilder.kt b/tools/protologtool/src/com/android/protolog/tool/ViewerConfigBuilder.kt index c1008263c083..175c71ff810b 100644 --- a/tools/protologtool/src/com/android/protolog/tool/ViewerConfigBuilder.kt +++ b/tools/protologtool/src/com/android/protolog/tool/ViewerConfigBuilder.kt @@ -46,7 +46,11 @@ class ViewerConfigBuilder( private val statements: MutableMap<Int, LogCall> = mutableMapOf() private val groups: MutableSet<LogGroup> = mutableSetOf() - fun findLogCalls(unit: CompilationUnit, fileName: String): List<Pair<LogCall, ParsingContext>> { + fun findLogCalls( + unit: CompilationUnit, + path: String, + packagePath: String + ): List<Pair<LogCall, ParsingContext>> { val calls = mutableListOf<Pair<LogCall, ParsingContext>>() val visitor = object : ProtoLogCallVisitor { override fun processCall( @@ -55,12 +59,12 @@ class ViewerConfigBuilder( level: LogLevel, group: LogGroup ) { - val logCall = LogCall(messageString, level, group, fileName) - val context = ParsingContext(fileName, call) + val logCall = LogCall(messageString, level, group, packagePath) + val context = ParsingContext(path, call) calls.add(logCall to context) } } - processor.process(unit, visitor, fileName) + processor.process(unit, visitor, path) return calls } |