summaryrefslogtreecommitdiff
path: root/java/lint.go
diff options
context:
space:
mode:
author Colin Cross <ccross@android.com> 2022-08-12 16:09:24 -0700
committer Colin Cross <ccross@android.com> 2022-08-15 16:05:03 -0700
commit62695b9f01d5c552c94c752198711e1f2a2baa5d (patch)
treee7a2dab0c8b1c98902f7a43a1dd7b10e28123ba5 /java/lint.go
parent7ddd08ad2b6e757efc619945078deb931bf311c9 (diff)
Collect suggested modifications from lint
Pass --apply-suggestions to lint, which will cause it to apply suggested fixes to the source files in the sandbox. Zip up the modified sources and export them outside the sandbox. Test: examine suggested-fixes.zip Bug: 216456886 Change-Id: Iaeb406462c38cf4b10e51d641432ba1fda9327fa
Diffstat (limited to 'java/lint.go')
-rw-r--r--java/lint.go19
1 files changed, 15 insertions, 4 deletions
diff --git a/java/lint.go b/java/lint.go
index e276345eb..5808e0d0c 100644
--- a/java/lint.go
+++ b/java/lint.go
@@ -210,7 +210,7 @@ func lintRBEExecStrategy(ctx android.ModuleContext) string {
return ctx.Config().GetenvWithDefault("RBE_LINT_EXEC_STRATEGY", remoteexec.LocalExecStrategy)
}
-func (l *linter) writeLintProjectXML(ctx android.ModuleContext, rule *android.RuleBuilder) lintPaths {
+func (l *linter) writeLintProjectXML(ctx android.ModuleContext, rule *android.RuleBuilder, srcsList android.Path) lintPaths {
projectXMLPath := android.PathForModuleOut(ctx, "lint", "project.xml")
// Lint looks for a lint.xml file next to the project.xml file, give it one.
configXMLPath := android.PathForModuleOut(ctx, "lint", "lint.xml")
@@ -241,8 +241,7 @@ func (l *linter) writeLintProjectXML(ctx android.ModuleContext, rule *android.Ru
// TODO(ccross): some of the files in l.srcs are generated sources and should be passed to
// lint separately.
- srcsList := android.PathForModuleOut(ctx, "lint-srcs.list")
- cmd.FlagWithRspFileInputList("--srcs ", srcsList, l.srcs)
+ cmd.FlagWithInput("--srcs ", srcsList)
cmd.FlagWithInput("--generated_srcs ", srcJarList)
@@ -373,7 +372,11 @@ func (l *linter) lint(ctx android.ModuleContext) {
rule.Temporary(manifest)
}
- lintPaths := l.writeLintProjectXML(ctx, rule)
+ srcsList := android.PathForModuleOut(ctx, "lint", "lint-srcs.list")
+ srcsListRsp := android.PathForModuleOut(ctx, "lint-srcs.list.rsp")
+ rule.Command().Text("cp").FlagWithRspFileInputList("", srcsListRsp, l.srcs).Output(srcsList)
+
+ lintPaths := l.writeLintProjectXML(ctx, rule, srcsList)
html := android.PathForModuleOut(ctx, "lint", "lint-report.html")
text := android.PathForModuleOut(ctx, "lint", "lint-report.txt")
@@ -433,6 +436,7 @@ func (l *linter) lint(ctx android.ModuleContext) {
FlagWithArg("--kotlin-language-level ", l.kotlinLanguageLevel).
FlagWithArg("--url ", fmt.Sprintf(".=.,%s=out", android.PathForOutput(ctx).String())).
Flag("--exitcode").
+ Flag("--apply-suggestions"). // applies suggested fixes to files in the sandbox
Flags(l.properties.Lint.Flags).
Implicit(annotationsZipPath).
Implicit(apiVersionsXMLPath)
@@ -458,6 +462,13 @@ func (l *linter) lint(ctx android.ModuleContext) {
// The HTML output contains a date, remove it to make the output deterministic.
rule.Command().Text(`sed -i.tmp -e 's|Check performed at .*\(</nav>\)|\1|'`).Output(html)
+ // The sources in the sandbox may have been modified by --apply-suggestions, zip them up and
+ // export them out of the sandbox.
+ rule.Command().BuiltTool("soong_zip").
+ FlagWithOutput("-o ", android.PathForModuleOut(ctx, "lint", "suggested-fixes.zip")).
+ FlagWithArg("-C ", cmd.PathForInput(android.PathForSource(ctx))).
+ FlagWithInput("-r ", srcsList)
+
rule.Build("lint", "lint")
l.outputs = lintOutputs{