Merge "Strict updatability linting against dependencies."
This commit is contained in:
commit
ccbbeb6965
5 changed files with 79 additions and 1 deletions
14
java/java.go
14
java/java.go
|
@ -1222,6 +1222,13 @@ func (j *Import) LintDepSets() LintDepSets {
|
|||
return LintDepSets{}
|
||||
}
|
||||
|
||||
func (j *Import) getStrictUpdatabilityLinting() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (j *Import) setStrictUpdatabilityLinting(bool) {
|
||||
}
|
||||
|
||||
func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
|
||||
ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
|
||||
|
||||
|
@ -1545,6 +1552,13 @@ func (j *DexImport) IsInstallable() bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func (j *DexImport) getStrictUpdatabilityLinting() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (j *DexImport) setStrictUpdatabilityLinting(bool) {
|
||||
}
|
||||
|
||||
func (j *DexImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
if len(j.properties.Jars) != 1 {
|
||||
ctx.PropertyErrorf("jars", "exactly one jar must be provided")
|
||||
|
|
34
java/lint.go
34
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -181,12 +181,22 @@ func TestJavaLintStrictUpdatabilityLinting(t *testing.T) {
|
|||
srcs: [
|
||||
"a.java",
|
||||
],
|
||||
static_libs: ["bar"],
|
||||
min_sdk_version: "29",
|
||||
sdk_version: "current",
|
||||
lint: {
|
||||
strict_updatability_linting: true,
|
||||
},
|
||||
}
|
||||
|
||||
java_library {
|
||||
name: "bar",
|
||||
srcs: [
|
||||
"a.java",
|
||||
],
|
||||
min_sdk_version: "29",
|
||||
sdk_version: "current",
|
||||
}
|
||||
`
|
||||
fs := android.MockFS{
|
||||
"lint-baseline.xml": nil,
|
||||
|
@ -201,4 +211,11 @@ func TestJavaLintStrictUpdatabilityLinting(t *testing.T) {
|
|||
"--baseline lint-baseline.xml --disallowed_issues NewApi") {
|
||||
t.Error("did not restrict baselining NewApi")
|
||||
}
|
||||
|
||||
bar := result.ModuleForTests("bar", "android_common")
|
||||
sboxProto = android.RuleBuilderSboxProtoForTests(t, bar.Output("lint.sbox.textproto"))
|
||||
if !strings.Contains(*sboxProto.Commands[0].Command,
|
||||
"--baseline lint-baseline.xml --disallowed_issues NewApi") {
|
||||
t.Error("did not restrict baselining NewApi")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2195,6 +2195,20 @@ func (module *SdkLibraryImport) LintDepSets() LintDepSets {
|
|||
}
|
||||
}
|
||||
|
||||
func (module *SdkLibraryImport) getStrictUpdatabilityLinting() bool {
|
||||
if module.implLibraryModule == nil {
|
||||
return false
|
||||
} else {
|
||||
return module.implLibraryModule.getStrictUpdatabilityLinting()
|
||||
}
|
||||
}
|
||||
|
||||
func (module *SdkLibraryImport) setStrictUpdatabilityLinting(strictLinting bool) {
|
||||
if module.implLibraryModule != nil {
|
||||
module.implLibraryModule.setStrictUpdatabilityLinting(strictLinting)
|
||||
}
|
||||
}
|
||||
|
||||
// to satisfy apex.javaDependency interface
|
||||
func (module *SdkLibraryImport) Stem() string {
|
||||
return module.BaseModuleName()
|
||||
|
|
|
@ -245,6 +245,7 @@ func registerRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
|
|||
RegisterStubsBuildComponents(ctx)
|
||||
RegisterSystemModulesBuildComponents(ctx)
|
||||
registerSystemserverClasspathBuildComponents(ctx)
|
||||
registerLintBuildComponents(ctx)
|
||||
}
|
||||
|
||||
// gatherRequiredDepsForTest gathers the module definitions used by
|
||||
|
|
Loading…
Reference in a new issue