From 38b5785e3f4474e07f7b9ab24041b017d11d7028 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Wed, 13 May 2020 16:08:09 +0100 Subject: [PATCH] java_sdk_library_import: Propagate prefer to child modules Bug: 155164730 Test: m nothing Change-Id: Idb06d79baf346ac570beada79880814c5ef6bb50 --- android/prebuilt.go | 4 ++++ java/sdk_library.go | 15 ++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/android/prebuilt.go b/android/prebuilt.go index 82745a498..ee4a13af2 100644 --- a/android/prebuilt.go +++ b/android/prebuilt.go @@ -69,6 +69,10 @@ func (p *Prebuilt) ForcePrefer() { p.properties.Prefer = proptools.BoolPtr(true) } +func (p *Prebuilt) Prefer() bool { + return proptools.Bool(p.properties.Prefer) +} + // The below source-related functions and the srcs, src fields are based on an assumption that // prebuilt modules have a static source property at the moment. Currently there is only one // exception, android_app_import, which chooses a source file depending on the product's DPI diff --git a/java/sdk_library.go b/java/sdk_library.go index 2650ab3e7..10e7138d0 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -1448,22 +1448,23 @@ func (module *sdkLibraryImport) createJavaImportForStubs(mctx android.Defaultabl } else if module.SystemExtSpecific() { props.System_ext_specific = proptools.BoolPtr(true) } - // If the build should use prebuilt sdks then set prefer to true on the stubs library. - // That will cause the prebuilt version of the stubs to override the source version. - if mctx.Config().UnbundledBuildUsePrebuiltSdks() { - props.Prefer = proptools.BoolPtr(true) - } + // The imports are preferred if the java_sdk_library_import is preferred. + props.Prefer = proptools.BoolPtr(module.prebuilt.Prefer()) mctx.CreateModule(ImportFactory, &props) } func (module *sdkLibraryImport) createPrebuiltStubsSources(mctx android.DefaultableHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) { props := struct { - Name *string - Srcs []string + Name *string + Srcs []string + Prefer *bool }{} props.Name = proptools.StringPtr(module.stubsSourceModuleName(apiScope)) props.Srcs = scopeProperties.Stub_srcs mctx.CreateModule(PrebuiltStubsSourcesFactory, &props) + + // The stubs source is preferred if the java_sdk_library_import is preferred. + props.Prefer = proptools.BoolPtr(module.prebuilt.Prefer()) } func (module *sdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) {