From 84f3dc1c9d2dd049e796000b329f21cf510b0990 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 4 Mar 2021 09:56:15 -0800 Subject: [PATCH 1/3] Use repackaged lint binary Lint references lint-classpath.jar, which does not contain any classes by has a manifest that points to other jars for the classpath. This breaks dependency tracking during the build. Use a lint tool that is repackaged into a single jar. Bug: 181681346 Test: m lint-check Change-Id: I07d2b7404c18626e03c5af3ef5a75dd7f899cb0e --- java/lint.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/java/lint.go b/java/lint.go index 827259573..af83664c6 100644 --- a/java/lint.go +++ b/java/lint.go @@ -329,8 +329,7 @@ func (l *linter) lint(ctx android.ModuleContext) { FlagWithArg("ANDROID_SDK_HOME=", homeDir.String()). FlagWithInput("SDK_ANNOTATIONS=", annotationsZipPath). FlagWithInput("LINT_OPTS=-DLINT_API_DATABASE=", apiVersionsXMLPath). - Tool(android.PathForSource(ctx, "prebuilts/cmdline-tools/tools/bin/lint")). - Implicit(android.PathForSource(ctx, "prebuilts/cmdline-tools/tools/lib/lint-classpath.jar")). + BuiltTool("lint"). Flag("--quiet"). FlagWithInput("--project ", projectXML). FlagWithInput("--config ", lintXML). From 00d93b143f3409241cf026be71e56dd696539e16 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 4 Mar 2021 10:00:09 -0800 Subject: [PATCH 2/3] Make common dependencies of lint use restat Use restat for the api_versions.xml and annotations.zip dependencies of lint so that frameworks/base changes don't always result in rerunning lint on every module. Bug: 181681346 Test: m lint-check Change-Id: Ic6a540b41cf79b21441311a8baefe528a3d90d8b --- android/defs.go | 9 +++++++++ java/lint.go | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/android/defs.go b/android/defs.go index 38ecb0505..1a767214c 100644 --- a/android/defs.go +++ b/android/defs.go @@ -57,6 +57,15 @@ var ( }, "cpFlags") + // A copy rule that only updates the output if it changed. + CpIfChanged = pctx.AndroidStaticRule("CpIfChanged", + blueprint.RuleParams{ + Command: "if ! cmp -s $in $out; then cp $in $out; fi", + Description: "cp if changed $out", + Restat: true, + }, + "cpFlags") + CpExecutable = pctx.AndroidStaticRule("CpExecutable", blueprint.RuleParams{ Command: "rm -f $out && cp $cpPreserveSymlinks $cpFlags $in $out && chmod +x $out", diff --git a/java/lint.go b/java/lint.go index af83664c6..12e412988 100644 --- a/java/lint.go +++ b/java/lint.go @@ -437,13 +437,13 @@ func (l *lintSingleton) copyLintDependencies(ctx android.SingletonContext) { } ctx.Build(pctx, android.BuildParams{ - Rule: android.Cp, + Rule: android.CpIfChanged, Input: android.OutputFileForModule(ctx, frameworkDocStubs, ".annotations.zip"), Output: copiedAnnotationsZipPath(ctx), }) ctx.Build(pctx, android.BuildParams{ - Rule: android.Cp, + Rule: android.CpIfChanged, Input: android.OutputFileForModule(ctx, frameworkDocStubs, ".api_versions.xml"), Output: copiedAPIVersionsXmlPath(ctx), }) From 5c113d13eb64f40e5d0d4212ca112cacc7979756 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 4 Mar 2021 10:01:34 -0800 Subject: [PATCH 3/3] Remove lint outputs to prevent showing old lint results on error The lint rules dumped the text output file to stdout on error. If the lint binary exited without updating the output file it would show old results. Remove the output files before running lint, and only dump the text output file if it exists. Bug: 181681346 Test: m lint-check Change-Id: I4fa962b1212e8715f234912a9a5e049d5c1540e8 --- java/lint.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/java/lint.go b/java/lint.go index 12e412988..50b84dc71 100644 --- a/java/lint.go +++ b/java/lint.go @@ -313,6 +313,7 @@ func (l *linter) lint(ctx android.ModuleContext) { rule.Command().Text("rm -rf").Flag(cacheDir.String()).Flag(homeDir.String()) rule.Command().Text("mkdir -p").Flag(cacheDir.String()).Flag(homeDir.String()) + rule.Command().Text("rm -f").Output(html).Output(text).Output(xml) var annotationsZipPath, apiVersionsXMLPath android.Path if ctx.Config().AlwaysUsePrebuiltSdks() { @@ -361,7 +362,7 @@ func (l *linter) lint(ctx android.ModuleContext) { } } - cmd.Text("|| (").Text("cat").Input(text).Text("; exit 7)").Text(")") + cmd.Text("|| (").Text("if [ -e").Input(text).Text("]; then cat").Input(text).Text("; fi; exit 7)").Text(")") rule.Command().Text("rm -rf").Flag(cacheDir.String()).Flag(homeDir.String())