-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #174 from grab/add-lint-custom-rules-inspector
add lint custom rule inspector
- Loading branch information
Showing
12 changed files
with
393 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
load("@grab_bazel_common//rules/android/lint:providers.bzl", "AndroidLintInfo") | ||
load("@grab_bazel_common//rules/android:utils.bzl", "utils") | ||
|
||
def _lint_inspector(ctx): | ||
lint_target = ctx.attr.lint_target | ||
target = ctx.attr.target | ||
|
||
lint_checks = ctx.attr.lint_target[AndroidLintInfo].inspect_info.lint_checks | ||
aars_dirs = ctx.attr.lint_target[AndroidLintInfo].inspect_info.aars_dirs | ||
|
||
executable = ctx.actions.declare_file("lint/%s_inspect.sh" % target.label.name) | ||
lint_rules = ctx.actions.declare_file("lint/%s_lint_rules.json" % target.label.name) | ||
|
||
ctx.actions.write( | ||
output = executable, | ||
content = """ | ||
#!/bin/bash | ||
echo "\nlint_rules: $(realpath {lint_rules})" | ||
""".format( | ||
lint_rules = lint_rules.short_path, | ||
), | ||
) | ||
|
||
mnemonic = "AndroidLintInspector" | ||
args = ctx.actions.args() | ||
|
||
args.add_joined( | ||
"--aars-dirs", | ||
aars_dirs, | ||
join_with = ",", | ||
map_each = utils.to_path, | ||
) | ||
args.add_joined( | ||
"--lint-checks", | ||
lint_checks, | ||
join_with = ",", | ||
map_each = utils.to_path, | ||
) | ||
args.add("--output", lint_rules.path) | ||
|
||
ctx.actions.run( | ||
mnemonic = mnemonic, | ||
inputs = depset( | ||
lint_checks + aars_dirs, | ||
), | ||
outputs = [lint_rules], | ||
executable = ctx.executable._lint_inspector_cli, | ||
arguments = [args], | ||
progress_message = "%s %s" % (mnemonic, str(ctx.label).lstrip("@")), | ||
) | ||
|
||
return [ | ||
DefaultInfo( | ||
executable = executable, | ||
runfiles = ctx.runfiles(files = [lint_rules]), | ||
files = depset([lint_rules]), | ||
), | ||
] | ||
|
||
lint_inspector = rule( | ||
implementation = _lint_inspector, | ||
executable = True, | ||
attrs = { | ||
"_lint_inspector_cli": attr.label( | ||
executable = True, | ||
cfg = "exec", | ||
default = Label("//tools/lint:lint_inspector"), | ||
), | ||
"target": attr.label( | ||
doc = "name of the android/kotlin/java target", | ||
), | ||
"lint_target": attr.label( | ||
doc = "The lint target to inspect", | ||
providers = [AndroidLintInfo], | ||
mandatory = True, | ||
), | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
tools/lint/src/main/java/com/grab/lint/inspector/ArgumentParser.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.grab.lint.inspector | ||
|
||
import com.github.ajalt.clikt.core.CliktCommand | ||
import com.github.ajalt.clikt.parameters.options.convert | ||
import com.github.ajalt.clikt.parameters.options.default | ||
import com.github.ajalt.clikt.parameters.options.option | ||
import com.github.ajalt.clikt.parameters.options.required | ||
import java.io.File | ||
|
||
class ArgumentParser : CliktCommand() { | ||
|
||
private val outPut by option( | ||
"-o", | ||
"--output", | ||
help = "a json file result that contains custom lint rules infos" | ||
).convert { File(it) }.required() | ||
|
||
private val lintChecks by option( | ||
"-lc", | ||
"--lint-checks", | ||
help = "jar files that contains custom lint checks" | ||
).convert { it.split(",").map { File(it) } }.default(emptyList()) | ||
|
||
private val aarDeps by option( | ||
"-ad", | ||
"--aars-dirs", | ||
help = "aars extract directories that contains custom lint checks" | ||
).convert { it.split(",").map { File(it) }.filter { it.name == "lint.jar" } }.default(emptyList()) | ||
|
||
override fun run() { | ||
Inspector(outPut, lintChecks, aarDeps).run() | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
tools/lint/src/main/java/com/grab/lint/inspector/BUILD.bazel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
load("@grab_bazel_common//rules:defs.bzl", "kotlin_library") | ||
|
||
kotlin_library( | ||
name = "lint-inspector-lib", | ||
srcs = glob([ | ||
"*.kt", | ||
]), | ||
visibility = [ | ||
"//visibility:public", | ||
], | ||
deps = [ | ||
"@bazel_common_maven//:com_android_tools_lint_lint_api", | ||
"@bazel_common_maven//:com_android_tools_lint_lint_checks", | ||
"@bazel_common_maven//:com_github_ajalt_clikt", | ||
"@bazel_common_maven//:com_squareup_moshi_moshi_kotlin", | ||
"@bazel_common_maven//:net_sf_kxml_kxml2", | ||
"@bazel_common_maven//:xmlpull_xmlpull", | ||
], | ||
) |
Oops, something went wrong.