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

Commit f7bbd2fe authored by Colin Cross's avatar Colin Cross
Browse files

Split DepIsInSameApex into outgoing and incoming

Prepare for calling DepIsInSameApex from the apex transition mutator
by splitting all the implementations in two, one that is called on the
outgoing module and only takes the depTag, and one that is called on the
incoming module and only takes the depTag.

apexBundle.depVisitor was passing the child into android.IsDepInSameApex
for both the parent and child paramters.  The parent field was only
used to find the type on which to call DepIsInSameApex, so this
effectively used the child's implementation of DepIsInSameApex.  That
used to be necessary when the parent and child were of different
module types, as the parent module type may not have been aware
of the rules for the child module type, but is no longer necessary
with split outgoing and incoming DepIsInSameApex.

Bug: 372543712
Test: all soong tests pass
Change-Id: If7c81ec3f7b1ea69d77e9ad7694e238820194e59
parent e489db47
Loading
Loading
Loading
Loading
+32 −7
Original line number Diff line number Diff line
@@ -149,15 +149,25 @@ var ApexBundleInfoProvider = blueprint.NewMutatorProvider[ApexBundleInfo]("apex_
// extracted from ApexModule to make it easier to define custom subsets of the ApexModule interface
// and improve code navigation within the IDE.
type DepIsInSameApex interface {
	// DepIsInSameApex tests if the other module 'dep' is considered as part of the same APEX as
	// this module. For example, a static lib dependency usually returns true here, while a
	// OutgoingDepIsInSameApex tests if the module depended on via 'tag' is considered as part of
	// the same APEX as this module. For example, a static lib dependency usually returns true here, while a
	// shared lib dependency to a stub library returns false.
	//
	// This method must not be called directly without first ignoring dependencies whose tags
	// implement ExcludeFromApexContentsTag. Calls from within the func passed to WalkPayloadDeps()
	// are fine as WalkPayloadDeps() will ignore those dependencies automatically. Otherwise, use
	// IsDepInSameApex instead.
	DepIsInSameApex(ctx BaseModuleContext, dep Module) bool
	OutgoingDepIsInSameApex(tag blueprint.DependencyTag) bool

	// IncomingDepIsInSameApex tests if this module depended on via 'tag' is considered as part of
	// the same APEX as the depending module module. For example, a static lib dependency usually
	// returns true here, while a shared lib dependency to a stub library returns false.
	//
	// This method must not be called directly without first ignoring dependencies whose tags
	// implement ExcludeFromApexContentsTag. Calls from within the func passed to WalkPayloadDeps()
	// are fine as WalkPayloadDeps() will ignore those dependencies automatically. Otherwise, use
	// IsDepInSameApex instead.
	IncomingDepIsInSameApex(tag blueprint.DependencyTag) bool
}

func IsDepInSameApex(ctx BaseModuleContext, module, dep Module) bool {
@@ -167,7 +177,14 @@ func IsDepInSameApex(ctx BaseModuleContext, module, dep Module) bool {
		// apex as the parent.
		return false
	}
	return module.(DepIsInSameApex).DepIsInSameApex(ctx, dep)

	if m, ok := module.(DepIsInSameApex); ok && !m.OutgoingDepIsInSameApex(depTag) {
		return false
	}
	if d, ok := dep.(DepIsInSameApex); ok && !d.IncomingDepIsInSameApex(depTag) {
		return false
	}
	return true
}

// ApexModule is the interface that a module type is expected to implement if the module has to be
@@ -385,7 +402,15 @@ func (m *ApexModuleBase) UniqueApexVariations() bool {
}

// Implements ApexModule
func (m *ApexModuleBase) DepIsInSameApex(ctx BaseModuleContext, dep Module) bool {
func (m *ApexModuleBase) OutgoingDepIsInSameApex(tag blueprint.DependencyTag) bool {
	// By default, if there is a dependency from A to B, we try to include both in the same
	// APEX, unless B is explicitly from outside of the APEX (i.e. a stubs lib). Thus, returning
	// true. This is overridden by some module types like apex.ApexBundle, cc.Module,
	// java.Module, etc.
	return true
}

func (m *ApexModuleBase) IncomingDepIsInSameApex(tag blueprint.DependencyTag) bool {
	// By default, if there is a dependency from A to B, we try to include both in the same
	// APEX, unless B is explicitly from outside of the APEX (i.e. a stubs lib). Thus, returning
	// true. This is overridden by some module types like apex.ApexBundle, cc.Module,
@@ -661,7 +686,7 @@ func ApexInfoMutator(ctx TopDownMutatorContext, module ApexModule) {
// variant.
func UpdateUniqueApexVariationsForDeps(mctx BottomUpMutatorContext, am ApexModule) {
	// anyInSameApex returns true if the two ApexInfo lists contain any values in an
	// InApexVariants list in common. It is used instead of DepIsInSameApex because it needs to
	// InApexVariants list in common. It is used instead of OutgoingDepIsInSameApex because it needs to
	// determine if the dep is in the same APEX due to being directly included, not only if it
	// is included _because_ it is a dependency.
	anyInSameApex := func(a, b ApexModule) bool {
@@ -813,7 +838,7 @@ func CheckMinSdkVersion(ctx ModuleContext, minSdkVersion ApiLevel, walk WalkPayl
			// dependencies.
			return false
		}
		if am, ok := from.(DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
		if !IsDepInSameApex(ctx, from, to) {
			return false
		}
		if m, ok := to.(ModuleWithMinSdkVersionCheck); ok {
+9 −6
Original line number Diff line number Diff line
@@ -1222,7 +1222,13 @@ const (
var _ android.DepIsInSameApex = (*apexBundle)(nil)

// Implements android.DepInInSameApex
func (a *apexBundle) DepIsInSameApex(_ android.BaseModuleContext, _ android.Module) bool {
func (a *apexBundle) OutgoingDepIsInSameApex(tag blueprint.DependencyTag) bool {
	// direct deps of an APEX bundle are all part of the APEX bundle
	// TODO(jiyong): shouldn't we look into the payload field of the dependencyTag?
	return true
}

func (a *apexBundle) IncomingDepIsInSameApex(tag blueprint.DependencyTag) bool {
	// direct deps of an APEX bundle are all part of the APEX bundle
	// TODO(jiyong): shouldn't we look into the payload field of the dependencyTag?
	return true
@@ -2109,17 +2115,14 @@ func (a *apexBundle) depVisitor(vctx *visitorContext, ctx android.ModuleContext,
			// like to record requiredNativeLibs even when
			// DepIsInSameAPex is false. We also shouldn't do
			// this for host.
			//
			// TODO(jiyong): explain why the same module is passed in twice.
			// Switching the first am to parent breaks lots of tests.
			if !android.IsDepInSameApex(ctx, am, am) {
			if !android.IsDepInSameApex(ctx, parent, am) {
				return false
			}

			vctx.filesInfo = append(vctx.filesInfo, af)
			return true // track transitive dependencies
		} else if rm, ok := child.(*rust.Module); ok {
			if !android.IsDepInSameApex(ctx, am, am) {
			if !android.IsDepInSameApex(ctx, parent, am) {
				return false
			}

+5 −2
Original line number Diff line number Diff line
@@ -274,12 +274,15 @@ func (p *prebuiltCommon) prebuiltApexContentsDeps(ctx android.BottomUpMutatorCon
}

// Implements android.DepInInSameApex
func (p *prebuiltCommon) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
	tag := ctx.OtherModuleDependencyTag(dep)
func (p *prebuiltCommon) OutgoingDepIsInSameApex(tag blueprint.DependencyTag) bool {
	_, ok := tag.(exportedDependencyTag)
	return ok
}

func (p *prebuiltCommon) IncomingDepIsInSameApex(tag blueprint.DependencyTag) bool {
	return true
}

// apexInfoMutator marks any modules for which this apex exports a file as requiring an apex
// specific variant and checks that they are supported.
//
+31 −26
Original line number Diff line number Diff line
@@ -3761,13 +3761,25 @@ func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Write
var _ android.ApexModule = (*Module)(nil)

// Implements android.ApexModule
func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
	depTag := ctx.OtherModuleDependencyTag(dep)
func (c *Module) OutgoingDepIsInSameApex(depTag blueprint.DependencyTag) bool {
	if depTag == stubImplDepTag {
		// We don't track from an implementation library to its stubs.
		return false
	}
	if depTag == staticVariantTag {
		// This dependency is for optimization (reuse *.o from the static lib). It doesn't
		// actually mean that the static lib (and its dependencies) are copied into the
		// APEX.
		return false
	}
	return true
}

func (c *Module) IncomingDepIsInSameApex(depTag blueprint.DependencyTag) bool {
	libDepTag, isLibDepTag := depTag.(libraryDependencyTag)

	if cc, ok := dep.(*Module); ok {
		if cc.HasStubsVariants() {
			if isLibDepTag && libDepTag.shared() {
	if c.HasStubsVariants() {
		if IsSharedDepTag(depTag) {
			// dynamic dep to a stubs lib crosses APEX boundary
			return false
		}
@@ -3775,8 +3787,11 @@ func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Modu
			// runtime dep to a stubs lib also crosses APEX boundary
			return false
		}
		if IsHeaderDepTag(depTag) {
			return false
		}
	}
		if cc.IsLlndk() {
	if c.IsLlndk() {
		return false
	}
	if isLibDepTag && libDepTag.fromStatic && libDepTag.shared() {
@@ -3789,17 +3804,7 @@ func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Modu
	if isLibDepTag && libDepTag.excludeInApex {
		return false
	}
	}
	if depTag == stubImplDepTag {
		// We don't track from an implementation library to its stubs.
		return false
	}
	if depTag == staticVariantTag {
		// This dependency is for optimization (reuse *.o from the static lib). It doesn't
		// actually mean that the static lib (and its dependencies) are copied into the
		// APEX.
		return false
	}

	return true
}

+2 −2
Original line number Diff line number Diff line
@@ -1603,8 +1603,8 @@ var _ UsesLibraryDependency = (*AARImport)(nil)
var _ android.ApexModule = (*AARImport)(nil)

// Implements android.ApexModule
func (a *AARImport) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
	return a.depIsInSameApex(ctx, dep)
func (a *AARImport) OutgoingDepIsInSameApex(tag blueprint.DependencyTag) bool {
	return a.depIsInSameApex(tag)
}

// Implements android.ApexModule
Loading