Merge "Disable strict_updatability_linting" am: 20eed826fd
am: e9e590670f
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2458068 Change-Id: I33064ac7303ad0380dcdb82b863d459ac42ac7c7 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -9500,187 +9500,188 @@ func ensureDoesNotContainRequiredDeps(t *testing.T, ctx *android.TestContext, mo
|
||||
}
|
||||
}
|
||||
|
||||
func TestApexStrictUpdtabilityLint(t *testing.T) {
|
||||
bpTemplate := `
|
||||
apex {
|
||||
name: "myapex",
|
||||
key: "myapex.key",
|
||||
java_libs: ["myjavalib"],
|
||||
updatable: %v,
|
||||
min_sdk_version: "29",
|
||||
}
|
||||
apex_key {
|
||||
name: "myapex.key",
|
||||
}
|
||||
java_library {
|
||||
name: "myjavalib",
|
||||
srcs: ["MyClass.java"],
|
||||
apex_available: [ "myapex" ],
|
||||
lint: {
|
||||
strict_updatability_linting: %v,
|
||||
},
|
||||
sdk_version: "current",
|
||||
min_sdk_version: "29",
|
||||
}
|
||||
`
|
||||
fs := android.MockFS{
|
||||
"lint-baseline.xml": nil,
|
||||
}
|
||||
|
||||
testCases := []struct {
|
||||
testCaseName string
|
||||
apexUpdatable bool
|
||||
javaStrictUpdtabilityLint bool
|
||||
lintFileExists bool
|
||||
disallowedFlagExpected bool
|
||||
}{
|
||||
{
|
||||
testCaseName: "lint-baseline.xml does not exist, no disallowed flag necessary in lint cmd",
|
||||
apexUpdatable: true,
|
||||
javaStrictUpdtabilityLint: true,
|
||||
lintFileExists: false,
|
||||
disallowedFlagExpected: false,
|
||||
},
|
||||
{
|
||||
testCaseName: "non-updatable apex respects strict_updatability of javalib",
|
||||
apexUpdatable: false,
|
||||
javaStrictUpdtabilityLint: false,
|
||||
lintFileExists: true,
|
||||
disallowedFlagExpected: false,
|
||||
},
|
||||
{
|
||||
testCaseName: "non-updatable apex respects strict updatability of javalib",
|
||||
apexUpdatable: false,
|
||||
javaStrictUpdtabilityLint: true,
|
||||
lintFileExists: true,
|
||||
disallowedFlagExpected: true,
|
||||
},
|
||||
{
|
||||
testCaseName: "updatable apex sets strict updatability of javalib to true",
|
||||
apexUpdatable: true,
|
||||
javaStrictUpdtabilityLint: false, // will be set to true by mutator
|
||||
lintFileExists: true,
|
||||
disallowedFlagExpected: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
bp := fmt.Sprintf(bpTemplate, testCase.apexUpdatable, testCase.javaStrictUpdtabilityLint)
|
||||
fixtures := []android.FixturePreparer{}
|
||||
if testCase.lintFileExists {
|
||||
fixtures = append(fixtures, fs.AddToFixture())
|
||||
}
|
||||
|
||||
result := testApex(t, bp, fixtures...)
|
||||
myjavalib := result.ModuleForTests("myjavalib", "android_common_apex29")
|
||||
sboxProto := android.RuleBuilderSboxProtoForTests(t, myjavalib.Output("lint.sbox.textproto"))
|
||||
disallowedFlagActual := strings.Contains(*sboxProto.Commands[0].Command, "--baseline lint-baseline.xml --disallowed_issues NewApi")
|
||||
|
||||
if disallowedFlagActual != testCase.disallowedFlagExpected {
|
||||
t.Errorf("Failed testcase: %v \nActual lint cmd: %v", testCase.testCaseName, *sboxProto.Commands[0].Command)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdatabilityLintSkipLibcore(t *testing.T) {
|
||||
bp := `
|
||||
apex {
|
||||
name: "myapex",
|
||||
key: "myapex.key",
|
||||
java_libs: ["myjavalib"],
|
||||
updatable: true,
|
||||
min_sdk_version: "29",
|
||||
}
|
||||
apex_key {
|
||||
name: "myapex.key",
|
||||
}
|
||||
java_library {
|
||||
name: "myjavalib",
|
||||
srcs: ["MyClass.java"],
|
||||
apex_available: [ "myapex" ],
|
||||
sdk_version: "current",
|
||||
min_sdk_version: "29",
|
||||
}
|
||||
`
|
||||
|
||||
testCases := []struct {
|
||||
testCaseName string
|
||||
moduleDirectory string
|
||||
disallowedFlagExpected bool
|
||||
}{
|
||||
{
|
||||
testCaseName: "lintable module defined outside libcore",
|
||||
moduleDirectory: "",
|
||||
disallowedFlagExpected: true,
|
||||
},
|
||||
{
|
||||
testCaseName: "lintable module defined in libcore root directory",
|
||||
moduleDirectory: "libcore/",
|
||||
disallowedFlagExpected: false,
|
||||
},
|
||||
{
|
||||
testCaseName: "lintable module defined in libcore child directory",
|
||||
moduleDirectory: "libcore/childdir/",
|
||||
disallowedFlagExpected: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
lintFileCreator := android.FixtureAddTextFile(testCase.moduleDirectory+"lint-baseline.xml", "")
|
||||
bpFileCreator := android.FixtureAddTextFile(testCase.moduleDirectory+"Android.bp", bp)
|
||||
result := testApex(t, "", lintFileCreator, bpFileCreator)
|
||||
myjavalib := result.ModuleForTests("myjavalib", "android_common_apex29")
|
||||
sboxProto := android.RuleBuilderSboxProtoForTests(t, myjavalib.Output("lint.sbox.textproto"))
|
||||
cmdFlags := fmt.Sprintf("--baseline %vlint-baseline.xml --disallowed_issues NewApi", testCase.moduleDirectory)
|
||||
disallowedFlagActual := strings.Contains(*sboxProto.Commands[0].Command, cmdFlags)
|
||||
|
||||
if disallowedFlagActual != testCase.disallowedFlagExpected {
|
||||
t.Errorf("Failed testcase: %v \nActual lint cmd: %v", testCase.testCaseName, *sboxProto.Commands[0].Command)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// checks transtive deps of an apex coming from bootclasspath_fragment
|
||||
func TestApexStrictUpdtabilityLintBcpFragmentDeps(t *testing.T) {
|
||||
bp := `
|
||||
apex {
|
||||
name: "myapex",
|
||||
key: "myapex.key",
|
||||
bootclasspath_fragments: ["mybootclasspathfragment"],
|
||||
updatable: true,
|
||||
min_sdk_version: "29",
|
||||
}
|
||||
apex_key {
|
||||
name: "myapex.key",
|
||||
}
|
||||
bootclasspath_fragment {
|
||||
name: "mybootclasspathfragment",
|
||||
contents: ["myjavalib"],
|
||||
apex_available: ["myapex"],
|
||||
hidden_api: {
|
||||
split_packages: ["*"],
|
||||
},
|
||||
}
|
||||
java_library {
|
||||
name: "myjavalib",
|
||||
srcs: ["MyClass.java"],
|
||||
apex_available: [ "myapex" ],
|
||||
sdk_version: "current",
|
||||
min_sdk_version: "29",
|
||||
compile_dex: true,
|
||||
}
|
||||
`
|
||||
fs := android.MockFS{
|
||||
"lint-baseline.xml": nil,
|
||||
}
|
||||
|
||||
result := testApex(t, bp, dexpreopt.FixtureSetApexBootJars("myapex:myjavalib"), fs.AddToFixture())
|
||||
myjavalib := result.ModuleForTests("myjavalib", "android_common_apex29")
|
||||
sboxProto := android.RuleBuilderSboxProtoForTests(t, myjavalib.Output("lint.sbox.textproto"))
|
||||
if !strings.Contains(*sboxProto.Commands[0].Command, "--baseline lint-baseline.xml --disallowed_issues NewApi") {
|
||||
t.Errorf("Strict updabality lint missing in myjavalib coming from bootclasspath_fragment mybootclasspath-fragment\nActual lint cmd: %v", *sboxProto.Commands[0].Command)
|
||||
}
|
||||
}
|
||||
// TODO(b/193460475): Re-enable this test
|
||||
//func TestApexStrictUpdtabilityLint(t *testing.T) {
|
||||
// bpTemplate := `
|
||||
// apex {
|
||||
// name: "myapex",
|
||||
// key: "myapex.key",
|
||||
// java_libs: ["myjavalib"],
|
||||
// updatable: %v,
|
||||
// min_sdk_version: "29",
|
||||
// }
|
||||
// apex_key {
|
||||
// name: "myapex.key",
|
||||
// }
|
||||
// java_library {
|
||||
// name: "myjavalib",
|
||||
// srcs: ["MyClass.java"],
|
||||
// apex_available: [ "myapex" ],
|
||||
// lint: {
|
||||
// strict_updatability_linting: %v,
|
||||
// },
|
||||
// sdk_version: "current",
|
||||
// min_sdk_version: "29",
|
||||
// }
|
||||
// `
|
||||
// fs := android.MockFS{
|
||||
// "lint-baseline.xml": nil,
|
||||
// }
|
||||
//
|
||||
// testCases := []struct {
|
||||
// testCaseName string
|
||||
// apexUpdatable bool
|
||||
// javaStrictUpdtabilityLint bool
|
||||
// lintFileExists bool
|
||||
// disallowedFlagExpected bool
|
||||
// }{
|
||||
// {
|
||||
// testCaseName: "lint-baseline.xml does not exist, no disallowed flag necessary in lint cmd",
|
||||
// apexUpdatable: true,
|
||||
// javaStrictUpdtabilityLint: true,
|
||||
// lintFileExists: false,
|
||||
// disallowedFlagExpected: false,
|
||||
// },
|
||||
// {
|
||||
// testCaseName: "non-updatable apex respects strict_updatability of javalib",
|
||||
// apexUpdatable: false,
|
||||
// javaStrictUpdtabilityLint: false,
|
||||
// lintFileExists: true,
|
||||
// disallowedFlagExpected: false,
|
||||
// },
|
||||
// {
|
||||
// testCaseName: "non-updatable apex respects strict updatability of javalib",
|
||||
// apexUpdatable: false,
|
||||
// javaStrictUpdtabilityLint: true,
|
||||
// lintFileExists: true,
|
||||
// disallowedFlagExpected: true,
|
||||
// },
|
||||
// {
|
||||
// testCaseName: "updatable apex sets strict updatability of javalib to true",
|
||||
// apexUpdatable: true,
|
||||
// javaStrictUpdtabilityLint: false, // will be set to true by mutator
|
||||
// lintFileExists: true,
|
||||
// disallowedFlagExpected: true,
|
||||
// },
|
||||
// }
|
||||
//
|
||||
// for _, testCase := range testCases {
|
||||
// bp := fmt.Sprintf(bpTemplate, testCase.apexUpdatable, testCase.javaStrictUpdtabilityLint)
|
||||
// fixtures := []android.FixturePreparer{}
|
||||
// if testCase.lintFileExists {
|
||||
// fixtures = append(fixtures, fs.AddToFixture())
|
||||
// }
|
||||
//
|
||||
// result := testApex(t, bp, fixtures...)
|
||||
// myjavalib := result.ModuleForTests("myjavalib", "android_common_apex29")
|
||||
// sboxProto := android.RuleBuilderSboxProtoForTests(t, myjavalib.Output("lint.sbox.textproto"))
|
||||
// disallowedFlagActual := strings.Contains(*sboxProto.Commands[0].Command, "--baseline lint-baseline.xml --disallowed_issues NewApi")
|
||||
//
|
||||
// if disallowedFlagActual != testCase.disallowedFlagExpected {
|
||||
// t.Errorf("Failed testcase: %v \nActual lint cmd: %v", testCase.testCaseName, *sboxProto.Commands[0].Command)
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//func TestUpdatabilityLintSkipLibcore(t *testing.T) {
|
||||
// bp := `
|
||||
// apex {
|
||||
// name: "myapex",
|
||||
// key: "myapex.key",
|
||||
// java_libs: ["myjavalib"],
|
||||
// updatable: true,
|
||||
// min_sdk_version: "29",
|
||||
// }
|
||||
// apex_key {
|
||||
// name: "myapex.key",
|
||||
// }
|
||||
// java_library {
|
||||
// name: "myjavalib",
|
||||
// srcs: ["MyClass.java"],
|
||||
// apex_available: [ "myapex" ],
|
||||
// sdk_version: "current",
|
||||
// min_sdk_version: "29",
|
||||
// }
|
||||
// `
|
||||
//
|
||||
// testCases := []struct {
|
||||
// testCaseName string
|
||||
// moduleDirectory string
|
||||
// disallowedFlagExpected bool
|
||||
// }{
|
||||
// {
|
||||
// testCaseName: "lintable module defined outside libcore",
|
||||
// moduleDirectory: "",
|
||||
// disallowedFlagExpected: true,
|
||||
// },
|
||||
// {
|
||||
// testCaseName: "lintable module defined in libcore root directory",
|
||||
// moduleDirectory: "libcore/",
|
||||
// disallowedFlagExpected: false,
|
||||
// },
|
||||
// {
|
||||
// testCaseName: "lintable module defined in libcore child directory",
|
||||
// moduleDirectory: "libcore/childdir/",
|
||||
// disallowedFlagExpected: true,
|
||||
// },
|
||||
// }
|
||||
//
|
||||
// for _, testCase := range testCases {
|
||||
// lintFileCreator := android.FixtureAddTextFile(testCase.moduleDirectory+"lint-baseline.xml", "")
|
||||
// bpFileCreator := android.FixtureAddTextFile(testCase.moduleDirectory+"Android.bp", bp)
|
||||
// result := testApex(t, "", lintFileCreator, bpFileCreator)
|
||||
// myjavalib := result.ModuleForTests("myjavalib", "android_common_apex29")
|
||||
// sboxProto := android.RuleBuilderSboxProtoForTests(t, myjavalib.Output("lint.sbox.textproto"))
|
||||
// cmdFlags := fmt.Sprintf("--baseline %vlint-baseline.xml --disallowed_issues NewApi", testCase.moduleDirectory)
|
||||
// disallowedFlagActual := strings.Contains(*sboxProto.Commands[0].Command, cmdFlags)
|
||||
//
|
||||
// if disallowedFlagActual != testCase.disallowedFlagExpected {
|
||||
// t.Errorf("Failed testcase: %v \nActual lint cmd: %v", testCase.testCaseName, *sboxProto.Commands[0].Command)
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//// checks transtive deps of an apex coming from bootclasspath_fragment
|
||||
//func TestApexStrictUpdtabilityLintBcpFragmentDeps(t *testing.T) {
|
||||
// bp := `
|
||||
// apex {
|
||||
// name: "myapex",
|
||||
// key: "myapex.key",
|
||||
// bootclasspath_fragments: ["mybootclasspathfragment"],
|
||||
// updatable: true,
|
||||
// min_sdk_version: "29",
|
||||
// }
|
||||
// apex_key {
|
||||
// name: "myapex.key",
|
||||
// }
|
||||
// bootclasspath_fragment {
|
||||
// name: "mybootclasspathfragment",
|
||||
// contents: ["myjavalib"],
|
||||
// apex_available: ["myapex"],
|
||||
// hidden_api: {
|
||||
// split_packages: ["*"],
|
||||
// },
|
||||
// }
|
||||
// java_library {
|
||||
// name: "myjavalib",
|
||||
// srcs: ["MyClass.java"],
|
||||
// apex_available: [ "myapex" ],
|
||||
// sdk_version: "current",
|
||||
// min_sdk_version: "29",
|
||||
// compile_dex: true,
|
||||
// }
|
||||
// `
|
||||
// fs := android.MockFS{
|
||||
// "lint-baseline.xml": nil,
|
||||
// }
|
||||
//
|
||||
// result := testApex(t, bp, dexpreopt.FixtureSetApexBootJars("myapex:myjavalib"), fs.AddToFixture())
|
||||
// myjavalib := result.ModuleForTests("myjavalib", "android_common_apex29")
|
||||
// sboxProto := android.RuleBuilderSboxProtoForTests(t, myjavalib.Output("lint.sbox.textproto"))
|
||||
// if !strings.Contains(*sboxProto.Commands[0].Command, "--baseline lint-baseline.xml --disallowed_issues NewApi") {
|
||||
// t.Errorf("Strict updabality lint missing in myjavalib coming from bootclasspath_fragment mybootclasspath-fragment\nActual lint cmd: %v", *sboxProto.Commands[0].Command)
|
||||
// }
|
||||
//}
|
||||
|
||||
// updatable apexes should propagate updatable=true to its apps
|
||||
func TestUpdatableApexEnforcesAppUpdatability(t *testing.T) {
|
||||
|
15
java/lint.go
15
java/lint.go
@@ -275,13 +275,14 @@ 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 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())
|
||||
cmd.FlagForEachArg("--disallowed_issues ", updatabilityChecks)
|
||||
}
|
||||
}
|
||||
// TODO(b/193460475): Re-enable strict updatability linting
|
||||
//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())
|
||||
// cmd.FlagForEachArg("--disallowed_issues ", updatabilityChecks)
|
||||
// }
|
||||
//}
|
||||
|
||||
return lintPaths{
|
||||
projectXML: projectXMLPath,
|
||||
|
@@ -174,51 +174,52 @@ func TestJavaLintBypassUpdatableChecks(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestJavaLintStrictUpdatabilityLinting(t *testing.T) {
|
||||
bp := `
|
||||
java_library {
|
||||
name: "foo",
|
||||
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,
|
||||
}
|
||||
|
||||
result := android.GroupFixturePreparers(PrepareForTestWithJavaDefaultModules, fs.AddToFixture()).
|
||||
RunTestWithBp(t, bp)
|
||||
|
||||
foo := result.ModuleForTests("foo", "android_common")
|
||||
sboxProto := android.RuleBuilderSboxProtoForTests(t, foo.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")
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
}
|
||||
// TODO(b/193460475): Re-enable this test
|
||||
//func TestJavaLintStrictUpdatabilityLinting(t *testing.T) {
|
||||
// bp := `
|
||||
// java_library {
|
||||
// name: "foo",
|
||||
// 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,
|
||||
// }
|
||||
//
|
||||
// result := android.GroupFixturePreparers(PrepareForTestWithJavaDefaultModules, fs.AddToFixture()).
|
||||
// RunTestWithBp(t, bp)
|
||||
//
|
||||
// foo := result.ModuleForTests("foo", "android_common")
|
||||
// sboxProto := android.RuleBuilderSboxProtoForTests(t, foo.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")
|
||||
// }
|
||||
//
|
||||
// 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")
|
||||
// }
|
||||
//}
|
||||
|
||||
func TestJavaLintDatabaseSelectionFull(t *testing.T) {
|
||||
testCases := []string{
|
||||
|
Reference in New Issue
Block a user