Merge changes from topic "lint-unbundled-apps" into rvc-dev
* changes: Build a zip of transitive lint reports for apps Add DepSets Support lint on unbundled builds
This commit is contained in:
@@ -131,6 +131,10 @@ func (library *Library) AndroidMkEntries() []android.AndroidMkEntries {
|
||||
entries.SetPath("LOCAL_SOONG_PROGUARD_DICT", library.proguardDictionary)
|
||||
}
|
||||
entries.SetString("LOCAL_MODULE_STEM", library.Stem())
|
||||
|
||||
entries.AddOptionalPath("LOCAL_SOONG_LINT_REPORTS", library.linter.outputs.transitiveHTMLZip)
|
||||
entries.AddOptionalPath("LOCAL_SOONG_LINT_REPORTS", library.linter.outputs.transitiveTextZip)
|
||||
entries.AddOptionalPath("LOCAL_SOONG_LINT_REPORTS", library.linter.outputs.transitiveXMLZip)
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -383,6 +387,10 @@ func (app *AndroidApp) AndroidMkEntries() []android.AndroidMkEntries {
|
||||
install := app.onDeviceDir + "/" + extra.Base()
|
||||
entries.AddStrings("LOCAL_SOONG_BUILT_INSTALLED", extra.String()+":"+install)
|
||||
}
|
||||
|
||||
entries.AddOptionalPath("LOCAL_SOONG_LINT_REPORTS", app.linter.outputs.transitiveHTMLZip)
|
||||
entries.AddOptionalPath("LOCAL_SOONG_LINT_REPORTS", app.linter.outputs.transitiveTextZip)
|
||||
entries.AddOptionalPath("LOCAL_SOONG_LINT_REPORTS", app.linter.outputs.transitiveXMLZip)
|
||||
},
|
||||
},
|
||||
ExtraFooters: []android.AndroidMkExtraFootersFunc{
|
||||
|
@@ -749,6 +749,7 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
a.linter.mergedManifest = a.aapt.mergedManifestFile
|
||||
a.linter.manifest = a.aapt.manifestPath
|
||||
a.linter.resources = a.aapt.resourceFiles
|
||||
a.linter.buildModuleReportZip = ctx.Config().UnbundledBuild()
|
||||
|
||||
dexJarFile := a.dexBuildActions(ctx)
|
||||
|
||||
|
138
java/lint.go
138
java/lint.go
@@ -67,12 +67,32 @@ type linter struct {
|
||||
kotlinLanguageLevel string
|
||||
outputs lintOutputs
|
||||
properties LintProperties
|
||||
|
||||
buildModuleReportZip bool
|
||||
}
|
||||
|
||||
type lintOutputs struct {
|
||||
html android.ModuleOutPath
|
||||
text android.ModuleOutPath
|
||||
xml android.ModuleOutPath
|
||||
|
||||
transitiveHTML *android.DepSet
|
||||
transitiveText *android.DepSet
|
||||
transitiveXML *android.DepSet
|
||||
|
||||
transitiveHTMLZip android.OptionalPath
|
||||
transitiveTextZip android.OptionalPath
|
||||
transitiveXMLZip android.OptionalPath
|
||||
}
|
||||
|
||||
type lintOutputIntf interface {
|
||||
lintOutputs() *lintOutputs
|
||||
}
|
||||
|
||||
var _ lintOutputIntf = (*linter)(nil)
|
||||
|
||||
func (l *linter) lintOutputs() *lintOutputs {
|
||||
return &l.outputs
|
||||
}
|
||||
|
||||
func (l *linter) enabled() bool {
|
||||
@@ -213,27 +233,49 @@ func (l *linter) lint(ctx android.ModuleContext) {
|
||||
|
||||
projectXML, lintXML, cacheDir, homeDir, deps := l.writeLintProjectXML(ctx, rule)
|
||||
|
||||
l.outputs.html = android.PathForModuleOut(ctx, "lint-report.html")
|
||||
l.outputs.text = android.PathForModuleOut(ctx, "lint-report.txt")
|
||||
l.outputs.xml = android.PathForModuleOut(ctx, "lint-report.xml")
|
||||
html := android.PathForModuleOut(ctx, "lint-report.html")
|
||||
text := android.PathForModuleOut(ctx, "lint-report.txt")
|
||||
xml := android.PathForModuleOut(ctx, "lint-report.xml")
|
||||
|
||||
htmlDeps := android.NewDepSetBuilder(android.POSTORDER).Direct(html)
|
||||
textDeps := android.NewDepSetBuilder(android.POSTORDER).Direct(text)
|
||||
xmlDeps := android.NewDepSetBuilder(android.POSTORDER).Direct(xml)
|
||||
|
||||
ctx.VisitDirectDepsWithTag(staticLibTag, func(dep android.Module) {
|
||||
if depLint, ok := dep.(lintOutputIntf); ok {
|
||||
depLintOutputs := depLint.lintOutputs()
|
||||
htmlDeps.Transitive(depLintOutputs.transitiveHTML)
|
||||
textDeps.Transitive(depLintOutputs.transitiveText)
|
||||
xmlDeps.Transitive(depLintOutputs.transitiveXML)
|
||||
}
|
||||
})
|
||||
|
||||
rule.Command().Text("rm -rf").Flag(cacheDir.String()).Flag(homeDir.String())
|
||||
rule.Command().Text("mkdir -p").Flag(cacheDir.String()).Flag(homeDir.String())
|
||||
|
||||
var annotationsZipPath, apiVersionsXMLPath android.Path
|
||||
if ctx.Config().UnbundledBuildUsePrebuiltSdks() {
|
||||
annotationsZipPath = android.PathForSource(ctx, "prebuilts/sdk/current/public/data/annotations.zip")
|
||||
apiVersionsXMLPath = android.PathForSource(ctx, "prebuilts/sdk/current/public/data/api-versions.xml")
|
||||
} else {
|
||||
annotationsZipPath = copiedAnnotationsZipPath(ctx)
|
||||
apiVersionsXMLPath = copiedAPIVersionsXmlPath(ctx)
|
||||
}
|
||||
|
||||
rule.Command().
|
||||
Text("(").
|
||||
Flag("JAVA_OPTS=-Xmx2048m").
|
||||
FlagWithArg("ANDROID_SDK_HOME=", homeDir.String()).
|
||||
FlagWithInput("SDK_ANNOTATIONS=", annotationsZipPath(ctx)).
|
||||
FlagWithInput("LINT_OPTS=-DLINT_API_DATABASE=", apiVersionsXmlPath(ctx)).
|
||||
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")).
|
||||
Flag("--quiet").
|
||||
FlagWithInput("--project ", projectXML).
|
||||
FlagWithInput("--config ", lintXML).
|
||||
FlagWithOutput("--html ", l.outputs.html).
|
||||
FlagWithOutput("--text ", l.outputs.text).
|
||||
FlagWithOutput("--xml ", l.outputs.xml).
|
||||
FlagWithOutput("--html ", html).
|
||||
FlagWithOutput("--text ", text).
|
||||
FlagWithOutput("--xml ", xml).
|
||||
FlagWithArg("--compile-sdk-version ", l.compileSdkVersion).
|
||||
FlagWithArg("--java-language-level ", l.javaLanguageLevel).
|
||||
FlagWithArg("--kotlin-language-level ", l.kotlinLanguageLevel).
|
||||
@@ -241,23 +283,37 @@ func (l *linter) lint(ctx android.ModuleContext) {
|
||||
Flag("--exitcode").
|
||||
Flags(l.properties.Lint.Flags).
|
||||
Implicits(deps).
|
||||
Text("|| (").Text("cat").Input(l.outputs.text).Text("; exit 7)").
|
||||
Text("|| (").Text("cat").Input(text).Text("; exit 7)").
|
||||
Text(")")
|
||||
|
||||
rule.Command().Text("rm -rf").Flag(cacheDir.String()).Flag(homeDir.String())
|
||||
|
||||
rule.Build(pctx, ctx, "lint", "lint")
|
||||
}
|
||||
|
||||
func (l *linter) lintOutputs() *lintOutputs {
|
||||
return &l.outputs
|
||||
}
|
||||
l.outputs = lintOutputs{
|
||||
html: html,
|
||||
text: text,
|
||||
xml: xml,
|
||||
|
||||
type lintOutputIntf interface {
|
||||
lintOutputs() *lintOutputs
|
||||
}
|
||||
transitiveHTML: htmlDeps.Build(),
|
||||
transitiveText: textDeps.Build(),
|
||||
transitiveXML: xmlDeps.Build(),
|
||||
}
|
||||
|
||||
var _ lintOutputIntf = (*linter)(nil)
|
||||
if l.buildModuleReportZip {
|
||||
htmlZip := android.PathForModuleOut(ctx, "lint-report-html.zip")
|
||||
l.outputs.transitiveHTMLZip = android.OptionalPathForPath(htmlZip)
|
||||
lintZip(ctx, l.outputs.transitiveHTML.ToSortedList(), htmlZip)
|
||||
|
||||
textZip := android.PathForModuleOut(ctx, "lint-report-text.zip")
|
||||
l.outputs.transitiveTextZip = android.OptionalPathForPath(textZip)
|
||||
lintZip(ctx, l.outputs.transitiveText.ToSortedList(), textZip)
|
||||
|
||||
xmlZip := android.PathForModuleOut(ctx, "lint-report-xml.zip")
|
||||
l.outputs.transitiveXMLZip = android.OptionalPathForPath(xmlZip)
|
||||
lintZip(ctx, l.outputs.transitiveXML.ToSortedList(), xmlZip)
|
||||
}
|
||||
}
|
||||
|
||||
type lintSingleton struct {
|
||||
htmlZip android.WritablePath
|
||||
@@ -271,7 +327,7 @@ func (l *lintSingleton) GenerateBuildActions(ctx android.SingletonContext) {
|
||||
}
|
||||
|
||||
func (l *lintSingleton) copyLintDependencies(ctx android.SingletonContext) {
|
||||
if ctx.Config().UnbundledBuild() {
|
||||
if ctx.Config().UnbundledBuildUsePrebuiltSdks() {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -297,25 +353,29 @@ func (l *lintSingleton) copyLintDependencies(ctx android.SingletonContext) {
|
||||
ctx.Build(pctx, android.BuildParams{
|
||||
Rule: android.Cp,
|
||||
Input: android.OutputFileForModule(ctx, frameworkDocStubs, ".annotations.zip"),
|
||||
Output: annotationsZipPath(ctx),
|
||||
Output: copiedAnnotationsZipPath(ctx),
|
||||
})
|
||||
|
||||
ctx.Build(pctx, android.BuildParams{
|
||||
Rule: android.Cp,
|
||||
Input: android.OutputFileForModule(ctx, frameworkDocStubs, ".api_versions.xml"),
|
||||
Output: apiVersionsXmlPath(ctx),
|
||||
Output: copiedAPIVersionsXmlPath(ctx),
|
||||
})
|
||||
}
|
||||
|
||||
func annotationsZipPath(ctx android.PathContext) android.WritablePath {
|
||||
func copiedAnnotationsZipPath(ctx android.PathContext) android.WritablePath {
|
||||
return android.PathForOutput(ctx, "lint", "annotations.zip")
|
||||
}
|
||||
|
||||
func apiVersionsXmlPath(ctx android.PathContext) android.WritablePath {
|
||||
func copiedAPIVersionsXmlPath(ctx android.PathContext) android.WritablePath {
|
||||
return android.PathForOutput(ctx, "lint", "api_versions.xml")
|
||||
}
|
||||
|
||||
func (l *lintSingleton) generateLintReportZips(ctx android.SingletonContext) {
|
||||
if ctx.Config().UnbundledBuild() {
|
||||
return
|
||||
}
|
||||
|
||||
var outputs []*lintOutputs
|
||||
var dirs []string
|
||||
ctx.VisitAllModules(func(m android.Module) {
|
||||
@@ -343,18 +403,7 @@ func (l *lintSingleton) generateLintReportZips(ctx android.SingletonContext) {
|
||||
paths = append(paths, get(output))
|
||||
}
|
||||
|
||||
sort.Slice(paths, func(i, j int) bool {
|
||||
return paths[i].String() < paths[j].String()
|
||||
})
|
||||
|
||||
rule := android.NewRuleBuilder()
|
||||
|
||||
rule.Command().BuiltTool(ctx, "soong_zip").
|
||||
FlagWithOutput("-o ", outputPath).
|
||||
FlagWithArg("-C ", android.PathForIntermediates(ctx).String()).
|
||||
FlagWithRspFileInputList("-l ", paths)
|
||||
|
||||
rule.Build(pctx, ctx, outputPath.Base(), outputPath.Base())
|
||||
lintZip(ctx, paths, outputPath)
|
||||
}
|
||||
|
||||
l.htmlZip = android.PathForOutput(ctx, "lint-report-html.zip")
|
||||
@@ -370,7 +419,9 @@ func (l *lintSingleton) generateLintReportZips(ctx android.SingletonContext) {
|
||||
}
|
||||
|
||||
func (l *lintSingleton) MakeVars(ctx android.MakeVarsContext) {
|
||||
ctx.DistForGoal("lint-check", l.htmlZip, l.textZip, l.xmlZip)
|
||||
if !ctx.Config().UnbundledBuild() {
|
||||
ctx.DistForGoal("lint-check", l.htmlZip, l.textZip, l.xmlZip)
|
||||
}
|
||||
}
|
||||
|
||||
var _ android.SingletonMakeVarsProvider = (*lintSingleton)(nil)
|
||||
@@ -379,3 +430,20 @@ func init() {
|
||||
android.RegisterSingletonType("lint",
|
||||
func() android.Singleton { return &lintSingleton{} })
|
||||
}
|
||||
|
||||
func lintZip(ctx android.BuilderContext, paths android.Paths, outputPath android.WritablePath) {
|
||||
paths = android.SortedUniquePaths(android.CopyOfPaths(paths))
|
||||
|
||||
sort.Slice(paths, func(i, j int) bool {
|
||||
return paths[i].String() < paths[j].String()
|
||||
})
|
||||
|
||||
rule := android.NewRuleBuilder()
|
||||
|
||||
rule.Command().BuiltTool(ctx, "soong_zip").
|
||||
FlagWithOutput("-o ", outputPath).
|
||||
FlagWithArg("-C ", android.PathForIntermediates(ctx).String()).
|
||||
FlagWithRspFileInputList("-l ", paths)
|
||||
|
||||
rule.Build(pctx, ctx, outputPath.Base(), outputPath.Base())
|
||||
}
|
||||
|
Reference in New Issue
Block a user