Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5523481e authored by Kiyoung Kim's avatar Kiyoung Kim
Browse files

Check if vintf_fragment modules' target partition

Current implementation allows vintf_fragment to be installed in the
different partition of a module referenced it via
vintf_fragment_modules, but this is unexpected behavior and should be
caught from the build system to avoid any unintended mistakes. This
change checks target parition of vintf_fragment module and any modules
referencing it, and fails if there is any mismatch found.

Bug: 322089980
Test: aosp_cf_x86_64_phone build succeeded
Change-Id: Ie8152d2f2616726e44a99fb1261be292f2b9ad54
parent 3507a28d
Loading
Loading
Loading
Loading
+22 −1
Original line number Diff line number Diff line
@@ -1063,8 +1063,29 @@ var vintfDepTag = struct {
}{}

func addVintfFragmentDeps(ctx BottomUpMutatorContext) {
	// Vintf manifests in the recovery partition will be ignored.
	if !ctx.Device() || ctx.Module().InstallInRecovery() {
		return
	}

	deviceConfig := ctx.DeviceConfig()

	mod := ctx.Module()
	ctx.AddDependency(mod, vintfDepTag, mod.VintfFragmentModuleNames(ctx)...)
	vintfModules := ctx.AddDependency(mod, vintfDepTag, mod.VintfFragmentModuleNames(ctx)...)

	modPartition := mod.PartitionTag(deviceConfig)
	for _, vintf := range vintfModules {
		if vintfModule, ok := vintf.(*vintfFragmentModule); ok {
			vintfPartition := vintfModule.PartitionTag(deviceConfig)
			if modPartition != vintfPartition {
				ctx.ModuleErrorf("Module %q(%q) and Vintf_fragment %q(%q) are installed to different partitions.",
					mod.Name(), modPartition,
					vintfModule.Name(), vintfPartition)
			}
		} else {
			ctx.ModuleErrorf("Only vintf_fragment type module should be listed in vintf_fragment_modules : %q", vintf.Name())
		}
	}
}

// AddProperties "registers" the provided props
+26 −0
Original line number Diff line number Diff line
@@ -1080,3 +1080,29 @@ func TestOutputFileForModule(t *testing.T) {
		})
	}
}

func TestVintfFragmentModulesChecksPartition(t *testing.T) {
	bp := `
	vintf_fragment {
		name: "vintfModA",
		src: "test_vintf_file",
		vendor: true,
	}
	deps {
		name: "modA",
		vintf_fragment_modules: [
			"vintfModA",
		]
	}
	`

	testPreparer := GroupFixturePreparers(
		PrepareForTestWithAndroidBuildComponents,
		prepareForModuleTests,
	)

	testPreparer.
		ExtendWithErrorHandler(FixtureExpectsOneErrorPattern(
			"Module .+ and Vintf_fragment .+ are installed to different partitions.")).
		RunTestWithBp(t, bp)
}