Set ANDROID_SDK_HOME when running lint

Lint tries to create ~/.android, set ANDROID_SDK_HOME to keep it
from attempting to write to the home directory, which may not be
writable.

Test: run lint
Bug: 159676171
Change-Id: I16375b88d309a8fa416b3a8efeabe15759889ae3
Merged-In: I16375b88d309a8fa416b3a8efeabe15759889ae3
(cherry picked from commit 977b6a822d)
This commit is contained in:
Colin Cross
2020-06-23 10:22:49 -07:00
parent 205a504053
commit bca9028825

View File

@@ -88,7 +88,7 @@ func (l *linter) deps(ctx android.BottomUpMutatorContext) {
} }
func (l *linter) writeLintProjectXML(ctx android.ModuleContext, func (l *linter) writeLintProjectXML(ctx android.ModuleContext,
rule *android.RuleBuilder) (projectXMLPath, configXMLPath, cacheDir android.WritablePath, deps android.Paths) { rule *android.RuleBuilder) (projectXMLPath, configXMLPath, cacheDir, homeDir android.WritablePath, deps android.Paths) {
var resourcesList android.WritablePath var resourcesList android.WritablePath
if len(l.resources) > 0 { if len(l.resources) > 0 {
@@ -106,6 +106,7 @@ func (l *linter) writeLintProjectXML(ctx android.ModuleContext,
// Lint looks for a lint.xml file next to the project.xml file, give it one. // Lint looks for a lint.xml file next to the project.xml file, give it one.
configXMLPath = android.PathForModuleOut(ctx, "lint", "lint.xml") configXMLPath = android.PathForModuleOut(ctx, "lint", "lint.xml")
cacheDir = android.PathForModuleOut(ctx, "lint", "cache") cacheDir = android.PathForModuleOut(ctx, "lint", "cache")
homeDir = android.PathForModuleOut(ctx, "lint", "home")
srcJarDir := android.PathForModuleOut(ctx, "lint-srcjars") srcJarDir := android.PathForModuleOut(ctx, "lint-srcjars")
srcJarList := zipSyncCmd(ctx, rule, srcJarDir, l.srcJars) srcJarList := zipSyncCmd(ctx, rule, srcJarDir, l.srcJars)
@@ -165,7 +166,7 @@ func (l *linter) writeLintProjectXML(ctx android.ModuleContext,
cmd.FlagForEachArg("--error_check ", l.properties.Lint.Error_checks) cmd.FlagForEachArg("--error_check ", l.properties.Lint.Error_checks)
cmd.FlagForEachArg("--fatal_check ", l.properties.Lint.Fatal_checks) cmd.FlagForEachArg("--fatal_check ", l.properties.Lint.Fatal_checks)
return projectXMLPath, configXMLPath, cacheDir, deps return projectXMLPath, configXMLPath, cacheDir, homeDir, deps
} }
// generateManifest adds a command to the rule to write a dummy manifest cat contains the // generateManifest adds a command to the rule to write a dummy manifest cat contains the
@@ -207,18 +208,19 @@ func (l *linter) lint(ctx android.ModuleContext) {
l.manifest = manifest l.manifest = manifest
} }
projectXML, lintXML, cacheDir, deps := l.writeLintProjectXML(ctx, rule) projectXML, lintXML, cacheDir, homeDir, deps := l.writeLintProjectXML(ctx, rule)
l.outputs.html = android.PathForModuleOut(ctx, "lint-report.html") l.outputs.html = android.PathForModuleOut(ctx, "lint-report.html")
l.outputs.text = android.PathForModuleOut(ctx, "lint-report.txt") l.outputs.text = android.PathForModuleOut(ctx, "lint-report.txt")
l.outputs.xml = android.PathForModuleOut(ctx, "lint-report.xml") l.outputs.xml = android.PathForModuleOut(ctx, "lint-report.xml")
rule.Command().Text("rm -rf").Flag(cacheDir.String()) rule.Command().Text("rm -rf").Flag(cacheDir.String()).Flag(homeDir.String())
rule.Command().Text("mkdir -p").Flag(cacheDir.String()) rule.Command().Text("mkdir -p").Flag(cacheDir.String()).Flag(homeDir.String())
rule.Command(). rule.Command().
Text("("). Text("(").
Flag("JAVA_OPTS=-Xmx2048m"). Flag("JAVA_OPTS=-Xmx2048m").
FlagWithArg("ANDROID_SDK_HOME=", homeDir.String()).
FlagWithInput("SDK_ANNOTATIONS=", annotationsZipPath(ctx)). FlagWithInput("SDK_ANNOTATIONS=", annotationsZipPath(ctx)).
FlagWithInput("LINT_OPTS=-DLINT_API_DATABASE=", apiVersionsXmlPath(ctx)). FlagWithInput("LINT_OPTS=-DLINT_API_DATABASE=", apiVersionsXmlPath(ctx)).
Tool(android.PathForSource(ctx, "prebuilts/cmdline-tools/tools/bin/lint")). Tool(android.PathForSource(ctx, "prebuilts/cmdline-tools/tools/bin/lint")).
@@ -239,7 +241,7 @@ func (l *linter) lint(ctx android.ModuleContext) {
Text("|| (").Text("cat").Input(l.outputs.text).Text("; exit 7)"). Text("|| (").Text("cat").Input(l.outputs.text).Text("; exit 7)").
Text(")") Text(")")
rule.Command().Text("rm -rf").Flag(cacheDir.String()) rule.Command().Text("rm -rf").Flag(cacheDir.String()).Flag(homeDir.String())
rule.Build(pctx, ctx, "lint", "lint") rule.Build(pctx, ctx, "lint", "lint")
} }