Restrict replacements of source dependencies with prebuilts am: 80342d72d0 am: 403b15074f

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1351596

Change-Id: I738152767fe955ec448471c60f246d58a96d4d7a
This commit is contained in:
Paul Duffin 2020-07-08 18:33:57 +00:00 committed by Automerger Merge Worker
commit 7bd62bef11
4 changed files with 29 additions and 3 deletions

View File

@ -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)
}

View File

@ -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()

View File

@ -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`,
})

View File

@ -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