diff options
author | Adrian Roos <roosa@google.com> | 2019-10-02 19:03:34 +0200 |
---|---|---|
committer | Adrian Roos <roosa@google.com> | 2019-10-02 19:03:34 +0200 |
commit | 125b839889420801a26bacd99251d53cad266539 (patch) | |
tree | 45b0c5822b22aab4b91e05fd55b473c1175eeac4 /tools/protologtool | |
parent | b125e0be9f05cddd7e32f5edea08939210958b31 (diff) |
ProtoLog: Better behavior when parsing fails
Improves behavior when parsing fails; now, ProtoLog skips the offending files, and
relies on the subsequent compilation step to catch the error.
Additionally, the build no longer fails when the canonical protolog.json file contains
obsolete entries.
Test: Introduce syntax error in services/core/ file, make and verify error messaging is sound
Change-Id: Ic23dec4a14489316ecb0e46bbabe246ddae29655
Diffstat (limited to 'tools/protologtool')
-rw-r--r-- | tools/protologtool/src/com/android/protolog/tool/ProtoLogTool.kt | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/tools/protologtool/src/com/android/protolog/tool/ProtoLogTool.kt b/tools/protologtool/src/com/android/protolog/tool/ProtoLogTool.kt index 97f3de2c1221..70ac0bee59b3 100644 --- a/tools/protologtool/src/com/android/protolog/tool/ProtoLogTool.kt +++ b/tools/protologtool/src/com/android/protolog/tool/ProtoLogTool.kt @@ -50,14 +50,19 @@ object ProtoLogTool { command.javaSourceArgs.forEach { path -> val file = File(path) val text = file.readText() - val code = tryParse(text, path) - val pack = if (code.packageDeclaration.isPresent) code.packageDeclaration - .get().nameAsString else "" - val newPath = pack.replace('.', '/') + '/' + file.name - val outSrc = when { - containsProtoLogText(text, command.protoLogClassNameArg) -> + val newPath = path + val outSrc = try { + val code = tryParse(text, path) + if (containsProtoLogText(text, command.protoLogClassNameArg)) { transformer.processClass(text, newPath, code) - else -> text + } else { + text + } + } catch (ex: ParsingException) { + // If we cannot parse this file, skip it (and log why). Compilation will fail + // in a subsequent build step. + println("\n${ex.message}\n") + text } outJar.putNextEntry(ZipEntry(newPath)) outJar.write(outSrc.toByteArray()) @@ -91,11 +96,17 @@ object ProtoLogTool { val file = File(path) val text = file.readText() if (containsProtoLogText(text, command.protoLogClassNameArg)) { - val code = tryParse(text, path) - val pack = if (code.packageDeclaration.isPresent) code.packageDeclaration - .get().nameAsString else "" - val newPath = pack.replace('.', '/') + '/' + file.name - builder.processClass(code, newPath) + try { + val code = tryParse(text, path) + val pack = if (code.packageDeclaration.isPresent) code.packageDeclaration + .get().nameAsString else "" + val newPath = pack.replace('.', '/') + '/' + file.name + builder.processClass(code, newPath) + } catch (ex: ParsingException) { + // If we cannot parse this file, skip it (and log why). Compilation will fail + // in a subsequent build step. + println("\n${ex.message}\n") + } } } val out = FileOutputStream(command.viewerConfigJsonArg) |