Skip to content

Commit 97ab9b8

Browse files
committed
all html code changes
1 parent 89fb6c9 commit 97ab9b8

8 files changed

Lines changed: 75 additions & 41 deletions

File tree

docs/rules.md

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rules/android_lint_test.bzl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def _test_impl(ctx):
2121
android_lint_results = _process_android_lint_issues(ctx, regenerate = False)
2222

2323
inputs = []
24-
inputs.append(android_lint_results.output)
24+
inputs.append(android_lint_results.xml_output)
2525
inputs.extend(ctx.attr._android_lint_output_validator.default_runfiles.files.to_list())
2626

2727
ctx.actions.write(
@@ -33,15 +33,19 @@ def _test_impl(ctx):
3333
{executable} --lint_baseline "{lint_baseline}"
3434
""".format(
3535
executable = ctx.executable._android_lint_output_validator.short_path,
36-
lint_baseline = android_lint_results.output.short_path,
36+
lint_baseline = android_lint_results.xml_output.short_path,
3737
),
3838
)
39-
39+
files_info = [ctx.outputs.executable]
40+
if android_lint_results.xml_output != None:
41+
files_info.append(android_lint_results.xml_output)
42+
if android_lint_results.html_output != None:
43+
files_info.append(android_lint_results.html_output)
4044
return [
4145
DefaultInfo(
4246
runfiles = ctx.runfiles(files = inputs),
4347
executable = ctx.outputs.executable,
44-
files = depset([ctx.outputs.executable, android_lint_results.output]),
48+
files = depset(files_info),
4549
),
4650
] + android_lint_results.providers
4751

rules/attrs.bzl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,11 @@ ATTRS = dict(
7777
default = [],
7878
doc = "Custom lint rules to run.",
7979
),
80+
output_formats = attr.string_list(
81+
mandatory = False,
82+
allow_empty = False,
83+
default = ["xml"],
84+
doc = "List of output formats to produce. Supported [xml, html]",
85+
),
8086
_use_auto_exec_groups = attr.bool(default = True),
8187
)

rules/impl.bzl

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def _run_android_lint(
1919
ctx,
2020
android_lint,
2121
module_name,
22-
output,
22+
xml_output,
2323
html_output,
2424
srcs,
2525
deps,
@@ -44,7 +44,7 @@ def _run_android_lint(
4444
ctx: The target context
4545
android_lint: The Android Lint binary to use
4646
module_name: The name of the module
47-
output: The output file
47+
xml_output: The xml_output file
4848
srcs: The source files
4949
deps: Depset of aars and jars to include on the classpath
5050
resource_files: The Android resource files
@@ -64,7 +64,7 @@ def _run_android_lint(
6464
android_lint_skip_bytecode_verifier: Disables bytecode verification
6565
"""
6666
inputs = []
67-
outputs = [output, html_output]
67+
outputs = []
6868

6969
args = ctx.actions.args()
7070
args.set_param_file_format("multiline")
@@ -115,16 +115,14 @@ def _run_android_lint(
115115
if android_lint_enable_check_dependencies:
116116
args.add("--enable-check-dependencies")
117117

118-
# Declare the output file
119-
args.add("--output", output)
120-
outputs.append(output)
121-
122-
args.add("--html-output", html_output)
123-
outputs.append(html_output)
124-
125-
label = ctx.attr.android_home.label
126-
if ctx.attr.android_home:
127-
args.add("--android_home", label.workspace_root)
118+
if xml_output != None:
119+
args.add("--xml-output", xml_output)
120+
outputs.append(xml_output)
121+
if html_output != None:
122+
args.add("--html-output", html_output)
123+
outputs.append(html_output)
124+
if len(outputs) == 0:
125+
fail("Lint cannot have no outputs!")
128126

129127
ctx.actions.run(
130128
mnemonic = "AndroidLint",
@@ -171,7 +169,7 @@ def process_android_lint_issues(ctx, regenerate):
171169
regenerate: Whether to regenerate the baseline files
172170
173171
Returns:
174-
A struct containing the output file and the providers
172+
A struct containing the output files and the providers
175173
"""
176174

177175
# Append the Android manifest file. Lint requires that the input manifest files be named
@@ -205,13 +203,20 @@ def process_android_lint_issues(ctx, regenerate):
205203
_utils.list_or_depset_to_list(_utils.get_android_lint_toolchain(ctx).android_lint_config.files),
206204
)
207205

208-
output = ctx.actions.declare_file("{}.xml".format(ctx.label.name))
209-
html_output = ctx.actions.declare_file("{}.html".format(ctx.label.name))
206+
baseline = getattr(ctx.file, "baseline", None)
207+
xml_output = None
208+
html_output = None
209+
for output_format in ctx.attr.output_formats:
210+
if output_format == "xml":
211+
xml_output = ctx.actions.declare_file("{}.xml".format(ctx.label.name))
212+
if output_format == "html":
213+
html_output = ctx.actions.declare_file("{}.html".format(ctx.label.name))
214+
210215
_run_android_lint(
211216
ctx,
212217
android_lint = _utils.only(_utils.list_or_depset_to_list(_utils.get_android_lint_toolchain(ctx).android_lint.files)),
213218
module_name = _get_module_name(ctx),
214-
output = output,
219+
xml_output = xml_output,
215220
html_output = html_output,
216221
srcs = ctx.files.srcs,
217222
deps = depset(transitive = deps),
@@ -220,7 +225,7 @@ def process_android_lint_issues(ctx, regenerate):
220225
compile_sdk_version = _utils.get_android_lint_toolchain(ctx).compile_sdk_version,
221226
java_language_level = _utils.get_android_lint_toolchain(ctx).java_language_level,
222227
kotlin_language_level = _utils.get_android_lint_toolchain(ctx).kotlin_language_level,
223-
baseline = getattr(ctx.file, "baseline", None),
228+
baseline = baseline,
224229
config = config,
225230
warnings_as_errors = ctx.attr.warnings_as_errors,
226231
custom_rules = ctx.files.custom_rules,
@@ -233,10 +238,14 @@ def process_android_lint_issues(ctx, regenerate):
233238
)
234239

235240
return struct(
236-
output = output,
241+
baseline = baseline,
242+
xml_output = xml_output,
243+
html_output = html_output,
237244
providers = [
238245
_AndroidLintResultsInfo(
239-
output = output,
246+
baseline = baseline,
247+
xml_output = xml_output,
248+
html_output = html_output,
240249
),
241250
],
242251
)

rules/providers.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
AndroidLintResultsInfo = provider(
55
"Info needed to evaluate lint results",
66
fields = {
7-
"output": "The Android Lint baseline output",
7+
"baseline": "The Android Lint baseline output",
8+
"xml_output": "The Android Lint xml output",
9+
"html_output": "The Android Lint html output",
810
},
911
)

src/cli/AndroidLintActionArgs.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ internal class AndroidLintActionArgs(
3232
transform = argsParserPathTransformer,
3333
)
3434

35-
val output: Path by parser.storing(
36-
names = arrayOf("--output"),
35+
val xmlOutput: Path? by parser.storing(
36+
names = arrayOf("--xml-output"),
3737
help = "",
3838
transform = argsParserPathTransformer,
39-
)
39+
).default { null }
4040

41-
val htmlOutput: Path by parser.storing(
41+
val htmlOutput: Path? by parser.storing(
4242
names = arrayOf("--html-output"),
4343
help = "",
4444
transform = argsParserPathTransformer,
45-
)
45+
).default { null }
4646

4747
val resources: List<Path> by parser.adding(
4848
names = arrayOf("--resource"),

src/cli/AndroidLintRunner.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,6 @@ internal class AndroidLintRunner {
9494
projectFilePath.pathString,
9595
"--path-variables",
9696
"PWD=$rootDirPath",
97-
"--xml",
98-
actionArgs.output.pathString,
99-
"--html",
100-
actionArgs.htmlOutput.pathString,
10197
"--exitcode",
10298
"--compile-sdk-version",
10399
actionArgs.compileSdkVersion,
@@ -115,6 +111,16 @@ internal class AndroidLintRunner {
115111
cacheDirectoryPath.pathString,
116112
"--client-id", "cli",
117113
)
114+
if (actionArgs.xmlOutput != null) {
115+
args.add("--xml")
116+
args.add(actionArgs.xmlOutput!!.pathString)
117+
}
118+
119+
if (actionArgs.htmlOutput != null) {
120+
args.add("--html")
121+
args.add(actionArgs.htmlOutput!!.pathString)
122+
}
123+
118124
if (actionArgs.warningsAsErrors) {
119125
args.add("-Werror")
120126
} else {

tests/src/cli/AndroidLintActionArgsTest.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ class AndroidLintActionArgsTest {
1919
"path/to/cli.jar",
2020
"--src",
2121
"path/to/Foo.kt",
22-
"--output",
23-
"output.jar",
22+
"--xml-output",
23+
"xml_output.xml",
24+
"--html-output",
25+
"html_output.html",
2426
"--resource",
2527
"path/to/resource/strings.xml",
2628
"--android-manifest",
@@ -54,7 +56,8 @@ class AndroidLintActionArgsTest {
5456

5557
assertThat(parseArgs.label).isEqualTo("test")
5658
assertThat(parseArgs.srcs).containsExactly(Paths.get("path/to/Foo.kt"))
57-
assertThat(parseArgs.output).isEqualTo(Paths.get("output.jar"))
59+
assertThat(parseArgs.xmlOutput).isEqualTo(Paths.get("xml_output.xml"))
60+
assertThat(parseArgs.htmlOutput).isEqualTo(Paths.get("html_output.html"))
5861
assertThat(parseArgs.resources).containsExactly(Paths.get("path/to/resource/strings.xml"))
5962
assertThat(parseArgs.baselineFile).isEqualTo(Paths.get("lib_lint_baseline.xml"))
6063
assertThat(parseArgs.config).isEqualTo(Paths.get("lint_config.xml"))

0 commit comments

Comments
 (0)