Skip to content

Commit

Permalink
Add dedicated flags to determine reusing project xml and models dir i…
Browse files Browse the repository at this point in the history
…n lint reporting action (#169)

Fixes #169
  • Loading branch information
arunkumar9t2 committed Apr 23, 2024
1 parent 88100e0 commit 80b321b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 16 deletions.
3 changes: 2 additions & 1 deletion rules/android/lint/lint_aspect.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions tools/lint/src/main/java/com/grab/lint/LintAnalyzeCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ class LintAnalyzeCommand : LintBaseCommand() {
Files.createDirectories(partialResults.toPath())
}

override val createProjectXml = true

override fun run(
workingDir: Path,
projectXml: File,
Expand Down
29 changes: 20 additions & 9 deletions tools/lint/src/main/java/com/grab/lint/LintBaseCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -161,6 +179,7 @@ abstract class LintBaseCommand : CliktCommand() {
minSdkVersion = minSdkVersion,
targetSdkVersion = targetSdkVersion,
partialResults = partialResults,
createModelsDir = createModelsDir,
modelsDir = modelsDir,
srcs = srcs,
resources = resources,
Expand Down Expand Up @@ -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.
*/
Expand Down
2 changes: 0 additions & 2 deletions tools/lint/src/main/java/com/grab/lint/LintReportCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions tools/lint/src/main/java/com/grab/lint/ProjectXmlCreator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class ProjectXmlCreator(
minSdkVersion: String,
targetSdkVersion: String,
partialResults: File,
createModelsDir: Boolean,
modelsDir: File,
srcs: List<String>,
resources: List<String>,
Expand All @@ -51,8 +52,7 @@ class ProjectXmlCreator(
dependencies: List<LintDependency>,
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,
Expand Down

0 comments on commit 80b321b

Please sign in to comment.