From 80b321b41d09220e118e2bf174f773d8dcc858a1 Mon Sep 17 00:00:00 2001 From: arunkumar9t2 Date: Tue, 23 Apr 2024 15:59:48 +0800 Subject: [PATCH] Add dedicated flags to determine reusing project xml and models dir in lint reporting action (#169) Fixes #169 --- rules/android/lint/lint_aspect.bzl | 3 +- .../java/com/grab/lint/LintAnalyzeCommand.kt | 2 -- .../java/com/grab/lint/LintBaseCommand.kt | 29 +++++++++++++------ .../java/com/grab/lint/LintReportCommand.kt | 2 -- .../java/com/grab/lint/ProjectXmlCreator.kt | 4 +-- 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/rules/android/lint/lint_aspect.bzl b/rules/android/lint/lint_aspect.bzl index c8c84251..e39962f0 100644 --- a/rules/android/lint/lint_aspect.bzl +++ b/rules/android/lint/lint_aspect.bzl @@ -398,7 +398,8 @@ def _lint_report_action( jdk_home = jdk_home, verbose = verbose, ) - + args.add("--no-create-project-xml") + args.add("--no-create-models-dir") args.add("--updated-baseline", updated_baseline) args.add("--fail-on-warning", fail_on_warning) args.add("--fail-on-information", fail_on_information) diff --git a/tools/lint/src/main/java/com/grab/lint/LintAnalyzeCommand.kt b/tools/lint/src/main/java/com/grab/lint/LintAnalyzeCommand.kt index ff0af27d..11543de4 100644 --- a/tools/lint/src/main/java/com/grab/lint/LintAnalyzeCommand.kt +++ b/tools/lint/src/main/java/com/grab/lint/LintAnalyzeCommand.kt @@ -17,8 +17,6 @@ class LintAnalyzeCommand : LintBaseCommand() { Files.createDirectories(partialResults.toPath()) } - override val createProjectXml = true - override fun run( workingDir: Path, projectXml: File, diff --git a/tools/lint/src/main/java/com/grab/lint/LintBaseCommand.kt b/tools/lint/src/main/java/com/grab/lint/LintBaseCommand.kt index 92d17041..65bf1969 100644 --- a/tools/lint/src/main/java/com/grab/lint/LintBaseCommand.kt +++ b/tools/lint/src/main/java/com/grab/lint/LintBaseCommand.kt @@ -79,7 +79,7 @@ abstract class LintBaseCommand : CliktCommand() { protected val jdkHome by option( "-j", "--jdk-home", - help = "Path fo Java home" + help = "Path to Java home" ).required() protected val verbose by option( @@ -99,6 +99,15 @@ abstract class LintBaseCommand : CliktCommand() { help = "Lint models directory containing models.xml" ).convert { File(it) }.required() + private val createModelsDir by option( + "-mc", + "--create-models-dir", + help = "Whether to create a new lint models dir specified via --models-dir" + ).flag( + "--no-create-models-dir", + default = true + ) + protected val inputBaseline by option( "-b", "--baseline", @@ -111,6 +120,15 @@ abstract class LintBaseCommand : CliktCommand() { help = "Path to project.xml that will be created/reused when invoking Lint CLI" ).convert { File(it) }.required() + private val createProjectXml by option( + "-pc", + "--create-project-xml", + help = "Whether to create a new project.xml or reuse one specified in --project-xml" + ).flag( + "--no-create-project-xml", + default = true + ) + private val compileSdkVersion: String by option( "-cs", "--compile-sdk-version", @@ -161,6 +179,7 @@ abstract class LintBaseCommand : CliktCommand() { minSdkVersion = minSdkVersion, targetSdkVersion = targetSdkVersion, partialResults = partialResults, + createModelsDir = createModelsDir, modelsDir = modelsDir, srcs = srcs, resources = resources, @@ -193,14 +212,6 @@ abstract class LintBaseCommand : CliktCommand() { tmpBaseline: File, ) - /** - * Create new project.xml at [projectXml]. - * - * Required for non-sandbox modes since we can't rely on file system state when executing in non sandbox modes as previous results might - * be still there. When true, a new project XML will be created at [projectXml] and if `false` will use the project xml at this location - */ - abstract val createProjectXml: Boolean - /** * Common options for Lint across different types of invocations, analyze or report. */ diff --git a/tools/lint/src/main/java/com/grab/lint/LintReportCommand.kt b/tools/lint/src/main/java/com/grab/lint/LintReportCommand.kt index 59055ad9..6227ba2a 100644 --- a/tools/lint/src/main/java/com/grab/lint/LintReportCommand.kt +++ b/tools/lint/src/main/java/com/grab/lint/LintReportCommand.kt @@ -72,8 +72,6 @@ class LintReportCommand : LintBaseCommand() { // No-op } - override val createProjectXml: Boolean = false - private fun runLint(workingDir: Path, projectXml: File, tmpBaseline: File, lintResultXml: File) { val cliArgs = (defaultLintOptions + listOf( "--project", projectXml.toString(), diff --git a/tools/lint/src/main/java/com/grab/lint/ProjectXmlCreator.kt b/tools/lint/src/main/java/com/grab/lint/ProjectXmlCreator.kt index c319c9cd..6eb8a04a 100644 --- a/tools/lint/src/main/java/com/grab/lint/ProjectXmlCreator.kt +++ b/tools/lint/src/main/java/com/grab/lint/ProjectXmlCreator.kt @@ -38,6 +38,7 @@ class ProjectXmlCreator( minSdkVersion: String, targetSdkVersion: String, partialResults: File, + createModelsDir: Boolean, modelsDir: File, srcs: List, resources: List, @@ -51,8 +52,7 @@ class ProjectXmlCreator( dependencies: List, verbose: Boolean ): File { - val lintModelsDir = if (modelsDir.exists() && modelsDir.walk().drop(1).any()) { - // For android_binary's report step we need to reuse models from analyze action so just return it if it exists + val lintModelsDir = if (!createModelsDir) { modelsDir } else LintModelCreator().create( compileSdkVersion = compileSdkVersion,