Prebuilt replacing source should not change partition
This reveals unintended mistake (setting a wrong target partition) at
build-time instead of runtime, which is much harder to debug.
Bug: 280368661
Test: m nothing (soong test)
Change-Id: Ic5e5e97ba918e24f7a59aceb405c2b105e28cccc
diff --git a/android/prebuilt_test.go b/android/prebuilt_test.go
index fa40d1f..fc47cfd 100644
--- a/android/prebuilt_test.go
+++ b/android/prebuilt_test.go
@@ -497,6 +497,52 @@
}
}
+func testPrebuiltError(t *testing.T, expectedError, bp string) {
+ t.Helper()
+ fs := MockFS{
+ "prebuilt_file": nil,
+ }
+ GroupFixturePreparers(
+ PrepareForTestWithArchMutator,
+ PrepareForTestWithPrebuilts,
+ PrepareForTestWithOverrides,
+ fs.AddToFixture(),
+ FixtureRegisterWithContext(registerTestPrebuiltModules),
+ ).
+ ExtendWithErrorHandler(FixtureExpectsAtLeastOneErrorMatchingPattern(expectedError)).
+ RunTestWithBp(t, bp)
+}
+
+func TestPrebuiltShouldNotChangePartition(t *testing.T) {
+ testPrebuiltError(t, `partition is different`, `
+ source {
+ name: "foo",
+ vendor: true,
+ }
+ prebuilt {
+ name: "foo",
+ prefer: true,
+ srcs: ["prebuilt_file"],
+ }`)
+}
+
+func TestPrebuiltShouldNotChangePartition_WithOverride(t *testing.T) {
+ testPrebuiltError(t, `partition is different`, `
+ source {
+ name: "foo",
+ vendor: true,
+ }
+ override_source {
+ name: "bar",
+ base: "foo",
+ }
+ prebuilt {
+ name: "bar",
+ prefer: true,
+ srcs: ["prebuilt_file"],
+ }`)
+}
+
func registerTestPrebuiltBuildComponents(ctx RegistrationContext) {
registerTestPrebuiltModules(ctx)