Use providers for lint
Bug: b/348040422
Test: lint_test.go
Flag: EXEMPT refactor
Change-Id: I420bee2c7056a3f4acee3af5955f79c504ea61d9
diff --git a/java/app_import.go b/java/app_import.go
index 045a89a..a54cf2f 100644
--- a/java/app_import.go
+++ b/java/app_import.go
@@ -533,10 +533,6 @@
return android.SdkSpecPrivate.ApiLevel
}
-func (a *AndroidAppImport) LintDepSets() LintDepSets {
- return LintDepSets{}
-}
-
var _ android.ApexModule = (*AndroidAppImport)(nil)
// Implements android.ApexModule
diff --git a/java/base.go b/java/base.go
index 3d42f46..fc8cf95 100644
--- a/java/base.go
+++ b/java/base.go
@@ -707,9 +707,6 @@
ctx.SetOutputFiles(android.Paths{m.dexer.proguardDictionary.Path()}, ".proguard_map")
}
ctx.SetOutputFiles(m.properties.Generated_srcjars, ".generated_srcjars")
- if m.linter.outputs.xml != nil {
- ctx.SetOutputFiles(android.Paths{m.linter.outputs.xml}, ".lint")
- }
}
func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
diff --git a/java/java.go b/java/java.go
index 95f4fd8..1fa0830 100644
--- a/java/java.go
+++ b/java/java.go
@@ -2607,10 +2607,6 @@
return nil
}
-func (j *Import) LintDepSets() LintDepSets {
- return LintDepSets{}
-}
-
func (j *Import) getStrictUpdatabilityLinting() bool {
return false
}
@@ -3120,10 +3116,6 @@
return nil
}
-func (a *DexImport) LintDepSets() LintDepSets {
- return LintDepSets{}
-}
-
func (j *DexImport) IsInstallable() bool {
return true
}
diff --git a/java/lint.go b/java/lint.go
index 6782adc..5cd49a8 100644
--- a/java/lint.go
+++ b/java/lint.go
@@ -19,6 +19,7 @@
"sort"
"strings"
+ "github.com/google/blueprint"
"github.com/google/blueprint/proptools"
"android/soong/android"
@@ -90,7 +91,6 @@
compileSdkKind android.SdkKind
javaLanguageLevel string
kotlinLanguageLevel string
- outputs lintOutputs
properties LintProperties
extraMainlineLintErrors []string
compile_data android.Paths
@@ -100,22 +100,7 @@
buildModuleReportZip bool
}
-type lintOutputs struct {
- html android.Path
- text android.Path
- xml android.Path
- referenceBaseline android.Path
-
- depSets LintDepSets
-}
-
-type lintOutputsIntf interface {
- lintOutputs() *lintOutputs
-}
-
type LintDepSetsIntf interface {
- LintDepSets() LintDepSets
-
// Methods used to propagate strict_updatability_linting values.
GetStrictUpdatabilityLinting() bool
SetStrictUpdatabilityLinting(bool)
@@ -144,15 +129,15 @@
return l
}
-func (l LintDepSetsBuilder) Transitive(depSets LintDepSets) LintDepSetsBuilder {
- if depSets.HTML != nil {
- l.HTML.Transitive(depSets.HTML)
+func (l LintDepSetsBuilder) Transitive(info *LintInfo) LintDepSetsBuilder {
+ if info.TransitiveHTML != nil {
+ l.HTML.Transitive(info.TransitiveHTML)
}
- if depSets.Text != nil {
- l.Text.Transitive(depSets.Text)
+ if info.TransitiveText != nil {
+ l.Text.Transitive(info.TransitiveText)
}
- if depSets.XML != nil {
- l.XML.Transitive(depSets.XML)
+ if info.TransitiveXML != nil {
+ l.XML.Transitive(info.TransitiveXML)
}
return l
}
@@ -209,10 +194,6 @@
},
}
-func (l *linter) LintDepSets() LintDepSets {
- return l.outputs.depSets
-}
-
func (l *linter) GetStrictUpdatabilityLinting() bool {
return BoolDefault(l.properties.Lint.Strict_updatability_linting, false)
}
@@ -223,10 +204,17 @@
var _ LintDepSetsIntf = (*linter)(nil)
-var _ lintOutputsIntf = (*linter)(nil)
+var LintProvider = blueprint.NewProvider[*LintInfo]()
-func (l *linter) lintOutputs() *lintOutputs {
- return &l.outputs
+type LintInfo struct {
+ HTML android.Path
+ Text android.Path
+ XML android.Path
+ ReferenceBaseline android.Path
+
+ TransitiveHTML *android.DepSet[android.Path]
+ TransitiveText *android.DepSet[android.Path]
+ TransitiveXML *android.DepSet[android.Path]
}
func (l *linter) enabled() bool {
@@ -447,11 +435,13 @@
depSetsBuilder := NewLintDepSetBuilder().Direct(html, text, xml)
ctx.VisitDirectDepsWithTag(staticLibTag, func(dep android.Module) {
- if depLint, ok := dep.(LintDepSetsIntf); ok {
- depSetsBuilder.Transitive(depLint.LintDepSets())
+ if info, ok := android.OtherModuleProvider(ctx, dep, LintProvider); ok {
+ depSetsBuilder.Transitive(info)
}
})
+ depSets := depSetsBuilder.Build()
+
rule.Command().Text("rm -rf").Flag(lintPaths.cacheDir.String()).Flag(lintPaths.homeDir.String())
rule.Command().Text("mkdir -p").Flag(lintPaths.cacheDir.String()).Flag(lintPaths.homeDir.String())
rule.Command().Text("rm -f").Output(html).Output(text).Output(xml)
@@ -530,22 +520,26 @@
rule.Build("lint", "lint")
- l.outputs = lintOutputs{
- html: html,
- text: text,
- xml: xml,
- referenceBaseline: referenceBaseline,
+ android.SetProvider(ctx, LintProvider, &LintInfo{
+ HTML: html,
+ Text: text,
+ XML: xml,
+ ReferenceBaseline: referenceBaseline,
- depSets: depSetsBuilder.Build(),
- }
+ TransitiveHTML: depSets.HTML,
+ TransitiveText: depSets.Text,
+ TransitiveXML: depSets.XML,
+ })
if l.buildModuleReportZip {
- l.reports = BuildModuleLintReportZips(ctx, l.LintDepSets())
+ l.reports = BuildModuleLintReportZips(ctx, depSets)
}
// Create a per-module phony target to run the lint check.
phonyName := ctx.ModuleName() + "-lint"
ctx.Phony(phonyName, xml)
+
+ ctx.SetOutputFiles(android.Paths{xml}, ".lint")
}
func BuildModuleLintReportZips(ctx android.ModuleContext, depSets LintDepSets) android.Paths {
@@ -642,7 +636,7 @@
return
}
- var outputs []*lintOutputs
+ var outputs []*LintInfo
var dirs []string
ctx.VisitAllModules(func(m android.Module) {
if ctx.Config().KatiEnabled() && !m.ExportedToMake() {
@@ -658,14 +652,14 @@
}
}
- if l, ok := m.(lintOutputsIntf); ok {
- outputs = append(outputs, l.lintOutputs())
+ if lintInfo, ok := android.OtherModuleProvider(ctx, m, LintProvider); ok {
+ outputs = append(outputs, lintInfo)
}
})
dirs = android.SortedUniqueStrings(dirs)
- zip := func(outputPath android.WritablePath, get func(*lintOutputs) android.Path) {
+ zip := func(outputPath android.WritablePath, get func(*LintInfo) android.Path) {
var paths android.Paths
for _, output := range outputs {
@@ -678,16 +672,16 @@
}
l.htmlZip = android.PathForOutput(ctx, "lint-report-html.zip")
- zip(l.htmlZip, func(l *lintOutputs) android.Path { return l.html })
+ zip(l.htmlZip, func(l *LintInfo) android.Path { return l.HTML })
l.textZip = android.PathForOutput(ctx, "lint-report-text.zip")
- zip(l.textZip, func(l *lintOutputs) android.Path { return l.text })
+ zip(l.textZip, func(l *LintInfo) android.Path { return l.Text })
l.xmlZip = android.PathForOutput(ctx, "lint-report-xml.zip")
- zip(l.xmlZip, func(l *lintOutputs) android.Path { return l.xml })
+ zip(l.xmlZip, func(l *LintInfo) android.Path { return l.XML })
l.referenceBaselineZip = android.PathForOutput(ctx, "lint-report-reference-baselines.zip")
- zip(l.referenceBaselineZip, func(l *lintOutputs) android.Path { return l.referenceBaseline })
+ zip(l.referenceBaselineZip, func(l *LintInfo) android.Path { return l.ReferenceBaseline })
ctx.Phony("lint-check", l.htmlZip, l.textZip, l.xmlZip, l.referenceBaselineZip)
}
diff --git a/java/sdk_library.go b/java/sdk_library.go
index 725aaed..5deb49f 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -1568,7 +1568,10 @@
module.dexer.proguardDictionary = module.implLibraryModule.dexer.proguardDictionary
module.dexer.proguardUsageZip = module.implLibraryModule.dexer.proguardUsageZip
module.linter.reports = module.implLibraryModule.linter.reports
- module.linter.outputs.depSets = module.implLibraryModule.LintDepSets()
+
+ if lintInfo, ok := android.OtherModuleProvider(ctx, module.implLibraryModule, LintProvider); ok {
+ android.SetProvider(ctx, LintProvider, lintInfo)
+ }
if !module.Host() {
module.hostdexInstallFile = module.implLibraryModule.hostdexInstallFile
@@ -2919,14 +2922,6 @@
}
// to satisfy apex.javaDependency interface
-func (module *SdkLibraryImport) LintDepSets() LintDepSets {
- if module.implLibraryModule == nil {
- return LintDepSets{}
- } else {
- return module.implLibraryModule.LintDepSets()
- }
-}
-
func (module *SdkLibraryImport) GetStrictUpdatabilityLinting() bool {
if module.implLibraryModule == nil {
return false