2019-11-18 10:16:27 +08:00
|
|
|
// Copyright (C) 2019 The Android Open Source Project
|
|
|
|
//
|
|
|
|
// 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 apex
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-05-15 05:15:24 +08:00
|
|
|
"strconv"
|
2019-11-18 10:16:27 +08:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"android/soong/android"
|
2020-05-15 05:15:24 +08:00
|
|
|
"android/soong/java"
|
2020-07-16 20:38:56 +08:00
|
|
|
|
2020-05-15 05:15:24 +08:00
|
|
|
"github.com/google/blueprint"
|
2019-11-18 10:16:27 +08:00
|
|
|
|
|
|
|
"github.com/google/blueprint/proptools"
|
|
|
|
)
|
|
|
|
|
2020-05-15 05:15:24 +08:00
|
|
|
var (
|
|
|
|
extractMatchingApex = pctx.StaticRule(
|
|
|
|
"extractMatchingApex",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: `rm -rf "$out" && ` +
|
|
|
|
`${extract_apks} -o "${out}" -allow-prereleased=${allow-prereleased} ` +
|
|
|
|
`-sdk-version=${sdk-version} -abis=${abis} -screen-densities=all -extract-single ` +
|
|
|
|
`${in}`,
|
|
|
|
CommandDeps: []string{"${extract_apks}"},
|
|
|
|
},
|
|
|
|
"abis", "allow-prereleased", "sdk-version")
|
|
|
|
)
|
|
|
|
|
2020-07-16 20:38:56 +08:00
|
|
|
type prebuilt interface {
|
|
|
|
isForceDisabled() bool
|
|
|
|
InstallFilename() string
|
|
|
|
}
|
|
|
|
|
|
|
|
type prebuiltCommon struct {
|
|
|
|
prebuilt android.Prebuilt
|
|
|
|
properties prebuiltCommonProperties
|
2021-04-07 00:02:08 +08:00
|
|
|
|
|
|
|
deapexerProperties DeapexerProperties
|
|
|
|
selectedApexProperties SelectedApexProperties
|
2020-07-16 20:38:56 +08:00
|
|
|
}
|
|
|
|
|
2020-07-25 06:35:40 +08:00
|
|
|
type sanitizedPrebuilt interface {
|
|
|
|
hasSanitizedSource(sanitizer string) bool
|
|
|
|
}
|
|
|
|
|
2020-07-16 20:38:56 +08:00
|
|
|
type prebuiltCommonProperties struct {
|
|
|
|
ForceDisable bool `blueprint:"mutated"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *prebuiltCommon) Prebuilt() *android.Prebuilt {
|
|
|
|
return &p.prebuilt
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *prebuiltCommon) isForceDisabled() bool {
|
|
|
|
return p.properties.ForceDisable
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *prebuiltCommon) checkForceDisable(ctx android.ModuleContext) bool {
|
|
|
|
// If the device is configured to use flattened APEX, force disable the prebuilt because
|
|
|
|
// the prebuilt is a non-flattened one.
|
|
|
|
forceDisable := ctx.Config().FlattenApex()
|
|
|
|
|
|
|
|
// Force disable the prebuilts when we are doing unbundled build. We do unbundled build
|
|
|
|
// to build the prebuilts themselves.
|
|
|
|
forceDisable = forceDisable || ctx.Config().UnbundledBuild()
|
|
|
|
|
|
|
|
// Force disable the prebuilts when coverage is enabled.
|
|
|
|
forceDisable = forceDisable || ctx.DeviceConfig().NativeCoverageEnabled()
|
|
|
|
forceDisable = forceDisable || ctx.Config().IsEnvTrue("EMMA_INSTRUMENT")
|
|
|
|
|
2020-07-25 06:35:40 +08:00
|
|
|
// b/137216042 don't use prebuilts when address sanitizer is on, unless the prebuilt has a sanitized source
|
|
|
|
sanitized := ctx.Module().(sanitizedPrebuilt)
|
|
|
|
forceDisable = forceDisable || (android.InList("address", ctx.Config().SanitizeDevice()) && !sanitized.hasSanitizedSource("address"))
|
|
|
|
forceDisable = forceDisable || (android.InList("hwaddress", ctx.Config().SanitizeDevice()) && !sanitized.hasSanitizedSource("hwaddress"))
|
2020-07-16 20:38:56 +08:00
|
|
|
|
|
|
|
if forceDisable && p.prebuilt.SourceExists() {
|
|
|
|
p.properties.ForceDisable = true
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-04-07 00:02:08 +08:00
|
|
|
func (p *prebuiltCommon) deapexerDeps(ctx android.BottomUpMutatorContext) {
|
|
|
|
// Add dependencies onto the java modules that represent the java libraries that are provided by
|
|
|
|
// and exported from this prebuilt apex.
|
|
|
|
for _, lib := range p.deapexerProperties.Exported_java_libs {
|
|
|
|
dep := prebuiltApexExportedModuleName(ctx, lib)
|
|
|
|
ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(), exportedJavaLibTag, dep)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// apexInfoMutator marks any modules for which this apex exports a file as requiring an apex
|
|
|
|
// specific variant and checks that they are supported.
|
|
|
|
//
|
|
|
|
// The apexMutator will ensure that the ApexInfo objects passed to BuildForApex(ApexInfo) are
|
|
|
|
// associated with the apex specific variant using the ApexInfoProvider for later retrieval.
|
|
|
|
//
|
|
|
|
// Unlike the source apex module type the prebuilt_apex module type cannot share compatible variants
|
|
|
|
// across prebuilt_apex modules. That is because there is no way to determine whether two
|
|
|
|
// prebuilt_apex modules that export files for the same module are compatible. e.g. they could have
|
|
|
|
// been built from different source at different times or they could have been built with different
|
|
|
|
// build options that affect the libraries.
|
|
|
|
//
|
|
|
|
// While it may be possible to provide sufficient information to determine whether two prebuilt_apex
|
|
|
|
// modules were compatible it would be a lot of work and would not provide much benefit for a couple
|
|
|
|
// of reasons:
|
|
|
|
// * The number of prebuilt_apex modules that will be exporting files for the same module will be
|
|
|
|
// low as the prebuilt_apex only exports files for the direct dependencies that require it and
|
|
|
|
// very few modules are direct dependencies of multiple prebuilt_apex modules, e.g. there are a
|
|
|
|
// few com.android.art* apex files that contain the same contents and could export files for the
|
|
|
|
// same modules but only one of them needs to do so. Contrast that with source apex modules which
|
|
|
|
// need apex specific variants for every module that contributes code to the apex, whether direct
|
|
|
|
// or indirect.
|
|
|
|
// * The build cost of a prebuilt_apex variant is generally low as at worst it will involve some
|
|
|
|
// extra copying of files. Contrast that with source apex modules that has to build each variant
|
|
|
|
// from source.
|
|
|
|
func (p *prebuiltCommon) apexInfoMutator(mctx android.TopDownMutatorContext) {
|
|
|
|
|
|
|
|
// Collect direct dependencies into contents.
|
|
|
|
contents := make(map[string]android.ApexMembership)
|
|
|
|
|
|
|
|
// Collect the list of dependencies.
|
|
|
|
var dependencies []android.ApexModule
|
|
|
|
mctx.VisitDirectDeps(func(m android.Module) {
|
|
|
|
tag := mctx.OtherModuleDependencyTag(m)
|
|
|
|
if tag == exportedJavaLibTag {
|
|
|
|
depName := mctx.OtherModuleName(m)
|
|
|
|
|
|
|
|
// It is an error if the other module is not a prebuilt.
|
|
|
|
if _, ok := m.(android.PrebuiltInterface); !ok {
|
|
|
|
mctx.PropertyErrorf("exported_java_libs", "%q is not a prebuilt module", depName)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// It is an error if the other module is not an ApexModule.
|
|
|
|
if _, ok := m.(android.ApexModule); !ok {
|
|
|
|
mctx.PropertyErrorf("exported_java_libs", "%q is not usable within an apex", depName)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Strip off the prebuilt_ prefix if present before storing content to ensure consistent
|
|
|
|
// behavior whether there is a corresponding source module present or not.
|
|
|
|
depName = android.RemoveOptionalPrebuiltPrefix(depName)
|
|
|
|
|
|
|
|
// Remember that this module was added as a direct dependency.
|
|
|
|
contents[depName] = contents[depName].Add(true)
|
|
|
|
|
|
|
|
// Add the module to the list of dependencies that need to have an APEX variant.
|
|
|
|
dependencies = append(dependencies, m.(android.ApexModule))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
// Create contents for the prebuilt_apex and store it away for later use.
|
|
|
|
apexContents := android.NewApexContents(contents)
|
|
|
|
mctx.SetProvider(ApexBundleInfoProvider, ApexBundleInfo{
|
|
|
|
Contents: apexContents,
|
|
|
|
})
|
|
|
|
|
|
|
|
// Create an ApexInfo for the prebuilt_apex.
|
|
|
|
apexInfo := android.ApexInfo{
|
|
|
|
ApexVariationName: mctx.ModuleName(),
|
|
|
|
InApexes: []string{mctx.ModuleName()},
|
|
|
|
ApexContents: []*android.ApexContents{apexContents},
|
|
|
|
ForPrebuiltApex: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mark the dependencies of this module as requiring a variant for this module.
|
|
|
|
for _, am := range dependencies {
|
|
|
|
am.BuildForApex(apexInfo)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-01 22:14:52 +08:00
|
|
|
// prebuiltApexSelectorModule is a private module type that is only created by the prebuilt_apex
|
|
|
|
// module. It selects the apex to use and makes it available for use by prebuilt_apex and the
|
|
|
|
// deapexer.
|
|
|
|
type prebuiltApexSelectorModule struct {
|
|
|
|
android.ModuleBase
|
|
|
|
|
|
|
|
apexFileProperties ApexFileProperties
|
|
|
|
|
|
|
|
inputApex android.Path
|
|
|
|
}
|
|
|
|
|
|
|
|
func privateApexSelectorModuleFactory() android.Module {
|
|
|
|
module := &prebuiltApexSelectorModule{}
|
|
|
|
module.AddProperties(
|
|
|
|
&module.apexFileProperties,
|
|
|
|
)
|
|
|
|
android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
|
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *prebuiltApexSelectorModule) Srcs() android.Paths {
|
|
|
|
return android.Paths{p.inputApex}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *prebuiltApexSelectorModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|
|
|
p.inputApex = android.SingleSourcePathFromSupplier(ctx, p.apexFileProperties.prebuiltApexSelector, "src")
|
|
|
|
}
|
|
|
|
|
2019-11-18 10:16:27 +08:00
|
|
|
type Prebuilt struct {
|
|
|
|
android.ModuleBase
|
2020-07-16 20:38:56 +08:00
|
|
|
prebuiltCommon
|
2019-11-18 10:16:27 +08:00
|
|
|
|
2021-03-01 22:14:52 +08:00
|
|
|
properties PrebuiltProperties
|
|
|
|
selectedApexProperties SelectedApexProperties
|
2019-11-18 10:16:27 +08:00
|
|
|
|
|
|
|
inputApex android.Path
|
|
|
|
installDir android.InstallPath
|
|
|
|
installFilename string
|
|
|
|
outputApex android.WritablePath
|
2020-01-08 00:57:58 +08:00
|
|
|
|
|
|
|
// list of commands to create symlinks for backward compatibility.
|
|
|
|
// these commands will be attached as LOCAL_POST_INSTALL_CMD
|
|
|
|
compatSymlinks []string
|
2019-11-18 10:16:27 +08:00
|
|
|
}
|
|
|
|
|
2021-01-14 01:03:51 +08:00
|
|
|
type ApexFileProperties struct {
|
2019-11-18 10:16:27 +08:00
|
|
|
// the path to the prebuilt .apex file to import.
|
2021-03-01 20:25:10 +08:00
|
|
|
//
|
|
|
|
// This cannot be marked as `android:"arch_variant"` because the `prebuilt_apex` is only mutated
|
|
|
|
// for android_common. That is so that it will have the same arch variant as, and so be compatible
|
|
|
|
// with, the source `apex` module type that it replaces.
|
2021-03-01 22:14:52 +08:00
|
|
|
Src *string `android:"path"`
|
2019-11-18 10:16:27 +08:00
|
|
|
Arch struct {
|
|
|
|
Arm struct {
|
2021-03-01 22:14:52 +08:00
|
|
|
Src *string `android:"path"`
|
2019-11-18 10:16:27 +08:00
|
|
|
}
|
|
|
|
Arm64 struct {
|
2021-03-01 22:14:52 +08:00
|
|
|
Src *string `android:"path"`
|
2019-11-18 10:16:27 +08:00
|
|
|
}
|
|
|
|
X86 struct {
|
2021-03-01 22:14:52 +08:00
|
|
|
Src *string `android:"path"`
|
2019-11-18 10:16:27 +08:00
|
|
|
}
|
|
|
|
X86_64 struct {
|
2021-03-01 22:14:52 +08:00
|
|
|
Src *string `android:"path"`
|
2019-11-18 10:16:27 +08:00
|
|
|
}
|
|
|
|
}
|
2021-01-14 01:03:51 +08:00
|
|
|
}
|
|
|
|
|
2021-03-01 20:25:10 +08:00
|
|
|
// prebuiltApexSelector selects the correct prebuilt APEX file for the build target.
|
|
|
|
//
|
|
|
|
// The ctx parameter can be for any module not just the prebuilt module so care must be taken not
|
|
|
|
// to use methods on it that are specific to the current module.
|
|
|
|
//
|
|
|
|
// See the ApexFileProperties.Src property.
|
|
|
|
func (p *ApexFileProperties) prebuiltApexSelector(ctx android.BaseModuleContext, prebuilt android.Module) []string {
|
|
|
|
multiTargets := prebuilt.MultiTargets()
|
|
|
|
if len(multiTargets) != 1 {
|
|
|
|
ctx.OtherModuleErrorf(prebuilt, "compile_multilib shouldn't be \"both\" for prebuilt_apex")
|
|
|
|
return nil
|
2021-01-14 01:03:51 +08:00
|
|
|
}
|
|
|
|
var src string
|
2021-03-01 20:25:10 +08:00
|
|
|
switch multiTargets[0].Arch.ArchType {
|
2021-01-14 01:03:51 +08:00
|
|
|
case android.Arm:
|
|
|
|
src = String(p.Arch.Arm.Src)
|
|
|
|
case android.Arm64:
|
|
|
|
src = String(p.Arch.Arm64.Src)
|
|
|
|
case android.X86:
|
|
|
|
src = String(p.Arch.X86.Src)
|
|
|
|
case android.X86_64:
|
|
|
|
src = String(p.Arch.X86_64.Src)
|
|
|
|
}
|
|
|
|
if src == "" {
|
|
|
|
src = String(p.Src)
|
|
|
|
}
|
|
|
|
|
2021-03-02 01:27:16 +08:00
|
|
|
if src == "" {
|
|
|
|
ctx.OtherModuleErrorf(prebuilt, "prebuilt_apex does not support %q", multiTargets[0].Arch.String())
|
|
|
|
// Drop through to return an empty string as the src (instead of nil) to avoid the prebuilt
|
|
|
|
// logic from reporting a more general, less useful message.
|
|
|
|
}
|
|
|
|
|
2021-03-01 20:25:10 +08:00
|
|
|
return []string{src}
|
2021-01-14 01:03:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type PrebuiltProperties struct {
|
|
|
|
ApexFileProperties
|
2019-11-18 10:16:27 +08:00
|
|
|
|
|
|
|
Installable *bool
|
|
|
|
// Optional name for the installed apex. If unspecified, name of the
|
|
|
|
// module is used as the file name
|
|
|
|
Filename *string
|
|
|
|
|
|
|
|
// Names of modules to be overridden. Listed modules can only be other binaries
|
|
|
|
// (in Make or Soong).
|
|
|
|
// This does not completely prevent installation of the overridden binaries, but if both
|
|
|
|
// binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
|
|
|
|
// from PRODUCT_PACKAGES.
|
|
|
|
Overrides []string
|
|
|
|
}
|
|
|
|
|
2020-07-25 06:35:40 +08:00
|
|
|
func (a *Prebuilt) hasSanitizedSource(sanitizer string) bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-11-18 10:16:27 +08:00
|
|
|
func (p *Prebuilt) installable() bool {
|
|
|
|
return p.properties.Installable == nil || proptools.Bool(p.properties.Installable)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Prebuilt) OutputFiles(tag string) (android.Paths, error) {
|
|
|
|
switch tag {
|
|
|
|
case "":
|
|
|
|
return android.Paths{p.outputApex}, nil
|
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("unsupported module reference tag %q", tag)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Prebuilt) InstallFilename() string {
|
|
|
|
return proptools.StringDefault(p.properties.Filename, p.BaseModuleName()+imageApexSuffix)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Prebuilt) Name() string {
|
2020-07-16 20:38:56 +08:00
|
|
|
return p.prebuiltCommon.prebuilt.Name(p.ModuleBase.Name())
|
2019-11-18 10:16:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex.
|
2020-11-03 01:32:38 +08:00
|
|
|
//
|
|
|
|
// If this needs to make files from within a `.apex` file available for use by other Soong modules,
|
|
|
|
// e.g. make dex implementation jars available for java_import modules isted in exported_java_libs,
|
|
|
|
// it does so as follows:
|
|
|
|
//
|
|
|
|
// 1. It creates a `deapexer` module that actually extracts the files from the `.apex` file and
|
|
|
|
// makes them available for use by other modules, at both Soong and ninja levels.
|
|
|
|
//
|
|
|
|
// 2. It adds a dependency onto those modules and creates an apex specific variant similar to what
|
|
|
|
// an `apex` module does. That ensures that code which looks for specific apex variant, e.g.
|
|
|
|
// dexpreopt, will work the same way from source and prebuilt.
|
|
|
|
//
|
|
|
|
// 3. The `deapexer` module adds a dependency from the modules that require the exported files onto
|
|
|
|
// itself so that they can retrieve the file paths to those files.
|
|
|
|
//
|
2021-03-01 22:14:52 +08:00
|
|
|
// It also creates a child module `selector` that is responsible for selecting the appropriate
|
|
|
|
// input apex for both the prebuilt_apex and the deapexer. That is needed for a couple of reasons:
|
|
|
|
// 1. To dedup the selection logic so it only runs in one module.
|
|
|
|
// 2. To allow the deapexer to be wired up to a different source for the input apex, e.g. an
|
|
|
|
// `apex_set`.
|
|
|
|
//
|
|
|
|
// prebuilt_apex
|
|
|
|
// / | \
|
|
|
|
// / | \
|
|
|
|
// V | V
|
|
|
|
// selector <--- deapexer <--- exported java lib
|
|
|
|
//
|
2019-11-18 10:16:27 +08:00
|
|
|
func PrebuiltFactory() android.Module {
|
|
|
|
module := &Prebuilt{}
|
2021-04-07 00:02:08 +08:00
|
|
|
module.AddProperties(&module.properties, &module.deapexerProperties, &module.selectedApexProperties)
|
2021-03-01 22:14:52 +08:00
|
|
|
android.InitSingleSourcePrebuiltModule(module, &module.selectedApexProperties, "Selected_apex")
|
2019-11-18 10:16:27 +08:00
|
|
|
android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
|
2020-11-03 01:32:38 +08:00
|
|
|
|
|
|
|
android.AddLoadHook(module, func(ctx android.LoadHookContext) {
|
2021-03-01 22:14:52 +08:00
|
|
|
baseModuleName := module.BaseModuleName()
|
|
|
|
|
|
|
|
apexSelectorModuleName := apexSelectorModuleName(baseModuleName)
|
|
|
|
createApexSelectorModule(ctx, apexSelectorModuleName, &module.properties.ApexFileProperties)
|
|
|
|
|
|
|
|
apexFileSource := ":" + apexSelectorModuleName
|
2021-04-07 00:02:08 +08:00
|
|
|
if len(module.deapexerProperties.Exported_java_libs) != 0 {
|
|
|
|
createDeapexerModule(ctx, deapexerModuleName(baseModuleName), apexFileSource, &module.deapexerProperties)
|
2020-11-03 01:32:38 +08:00
|
|
|
}
|
2021-03-01 22:14:52 +08:00
|
|
|
|
|
|
|
// Add a source reference to retrieve the selected apex from the selector module.
|
|
|
|
module.selectedApexProperties.Selected_apex = proptools.StringPtr(apexFileSource)
|
2020-11-03 01:32:38 +08:00
|
|
|
})
|
|
|
|
|
2019-11-18 10:16:27 +08:00
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
2021-03-01 22:14:52 +08:00
|
|
|
func createApexSelectorModule(ctx android.LoadHookContext, name string, apexFileProperties *ApexFileProperties) {
|
|
|
|
props := struct {
|
|
|
|
Name *string
|
|
|
|
}{
|
|
|
|
Name: proptools.StringPtr(name),
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.CreateModule(privateApexSelectorModuleFactory,
|
|
|
|
&props,
|
|
|
|
apexFileProperties,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func createDeapexerModule(ctx android.LoadHookContext, deapexerName string, apexFileSource string, deapexerProperties *DeapexerProperties) {
|
|
|
|
props := struct {
|
|
|
|
Name *string
|
|
|
|
Selected_apex *string
|
|
|
|
}{
|
|
|
|
Name: proptools.StringPtr(deapexerName),
|
|
|
|
Selected_apex: proptools.StringPtr(apexFileSource),
|
|
|
|
}
|
|
|
|
ctx.CreateModule(privateDeapexerFactory,
|
|
|
|
&props,
|
|
|
|
deapexerProperties,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func deapexerModuleName(baseModuleName string) string {
|
|
|
|
return baseModuleName + ".deapexer"
|
|
|
|
}
|
|
|
|
|
|
|
|
func apexSelectorModuleName(baseModuleName string) string {
|
|
|
|
return baseModuleName + ".apex.selector"
|
|
|
|
}
|
|
|
|
|
2020-11-03 01:32:38 +08:00
|
|
|
func prebuiltApexExportedModuleName(ctx android.BottomUpMutatorContext, name string) string {
|
|
|
|
// The prebuilt_apex should be depending on prebuilt modules but as this runs after
|
|
|
|
// prebuilt_rename the prebuilt module may or may not be using the prebuilt_ prefixed named. So,
|
|
|
|
// check to see if the prefixed name is in use first, if it is then use that, otherwise assume
|
|
|
|
// the unprefixed name is the one to use. If the unprefixed one turns out to be a source module
|
|
|
|
// and not a renamed prebuilt module then that will be detected and reported as an error when
|
|
|
|
// processing the dependency in ApexInfoMutator().
|
2021-04-02 17:24:13 +08:00
|
|
|
prebuiltName := android.PrebuiltNameFromSource(name)
|
2020-11-03 01:32:38 +08:00
|
|
|
if ctx.OtherModuleExists(prebuiltName) {
|
|
|
|
name = prebuiltName
|
|
|
|
}
|
|
|
|
return name
|
|
|
|
}
|
|
|
|
|
2021-02-08 19:01:58 +08:00
|
|
|
type exportedDependencyTag struct {
|
|
|
|
blueprint.BaseDependencyTag
|
|
|
|
name string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mark this tag so dependencies that use it are excluded from visibility enforcement.
|
|
|
|
//
|
|
|
|
// This does allow any prebuilt_apex to reference any module which does open up a small window for
|
|
|
|
// restricted visibility modules to be referenced from the wrong prebuilt_apex. However, doing so
|
|
|
|
// avoids opening up a much bigger window by widening the visibility of modules that need files
|
|
|
|
// provided by the prebuilt_apex to include all the possible locations they may be defined, which
|
|
|
|
// could include everything below vendor/.
|
|
|
|
//
|
|
|
|
// A prebuilt_apex that references a module via this tag will have to contain the appropriate files
|
|
|
|
// corresponding to that module, otherwise it will fail when attempting to retrieve the files from
|
|
|
|
// the .apex file. It will also have to be included in the module's apex_available property too.
|
|
|
|
// That makes it highly unlikely that a prebuilt_apex would reference a restricted module
|
|
|
|
// incorrectly.
|
|
|
|
func (t exportedDependencyTag) ExcludeFromVisibilityEnforcement() {}
|
|
|
|
|
|
|
|
var (
|
|
|
|
exportedJavaLibTag = exportedDependencyTag{name: "exported_java_lib"}
|
|
|
|
)
|
|
|
|
|
2021-01-26 22:18:53 +08:00
|
|
|
func (p *Prebuilt) DepsMutator(ctx android.BottomUpMutatorContext) {
|
2021-04-07 00:02:08 +08:00
|
|
|
p.deapexerDeps(ctx)
|
2020-11-03 01:32:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ ApexInfoMutator = (*Prebuilt)(nil)
|
|
|
|
|
|
|
|
func (p *Prebuilt) ApexInfoMutator(mctx android.TopDownMutatorContext) {
|
2021-04-07 00:02:08 +08:00
|
|
|
p.apexInfoMutator(mctx)
|
2019-11-18 10:16:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Prebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|
|
|
// TODO(jungjw): Check the key validity.
|
2021-03-01 22:14:52 +08:00
|
|
|
p.inputApex = android.OptionalPathForModuleSrc(ctx, p.selectedApexProperties.Selected_apex).Path()
|
2019-11-18 10:16:27 +08:00
|
|
|
p.installDir = android.PathForModuleInstall(ctx, "apex")
|
|
|
|
p.installFilename = p.InstallFilename()
|
|
|
|
if !strings.HasSuffix(p.installFilename, imageApexSuffix) {
|
|
|
|
ctx.ModuleErrorf("filename should end in %s for prebuilt_apex", imageApexSuffix)
|
|
|
|
}
|
|
|
|
p.outputApex = android.PathForModuleOut(ctx, p.installFilename)
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: android.Cp,
|
|
|
|
Input: p.inputApex,
|
|
|
|
Output: p.outputApex,
|
|
|
|
})
|
2020-07-16 20:38:56 +08:00
|
|
|
|
|
|
|
if p.prebuiltCommon.checkForceDisable(ctx) {
|
2020-12-17 02:20:23 +08:00
|
|
|
p.HideFromMake()
|
2020-07-16 20:38:56 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-11-18 10:16:27 +08:00
|
|
|
if p.installable() {
|
|
|
|
ctx.InstallFile(p.installDir, p.installFilename, p.inputApex)
|
|
|
|
}
|
|
|
|
|
2020-01-08 00:57:58 +08:00
|
|
|
// in case that prebuilt_apex replaces source apex (using prefer: prop)
|
|
|
|
p.compatSymlinks = makeCompatSymlinks(p.BaseModuleName(), ctx)
|
|
|
|
// or that prebuilt_apex overrides other apexes (using overrides: prop)
|
|
|
|
for _, overridden := range p.properties.Overrides {
|
|
|
|
p.compatSymlinks = append(p.compatSymlinks, makeCompatSymlinks(overridden, ctx)...)
|
|
|
|
}
|
2019-11-18 10:16:27 +08:00
|
|
|
}
|
|
|
|
|
2019-12-03 12:24:29 +08:00
|
|
|
func (p *Prebuilt) AndroidMkEntries() []android.AndroidMkEntries {
|
|
|
|
return []android.AndroidMkEntries{android.AndroidMkEntries{
|
2019-11-18 10:16:27 +08:00
|
|
|
Class: "ETC",
|
|
|
|
OutputFile: android.OptionalPathForPath(p.inputApex),
|
|
|
|
Include: "$(BUILD_PREBUILT)",
|
|
|
|
ExtraEntries: []android.AndroidMkExtraEntriesFunc{
|
2020-07-04 04:18:24 +08:00
|
|
|
func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
|
2019-11-18 10:16:27 +08:00
|
|
|
entries.SetString("LOCAL_MODULE_PATH", p.installDir.ToMakePath().String())
|
|
|
|
entries.SetString("LOCAL_MODULE_STEM", p.installFilename)
|
|
|
|
entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable())
|
|
|
|
entries.AddStrings("LOCAL_OVERRIDES_MODULES", p.properties.Overrides...)
|
2020-01-08 00:57:58 +08:00
|
|
|
if len(p.compatSymlinks) > 0 {
|
|
|
|
entries.SetString("LOCAL_POST_INSTALL_CMD", strings.Join(p.compatSymlinks, " && "))
|
|
|
|
}
|
2019-11-18 10:16:27 +08:00
|
|
|
},
|
|
|
|
},
|
2019-12-03 12:24:29 +08:00
|
|
|
}}
|
2019-11-18 10:16:27 +08:00
|
|
|
}
|
2020-05-15 05:15:24 +08:00
|
|
|
|
2021-04-06 23:09:30 +08:00
|
|
|
// prebuiltApexExtractorModule is a private module type that is only created by the prebuilt_apex
|
|
|
|
// module. It extracts the correct apex to use and makes it available for use by apex_set.
|
|
|
|
type prebuiltApexExtractorModule struct {
|
|
|
|
android.ModuleBase
|
|
|
|
|
|
|
|
properties ApexExtractorProperties
|
|
|
|
|
|
|
|
extractedApex android.WritablePath
|
|
|
|
}
|
|
|
|
|
|
|
|
func privateApexExtractorModuleFactory() android.Module {
|
|
|
|
module := &prebuiltApexExtractorModule{}
|
|
|
|
module.AddProperties(
|
|
|
|
&module.properties,
|
|
|
|
)
|
|
|
|
android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
|
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *prebuiltApexExtractorModule) Srcs() android.Paths {
|
|
|
|
return android.Paths{p.extractedApex}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *prebuiltApexExtractorModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|
|
|
srcsSupplier := func(ctx android.BaseModuleContext, prebuilt android.Module) []string {
|
|
|
|
return p.properties.prebuiltSrcs(ctx)
|
|
|
|
}
|
|
|
|
apexSet := android.SingleSourcePathFromSupplier(ctx, srcsSupplier, "set")
|
|
|
|
p.extractedApex = android.PathForModuleOut(ctx, "extracted", apexSet.Base())
|
|
|
|
ctx.Build(pctx,
|
|
|
|
android.BuildParams{
|
|
|
|
Rule: extractMatchingApex,
|
|
|
|
Description: "Extract an apex from an apex set",
|
|
|
|
Inputs: android.Paths{apexSet},
|
|
|
|
Output: p.extractedApex,
|
|
|
|
Args: map[string]string{
|
|
|
|
"abis": strings.Join(java.SupportedAbis(ctx), ","),
|
|
|
|
"allow-prereleased": strconv.FormatBool(proptools.Bool(p.properties.Prerelease)),
|
|
|
|
"sdk-version": ctx.Config().PlatformSdkVersion().String(),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-05-15 05:15:24 +08:00
|
|
|
type ApexSet struct {
|
|
|
|
android.ModuleBase
|
2020-07-16 20:38:56 +08:00
|
|
|
prebuiltCommon
|
2020-05-15 05:15:24 +08:00
|
|
|
|
|
|
|
properties ApexSetProperties
|
|
|
|
|
|
|
|
installDir android.InstallPath
|
|
|
|
installFilename string
|
|
|
|
outputApex android.WritablePath
|
|
|
|
|
|
|
|
// list of commands to create symlinks for backward compatibility.
|
|
|
|
// these commands will be attached as LOCAL_POST_INSTALL_CMD
|
|
|
|
compatSymlinks []string
|
2020-06-30 05:34:23 +08:00
|
|
|
|
|
|
|
hostRequired []string
|
|
|
|
postInstallCommands []string
|
2020-05-15 05:15:24 +08:00
|
|
|
}
|
|
|
|
|
2021-04-06 23:09:30 +08:00
|
|
|
type ApexExtractorProperties struct {
|
2020-05-15 05:15:24 +08:00
|
|
|
// the .apks file path that contains prebuilt apex files to be extracted.
|
|
|
|
Set *string
|
|
|
|
|
2020-07-25 06:35:40 +08:00
|
|
|
Sanitized struct {
|
|
|
|
None struct {
|
|
|
|
Set *string
|
|
|
|
}
|
|
|
|
Address struct {
|
|
|
|
Set *string
|
|
|
|
}
|
|
|
|
Hwaddress struct {
|
|
|
|
Set *string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-15 05:15:24 +08:00
|
|
|
// apexes in this set use prerelease SDK version
|
|
|
|
Prerelease *bool
|
|
|
|
}
|
|
|
|
|
2021-04-06 23:09:30 +08:00
|
|
|
func (e *ApexExtractorProperties) prebuiltSrcs(ctx android.BaseModuleContext) []string {
|
2020-07-25 06:35:40 +08:00
|
|
|
var srcs []string
|
2021-04-06 23:09:30 +08:00
|
|
|
if e.Set != nil {
|
|
|
|
srcs = append(srcs, *e.Set)
|
2020-07-25 06:35:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var sanitizers []string
|
|
|
|
if ctx.Host() {
|
|
|
|
sanitizers = ctx.Config().SanitizeHost()
|
|
|
|
} else {
|
|
|
|
sanitizers = ctx.Config().SanitizeDevice()
|
|
|
|
}
|
|
|
|
|
2021-04-06 23:09:30 +08:00
|
|
|
if android.InList("address", sanitizers) && e.Sanitized.Address.Set != nil {
|
|
|
|
srcs = append(srcs, *e.Sanitized.Address.Set)
|
|
|
|
} else if android.InList("hwaddress", sanitizers) && e.Sanitized.Hwaddress.Set != nil {
|
|
|
|
srcs = append(srcs, *e.Sanitized.Hwaddress.Set)
|
|
|
|
} else if e.Sanitized.None.Set != nil {
|
|
|
|
srcs = append(srcs, *e.Sanitized.None.Set)
|
2020-07-25 06:35:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return srcs
|
|
|
|
}
|
|
|
|
|
2021-04-06 23:09:30 +08:00
|
|
|
type ApexSetProperties struct {
|
|
|
|
ApexExtractorProperties
|
|
|
|
|
|
|
|
// whether the extracted apex file installable.
|
|
|
|
Installable *bool
|
|
|
|
|
|
|
|
// optional name for the installed apex. If unspecified, name of the
|
|
|
|
// module is used as the file name
|
|
|
|
Filename *string
|
|
|
|
|
|
|
|
// names of modules to be overridden. Listed modules can only be other binaries
|
|
|
|
// (in Make or Soong).
|
|
|
|
// This does not completely prevent installation of the overridden binaries, but if both
|
|
|
|
// binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
|
|
|
|
// from PRODUCT_PACKAGES.
|
|
|
|
Overrides []string
|
|
|
|
}
|
|
|
|
|
2020-07-25 06:35:40 +08:00
|
|
|
func (a *ApexSet) hasSanitizedSource(sanitizer string) bool {
|
|
|
|
if sanitizer == "address" {
|
|
|
|
return a.properties.Sanitized.Address.Set != nil
|
|
|
|
}
|
|
|
|
if sanitizer == "hwaddress" {
|
|
|
|
return a.properties.Sanitized.Hwaddress.Set != nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-05-15 05:15:24 +08:00
|
|
|
func (a *ApexSet) installable() bool {
|
|
|
|
return a.properties.Installable == nil || proptools.Bool(a.properties.Installable)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *ApexSet) InstallFilename() string {
|
|
|
|
return proptools.StringDefault(a.properties.Filename, a.BaseModuleName()+imageApexSuffix)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *ApexSet) Name() string {
|
2020-07-16 20:38:56 +08:00
|
|
|
return a.prebuiltCommon.prebuilt.Name(a.ModuleBase.Name())
|
2020-05-15 05:15:24 +08:00
|
|
|
}
|
|
|
|
|
2020-06-12 16:26:31 +08:00
|
|
|
func (a *ApexSet) Overrides() []string {
|
|
|
|
return a.properties.Overrides
|
|
|
|
}
|
|
|
|
|
2020-05-15 05:15:24 +08:00
|
|
|
// prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex.
|
|
|
|
func apexSetFactory() android.Module {
|
|
|
|
module := &ApexSet{}
|
2021-04-06 23:00:22 +08:00
|
|
|
module.AddProperties(&module.properties, &module.selectedApexProperties, &module.deapexerProperties)
|
2020-07-25 06:35:40 +08:00
|
|
|
|
2021-04-06 23:09:30 +08:00
|
|
|
android.InitSingleSourcePrebuiltModule(module, &module.selectedApexProperties, "Selected_apex")
|
2020-05-15 05:15:24 +08:00
|
|
|
android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
|
2021-04-06 23:09:30 +08:00
|
|
|
|
|
|
|
android.AddLoadHook(module, func(ctx android.LoadHookContext) {
|
|
|
|
baseModuleName := module.BaseModuleName()
|
|
|
|
|
|
|
|
apexExtractorModuleName := apexExtractorModuleName(baseModuleName)
|
|
|
|
createApexExtractorModule(ctx, apexExtractorModuleName, &module.properties.ApexExtractorProperties)
|
|
|
|
|
|
|
|
apexFileSource := ":" + apexExtractorModuleName
|
2021-04-06 23:00:22 +08:00
|
|
|
if len(module.deapexerProperties.Exported_java_libs) != 0 {
|
|
|
|
createDeapexerModule(ctx, deapexerModuleName(baseModuleName), apexFileSource, &module.deapexerProperties)
|
|
|
|
}
|
2021-04-06 23:09:30 +08:00
|
|
|
|
|
|
|
// After passing the arch specific src properties to the creating the apex selector module
|
|
|
|
module.selectedApexProperties.Selected_apex = proptools.StringPtr(apexFileSource)
|
|
|
|
})
|
|
|
|
|
2020-05-15 05:15:24 +08:00
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
2021-04-06 23:09:30 +08:00
|
|
|
func createApexExtractorModule(ctx android.LoadHookContext, name string, apexExtractorProperties *ApexExtractorProperties) {
|
|
|
|
props := struct {
|
|
|
|
Name *string
|
|
|
|
}{
|
|
|
|
Name: proptools.StringPtr(name),
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.CreateModule(privateApexExtractorModuleFactory,
|
|
|
|
&props,
|
|
|
|
apexExtractorProperties,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func apexExtractorModuleName(baseModuleName string) string {
|
|
|
|
return baseModuleName + ".apex.extractor"
|
|
|
|
}
|
|
|
|
|
2021-04-06 23:00:22 +08:00
|
|
|
func (a *ApexSet) DepsMutator(ctx android.BottomUpMutatorContext) {
|
|
|
|
a.deapexerDeps(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ ApexInfoMutator = (*ApexSet)(nil)
|
|
|
|
|
|
|
|
func (a *ApexSet) ApexInfoMutator(mctx android.TopDownMutatorContext) {
|
|
|
|
a.apexInfoMutator(mctx)
|
|
|
|
}
|
|
|
|
|
2020-05-15 05:15:24 +08:00
|
|
|
func (a *ApexSet) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|
|
|
a.installFilename = a.InstallFilename()
|
|
|
|
if !strings.HasSuffix(a.installFilename, imageApexSuffix) {
|
|
|
|
ctx.ModuleErrorf("filename should end in %s for apex_set", imageApexSuffix)
|
|
|
|
}
|
|
|
|
|
2021-04-06 23:09:30 +08:00
|
|
|
inputApex := android.OptionalPathForModuleSrc(ctx, a.selectedApexProperties.Selected_apex).Path()
|
2020-05-15 05:15:24 +08:00
|
|
|
a.outputApex = android.PathForModuleOut(ctx, a.installFilename)
|
2021-04-06 23:09:30 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: android.Cp,
|
|
|
|
Input: inputApex,
|
|
|
|
Output: a.outputApex,
|
|
|
|
})
|
2020-07-16 20:38:56 +08:00
|
|
|
|
|
|
|
if a.prebuiltCommon.checkForceDisable(ctx) {
|
2020-12-17 02:20:23 +08:00
|
|
|
a.HideFromMake()
|
2020-07-16 20:38:56 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-05-15 05:15:24 +08:00
|
|
|
a.installDir = android.PathForModuleInstall(ctx, "apex")
|
|
|
|
if a.installable() {
|
|
|
|
ctx.InstallFile(a.installDir, a.installFilename, a.outputApex)
|
|
|
|
}
|
|
|
|
|
|
|
|
// in case that apex_set replaces source apex (using prefer: prop)
|
|
|
|
a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
|
|
|
|
// or that apex_set overrides other apexes (using overrides: prop)
|
|
|
|
for _, overridden := range a.properties.Overrides {
|
|
|
|
a.compatSymlinks = append(a.compatSymlinks, makeCompatSymlinks(overridden, ctx)...)
|
|
|
|
}
|
2020-06-30 05:34:23 +08:00
|
|
|
|
|
|
|
if ctx.Config().InstallExtraFlattenedApexes() {
|
|
|
|
// flattened apex should be in /system_ext/apex
|
|
|
|
flattenedApexDir := android.PathForModuleInstall(&systemExtContext{ctx}, "apex", a.BaseModuleName())
|
|
|
|
a.postInstallCommands = append(a.postInstallCommands,
|
|
|
|
fmt.Sprintf("$(HOST_OUT_EXECUTABLES)/deapexer --debugfs_path $(HOST_OUT_EXECUTABLES)/debugfs extract %s %s",
|
|
|
|
a.outputApex.String(),
|
|
|
|
flattenedApexDir.ToMakePath().String(),
|
|
|
|
))
|
|
|
|
a.hostRequired = []string{"deapexer", "debugfs"}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type systemExtContext struct {
|
|
|
|
android.ModuleContext
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*systemExtContext) SystemExtSpecific() bool {
|
|
|
|
return true
|
2020-05-15 05:15:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *ApexSet) AndroidMkEntries() []android.AndroidMkEntries {
|
|
|
|
return []android.AndroidMkEntries{android.AndroidMkEntries{
|
2020-06-30 05:34:23 +08:00
|
|
|
Class: "ETC",
|
|
|
|
OutputFile: android.OptionalPathForPath(a.outputApex),
|
|
|
|
Include: "$(BUILD_PREBUILT)",
|
|
|
|
Host_required: a.hostRequired,
|
2020-05-15 05:15:24 +08:00
|
|
|
ExtraEntries: []android.AndroidMkExtraEntriesFunc{
|
2020-07-04 04:18:24 +08:00
|
|
|
func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
|
2020-05-15 05:15:24 +08:00
|
|
|
entries.SetString("LOCAL_MODULE_PATH", a.installDir.ToMakePath().String())
|
|
|
|
entries.SetString("LOCAL_MODULE_STEM", a.installFilename)
|
|
|
|
entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !a.installable())
|
|
|
|
entries.AddStrings("LOCAL_OVERRIDES_MODULES", a.properties.Overrides...)
|
2020-06-30 05:34:23 +08:00
|
|
|
postInstallCommands := append([]string{}, a.postInstallCommands...)
|
|
|
|
postInstallCommands = append(postInstallCommands, a.compatSymlinks...)
|
|
|
|
if len(postInstallCommands) > 0 {
|
|
|
|
entries.SetString("LOCAL_POST_INSTALL_CMD", strings.Join(postInstallCommands, " && "))
|
2020-05-15 05:15:24 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
}
|