diff options
author | 2021-05-10 15:30:00 -0700 | |
---|---|---|
committer | 2021-05-10 15:30:00 -0700 | |
commit | 476b9d6d17aa57fe34b6c46c23bfda1e73efa4ec (patch) | |
tree | 4870f7b1465d6f6e4af36f886c6d32085e01f2ef /java/lint.go | |
parent | d8561166eb3c360ecd6cfbbc1356bfc70e67c0b2 (diff) |
Strict updatability linting against dependencies.
Propagate strict_updatability_linting to transitive dependencies using a
top-down mutator.
Test: lint_test.go
Bug: 182349282
Change-Id: Ifc9e58f1a597e3c7725ee49b4027afb6f42f45cb
Diffstat (limited to 'java/lint.go')
-rw-r--r-- | java/lint.go | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/java/lint.go b/java/lint.go index 5e392742c..9f769dfe3 100644 --- a/java/lint.go +++ b/java/lint.go @@ -103,6 +103,10 @@ type lintOutputsIntf interface { type lintDepSetsIntf interface { LintDepSets() LintDepSets + + // Methods used to propagate strict_updatability_linting values. + getStrictUpdatabilityLinting() bool + setStrictUpdatabilityLinting(bool) } type LintDepSets struct { @@ -153,6 +157,14 @@ func (l *linter) LintDepSets() LintDepSets { return l.outputs.depSets } +func (l *linter) getStrictUpdatabilityLinting() bool { + return BoolDefault(l.properties.Lint.Strict_updatability_linting, false) +} + +func (l *linter) setStrictUpdatabilityLinting(strictLinting bool) { + l.properties.Lint.Strict_updatability_linting = &strictLinting +} + var _ lintDepSetsIntf = (*linter)(nil) var _ lintOutputsIntf = (*linter)(nil) @@ -260,7 +272,7 @@ func (l *linter) writeLintProjectXML(ctx android.ModuleContext, rule *android.Ru cmd.FlagForEachArg("--error_check ", l.properties.Lint.Error_checks) cmd.FlagForEachArg("--fatal_check ", l.properties.Lint.Fatal_checks) - if BoolDefault(l.properties.Lint.Strict_updatability_linting, false) { + if l.getStrictUpdatabilityLinting() { // Verify the module does not baseline issues that endanger safe updatability. if baselinePath := l.getBaselineFilepath(ctx); baselinePath.Valid() { cmd.FlagWithInput("--baseline ", baselinePath.Path()) @@ -586,6 +598,14 @@ var _ android.SingletonMakeVarsProvider = (*lintSingleton)(nil) func init() { android.RegisterSingletonType("lint", func() android.Singleton { return &lintSingleton{} }) + + registerLintBuildComponents(android.InitRegistrationContext) +} + +func registerLintBuildComponents(ctx android.RegistrationContext) { + ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) { + ctx.TopDown("enforce_strict_updatability_linting", enforceStrictUpdatabilityLintingMutator).Parallel() + }) } func lintZip(ctx android.BuilderContext, paths android.Paths, outputPath android.WritablePath) { @@ -604,3 +624,15 @@ func lintZip(ctx android.BuilderContext, paths android.Paths, outputPath android rule.Build(outputPath.Base(), outputPath.Base()) } + +// Enforce the strict updatability linting to all applicable transitive dependencies. +func enforceStrictUpdatabilityLintingMutator(ctx android.TopDownMutatorContext) { + m := ctx.Module() + if d, ok := m.(lintDepSetsIntf); ok && d.getStrictUpdatabilityLinting() { + ctx.VisitDirectDepsWithTag(staticLibTag, func(d android.Module) { + if a, ok := d.(lintDepSetsIntf); ok { + a.setStrictUpdatabilityLinting(true) + } + }) + } +} |