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
This commit is contained in:
14
java/java.go
14
java/java.go
@@ -1222,6 +1222,13 @@ func (j *Import) LintDepSets() LintDepSets {
|
|||||||
return LintDepSets{}
|
return LintDepSets{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (j *Import) getStrictUpdatabilityLinting() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (j *Import) setStrictUpdatabilityLinting(bool) {
|
||||||
|
}
|
||||||
|
|
||||||
func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
|
func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
|
||||||
ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
|
ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
|
||||||
|
|
||||||
@@ -1545,6 +1552,13 @@ func (j *DexImport) IsInstallable() bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (j *DexImport) getStrictUpdatabilityLinting() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (j *DexImport) setStrictUpdatabilityLinting(bool) {
|
||||||
|
}
|
||||||
|
|
||||||
func (j *DexImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
func (j *DexImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||||
if len(j.properties.Jars) != 1 {
|
if len(j.properties.Jars) != 1 {
|
||||||
ctx.PropertyErrorf("jars", "exactly one jar must be provided")
|
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 {
|
type lintDepSetsIntf interface {
|
||||||
LintDepSets() LintDepSets
|
LintDepSets() LintDepSets
|
||||||
|
|
||||||
|
// Methods used to propagate strict_updatability_linting values.
|
||||||
|
getStrictUpdatabilityLinting() bool
|
||||||
|
setStrictUpdatabilityLinting(bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
type LintDepSets struct {
|
type LintDepSets struct {
|
||||||
@@ -153,6 +157,14 @@ func (l *linter) LintDepSets() LintDepSets {
|
|||||||
return l.outputs.depSets
|
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 _ lintDepSetsIntf = (*linter)(nil)
|
||||||
|
|
||||||
var _ lintOutputsIntf = (*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("--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)
|
||||||
|
|
||||||
if BoolDefault(l.properties.Lint.Strict_updatability_linting, false) {
|
if l.getStrictUpdatabilityLinting() {
|
||||||
// Verify the module does not baseline issues that endanger safe updatability.
|
// Verify the module does not baseline issues that endanger safe updatability.
|
||||||
if baselinePath := l.getBaselineFilepath(ctx); baselinePath.Valid() {
|
if baselinePath := l.getBaselineFilepath(ctx); baselinePath.Valid() {
|
||||||
cmd.FlagWithInput("--baseline ", baselinePath.Path())
|
cmd.FlagWithInput("--baseline ", baselinePath.Path())
|
||||||
@@ -586,6 +598,14 @@ var _ android.SingletonMakeVarsProvider = (*lintSingleton)(nil)
|
|||||||
func init() {
|
func init() {
|
||||||
android.RegisterSingletonType("lint",
|
android.RegisterSingletonType("lint",
|
||||||
func() android.Singleton { return &lintSingleton{} })
|
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) {
|
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())
|
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: [
|
srcs: [
|
||||||
"a.java",
|
"a.java",
|
||||||
],
|
],
|
||||||
|
static_libs: ["bar"],
|
||||||
min_sdk_version: "29",
|
min_sdk_version: "29",
|
||||||
sdk_version: "current",
|
sdk_version: "current",
|
||||||
lint: {
|
lint: {
|
||||||
strict_updatability_linting: true,
|
strict_updatability_linting: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
java_library {
|
||||||
|
name: "bar",
|
||||||
|
srcs: [
|
||||||
|
"a.java",
|
||||||
|
],
|
||||||
|
min_sdk_version: "29",
|
||||||
|
sdk_version: "current",
|
||||||
|
}
|
||||||
`
|
`
|
||||||
fs := android.MockFS{
|
fs := android.MockFS{
|
||||||
"lint-baseline.xml": nil,
|
"lint-baseline.xml": nil,
|
||||||
@@ -201,4 +211,11 @@ func TestJavaLintStrictUpdatabilityLinting(t *testing.T) {
|
|||||||
"--baseline lint-baseline.xml --disallowed_issues NewApi") {
|
"--baseline lint-baseline.xml --disallowed_issues NewApi") {
|
||||||
t.Error("did not restrict baselining 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
|
// to satisfy apex.javaDependency interface
|
||||||
func (module *SdkLibraryImport) Stem() string {
|
func (module *SdkLibraryImport) Stem() string {
|
||||||
return module.BaseModuleName()
|
return module.BaseModuleName()
|
||||||
|
@@ -245,6 +245,7 @@ func registerRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
|
|||||||
RegisterStubsBuildComponents(ctx)
|
RegisterStubsBuildComponents(ctx)
|
||||||
RegisterSystemModulesBuildComponents(ctx)
|
RegisterSystemModulesBuildComponents(ctx)
|
||||||
registerSystemserverClasspathBuildComponents(ctx)
|
registerSystemserverClasspathBuildComponents(ctx)
|
||||||
|
registerLintBuildComponents(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// gatherRequiredDepsForTest gathers the module definitions used by
|
// gatherRequiredDepsForTest gathers the module definitions used by
|
||||||
|
Reference in New Issue
Block a user