Merge "java_sdk_library - Use prebuilt/prefer for unbundled app builds" am: 7300095182 am: bef2f16ca4

Change-Id: I7b3f90196380e5663e05e8b7325aa75cd832e8b6
This commit is contained in:
Automerger Merge Worker
2020-02-07 06:00:34 +00:00
2 changed files with 28 additions and 17 deletions

View File

@@ -62,6 +62,10 @@ func (p *Prebuilt) Name(name string) string {
return "prebuilt_" + name
}
func (p *Prebuilt) ForcePrefer() {
p.properties.Prefer = proptools.BoolPtr(true)
}
// 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

View File

@@ -265,13 +265,11 @@ func (module *SdkLibrary) getActiveApiScopes() apiScopes {
}
func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
useBuiltStubs := !ctx.Config().UnbundledBuildUsePrebuiltSdks()
for _, apiScope := range module.getActiveApiScopes() {
// Add dependencies to the stubs library
if useBuiltStubs {
ctx.AddVariationDependencies(nil, apiScope.stubsTag, module.stubsName(apiScope))
}
ctx.AddVariationDependencies(nil, apiScope.stubsTag, module.stubsName(apiScope))
// And the api file
ctx.AddVariationDependencies(nil, apiScope.apiFileTag, module.docsName(apiScope))
}
@@ -466,9 +464,6 @@ func (module *SdkLibrary) createStubsLibrary(mctx android.LoadHookContext, apiSc
Compile_dex *bool
Java_version *string
Product_variables struct {
Unbundled_build struct {
Enabled *bool
}
Pdk struct {
Enabled *bool
}
@@ -487,10 +482,6 @@ func (module *SdkLibrary) createStubsLibrary(mctx android.LoadHookContext, apiSc
props.System_modules = module.Library.Module.deviceProperties.System_modules
props.Installable = proptools.BoolPtr(false)
props.Libs = module.sdkLibraryProperties.Stub_only_libs
// Unbundled apps will use the prebult one from /prebuilts/sdk
if mctx.Config().UnbundledBuildUsePrebuiltSdks() {
props.Product_variables.Unbundled_build.Enabled = proptools.BoolPtr(false)
}
props.Product_variables.Pdk.Enabled = proptools.BoolPtr(false)
props.Openjdk9.Srcs = module.Library.Module.properties.Openjdk9.Srcs
props.Openjdk9.Javacflags = module.Library.Module.properties.Openjdk9.Javacflags
@@ -651,7 +642,7 @@ func (module *SdkLibrary) createXmlFile(mctx android.LoadHookContext) {
mctx.CreateModule(android.PrebuiltEtcFactory, &etcProps)
}
func (module *SdkLibrary) PrebuiltJars(ctx android.BaseModuleContext, s sdkSpec) android.Paths {
func PrebuiltJars(ctx android.BaseModuleContext, baseName string, s sdkSpec) android.Paths {
var ver sdkVersion
var kind sdkKind
if s.usePrebuilt(ctx) {
@@ -665,7 +656,7 @@ func (module *SdkLibrary) PrebuiltJars(ctx android.BaseModuleContext, s sdkSpec)
}
dir := filepath.Join("prebuilts", "sdk", ver.String(), kind.String())
jar := filepath.Join(dir, module.BaseModuleName()+".jar")
jar := filepath.Join(dir, baseName+".jar")
jarPath := android.ExistentPathForSource(ctx, jar)
if !jarPath.Valid() {
if ctx.Config().AllowMissingDependencies() {
@@ -683,10 +674,9 @@ func (module *SdkLibrary) sdkJars(
sdkVersion sdkSpec,
headerJars bool) android.Paths {
// If a specific numeric version has been requested or the build is explicitly configured
// for it then use prebuilt versions of the sdk.
if sdkVersion.version.isNumbered() || ctx.Config().UnbundledBuildUsePrebuiltSdks() {
return module.PrebuiltJars(ctx, sdkVersion)
// If a specific numeric version has been requested then use prebuilt versions of the sdk.
if sdkVersion.version.isNumbered() {
return PrebuiltJars(ctx, module.BaseModuleName(), sdkVersion)
} else {
if !sdkVersion.specified() {
if headerJars {
@@ -899,6 +889,11 @@ func (module *sdkLibraryImport) Name() string {
func (module *sdkLibraryImport) createInternalModules(mctx android.LoadHookContext) {
// If the build is configured to use prebuilts then force this to be preferred.
if mctx.Config().UnbundledBuildUsePrebuiltSdks() {
module.prebuilt.ForcePrefer()
}
for apiScope, scopeProperties := range module.scopeProperties() {
if len(scopeProperties.Jars) == 0 {
continue
@@ -914,6 +909,7 @@ func (module *sdkLibraryImport) createInternalModules(mctx android.LoadHookConte
Sdk_version *string
Libs []string
Jars []string
Prefer *bool
}{}
props.Name = proptools.StringPtr(apiScope.stubsModuleName(module.BaseModuleName()))
@@ -933,6 +929,12 @@ func (module *sdkLibraryImport) createInternalModules(mctx android.LoadHookConte
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)
}
mctx.CreateModule(ImportFactory, &props)
}
@@ -980,6 +982,11 @@ func (module *sdkLibraryImport) sdkJars(
ctx android.BaseModuleContext,
sdkVersion sdkSpec) android.Paths {
// If a specific numeric version has been requested then use prebuilt versions of the sdk.
if sdkVersion.version.isNumbered() {
return PrebuiltJars(ctx, module.BaseModuleName(), sdkVersion)
}
var apiScope *apiScope
switch sdkVersion.kind {
case sdkSystem: