Merge "Disable strict_updatability_linting" am: 20eed826fd

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2458068

Change-Id: I3ef301daab9e0341d60d2266e6a5290e2b9dd916
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Cole Faust
2023-03-01 00:37:49 +00:00
committed by Automerger Merge Worker
3 changed files with 236 additions and 233 deletions

View File

@@ -9500,187 +9500,188 @@ func ensureDoesNotContainRequiredDeps(t *testing.T, ctx *android.TestContext, mo
} }
} }
func TestApexStrictUpdtabilityLint(t *testing.T) { // TODO(b/193460475): Re-enable this test
bpTemplate := ` //func TestApexStrictUpdtabilityLint(t *testing.T) {
apex { // bpTemplate := `
name: "myapex", // apex {
key: "myapex.key", // name: "myapex",
java_libs: ["myjavalib"], // key: "myapex.key",
updatable: %v, // java_libs: ["myjavalib"],
min_sdk_version: "29", // updatable: %v,
} // min_sdk_version: "29",
apex_key { // }
name: "myapex.key", // apex_key {
} // name: "myapex.key",
java_library { // }
name: "myjavalib", // java_library {
srcs: ["MyClass.java"], // name: "myjavalib",
apex_available: [ "myapex" ], // srcs: ["MyClass.java"],
lint: { // apex_available: [ "myapex" ],
strict_updatability_linting: %v, // lint: {
}, // strict_updatability_linting: %v,
sdk_version: "current", // },
min_sdk_version: "29", // sdk_version: "current",
} // min_sdk_version: "29",
` // }
fs := android.MockFS{ // `
"lint-baseline.xml": nil, // fs := android.MockFS{
} // "lint-baseline.xml": nil,
// }
testCases := []struct { //
testCaseName string // testCases := []struct {
apexUpdatable bool // testCaseName string
javaStrictUpdtabilityLint bool // apexUpdatable bool
lintFileExists bool // javaStrictUpdtabilityLint bool
disallowedFlagExpected bool // lintFileExists bool
}{ // disallowedFlagExpected bool
{ // }{
testCaseName: "lint-baseline.xml does not exist, no disallowed flag necessary in lint cmd", // {
apexUpdatable: true, // testCaseName: "lint-baseline.xml does not exist, no disallowed flag necessary in lint cmd",
javaStrictUpdtabilityLint: true, // apexUpdatable: true,
lintFileExists: false, // javaStrictUpdtabilityLint: true,
disallowedFlagExpected: false, // lintFileExists: false,
}, // disallowedFlagExpected: false,
{ // },
testCaseName: "non-updatable apex respects strict_updatability of javalib", // {
apexUpdatable: false, // testCaseName: "non-updatable apex respects strict_updatability of javalib",
javaStrictUpdtabilityLint: false, // apexUpdatable: false,
lintFileExists: true, // javaStrictUpdtabilityLint: false,
disallowedFlagExpected: false, // lintFileExists: true,
}, // disallowedFlagExpected: false,
{ // },
testCaseName: "non-updatable apex respects strict updatability of javalib", // {
apexUpdatable: false, // testCaseName: "non-updatable apex respects strict updatability of javalib",
javaStrictUpdtabilityLint: true, // apexUpdatable: false,
lintFileExists: true, // javaStrictUpdtabilityLint: true,
disallowedFlagExpected: true, // lintFileExists: true,
}, // disallowedFlagExpected: true,
{ // },
testCaseName: "updatable apex sets strict updatability of javalib to true", // {
apexUpdatable: true, // testCaseName: "updatable apex sets strict updatability of javalib to true",
javaStrictUpdtabilityLint: false, // will be set to true by mutator // apexUpdatable: true,
lintFileExists: true, // javaStrictUpdtabilityLint: false, // will be set to true by mutator
disallowedFlagExpected: true, // lintFileExists: true,
}, // disallowedFlagExpected: true,
} // },
// }
for _, testCase := range testCases { //
bp := fmt.Sprintf(bpTemplate, testCase.apexUpdatable, testCase.javaStrictUpdtabilityLint) // for _, testCase := range testCases {
fixtures := []android.FixturePreparer{} // bp := fmt.Sprintf(bpTemplate, testCase.apexUpdatable, testCase.javaStrictUpdtabilityLint)
if testCase.lintFileExists { // fixtures := []android.FixturePreparer{}
fixtures = append(fixtures, fs.AddToFixture()) // if testCase.lintFileExists {
} // fixtures = append(fixtures, fs.AddToFixture())
// }
result := testApex(t, bp, fixtures...) //
myjavalib := result.ModuleForTests("myjavalib", "android_common_apex29") // result := testApex(t, bp, fixtures...)
sboxProto := android.RuleBuilderSboxProtoForTests(t, myjavalib.Output("lint.sbox.textproto")) // myjavalib := result.ModuleForTests("myjavalib", "android_common_apex29")
disallowedFlagActual := strings.Contains(*sboxProto.Commands[0].Command, "--baseline lint-baseline.xml --disallowed_issues NewApi") // 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) // 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 := ` //func TestUpdatabilityLintSkipLibcore(t *testing.T) {
apex { // bp := `
name: "myapex", // apex {
key: "myapex.key", // name: "myapex",
java_libs: ["myjavalib"], // key: "myapex.key",
updatable: true, // java_libs: ["myjavalib"],
min_sdk_version: "29", // updatable: true,
} // min_sdk_version: "29",
apex_key { // }
name: "myapex.key", // apex_key {
} // name: "myapex.key",
java_library { // }
name: "myjavalib", // java_library {
srcs: ["MyClass.java"], // name: "myjavalib",
apex_available: [ "myapex" ], // srcs: ["MyClass.java"],
sdk_version: "current", // apex_available: [ "myapex" ],
min_sdk_version: "29", // sdk_version: "current",
} // min_sdk_version: "29",
` // }
// `
testCases := []struct { //
testCaseName string // testCases := []struct {
moduleDirectory string // testCaseName string
disallowedFlagExpected bool // moduleDirectory string
}{ // disallowedFlagExpected bool
{ // }{
testCaseName: "lintable module defined outside libcore", // {
moduleDirectory: "", // testCaseName: "lintable module defined outside libcore",
disallowedFlagExpected: true, // moduleDirectory: "",
}, // disallowedFlagExpected: true,
{ // },
testCaseName: "lintable module defined in libcore root directory", // {
moduleDirectory: "libcore/", // testCaseName: "lintable module defined in libcore root directory",
disallowedFlagExpected: false, // moduleDirectory: "libcore/",
}, // disallowedFlagExpected: false,
{ // },
testCaseName: "lintable module defined in libcore child directory", // {
moduleDirectory: "libcore/childdir/", // testCaseName: "lintable module defined in libcore child directory",
disallowedFlagExpected: true, // moduleDirectory: "libcore/childdir/",
}, // disallowedFlagExpected: true,
} // },
// }
for _, testCase := range testCases { //
lintFileCreator := android.FixtureAddTextFile(testCase.moduleDirectory+"lint-baseline.xml", "") // for _, testCase := range testCases {
bpFileCreator := android.FixtureAddTextFile(testCase.moduleDirectory+"Android.bp", bp) // lintFileCreator := android.FixtureAddTextFile(testCase.moduleDirectory+"lint-baseline.xml", "")
result := testApex(t, "", lintFileCreator, bpFileCreator) // bpFileCreator := android.FixtureAddTextFile(testCase.moduleDirectory+"Android.bp", bp)
myjavalib := result.ModuleForTests("myjavalib", "android_common_apex29") // result := testApex(t, "", lintFileCreator, bpFileCreator)
sboxProto := android.RuleBuilderSboxProtoForTests(t, myjavalib.Output("lint.sbox.textproto")) // myjavalib := result.ModuleForTests("myjavalib", "android_common_apex29")
cmdFlags := fmt.Sprintf("--baseline %vlint-baseline.xml --disallowed_issues NewApi", testCase.moduleDirectory) // sboxProto := android.RuleBuilderSboxProtoForTests(t, myjavalib.Output("lint.sbox.textproto"))
disallowedFlagActual := strings.Contains(*sboxProto.Commands[0].Command, cmdFlags) // 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) // 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) { //// checks transtive deps of an apex coming from bootclasspath_fragment
bp := ` //func TestApexStrictUpdtabilityLintBcpFragmentDeps(t *testing.T) {
apex { // bp := `
name: "myapex", // apex {
key: "myapex.key", // name: "myapex",
bootclasspath_fragments: ["mybootclasspathfragment"], // key: "myapex.key",
updatable: true, // bootclasspath_fragments: ["mybootclasspathfragment"],
min_sdk_version: "29", // updatable: true,
} // min_sdk_version: "29",
apex_key { // }
name: "myapex.key", // apex_key {
} // name: "myapex.key",
bootclasspath_fragment { // }
name: "mybootclasspathfragment", // bootclasspath_fragment {
contents: ["myjavalib"], // name: "mybootclasspathfragment",
apex_available: ["myapex"], // contents: ["myjavalib"],
hidden_api: { // apex_available: ["myapex"],
split_packages: ["*"], // hidden_api: {
}, // split_packages: ["*"],
} // },
java_library { // }
name: "myjavalib", // java_library {
srcs: ["MyClass.java"], // name: "myjavalib",
apex_available: [ "myapex" ], // srcs: ["MyClass.java"],
sdk_version: "current", // apex_available: [ "myapex" ],
min_sdk_version: "29", // sdk_version: "current",
compile_dex: true, // min_sdk_version: "29",
} // compile_dex: true,
` // }
fs := android.MockFS{ // `
"lint-baseline.xml": nil, // fs := android.MockFS{
} // "lint-baseline.xml": nil,
// }
result := testApex(t, bp, dexpreopt.FixtureSetApexBootJars("myapex:myjavalib"), fs.AddToFixture()) //
myjavalib := result.ModuleForTests("myjavalib", "android_common_apex29") // result := testApex(t, bp, dexpreopt.FixtureSetApexBootJars("myapex:myjavalib"), fs.AddToFixture())
sboxProto := android.RuleBuilderSboxProtoForTests(t, myjavalib.Output("lint.sbox.textproto")) // myjavalib := result.ModuleForTests("myjavalib", "android_common_apex29")
if !strings.Contains(*sboxProto.Commands[0].Command, "--baseline lint-baseline.xml --disallowed_issues NewApi") { // sboxProto := android.RuleBuilderSboxProtoForTests(t, myjavalib.Output("lint.sbox.textproto"))
t.Errorf("Strict updabality lint missing in myjavalib coming from bootclasspath_fragment mybootclasspath-fragment\nActual lint cmd: %v", *sboxProto.Commands[0].Command) // 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 // updatable apexes should propagate updatable=true to its apps
func TestUpdatableApexEnforcesAppUpdatability(t *testing.T) { func TestUpdatableApexEnforcesAppUpdatability(t *testing.T) {

View File

@@ -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("--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 l.GetStrictUpdatabilityLinting() { // TODO(b/193460475): Re-enable strict updatability linting
// Verify the module does not baseline issues that endanger safe updatability. //if l.GetStrictUpdatabilityLinting() {
if baselinePath := l.getBaselineFilepath(ctx); baselinePath.Valid() { // // Verify the module does not baseline issues that endanger safe updatability.
cmd.FlagWithInput("--baseline ", baselinePath.Path()) // if baselinePath := l.getBaselineFilepath(ctx); baselinePath.Valid() {
cmd.FlagForEachArg("--disallowed_issues ", updatabilityChecks) // cmd.FlagWithInput("--baseline ", baselinePath.Path())
} // cmd.FlagForEachArg("--disallowed_issues ", updatabilityChecks)
} // }
//}
return lintPaths{ return lintPaths{
projectXML: projectXMLPath, projectXML: projectXMLPath,

View File

@@ -174,51 +174,52 @@ func TestJavaLintBypassUpdatableChecks(t *testing.T) {
} }
} }
func TestJavaLintStrictUpdatabilityLinting(t *testing.T) { // TODO(b/193460475): Re-enable this test
bp := ` //func TestJavaLintStrictUpdatabilityLinting(t *testing.T) {
java_library { // bp := `
name: "foo", // java_library {
srcs: [ // name: "foo",
"a.java", // srcs: [
], // "a.java",
static_libs: ["bar"], // ],
min_sdk_version: "29", // static_libs: ["bar"],
sdk_version: "current", // min_sdk_version: "29",
lint: { // sdk_version: "current",
strict_updatability_linting: true, // lint: {
}, // strict_updatability_linting: true,
} // },
// }
java_library { //
name: "bar", // java_library {
srcs: [ // name: "bar",
"a.java", // srcs: [
], // "a.java",
min_sdk_version: "29", // ],
sdk_version: "current", // min_sdk_version: "29",
} // sdk_version: "current",
` // }
fs := android.MockFS{ // `
"lint-baseline.xml": nil, // fs := android.MockFS{
} // "lint-baseline.xml": nil,
// }
result := android.GroupFixturePreparers(PrepareForTestWithJavaDefaultModules, fs.AddToFixture()). //
RunTestWithBp(t, bp) // result := android.GroupFixturePreparers(PrepareForTestWithJavaDefaultModules, fs.AddToFixture()).
// RunTestWithBp(t, bp)
foo := result.ModuleForTests("foo", "android_common") //
sboxProto := android.RuleBuilderSboxProtoForTests(t, foo.Output("lint.sbox.textproto")) // foo := result.ModuleForTests("foo", "android_common")
if !strings.Contains(*sboxProto.Commands[0].Command, // sboxProto := android.RuleBuilderSboxProtoForTests(t, foo.Output("lint.sbox.textproto"))
"--baseline lint-baseline.xml --disallowed_issues NewApi") { // if !strings.Contains(*sboxProto.Commands[0].Command,
t.Error("did not restrict baselining NewApi") // "--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")) // bar := result.ModuleForTests("bar", "android_common")
if !strings.Contains(*sboxProto.Commands[0].Command, // sboxProto = android.RuleBuilderSboxProtoForTests(t, bar.Output("lint.sbox.textproto"))
"--baseline lint-baseline.xml --disallowed_issues NewApi") { // if !strings.Contains(*sboxProto.Commands[0].Command,
t.Error("did not restrict baselining NewApi") // "--baseline lint-baseline.xml --disallowed_issues NewApi") {
} // t.Error("did not restrict baselining NewApi")
} // }
//}
func TestJavaLintDatabaseSelectionFull(t *testing.T) { func TestJavaLintDatabaseSelectionFull(t *testing.T) {
testCases := []string{ testCases := []string{