9231537fe2
Previously, SdkSpec was constructed only from the user string. It didn't make use of the Config struct where information about the latest stable SDK version, etc. is recorded. As a result, the build system couldn't check if the sdk version "current" is referring to the in-development (i.e. not-yet-frozen) SDK version or the latest stable version. "current" was always assumed to be in-development (IsPreview() returns true) even when Platform_sdk_final == true. As the first step for fixing that, this change requires android.EarlyModuleContext to be passed when constructing SdkSpec from the user string. In the following changes, "current" will be mapped to either FutureApiLevel (10000) or one of the FinalApiLevels() depending on whether the platform SDK was finalized or not. Bug: 175678607 Test: m Change-Id: Ifea12ebf147ecccf12e7266dd382819806571543
218 lines
8.1 KiB
Go
218 lines
8.1 KiB
Go
// Copyright 2020 Google Inc. All rights reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package java
|
|
|
|
// This file contains the module implementations for runtime_resource_overlay and
|
|
// override_runtime_resource_overlay.
|
|
|
|
import "android/soong/android"
|
|
|
|
func init() {
|
|
RegisterRuntimeResourceOverlayBuildComponents(android.InitRegistrationContext)
|
|
}
|
|
|
|
func RegisterRuntimeResourceOverlayBuildComponents(ctx android.RegistrationContext) {
|
|
ctx.RegisterModuleType("runtime_resource_overlay", RuntimeResourceOverlayFactory)
|
|
ctx.RegisterModuleType("override_runtime_resource_overlay", OverrideRuntimeResourceOverlayModuleFactory)
|
|
}
|
|
|
|
type RuntimeResourceOverlay struct {
|
|
android.ModuleBase
|
|
android.DefaultableModuleBase
|
|
android.OverridableModuleBase
|
|
aapt
|
|
|
|
properties RuntimeResourceOverlayProperties
|
|
overridableProperties OverridableRuntimeResourceOverlayProperties
|
|
|
|
certificate Certificate
|
|
|
|
outputFile android.Path
|
|
installDir android.InstallPath
|
|
}
|
|
|
|
type RuntimeResourceOverlayProperties struct {
|
|
// the name of a certificate in the default certificate directory or an android_app_certificate
|
|
// module name in the form ":module".
|
|
Certificate *string
|
|
|
|
// Name of the signing certificate lineage file.
|
|
Lineage *string
|
|
|
|
// optional theme name. If specified, the overlay package will be applied
|
|
// only when the ro.boot.vendor.overlay.theme system property is set to the same value.
|
|
Theme *string
|
|
|
|
// If not blank, set to the version of the sdk to compile against. This
|
|
// can be either an API version (e.g. "29" for API level 29 AKA Android 10)
|
|
// or special subsets of the current platform, for example "none", "current",
|
|
// "core", "system", "test". See build/soong/java/sdk.go for the full and
|
|
// up-to-date list of possible values.
|
|
// Defaults to compiling against the current platform.
|
|
Sdk_version *string
|
|
|
|
// if not blank, set the minimum version of the sdk that the compiled artifacts will run against.
|
|
// Defaults to sdk_version if not set.
|
|
Min_sdk_version *string
|
|
|
|
// list of android_library modules whose resources are extracted and linked against statically
|
|
Static_libs []string
|
|
|
|
// list of android_app modules whose resources are extracted and linked against
|
|
Resource_libs []string
|
|
|
|
// Names of modules to be overridden. Listed modules can only be other overlays
|
|
// (in Make or Soong).
|
|
// This does not completely prevent installation of the overridden overlays, but if both
|
|
// overlays would be installed by default (in PRODUCT_PACKAGES) the other overlay will be removed
|
|
// from PRODUCT_PACKAGES.
|
|
Overrides []string
|
|
}
|
|
|
|
// RuntimeResourceOverlayModule interface is used by the apex package to gather information from
|
|
// a RuntimeResourceOverlay module.
|
|
type RuntimeResourceOverlayModule interface {
|
|
android.Module
|
|
OutputFile() android.Path
|
|
Certificate() Certificate
|
|
Theme() string
|
|
}
|
|
|
|
func (r *RuntimeResourceOverlay) DepsMutator(ctx android.BottomUpMutatorContext) {
|
|
sdkDep := decodeSdkDep(ctx, android.SdkContext(r))
|
|
if sdkDep.hasFrameworkLibs() {
|
|
r.aapt.deps(ctx, sdkDep)
|
|
}
|
|
|
|
cert := android.SrcIsModule(String(r.properties.Certificate))
|
|
if cert != "" {
|
|
ctx.AddDependency(ctx.Module(), certificateTag, cert)
|
|
}
|
|
|
|
ctx.AddVariationDependencies(nil, staticLibTag, r.properties.Static_libs...)
|
|
ctx.AddVariationDependencies(nil, libTag, r.properties.Resource_libs...)
|
|
}
|
|
|
|
func (r *RuntimeResourceOverlay) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|
// Compile and link resources
|
|
r.aapt.hasNoCode = true
|
|
// Do not remove resources without default values nor dedupe resource configurations with the same value
|
|
aaptLinkFlags := []string{"--no-resource-deduping", "--no-resource-removal"}
|
|
// Allow the override of "package name" and "overlay target package name"
|
|
manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(ctx.ModuleName())
|
|
if overridden || r.overridableProperties.Package_name != nil {
|
|
// The product override variable has a priority over the package_name property.
|
|
if !overridden {
|
|
manifestPackageName = *r.overridableProperties.Package_name
|
|
}
|
|
aaptLinkFlags = append(aaptLinkFlags, generateAaptRenamePackageFlags(manifestPackageName, false)...)
|
|
}
|
|
if r.overridableProperties.Target_package_name != nil {
|
|
aaptLinkFlags = append(aaptLinkFlags,
|
|
"--rename-overlay-target-package "+*r.overridableProperties.Target_package_name)
|
|
}
|
|
r.aapt.buildActions(ctx, r, nil, aaptLinkFlags...)
|
|
|
|
// Sign the built package
|
|
_, certificates := collectAppDeps(ctx, r, false, false)
|
|
certificates = processMainCert(r.ModuleBase, String(r.properties.Certificate), certificates, ctx)
|
|
signed := android.PathForModuleOut(ctx, "signed", r.Name()+".apk")
|
|
var lineageFile android.Path
|
|
if lineage := String(r.properties.Lineage); lineage != "" {
|
|
lineageFile = android.PathForModuleSrc(ctx, lineage)
|
|
}
|
|
SignAppPackage(ctx, signed, r.aapt.exportPackage, certificates, nil, lineageFile)
|
|
r.certificate = certificates[0]
|
|
|
|
r.outputFile = signed
|
|
r.installDir = android.PathForModuleInstall(ctx, "overlay", String(r.properties.Theme))
|
|
ctx.InstallFile(r.installDir, r.outputFile.Base(), r.outputFile)
|
|
}
|
|
|
|
func (r *RuntimeResourceOverlay) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
|
|
return android.SdkSpecFrom(ctx, String(r.properties.Sdk_version))
|
|
}
|
|
|
|
func (r *RuntimeResourceOverlay) SystemModules() string {
|
|
return ""
|
|
}
|
|
|
|
func (r *RuntimeResourceOverlay) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
|
|
if r.properties.Min_sdk_version != nil {
|
|
return android.SdkSpecFrom(ctx, *r.properties.Min_sdk_version)
|
|
}
|
|
return r.SdkVersion(ctx)
|
|
}
|
|
|
|
func (r *RuntimeResourceOverlay) TargetSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
|
|
return r.SdkVersion(ctx)
|
|
}
|
|
|
|
func (r *RuntimeResourceOverlay) Certificate() Certificate {
|
|
return r.certificate
|
|
}
|
|
|
|
func (r *RuntimeResourceOverlay) OutputFile() android.Path {
|
|
return r.outputFile
|
|
}
|
|
|
|
func (r *RuntimeResourceOverlay) Theme() string {
|
|
return String(r.properties.Theme)
|
|
}
|
|
|
|
// runtime_resource_overlay generates a resource-only apk file that can overlay application and
|
|
// system resources at run time.
|
|
func RuntimeResourceOverlayFactory() android.Module {
|
|
module := &RuntimeResourceOverlay{}
|
|
module.AddProperties(
|
|
&module.properties,
|
|
&module.aaptProperties,
|
|
&module.overridableProperties)
|
|
|
|
android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
|
|
android.InitDefaultableModule(module)
|
|
android.InitOverridableModule(module, &module.properties.Overrides)
|
|
return module
|
|
}
|
|
|
|
// runtime_resource_overlay properties that can be overridden by override_runtime_resource_overlay
|
|
type OverridableRuntimeResourceOverlayProperties struct {
|
|
// the package name of this app. The package name in the manifest file is used if one was not given.
|
|
Package_name *string
|
|
|
|
// the target package name of this overlay app. The target package name in the manifest file is used if one was not given.
|
|
Target_package_name *string
|
|
}
|
|
|
|
type OverrideRuntimeResourceOverlay struct {
|
|
android.ModuleBase
|
|
android.OverrideModuleBase
|
|
}
|
|
|
|
func (i *OverrideRuntimeResourceOverlay) GenerateAndroidBuildActions(_ android.ModuleContext) {
|
|
// All the overrides happen in the base module.
|
|
// TODO(jungjw): Check the base module type.
|
|
}
|
|
|
|
// override_runtime_resource_overlay is used to create a module based on another
|
|
// runtime_resource_overlay module by overriding some of its properties.
|
|
func OverrideRuntimeResourceOverlayModuleFactory() android.Module {
|
|
m := &OverrideRuntimeResourceOverlay{}
|
|
m.AddProperties(&OverridableRuntimeResourceOverlayProperties{})
|
|
|
|
android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
|
|
android.InitOverrideModule(m)
|
|
return m
|
|
}
|