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

Commit 11edf557 authored by Cole Faust's avatar Cole Faust
Browse files

Add bazel-built modules as deps on the system image

These bazel-built modules will be installed into the system image
as part of the bazel rule, rather than going through the make staging
directory.

Bug: 297269187
Test: m bazel_sandwich
Change-Id: I96c6e58f8e0898b2ad92cb7069745ca2059a39f8
parent 03787bea
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -81,6 +81,11 @@ type BazelConversionStatus struct {
	// If non-nil, indicates that the module could not be converted successfully
	// with bp2build. This will describe the reason the module could not be converted.
	UnconvertedReason *UnconvertedReason

	// The Partition this module will be installed on.
	// TODO(b/306200980) Investigate how to handle modules that are installed in multiple
	// partitions.
	Partition string `blueprint:"mutated"`
}

// The reason a module could not be converted to a BUILD target via bp2build.
@@ -674,6 +679,9 @@ func bp2buildConversionMutator(ctx BottomUpMutatorContext) {

	bModule.ConvertWithBp2build(ctx)

	installCtx := &baseModuleContextToModuleInstallPathContext{ctx}
	ctx.Module().base().setPartitionForBp2build(modulePartition(installCtx, true))

	if len(ctx.Module().base().Bp2buildTargets()) == 0 && ctx.Module().base().GetUnconvertedReason() == nil {
		panic(fmt.Errorf("illegal bp2build invariant: module '%s' was neither converted nor marked unconvertible", ctx.ModuleName()))
	}
+49 −49
Original line number Diff line number Diff line
@@ -245,6 +245,55 @@ type noopBazelContext struct{}

var _ BazelContext = noopBazelContext{}

func (n noopBazelContext) QueueBazelRequest(_ string, _ cqueryRequest, _ configKey) {
	panic("unimplemented")
}

func (n noopBazelContext) QueueBazelSandwichCqueryRequests(config Config) error {
	panic("unimplemented")
}

func (n noopBazelContext) GetOutputFiles(_ string, _ configKey) ([]string, error) {
	panic("unimplemented")
}

func (n noopBazelContext) GetCcInfo(_ string, _ configKey) (cquery.CcInfo, error) {
	panic("unimplemented")
}

func (n noopBazelContext) GetApexInfo(_ string, _ configKey) (cquery.ApexInfo, error) {
	panic("unimplemented")
}

func (n noopBazelContext) GetCcUnstrippedInfo(_ string, _ configKey) (cquery.CcUnstrippedInfo, error) {
	//TODO implement me
	panic("implement me")
}

func (n noopBazelContext) GetPrebuiltFileInfo(_ string, _ configKey) (cquery.PrebuiltFileInfo, error) {
	panic("implement me")
}

func (n noopBazelContext) InvokeBazel(_ Config, _ invokeBazelContext) error {
	panic("unimplemented")
}

func (m noopBazelContext) OutputBase() string {
	return ""
}

func (n noopBazelContext) IsModuleNameAllowed(_ string, _ bool) bool {
	return false
}

func (m noopBazelContext) BuildStatementsToRegister() []*bazel.BuildStatement {
	return []*bazel.BuildStatement{}
}

func (m noopBazelContext) AqueryDepsets() []bazel.AqueryDepset {
	return []bazel.AqueryDepset{}
}

// A bazel context to use for tests.
type MockBazelContext struct {
	OutputBaseDir string
@@ -427,55 +476,6 @@ func (bazelCtx *mixedBuildBazelContext) GetPrebuiltFileInfo(label string, cfgKey
	return cquery.PrebuiltFileInfo{}, fmt.Errorf("no bazel response for %s", key)
}

func (n noopBazelContext) QueueBazelRequest(_ string, _ cqueryRequest, _ configKey) {
	panic("unimplemented")
}

func (n noopBazelContext) QueueBazelSandwichCqueryRequests(config Config) error {
	panic("unimplemented")
}

func (n noopBazelContext) GetOutputFiles(_ string, _ configKey) ([]string, error) {
	panic("unimplemented")
}

func (n noopBazelContext) GetCcInfo(_ string, _ configKey) (cquery.CcInfo, error) {
	panic("unimplemented")
}

func (n noopBazelContext) GetApexInfo(_ string, _ configKey) (cquery.ApexInfo, error) {
	panic("unimplemented")
}

func (n noopBazelContext) GetCcUnstrippedInfo(_ string, _ configKey) (cquery.CcUnstrippedInfo, error) {
	//TODO implement me
	panic("implement me")
}

func (n noopBazelContext) GetPrebuiltFileInfo(_ string, _ configKey) (cquery.PrebuiltFileInfo, error) {
	panic("implement me")
}

func (n noopBazelContext) InvokeBazel(_ Config, _ invokeBazelContext) error {
	panic("unimplemented")
}

func (m noopBazelContext) OutputBase() string {
	return ""
}

func (n noopBazelContext) IsModuleNameAllowed(_ string, _ bool) bool {
	return false
}

func (m noopBazelContext) BuildStatementsToRegister() []*bazel.BuildStatement {
	return []*bazel.BuildStatement{}
}

func (m noopBazelContext) AqueryDepsets() []bazel.AqueryDepset {
	return []bazel.AqueryDepset{}
}

func AddToStringSet(set map[string]bool, items []string) {
	for _, item := range items {
		set[item] = true
+4 −0
Original line number Diff line number Diff line
@@ -900,6 +900,10 @@ func (c *config) KatiEnabled() bool {
	return c.katiEnabled
}

func (c *config) ProductVariables() ProductVariables {
	return c.productVariables
}

func (c *config) BuildId() string {
	return String(c.productVariables.BuildId)
}
+10 −0
Original line number Diff line number Diff line
@@ -572,6 +572,7 @@ type Module interface {
	Bp2buildTargets() []bp2buildInfo
	GetUnconvertedBp2buildDeps() []string
	GetMissingBp2buildDeps() []string
	GetPartitionForBp2build() string

	BuildParamsForTests() []BuildParams
	RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams
@@ -1651,6 +1652,10 @@ func (m *ModuleBase) addBp2buildInfo(info bp2buildInfo) {
	m.commonProperties.BazelConversionStatus.Bp2buildInfo = append(m.commonProperties.BazelConversionStatus.Bp2buildInfo, info)
}

func (m *ModuleBase) setPartitionForBp2build(partition string) {
	m.commonProperties.BazelConversionStatus.Partition = partition
}

func (m *ModuleBase) setBp2buildUnconvertible(reasonType bp2build_metrics_proto.UnconvertedReasonType, detail string) {
	m.commonProperties.BazelConversionStatus.UnconvertedReason = &UnconvertedReason{
		ReasonType: int(reasonType),
@@ -1667,6 +1672,11 @@ func (m *ModuleBase) Bp2buildTargets() []bp2buildInfo {
	return m.commonProperties.BazelConversionStatus.Bp2buildInfo
}

// Bp2buildTargets returns the Bazel targets bp2build generated for this module.
func (m *ModuleBase) GetPartitionForBp2build() string {
	return m.commonProperties.BazelConversionStatus.Partition
}

// AddUnconvertedBp2buildDep stores module name of a dependency that was not converted to Bazel.
func (b *baseModuleContext) AddUnconvertedBp2buildDep(dep string) {
	unconvertedDeps := &b.Module().base().commonProperties.BazelConversionStatus.UnconvertedDeps
+45 −3
Original line number Diff line number Diff line
@@ -116,6 +116,48 @@ type ModuleInstallPathContext interface {

var _ ModuleInstallPathContext = ModuleContext(nil)

type baseModuleContextToModuleInstallPathContext struct {
	BaseModuleContext
}

func (ctx *baseModuleContextToModuleInstallPathContext) InstallInData() bool {
	return ctx.Module().InstallInData()
}

func (ctx *baseModuleContextToModuleInstallPathContext) InstallInTestcases() bool {
	return ctx.Module().InstallInTestcases()
}

func (ctx *baseModuleContextToModuleInstallPathContext) InstallInSanitizerDir() bool {
	return ctx.Module().InstallInSanitizerDir()
}

func (ctx *baseModuleContextToModuleInstallPathContext) InstallInRamdisk() bool {
	return ctx.Module().InstallInRamdisk()
}

func (ctx *baseModuleContextToModuleInstallPathContext) InstallInVendorRamdisk() bool {
	return ctx.Module().InstallInVendorRamdisk()
}

func (ctx *baseModuleContextToModuleInstallPathContext) InstallInDebugRamdisk() bool {
	return ctx.Module().InstallInDebugRamdisk()
}

func (ctx *baseModuleContextToModuleInstallPathContext) InstallInRecovery() bool {
	return ctx.Module().InstallInRecovery()
}

func (ctx *baseModuleContextToModuleInstallPathContext) InstallInRoot() bool {
	return ctx.Module().InstallInRoot()
}

func (ctx *baseModuleContextToModuleInstallPathContext) InstallForceOS() (*OsType, *ArchType) {
	return ctx.Module().InstallForceOS()
}

var _ ModuleInstallPathContext = (*baseModuleContextToModuleInstallPathContext)(nil)

// errorfContext is the interface containing the Errorf method matching the
// Errorf method in blueprint.SingletonContext.
type errorfContext interface {
@@ -1683,7 +1725,7 @@ func (p InstallPath) ToMakePath() InstallPath {
// module appended with paths...
func PathForModuleInstall(ctx ModuleInstallPathContext, pathComponents ...string) InstallPath {
	os, arch := osAndArch(ctx)
	partition := modulePartition(ctx, os)
	partition := modulePartition(ctx, os.Class == Device)
	return pathForInstall(ctx, os, arch, partition, pathComponents...)
}

@@ -1785,12 +1827,12 @@ func InstallPathToOnDevicePath(ctx PathContext, path InstallPath) string {
	return "/" + rel
}

func modulePartition(ctx ModuleInstallPathContext, os OsType) string {
func modulePartition(ctx ModuleInstallPathContext, device bool) string {
	var partition string
	if ctx.InstallInTestcases() {
		// "testcases" install directory can be used for host or device modules.
		partition = "testcases"
	} else if os.Class == Device {
	} else if device {
		if ctx.InstallInData() {
			partition = "data"
		} else if ctx.InstallInRamdisk() {
Loading