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

Commit 80342d72 authored by Paul Duffin's avatar Paul Duffin
Browse files

Restrict replacements of source dependencies with prebuilts

Previously, when java_sdk_library_import was preferred over a
java_sdk_library the latter ends up depending on the prebuilt child
modules created by the java_sdk_library_import instead of the source
child modules that it created itself. That was because all dependencies
on those source child modules were replaced with the corresponding
prebuilt child modules.

This change prevents those dependencies from being replaced to preserve
the dependencies from java_sdk_library onto its source child modules by
making the replacement conditional depending on the tag used. It also
updates the affected test.

Bug: 159902351
Test: m nothing
Change-Id: I4441b901dedfd44b9769df1ac2e248b94834cf85
parent 44f1d840
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -214,6 +214,7 @@ type BottomUpMutatorContext interface {
	AddFarVariationDependencies([]blueprint.Variation, blueprint.DependencyTag, ...string)
	AddInterVariantDependency(tag blueprint.DependencyTag, from, to blueprint.Module)
	ReplaceDependencies(string)
	ReplaceDependenciesIf(string, blueprint.ReplaceDependencyPredicate)
	AliasVariation(variationName string)
}

@@ -428,6 +429,10 @@ func (b *bottomUpMutatorContext) ReplaceDependencies(name string) {
	b.bp.ReplaceDependencies(name)
}

func (b *bottomUpMutatorContext) ReplaceDependenciesIf(name string, predicate blueprint.ReplaceDependencyPredicate) {
	b.bp.ReplaceDependenciesIf(name, predicate)
}

func (b *bottomUpMutatorContext) AliasVariation(variationName string) {
	b.bp.AliasVariation(variationName)
}
+17 −1
Original line number Diff line number Diff line
@@ -30,6 +30,16 @@ func RegisterPrebuiltMutators(ctx RegistrationContext) {
	ctx.PostDepsMutators(RegisterPrebuiltsPostDepsMutators)
}

// Marks a dependency tag as possibly preventing a reference to a source from being
// replaced with the prebuilt.
type ReplaceSourceWithPrebuilt interface {
	blueprint.DependencyTag

	// Return true if the dependency defined by this tag should be replaced with the
	// prebuilt.
	ReplaceSourceWithPrebuilt() bool
}

type prebuiltDependencyTag struct {
	blueprint.BaseDependencyTag
}
@@ -260,7 +270,13 @@ func PrebuiltPostDepsMutator(ctx BottomUpMutatorContext) {
		name := m.base().BaseModuleName()
		if p.properties.UsePrebuilt {
			if p.properties.SourceExists {
				ctx.ReplaceDependencies(name)
				ctx.ReplaceDependenciesIf(name, func(from blueprint.Module, tag blueprint.DependencyTag, to blueprint.Module) bool {
					if t, ok := tag.(ReplaceSourceWithPrebuilt); ok {
						return t.ReplaceSourceWithPrebuilt()
					}

					return true
				})
			}
		} else {
			m.SkipInstall()
+1 −2
Original line number Diff line number Diff line
@@ -718,9 +718,8 @@ func TestJavaSdkLibraryImport_Preferred(t *testing.T) {
	checkModuleDependencies(t, ctx, "sdklib", "android_common", []string{
		`dex2oatd`,
		`prebuilt_sdklib`,
		// This should be sdklib.stubs but is switched to the prebuilt because it is preferred.
		`prebuilt_sdklib.stubs`,
		`sdklib.impl`,
		`sdklib.stubs`,
		`sdklib.stubs.source`,
		`sdklib.xml`,
	})
+6 −0
Original line number Diff line number Diff line
@@ -70,6 +70,12 @@ func (tag scopeDependencyTag) extractDepInfo(ctx android.ModuleContext, dep andr
	}
}

var _ android.ReplaceSourceWithPrebuilt = (*scopeDependencyTag)(nil)

func (tag scopeDependencyTag) ReplaceSourceWithPrebuilt() bool {
	return false
}

// Provides information about an api scope, e.g. public, system, test.
type apiScope struct {
	// The name of the api scope, e.g. public, system, test