2019-11-18 03:16:27 +01: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"
|
2021-06-15 20:10:11 +02:00
|
|
|
"io"
|
2021-11-04 20:01:18 +01:00
|
|
|
"path/filepath"
|
2020-05-14 23:15:24 +02:00
|
|
|
"strconv"
|
2019-11-18 03:16:27 +01:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"android/soong/android"
|
2023-12-06 20:40:24 +01:00
|
|
|
"android/soong/dexpreopt"
|
2020-05-14 23:15:24 +02:00
|
|
|
"android/soong/java"
|
2022-03-19 01:33:24 +01:00
|
|
|
"android/soong/provenance"
|
2022-11-25 15:06:46 +01:00
|
|
|
|
2020-05-14 23:15:24 +02:00
|
|
|
"github.com/google/blueprint"
|
2019-11-18 03:16:27 +01:00
|
|
|
"github.com/google/blueprint/proptools"
|
|
|
|
)
|
|
|
|
|
2020-05-14 23:15:24 +02:00
|
|
|
var (
|
|
|
|
extractMatchingApex = pctx.StaticRule(
|
|
|
|
"extractMatchingApex",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: `rm -rf "$out" && ` +
|
|
|
|
`${extract_apks} -o "${out}" -allow-prereleased=${allow-prereleased} ` +
|
2023-03-21 00:19:53 +01:00
|
|
|
`-sdk-version=${sdk-version} -skip-sdk-check=${skip-sdk-check} -abis=${abis} ` +
|
|
|
|
`-screen-densities=all -extract-single ` +
|
2020-05-14 23:15:24 +02:00
|
|
|
`${in}`,
|
|
|
|
CommandDeps: []string{"${extract_apks}"},
|
|
|
|
},
|
2023-03-21 00:19:53 +01:00
|
|
|
"abis", "allow-prereleased", "sdk-version", "skip-sdk-check")
|
2020-05-14 23:15:24 +02:00
|
|
|
)
|
|
|
|
|
2020-07-16 14:38:56 +02:00
|
|
|
type prebuilt interface {
|
|
|
|
isForceDisabled() bool
|
|
|
|
InstallFilename() string
|
|
|
|
}
|
|
|
|
|
|
|
|
type prebuiltCommon struct {
|
2021-06-15 12:34:01 +02:00
|
|
|
android.ModuleBase
|
2023-12-06 20:40:24 +01:00
|
|
|
java.Dexpreopter
|
2021-05-05 17:58:08 +02:00
|
|
|
prebuilt android.Prebuilt
|
2021-04-06 18:02:08 +02:00
|
|
|
|
2021-05-05 17:58:08 +02:00
|
|
|
// Properties common to both prebuilt_apex and apex_set.
|
2021-06-15 12:34:01 +02:00
|
|
|
prebuiltCommonProperties *PrebuiltCommonProperties
|
|
|
|
|
|
|
|
installDir android.InstallPath
|
|
|
|
installFilename string
|
2021-11-04 20:01:18 +01:00
|
|
|
installedFile android.InstallPath
|
2021-06-15 12:34:01 +02:00
|
|
|
outputApex android.WritablePath
|
|
|
|
|
2023-10-30 08:17:56 +01:00
|
|
|
// fragment for this apex for apexkeys.txt
|
|
|
|
apexKeysPath android.WritablePath
|
|
|
|
|
2021-06-15 20:10:11 +02:00
|
|
|
// A list of apexFile objects created in prebuiltCommon.initApexFilesForAndroidMk which are used
|
|
|
|
// to create make modules in prebuiltCommon.AndroidMkEntries.
|
|
|
|
apexFilesForAndroidMk []apexFile
|
|
|
|
|
2021-11-04 20:01:18 +01:00
|
|
|
// Installed locations of symlinks for backward compatibility.
|
|
|
|
compatSymlinks android.InstallPaths
|
2021-06-15 12:34:01 +02:00
|
|
|
|
2022-01-28 15:58:56 +01:00
|
|
|
hostRequired []string
|
|
|
|
requiredModuleNames []string
|
2020-07-16 14:38:56 +02:00
|
|
|
}
|
|
|
|
|
2020-07-25 00:35:40 +02:00
|
|
|
type sanitizedPrebuilt interface {
|
|
|
|
hasSanitizedSource(sanitizer string) bool
|
|
|
|
}
|
|
|
|
|
2021-06-15 12:34:01 +02:00
|
|
|
type PrebuiltCommonProperties struct {
|
2021-05-05 17:58:08 +02:00
|
|
|
SelectedApexProperties
|
|
|
|
|
2021-06-24 15:37:13 +02:00
|
|
|
// Canonical name of this APEX. Used to determine the path to the activated APEX on
|
|
|
|
// device (/apex/<apex_name>). If unspecified, follows the name property.
|
|
|
|
Apex_name *string
|
|
|
|
|
2024-01-03 19:57:03 +01:00
|
|
|
// Name of the source APEX that gets shadowed by this prebuilt
|
|
|
|
// e.g. com.mycompany.android.myapex
|
|
|
|
// If unspecified, follows the naming convention that the source apex of
|
|
|
|
// the prebuilt is Name() without "prebuilt_" prefix
|
|
|
|
Source_apex_name *string
|
|
|
|
|
2020-07-16 14:38:56 +02:00
|
|
|
ForceDisable bool `blueprint:"mutated"`
|
2021-05-05 19:03:47 +02:00
|
|
|
|
2021-06-15 12:34:01 +02:00
|
|
|
// whether the extracted apex file is 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
|
|
|
|
|
2021-05-05 19:03:47 +02:00
|
|
|
// List of java libraries that are embedded inside this prebuilt APEX bundle and for which this
|
|
|
|
// APEX bundle will create an APEX variant and provide dex implementation jars for use by
|
|
|
|
// dexpreopt and boot jars package check.
|
|
|
|
Exported_java_libs []string
|
|
|
|
|
|
|
|
// List of bootclasspath fragments inside this prebuilt APEX bundle and for which this APEX
|
|
|
|
// bundle will create an APEX variant.
|
|
|
|
Exported_bootclasspath_fragments []string
|
2021-09-26 05:54:25 +02:00
|
|
|
|
|
|
|
// List of systemserverclasspath fragments inside this prebuilt APEX bundle and for which this
|
|
|
|
// APEX bundle will create an APEX variant.
|
|
|
|
Exported_systemserverclasspath_fragments []string
|
2024-03-11 22:37:25 +01:00
|
|
|
|
|
|
|
// Path to the .prebuilt_info file of the prebuilt apex.
|
|
|
|
// In case of mainline modules, the .prebuilt_info file contains the build_id that was used to
|
|
|
|
// generate the prebuilt.
|
|
|
|
Prebuilt_info *string `android:"path"`
|
2020-07-16 14:38:56 +02:00
|
|
|
}
|
|
|
|
|
2021-06-15 12:34:01 +02:00
|
|
|
// initPrebuiltCommon initializes the prebuiltCommon structure and performs initialization of the
|
|
|
|
// module that is common to Prebuilt and ApexSet.
|
|
|
|
func (p *prebuiltCommon) initPrebuiltCommon(module android.Module, properties *PrebuiltCommonProperties) {
|
|
|
|
p.prebuiltCommonProperties = properties
|
|
|
|
android.InitSingleSourcePrebuiltModule(module.(android.PrebuiltInterface), properties, "Selected_apex")
|
|
|
|
android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
|
|
|
|
}
|
|
|
|
|
2021-06-24 15:37:13 +02:00
|
|
|
func (p *prebuiltCommon) ApexVariationName() string {
|
2024-01-03 19:57:03 +01:00
|
|
|
return proptools.StringDefault(p.prebuiltCommonProperties.Apex_name, p.BaseModuleName())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *prebuiltCommon) BaseModuleName() string {
|
|
|
|
return proptools.StringDefault(p.prebuiltCommonProperties.Source_apex_name, p.ModuleBase.BaseModuleName())
|
2021-06-24 15:37:13 +02:00
|
|
|
}
|
|
|
|
|
2020-07-16 14:38:56 +02:00
|
|
|
func (p *prebuiltCommon) Prebuilt() *android.Prebuilt {
|
|
|
|
return &p.prebuilt
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *prebuiltCommon) isForceDisabled() bool {
|
2021-05-05 17:58:08 +02:00
|
|
|
return p.prebuiltCommonProperties.ForceDisable
|
2020-07-16 14:38:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *prebuiltCommon) checkForceDisable(ctx android.ModuleContext) bool {
|
2023-06-20 09:25:59 +02:00
|
|
|
forceDisable := false
|
2020-07-16 14:38:56 +02:00
|
|
|
|
|
|
|
// Force disable the prebuilts when we are doing unbundled build. We do unbundled build
|
|
|
|
// to build the prebuilts themselves.
|
|
|
|
forceDisable = forceDisable || ctx.Config().UnbundledBuild()
|
|
|
|
|
2020-07-25 00:35:40 +02: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 14:38:56 +02:00
|
|
|
|
|
|
|
if forceDisable && p.prebuilt.SourceExists() {
|
2021-05-05 17:58:08 +02:00
|
|
|
p.prebuiltCommonProperties.ForceDisable = true
|
2020-07-16 14:38:56 +02:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-06-15 12:34:01 +02:00
|
|
|
func (p *prebuiltCommon) InstallFilename() string {
|
|
|
|
return proptools.StringDefault(p.prebuiltCommonProperties.Filename, p.BaseModuleName()+imageApexSuffix)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *prebuiltCommon) Name() string {
|
|
|
|
return p.prebuilt.Name(p.ModuleBase.Name())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *prebuiltCommon) Overrides() []string {
|
|
|
|
return p.prebuiltCommonProperties.Overrides
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *prebuiltCommon) installable() bool {
|
|
|
|
return proptools.BoolDefault(p.prebuiltCommonProperties.Installable, true)
|
|
|
|
}
|
|
|
|
|
2023-12-06 20:40:24 +01:00
|
|
|
// To satisfy java.DexpreopterInterface
|
|
|
|
func (p *prebuiltCommon) IsInstallable() bool {
|
|
|
|
return p.installable()
|
|
|
|
}
|
|
|
|
|
|
|
|
// initApexFilesForAndroidMk initializes the prebuiltCommon.requiredModuleNames field with the install only deps of the prebuilt apex
|
2021-06-15 20:10:11 +02:00
|
|
|
func (p *prebuiltCommon) initApexFilesForAndroidMk(ctx android.ModuleContext) {
|
2023-12-06 20:40:24 +01:00
|
|
|
// If this apex contains a system server jar, then the dexpreopt artifacts should be added as required
|
|
|
|
for _, install := range p.Dexpreopter.DexpreoptBuiltInstalledForApex() {
|
|
|
|
p.requiredModuleNames = append(p.requiredModuleNames, install.FullModuleName())
|
|
|
|
}
|
|
|
|
}
|
2021-06-15 20:10:11 +02:00
|
|
|
|
2023-12-06 20:40:24 +01:00
|
|
|
// If this prebuilt has system server jar, create the rules to dexpreopt it and install it alongside the prebuilt apex
|
|
|
|
func (p *prebuiltCommon) dexpreoptSystemServerJars(ctx android.ModuleContext) {
|
|
|
|
// If this apex does not export anything, return
|
|
|
|
if !p.hasExportedDeps() {
|
|
|
|
return
|
|
|
|
}
|
2024-01-24 00:56:29 +01:00
|
|
|
// If this prebuilt apex has not been selected, return
|
|
|
|
if p.IsHideFromMake() {
|
|
|
|
return
|
|
|
|
}
|
2023-12-06 20:40:24 +01:00
|
|
|
// Use apex_name to determine the api domain of this prebuilt apex
|
|
|
|
apexName := p.ApexVariationName()
|
2023-12-13 00:23:53 +01:00
|
|
|
di, err := android.FindDeapexerProviderForModule(ctx)
|
|
|
|
if err != nil {
|
|
|
|
ctx.ModuleErrorf(err.Error())
|
|
|
|
}
|
2023-12-06 20:40:24 +01:00
|
|
|
dc := dexpreopt.GetGlobalConfig(ctx)
|
|
|
|
systemServerJarList := dc.AllApexSystemServerJars(ctx)
|
|
|
|
|
|
|
|
for i := 0; i < systemServerJarList.Len(); i++ {
|
|
|
|
sscpApex := systemServerJarList.Apex(i)
|
|
|
|
sscpJar := systemServerJarList.Jar(i)
|
|
|
|
if apexName != sscpApex {
|
|
|
|
continue
|
2021-06-15 20:10:11 +02:00
|
|
|
}
|
2023-12-06 20:40:24 +01:00
|
|
|
p.Dexpreopter.DexpreoptPrebuiltApexSystemServerJars(ctx, sscpJar, di)
|
|
|
|
}
|
2021-06-15 20:10:11 +02:00
|
|
|
}
|
|
|
|
|
2021-09-09 10:12:46 +02:00
|
|
|
func (p *prebuiltCommon) addRequiredModules(entries *android.AndroidMkEntries) {
|
|
|
|
for _, fi := range p.apexFilesForAndroidMk {
|
|
|
|
entries.AddStrings("LOCAL_REQUIRED_MODULES", fi.requiredModuleNames...)
|
|
|
|
entries.AddStrings("LOCAL_TARGET_REQUIRED_MODULES", fi.targetRequiredModuleNames...)
|
|
|
|
entries.AddStrings("LOCAL_HOST_REQUIRED_MODULES", fi.hostRequiredModuleNames...)
|
|
|
|
}
|
2022-01-28 15:58:56 +01:00
|
|
|
entries.AddStrings("LOCAL_REQUIRED_MODULES", p.requiredModuleNames...)
|
2021-09-09 10:12:46 +02:00
|
|
|
}
|
|
|
|
|
2021-06-15 12:34:01 +02:00
|
|
|
func (p *prebuiltCommon) AndroidMkEntries() []android.AndroidMkEntries {
|
2021-06-15 20:10:11 +02:00
|
|
|
entriesList := []android.AndroidMkEntries{
|
2021-06-15 12:34:01 +02:00
|
|
|
{
|
|
|
|
Class: "ETC",
|
|
|
|
OutputFile: android.OptionalPathForPath(p.outputApex),
|
|
|
|
Include: "$(BUILD_PREBUILT)",
|
|
|
|
Host_required: p.hostRequired,
|
2024-01-03 19:57:03 +01:00
|
|
|
OverrideName: p.BaseModuleName(),
|
2021-06-15 12:34:01 +02:00
|
|
|
ExtraEntries: []android.AndroidMkExtraEntriesFunc{
|
|
|
|
func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
|
2021-11-12 03:59:15 +01:00
|
|
|
entries.SetString("LOCAL_MODULE_PATH", p.installDir.String())
|
2021-06-15 12:34:01 +02:00
|
|
|
entries.SetString("LOCAL_MODULE_STEM", p.installFilename)
|
2021-11-04 20:01:18 +01:00
|
|
|
entries.SetPath("LOCAL_SOONG_INSTALLED_MODULE", p.installedFile)
|
|
|
|
entries.SetString("LOCAL_SOONG_INSTALL_PAIRS", p.outputApex.String()+":"+p.installedFile.String())
|
2023-08-19 01:05:44 +02:00
|
|
|
entries.AddStrings("LOCAL_SOONG_INSTALL_SYMLINKS", p.compatSymlinks.Strings()...)
|
2021-06-15 12:34:01 +02:00
|
|
|
entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable())
|
|
|
|
entries.AddStrings("LOCAL_OVERRIDES_MODULES", p.prebuiltCommonProperties.Overrides...)
|
2023-10-30 08:17:56 +01:00
|
|
|
entries.SetString("LOCAL_APEX_KEY_PATH", p.apexKeysPath.String())
|
2021-09-09 10:12:46 +02:00
|
|
|
p.addRequiredModules(entries)
|
2021-06-15 12:34:01 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2021-06-15 20:10:11 +02:00
|
|
|
|
2023-12-06 20:40:24 +01:00
|
|
|
// Add the dexpreopt artifacts to androidmk
|
|
|
|
for _, install := range p.Dexpreopter.DexpreoptBuiltInstalledForApex() {
|
|
|
|
entriesList = append(entriesList, install.ToMakeEntries())
|
|
|
|
}
|
|
|
|
|
2021-06-15 20:10:11 +02:00
|
|
|
// Iterate over the apexFilesForAndroidMk list and create an AndroidMkEntries struct for each
|
|
|
|
// file. This provides similar behavior to that provided in apexBundle.AndroidMk() as it makes the
|
|
|
|
// apex specific variants of the exported java modules available for use from within make.
|
|
|
|
apexName := p.BaseModuleName()
|
|
|
|
for _, fi := range p.apexFilesForAndroidMk {
|
2021-06-17 14:33:09 +02:00
|
|
|
entries := p.createEntriesForApexFile(fi, apexName)
|
2021-06-15 20:10:11 +02:00
|
|
|
entriesList = append(entriesList, entries)
|
|
|
|
}
|
|
|
|
|
|
|
|
return entriesList
|
2021-06-15 12:34:01 +02:00
|
|
|
}
|
|
|
|
|
2021-06-17 14:33:09 +02:00
|
|
|
// createEntriesForApexFile creates an AndroidMkEntries for the supplied apexFile
|
|
|
|
func (p *prebuiltCommon) createEntriesForApexFile(fi apexFile, apexName string) android.AndroidMkEntries {
|
|
|
|
moduleName := fi.androidMkModuleName + "." + apexName
|
|
|
|
entries := android.AndroidMkEntries{
|
|
|
|
Class: fi.class.nameInMake(),
|
|
|
|
OverrideName: moduleName,
|
|
|
|
OutputFile: android.OptionalPathForPath(fi.builtFile),
|
|
|
|
Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
|
|
|
|
ExtraEntries: []android.AndroidMkExtraEntriesFunc{
|
|
|
|
func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
|
2021-11-12 03:59:15 +01:00
|
|
|
entries.SetString("LOCAL_MODULE_PATH", p.installDir.String())
|
2021-11-24 00:17:33 +01:00
|
|
|
entries.SetString("LOCAL_SOONG_INSTALLED_MODULE", filepath.Join(p.installDir.String(), fi.stem()))
|
|
|
|
entries.SetString("LOCAL_SOONG_INSTALL_PAIRS",
|
2021-11-04 20:01:18 +01:00
|
|
|
fi.builtFile.String()+":"+filepath.Join(p.installDir.String(), fi.stem()))
|
2021-06-17 14:33:09 +02:00
|
|
|
|
|
|
|
// soong_java_prebuilt.mk sets LOCAL_MODULE_SUFFIX := .jar Therefore
|
|
|
|
// we need to remove the suffix from LOCAL_MODULE_STEM, otherwise
|
|
|
|
// we will have foo.jar.jar
|
|
|
|
entries.SetString("LOCAL_MODULE_STEM", strings.TrimSuffix(fi.stem(), ".jar"))
|
|
|
|
entries.SetString("LOCAL_SOONG_DEX_JAR", fi.builtFile.String())
|
|
|
|
entries.SetString("LOCAL_DEX_PREOPT", "false")
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ExtraFooters: []android.AndroidMkExtraFootersFunc{
|
|
|
|
func(w io.Writer, name, prefix, moduleDir string) {
|
|
|
|
// m <module_name> will build <module_name>.<apex_name> as well.
|
|
|
|
if fi.androidMkModuleName != moduleName {
|
|
|
|
fmt.Fprintf(w, ".PHONY: %s\n", fi.androidMkModuleName)
|
|
|
|
fmt.Fprintf(w, "%s: %s\n", fi.androidMkModuleName, moduleName)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return entries
|
|
|
|
}
|
|
|
|
|
2021-05-05 15:13:27 +02:00
|
|
|
// prebuiltApexModuleCreator defines the methods that need to be implemented by prebuilt_apex and
|
|
|
|
// apex_set in order to create the modules needed to provide access to the prebuilt .apex file.
|
|
|
|
type prebuiltApexModuleCreator interface {
|
|
|
|
createPrebuiltApexModules(ctx android.TopDownMutatorContext)
|
|
|
|
}
|
|
|
|
|
|
|
|
// prebuiltApexModuleCreatorMutator is the mutator responsible for invoking the
|
|
|
|
// prebuiltApexModuleCreator's createPrebuiltApexModules method.
|
|
|
|
//
|
|
|
|
// It is registered as a pre-arch mutator as it must run after the ComponentDepsMutator because it
|
|
|
|
// will need to access dependencies added by that (exported modules) but must run before the
|
|
|
|
// DepsMutator so that the deapexer module it creates can add dependencies onto itself from the
|
|
|
|
// exported modules.
|
|
|
|
func prebuiltApexModuleCreatorMutator(ctx android.TopDownMutatorContext) {
|
|
|
|
module := ctx.Module()
|
|
|
|
if creator, ok := module.(prebuiltApexModuleCreator); ok {
|
|
|
|
creator.createPrebuiltApexModules(ctx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-20 16:10:48 +02:00
|
|
|
func (p *prebuiltCommon) hasExportedDeps() bool {
|
|
|
|
return len(p.prebuiltCommonProperties.Exported_java_libs) > 0 ||
|
|
|
|
len(p.prebuiltCommonProperties.Exported_bootclasspath_fragments) > 0 ||
|
|
|
|
len(p.prebuiltCommonProperties.Exported_systemserverclasspath_fragments) > 0
|
|
|
|
}
|
|
|
|
|
|
|
|
// prebuiltApexContentsDeps adds dependencies onto the prebuilt apex module's contents.
|
|
|
|
func (p *prebuiltCommon) prebuiltApexContentsDeps(ctx android.BottomUpMutatorContext) {
|
|
|
|
module := ctx.Module()
|
2021-09-26 05:54:25 +02:00
|
|
|
|
|
|
|
for _, dep := range p.prebuiltCommonProperties.Exported_java_libs {
|
2023-04-20 16:10:48 +02:00
|
|
|
prebuiltDep := android.PrebuiltNameFromSource(dep)
|
|
|
|
ctx.AddDependency(module, exportedJavaLibTag, prebuiltDep)
|
2021-09-26 05:54:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, dep := range p.prebuiltCommonProperties.Exported_bootclasspath_fragments {
|
2023-04-20 16:10:48 +02:00
|
|
|
prebuiltDep := android.PrebuiltNameFromSource(dep)
|
|
|
|
ctx.AddDependency(module, exportedBootclasspathFragmentTag, prebuiltDep)
|
2021-09-26 05:54:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, dep := range p.prebuiltCommonProperties.Exported_systemserverclasspath_fragments {
|
|
|
|
prebuiltDep := android.PrebuiltNameFromSource(dep)
|
2023-04-20 16:10:48 +02:00
|
|
|
ctx.AddDependency(module, exportedSystemserverclasspathFragmentTag, prebuiltDep)
|
2021-04-22 02:45:29 +02:00
|
|
|
}
|
2021-04-06 18:02:08 +02:00
|
|
|
}
|
|
|
|
|
2021-05-05 13:07:00 +02:00
|
|
|
// Implements android.DepInInSameApex
|
|
|
|
func (p *prebuiltCommon) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
|
|
|
|
tag := ctx.OtherModuleDependencyTag(dep)
|
|
|
|
_, ok := tag.(exportedDependencyTag)
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
2021-04-06 18:02:08 +02:00
|
|
|
// 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:
|
2022-08-16 19:27:33 +02:00
|
|
|
// - 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.
|
2021-04-06 18:02:08 +02:00
|
|
|
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
|
2021-05-05 13:07:00 +02:00
|
|
|
mctx.WalkDeps(func(child, parent android.Module) bool {
|
|
|
|
// If the child is not in the same apex as the parent then exit immediately and do not visit
|
|
|
|
// any of the child's dependencies.
|
|
|
|
if !android.IsDepInSameApex(mctx, parent, child) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
tag := mctx.OtherModuleDependencyTag(child)
|
|
|
|
depName := mctx.OtherModuleName(child)
|
2021-04-22 02:45:29 +02:00
|
|
|
if exportedTag, ok := tag.(exportedDependencyTag); ok {
|
|
|
|
propertyName := exportedTag.name
|
2021-04-06 18:02:08 +02:00
|
|
|
|
|
|
|
// It is an error if the other module is not a prebuilt.
|
2021-05-05 13:07:00 +02:00
|
|
|
if !android.IsModulePrebuilt(child) {
|
2021-04-22 02:45:29 +02:00
|
|
|
mctx.PropertyErrorf(propertyName, "%q is not a prebuilt module", depName)
|
2021-05-05 13:07:00 +02:00
|
|
|
return false
|
2021-04-06 18:02:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// It is an error if the other module is not an ApexModule.
|
2021-05-05 13:07:00 +02:00
|
|
|
if _, ok := child.(android.ApexModule); !ok {
|
2021-04-22 02:45:29 +02:00
|
|
|
mctx.PropertyErrorf(propertyName, "%q is not usable within an apex", depName)
|
2021-05-05 13:07:00 +02:00
|
|
|
return false
|
2021-04-06 18:02:08 +02:00
|
|
|
}
|
2021-05-05 13:07:00 +02:00
|
|
|
}
|
2021-04-06 18:02:08 +02:00
|
|
|
|
2021-06-29 19:38:38 +02:00
|
|
|
// Ignore any modules that do not implement ApexModule as they cannot have an APEX specific
|
|
|
|
// variant.
|
|
|
|
if _, ok := child.(android.ApexModule); !ok {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-05-05 13:07:00 +02:00
|
|
|
// 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)
|
2021-04-06 18:02:08 +02:00
|
|
|
|
2021-05-05 13:07:00 +02:00
|
|
|
// Remember if this module was added as a direct dependency.
|
|
|
|
direct := parent == mctx.Module()
|
|
|
|
contents[depName] = contents[depName].Add(direct)
|
2021-04-06 18:02:08 +02:00
|
|
|
|
2021-05-05 13:07:00 +02:00
|
|
|
// Add the module to the list of dependencies that need to have an APEX variant.
|
|
|
|
dependencies = append(dependencies, child.(android.ApexModule))
|
|
|
|
|
|
|
|
return true
|
2021-04-06 18:02:08 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
// Create contents for the prebuilt_apex and store it away for later use.
|
|
|
|
apexContents := android.NewApexContents(contents)
|
2024-01-25 20:25:42 +01:00
|
|
|
android.SetProvider(mctx, android.ApexBundleInfoProvider, android.ApexBundleInfo{
|
2021-04-06 18:02:08 +02:00
|
|
|
Contents: apexContents,
|
|
|
|
})
|
|
|
|
|
|
|
|
// Create an ApexInfo for the prebuilt_apex.
|
2021-06-24 15:37:13 +02:00
|
|
|
apexVariationName := p.ApexVariationName()
|
2021-04-06 18:02:08 +02:00
|
|
|
apexInfo := android.ApexInfo{
|
2021-05-27 13:17:00 +02:00
|
|
|
ApexVariationName: apexVariationName,
|
|
|
|
InApexVariants: []string{apexVariationName},
|
2024-01-03 19:57:03 +01:00
|
|
|
InApexModules: []string{p.BaseModuleName()}, // BaseModuleName() to avoid the prebuilt_ prefix.
|
2021-04-06 18:02:08 +02:00
|
|
|
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 15:14:52 +01: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 03:16:27 +01:00
|
|
|
type Prebuilt struct {
|
2020-07-16 14:38:56 +02:00
|
|
|
prebuiltCommon
|
2019-11-18 03:16:27 +01:00
|
|
|
|
2021-05-05 17:58:08 +02:00
|
|
|
properties PrebuiltProperties
|
2019-11-18 03:16:27 +01:00
|
|
|
|
2021-06-15 12:34:01 +02:00
|
|
|
inputApex android.Path
|
2022-03-19 01:33:24 +01:00
|
|
|
|
|
|
|
provenanceMetaDataFile android.OutputPath
|
2019-11-18 03:16:27 +01:00
|
|
|
}
|
|
|
|
|
2021-01-13 18:03:51 +01:00
|
|
|
type ApexFileProperties struct {
|
2019-11-18 03:16:27 +01:00
|
|
|
// the path to the prebuilt .apex file to import.
|
2021-03-01 13:25:10 +01: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 15:14:52 +01:00
|
|
|
Src *string `android:"path"`
|
2019-11-18 03:16:27 +01:00
|
|
|
Arch struct {
|
|
|
|
Arm struct {
|
2021-03-01 15:14:52 +01:00
|
|
|
Src *string `android:"path"`
|
2019-11-18 03:16:27 +01:00
|
|
|
}
|
|
|
|
Arm64 struct {
|
2021-03-01 15:14:52 +01:00
|
|
|
Src *string `android:"path"`
|
2019-11-18 03:16:27 +01:00
|
|
|
}
|
2022-10-12 13:28:48 +02:00
|
|
|
Riscv64 struct {
|
|
|
|
Src *string `android:"path"`
|
|
|
|
}
|
2019-11-18 03:16:27 +01:00
|
|
|
X86 struct {
|
2021-03-01 15:14:52 +01:00
|
|
|
Src *string `android:"path"`
|
2019-11-18 03:16:27 +01:00
|
|
|
}
|
|
|
|
X86_64 struct {
|
2021-03-01 15:14:52 +01:00
|
|
|
Src *string `android:"path"`
|
2019-11-18 03:16:27 +01:00
|
|
|
}
|
|
|
|
}
|
2021-01-13 18:03:51 +01:00
|
|
|
}
|
|
|
|
|
2021-03-01 13:25:10 +01: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-13 18:03:51 +01:00
|
|
|
}
|
|
|
|
var src string
|
2021-03-01 13:25:10 +01:00
|
|
|
switch multiTargets[0].Arch.ArchType {
|
2021-01-13 18:03:51 +01:00
|
|
|
case android.Arm:
|
|
|
|
src = String(p.Arch.Arm.Src)
|
|
|
|
case android.Arm64:
|
|
|
|
src = String(p.Arch.Arm64.Src)
|
2022-10-12 13:28:48 +02:00
|
|
|
case android.Riscv64:
|
|
|
|
src = String(p.Arch.Riscv64.Src)
|
2022-11-01 17:26:51 +01:00
|
|
|
// HACK: fall back to arm64 prebuilts, the riscv64 ones don't exist yet.
|
|
|
|
if src == "" {
|
|
|
|
src = String(p.Arch.Arm64.Src)
|
|
|
|
}
|
2021-01-13 18:03:51 +01:00
|
|
|
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-01 18:27:16 +01:00
|
|
|
if src == "" {
|
2022-10-04 07:02:09 +02:00
|
|
|
if ctx.Config().AllowMissingDependencies() {
|
|
|
|
ctx.AddMissingDependencies([]string{ctx.OtherModuleName(prebuilt)})
|
|
|
|
} else {
|
|
|
|
ctx.OtherModuleErrorf(prebuilt, "prebuilt_apex does not support %q", multiTargets[0].Arch.String())
|
|
|
|
}
|
2021-03-01 18:27:16 +01:00
|
|
|
// 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 13:25:10 +01:00
|
|
|
return []string{src}
|
2021-01-13 18:03:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type PrebuiltProperties struct {
|
|
|
|
ApexFileProperties
|
2019-11-18 03:16:27 +01:00
|
|
|
|
2021-06-15 12:34:01 +02:00
|
|
|
PrebuiltCommonProperties
|
2019-11-18 03:16:27 +01:00
|
|
|
}
|
|
|
|
|
2020-07-25 00:35:40 +02:00
|
|
|
func (a *Prebuilt) hasSanitizedSource(sanitizer string) bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-11-18 03:16:27 +01:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex.
|
|
|
|
func PrebuiltFactory() android.Module {
|
|
|
|
module := &Prebuilt{}
|
2021-06-15 12:34:01 +02:00
|
|
|
module.AddProperties(&module.properties)
|
|
|
|
module.initPrebuiltCommon(module, &module.properties.PrebuiltCommonProperties)
|
2020-11-02 18:32:38 +01:00
|
|
|
|
2019-11-18 03:16:27 +01:00
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
2021-05-05 15:13:27 +02:00
|
|
|
func createApexSelectorModule(ctx android.TopDownMutatorContext, name string, apexFileProperties *ApexFileProperties) {
|
2021-03-01 15:14:52 +01:00
|
|
|
props := struct {
|
|
|
|
Name *string
|
|
|
|
}{
|
|
|
|
Name: proptools.StringPtr(name),
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.CreateModule(privateApexSelectorModuleFactory,
|
|
|
|
&props,
|
|
|
|
apexFileProperties,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-05-05 15:13:27 +02:00
|
|
|
// createDeapexerModuleIfNeeded will create a deapexer module if it is needed.
|
|
|
|
//
|
2021-05-05 16:09:44 +02:00
|
|
|
// A deapexer module is only needed when the prebuilt apex specifies one or more modules in either
|
|
|
|
// the `exported_java_libs` or `exported_bootclasspath_fragments` properties as that indicates that
|
|
|
|
// the listed modules need access to files from within the prebuilt .apex file.
|
2021-09-26 05:54:25 +02:00
|
|
|
func (p *prebuiltCommon) createDeapexerModuleIfNeeded(ctx android.TopDownMutatorContext, deapexerName string, apexFileSource string) {
|
2021-05-05 15:13:27 +02:00
|
|
|
// Only create the deapexer module if it is needed.
|
2023-04-20 16:10:48 +02:00
|
|
|
if !p.hasExportedDeps() {
|
2021-05-05 15:13:27 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-05-05 16:09:44 +02:00
|
|
|
// Compute the deapexer properties from the transitive dependencies of this module.
|
2021-06-07 11:25:31 +02:00
|
|
|
commonModules := []string{}
|
2024-01-25 23:12:50 +01:00
|
|
|
dexpreoptProfileGuidedModules := []string{}
|
2021-06-17 16:59:07 +02:00
|
|
|
exportedFiles := []string{}
|
2021-05-05 16:09:44 +02:00
|
|
|
ctx.WalkDeps(func(child, parent android.Module) bool {
|
|
|
|
tag := ctx.OtherModuleDependencyTag(child)
|
|
|
|
|
2021-06-17 15:56:05 +02:00
|
|
|
// If the child is not in the same apex as the parent then ignore it and all its children.
|
|
|
|
if !android.IsDepInSameApex(ctx, parent, child) {
|
|
|
|
return false
|
|
|
|
}
|
2021-05-05 19:03:47 +02:00
|
|
|
|
Use source_module_name to determine the contents of prebuilt apexes
There are a couple of instances in apex/ and java/ that rely on the naming
convention that the jars exported by prebuilt apexes follow the name of
the java_sdk_library_import, minus the prebuilt_ prefix. With muliple
module sdk prebuilts in trunk stable, this naming convention might not
be valid. Use `source_module_name` instead.
```
prebuilt_sscp_fragment {name: "", contents: ["service-foo.v2"]}
java_import {name: "service-foo.v2", source_module_name: "service-foo"},
```
We should use service-foo and not service-foo.v2 because
1. The prebuilt apex contains service-foo.dex
2. PRODUCT_*JARS will contain service-foo and not service-foo.v2
For clarity, this CL does not drop the current mechanism where prebuilt bcp
fragments create a dependency edge to prebuilt java or java_sdk_library
imports. There is still some discussion around whether we can remove
that completely (b/320711431). If we were to do that, then the
Android.bp files will become
```
prebuilt_sscp_fragment {name: "", contents: ["service-foo"]}
```
Bug: 322175508
Test: Added a unit test
Test: In internal, lunch cf_x86_64_only_phone-next-userdebug && m
nothing # .ninja files identical
Test: In internal, created a parallel set of v2 prebuilts of
java_sdk_library_import and prebuilt_bcp_fragments for adservices && m
nothing # build passes
Change-Id: Ia899d75e826fa1a559368d706eaa65835f748d40
2024-01-19 01:22:22 +01:00
|
|
|
name := java.ModuleStemForDeapexing(child)
|
2021-06-17 15:56:05 +02:00
|
|
|
if _, ok := tag.(android.RequiresFilesFromPrebuiltApexTag); ok {
|
2021-06-07 11:25:31 +02:00
|
|
|
commonModules = append(commonModules, name)
|
|
|
|
|
2024-01-25 23:12:50 +01:00
|
|
|
extract := child.(android.RequiredFilesFromPrebuiltApex)
|
|
|
|
requiredFiles := extract.RequiredFilesFromPrebuiltApex(ctx)
|
2021-06-17 16:59:07 +02:00
|
|
|
exportedFiles = append(exportedFiles, requiredFiles...)
|
2021-06-07 11:25:31 +02:00
|
|
|
|
2024-01-25 23:12:50 +01:00
|
|
|
if extract.UseProfileGuidedDexpreopt() {
|
|
|
|
dexpreoptProfileGuidedModules = append(dexpreoptProfileGuidedModules, name)
|
|
|
|
}
|
|
|
|
|
2021-06-17 15:56:05 +02:00
|
|
|
// Visit the dependencies of this module just in case they also require files from the
|
|
|
|
// prebuilt apex.
|
2021-05-05 16:09:44 +02:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
|
2021-05-05 19:03:47 +02:00
|
|
|
// Create properties for deapexer module.
|
|
|
|
deapexerProperties := &DeapexerProperties{
|
2021-06-07 11:25:31 +02:00
|
|
|
// Remove any duplicates from the common modules lists as a module may be included via a direct
|
2021-05-05 19:03:47 +02:00
|
|
|
// dependency as well as transitive ones.
|
2024-01-25 23:12:50 +01:00
|
|
|
CommonModules: android.SortedUniqueStrings(commonModules),
|
|
|
|
DexpreoptProfileGuidedModules: android.SortedUniqueStrings(dexpreoptProfileGuidedModules),
|
2021-05-05 19:03:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Populate the exported files property in a fixed order.
|
2021-06-17 16:59:07 +02:00
|
|
|
deapexerProperties.ExportedFiles = android.SortedUniqueStrings(exportedFiles)
|
2021-05-05 16:09:44 +02:00
|
|
|
|
2021-03-01 15:14:52 +01:00
|
|
|
props := struct {
|
|
|
|
Name *string
|
|
|
|
Selected_apex *string
|
|
|
|
}{
|
|
|
|
Name: proptools.StringPtr(deapexerName),
|
|
|
|
Selected_apex: proptools.StringPtr(apexFileSource),
|
|
|
|
}
|
|
|
|
ctx.CreateModule(privateDeapexerFactory,
|
|
|
|
&props,
|
|
|
|
deapexerProperties,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func apexSelectorModuleName(baseModuleName string) string {
|
|
|
|
return baseModuleName + ".apex.selector"
|
|
|
|
}
|
|
|
|
|
2020-11-02 18:32:38 +01: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 11:24:13 +02:00
|
|
|
prebuiltName := android.PrebuiltNameFromSource(name)
|
2020-11-02 18:32:38 +01:00
|
|
|
if ctx.OtherModuleExists(prebuiltName) {
|
|
|
|
name = prebuiltName
|
|
|
|
}
|
|
|
|
return name
|
|
|
|
}
|
|
|
|
|
2021-02-08 12:01:58 +01: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() {}
|
|
|
|
|
2021-06-17 15:56:05 +02:00
|
|
|
func (t exportedDependencyTag) RequiresFilesFromPrebuiltApex() {}
|
|
|
|
|
|
|
|
var _ android.RequiresFilesFromPrebuiltApexTag = exportedDependencyTag{}
|
|
|
|
|
2021-02-08 12:01:58 +01:00
|
|
|
var (
|
2021-09-26 05:54:25 +02:00
|
|
|
exportedJavaLibTag = exportedDependencyTag{name: "exported_java_libs"}
|
|
|
|
exportedBootclasspathFragmentTag = exportedDependencyTag{name: "exported_bootclasspath_fragments"}
|
|
|
|
exportedSystemserverclasspathFragmentTag = exportedDependencyTag{name: "exported_systemserverclasspath_fragments"}
|
2021-02-08 12:01:58 +01:00
|
|
|
)
|
|
|
|
|
2021-05-05 15:13:27 +02:00
|
|
|
var _ prebuiltApexModuleCreator = (*Prebuilt)(nil)
|
|
|
|
|
|
|
|
// createPrebuiltApexModules creates modules necessary to export files from the prebuilt apex to the
|
|
|
|
// build.
|
|
|
|
//
|
|
|
|
// 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 listed in exported_java_libs,
|
|
|
|
// it does so as follows:
|
|
|
|
//
|
2022-08-16 19:27:33 +02:00
|
|
|
// 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.
|
2021-05-05 15:13:27 +02:00
|
|
|
//
|
2022-08-16 19:27:33 +02:00
|
|
|
// 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.
|
2021-05-05 15:13:27 +02:00
|
|
|
//
|
2022-08-16 19:27:33 +02:00
|
|
|
// 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-05-05 15:13:27 +02: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:
|
|
|
|
//
|
2022-08-16 19:27:33 +02:00
|
|
|
// 1. To dedup the selection logic so it only runs in one module.
|
2021-05-05 15:13:27 +02:00
|
|
|
//
|
2022-08-16 19:27:33 +02:00
|
|
|
// 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 V
|
|
|
|
// selector <--- deapexer <--- exported java lib
|
2021-05-05 15:13:27 +02:00
|
|
|
func (p *Prebuilt) createPrebuiltApexModules(ctx android.TopDownMutatorContext) {
|
2024-01-03 19:57:03 +01:00
|
|
|
apexSelectorModuleName := apexSelectorModuleName(p.Name())
|
2021-05-05 15:13:27 +02:00
|
|
|
createApexSelectorModule(ctx, apexSelectorModuleName, &p.properties.ApexFileProperties)
|
|
|
|
|
|
|
|
apexFileSource := ":" + apexSelectorModuleName
|
2024-01-03 19:57:03 +01:00
|
|
|
p.createDeapexerModuleIfNeeded(ctx, deapexerModuleName(p.Name()), apexFileSource)
|
2021-05-05 15:13:27 +02:00
|
|
|
|
|
|
|
// Add a source reference to retrieve the selected apex from the selector module.
|
2021-05-05 17:58:08 +02:00
|
|
|
p.prebuiltCommonProperties.Selected_apex = proptools.StringPtr(apexFileSource)
|
2021-05-05 15:13:27 +02:00
|
|
|
}
|
|
|
|
|
2021-05-05 16:09:44 +02:00
|
|
|
func (p *Prebuilt) ComponentDepsMutator(ctx android.BottomUpMutatorContext) {
|
|
|
|
p.prebuiltApexContentsDeps(ctx)
|
2020-11-02 18:32:38 +01:00
|
|
|
}
|
|
|
|
|
2023-12-06 20:40:24 +01:00
|
|
|
func (p *prebuiltCommon) DepsMutator(ctx android.BottomUpMutatorContext) {
|
|
|
|
if p.hasExportedDeps() {
|
|
|
|
// Create a dependency from the prebuilt apex (prebuilt_apex/apex_set) to the internal deapexer module
|
|
|
|
// The deapexer will return a provider that will be bubbled up to the rdeps of apexes (e.g. dex_bootjars)
|
2024-01-03 19:57:03 +01:00
|
|
|
ctx.AddDependency(ctx.Module(), android.DeapexerTag, deapexerModuleName(p.Name()))
|
2023-12-06 20:40:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-02 18:32:38 +01:00
|
|
|
var _ ApexInfoMutator = (*Prebuilt)(nil)
|
|
|
|
|
|
|
|
func (p *Prebuilt) ApexInfoMutator(mctx android.TopDownMutatorContext) {
|
2021-04-06 18:02:08 +02:00
|
|
|
p.apexInfoMutator(mctx)
|
2019-11-18 03:16:27 +01:00
|
|
|
}
|
|
|
|
|
2023-12-13 01:06:32 +01:00
|
|
|
// Set a provider containing information about the jars and .prof provided by the apex
|
|
|
|
// Apexes built from prebuilts retrieve this information by visiting its internal deapexer module
|
|
|
|
// Used by dex_bootjars to generate the boot image
|
|
|
|
func (p *prebuiltCommon) provideApexExportsInfo(ctx android.ModuleContext) {
|
|
|
|
if !p.hasExportedDeps() {
|
|
|
|
// nothing to do
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if di, err := android.FindDeapexerProviderForModule(ctx); err == nil {
|
2023-12-13 01:06:32 +01:00
|
|
|
javaModuleToDexPath := map[string]android.Path{}
|
|
|
|
for _, commonModule := range di.GetExportedModuleNames() {
|
|
|
|
if dex := di.PrebuiltExportPath(java.ApexRootRelativePathToJavaLib(commonModule)); dex != nil {
|
|
|
|
javaModuleToDexPath[commonModule] = dex
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-13 01:06:32 +01:00
|
|
|
exports := android.ApexExportsInfo{
|
2023-12-13 01:06:32 +01:00
|
|
|
ApexName: p.ApexVariationName(),
|
|
|
|
ProfilePathOnHost: di.PrebuiltExportPath(java.ProfileInstallPathInApex),
|
|
|
|
LibraryNameToDexJarPathOnHost: javaModuleToDexPath,
|
2023-12-13 01:06:32 +01:00
|
|
|
}
|
2023-12-22 01:05:04 +01:00
|
|
|
android.SetProvider(ctx, android.ApexExportsInfoProvider, exports)
|
2023-12-13 01:06:32 +01:00
|
|
|
} else {
|
|
|
|
ctx.ModuleErrorf(err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-11 22:37:25 +01:00
|
|
|
// Set prebuiltInfoProvider. This will be used by `apex_prebuiltinfo_singleton` to print out a metadata file
|
|
|
|
// with information about whether source or prebuilt of an apex was used during the build.
|
|
|
|
func (p *prebuiltCommon) providePrebuiltInfo(ctx android.ModuleContext) {
|
2024-03-11 22:37:25 +01:00
|
|
|
info := android.PrebuiltInfo{
|
|
|
|
Name: p.BaseModuleName(),
|
2024-03-11 22:37:25 +01:00
|
|
|
Is_prebuilt: true,
|
|
|
|
}
|
|
|
|
// If Prebuilt_info information is available in the soong module definition, add it to prebuilt_info.json.
|
|
|
|
if p.prebuiltCommonProperties.Prebuilt_info != nil {
|
|
|
|
info.Prebuilt_info_file_path = android.PathForModuleSrc(ctx, *p.prebuiltCommonProperties.Prebuilt_info).String()
|
|
|
|
}
|
2024-03-11 22:37:25 +01:00
|
|
|
android.SetProvider(ctx, android.PrebuiltInfoProvider, info)
|
2024-03-11 22:37:25 +01:00
|
|
|
}
|
|
|
|
|
2019-11-18 03:16:27 +01:00
|
|
|
func (p *Prebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2023-10-30 08:17:56 +01:00
|
|
|
p.apexKeysPath = writeApexKeys(ctx, p)
|
2019-11-18 03:16:27 +01:00
|
|
|
// TODO(jungjw): Check the key validity.
|
2021-05-05 17:58:08 +02:00
|
|
|
p.inputApex = android.OptionalPathForModuleSrc(ctx, p.prebuiltCommonProperties.Selected_apex).Path()
|
2019-11-18 03:16:27 +01: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 14:38:56 +02:00
|
|
|
|
|
|
|
if p.prebuiltCommon.checkForceDisable(ctx) {
|
2020-12-16 19:20:23 +01:00
|
|
|
p.HideFromMake()
|
2020-07-16 14:38:56 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-12-06 20:40:24 +01:00
|
|
|
// dexpreopt any system server jars if present
|
|
|
|
p.dexpreoptSystemServerJars(ctx)
|
|
|
|
|
2023-12-13 01:06:32 +01:00
|
|
|
// provide info used for generating the boot image
|
|
|
|
p.provideApexExportsInfo(ctx)
|
|
|
|
|
2024-03-11 22:37:25 +01:00
|
|
|
p.providePrebuiltInfo(ctx)
|
|
|
|
|
2021-06-15 20:10:11 +02:00
|
|
|
// Save the files that need to be made available to Make.
|
|
|
|
p.initApexFilesForAndroidMk(ctx)
|
|
|
|
|
2020-01-07 17:57:58 +01:00
|
|
|
// in case that prebuilt_apex replaces source apex (using prefer: prop)
|
2023-08-23 04:11:43 +02:00
|
|
|
p.compatSymlinks = makeCompatSymlinks(p.BaseModuleName(), ctx)
|
2020-01-07 17:57:58 +01:00
|
|
|
// or that prebuilt_apex overrides other apexes (using overrides: prop)
|
2021-06-15 12:34:01 +02:00
|
|
|
for _, overridden := range p.prebuiltCommonProperties.Overrides {
|
2023-08-23 04:11:43 +02:00
|
|
|
p.compatSymlinks = append(p.compatSymlinks, makeCompatSymlinks(overridden, ctx)...)
|
2021-11-04 20:01:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if p.installable() {
|
2023-11-15 21:29:33 +01:00
|
|
|
p.installedFile = ctx.InstallFile(p.installDir, p.installFilename, p.inputApex, p.compatSymlinks...)
|
2022-03-19 01:33:24 +01:00
|
|
|
p.provenanceMetaDataFile = provenance.GenerateArtifactProvenanceMetaData(ctx, p.inputApex, p.installedFile)
|
2020-01-07 17:57:58 +01:00
|
|
|
}
|
2019-11-18 03:16:27 +01:00
|
|
|
}
|
|
|
|
|
2022-03-19 01:33:24 +01:00
|
|
|
func (p *Prebuilt) ProvenanceMetaDataFile() android.OutputPath {
|
|
|
|
return p.provenanceMetaDataFile
|
|
|
|
}
|
|
|
|
|
2021-04-06 17:09:30 +02: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)
|
|
|
|
}
|
2022-12-12 19:00:47 +01:00
|
|
|
defaultAllowPrerelease := ctx.Config().IsEnvTrue("SOONG_ALLOW_PRERELEASE_APEXES")
|
2021-04-06 17:09:30 +02:00
|
|
|
apexSet := android.SingleSourcePathFromSupplier(ctx, srcsSupplier, "set")
|
|
|
|
p.extractedApex = android.PathForModuleOut(ctx, "extracted", apexSet.Base())
|
2022-11-25 15:06:46 +01:00
|
|
|
// Filter out NativeBridge archs (b/260115309)
|
|
|
|
abis := java.SupportedAbis(ctx, true)
|
2021-04-06 17:09:30 +02:00
|
|
|
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{
|
2022-11-25 15:06:46 +01:00
|
|
|
"abis": strings.Join(abis, ","),
|
2022-12-12 19:00:47 +01:00
|
|
|
"allow-prereleased": strconv.FormatBool(proptools.BoolDefault(p.properties.Prerelease, defaultAllowPrerelease)),
|
2021-04-06 17:09:30 +02:00
|
|
|
"sdk-version": ctx.Config().PlatformSdkVersion().String(),
|
2023-03-21 00:19:53 +01:00
|
|
|
"skip-sdk-check": strconv.FormatBool(ctx.Config().IsEnvTrue("SOONG_SKIP_APPSET_SDK_CHECK")),
|
2021-04-06 17:09:30 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-05-14 23:15:24 +02:00
|
|
|
type ApexSet struct {
|
2020-07-16 14:38:56 +02:00
|
|
|
prebuiltCommon
|
2020-05-14 23:15:24 +02:00
|
|
|
|
|
|
|
properties ApexSetProperties
|
|
|
|
}
|
|
|
|
|
2021-04-06 17:09:30 +02:00
|
|
|
type ApexExtractorProperties struct {
|
2020-05-14 23:15:24 +02:00
|
|
|
// the .apks file path that contains prebuilt apex files to be extracted.
|
2022-09-27 02:27:08 +02:00
|
|
|
Set *string `android:"path"`
|
2020-05-14 23:15:24 +02:00
|
|
|
|
2020-07-25 00:35:40 +02:00
|
|
|
Sanitized struct {
|
|
|
|
None struct {
|
2022-09-27 02:27:08 +02:00
|
|
|
Set *string `android:"path"`
|
2020-07-25 00:35:40 +02:00
|
|
|
}
|
|
|
|
Address struct {
|
2022-09-27 02:27:08 +02:00
|
|
|
Set *string `android:"path"`
|
2020-07-25 00:35:40 +02:00
|
|
|
}
|
|
|
|
Hwaddress struct {
|
2022-09-27 02:27:08 +02:00
|
|
|
Set *string `android:"path"`
|
2020-07-25 00:35:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-14 23:15:24 +02:00
|
|
|
// apexes in this set use prerelease SDK version
|
|
|
|
Prerelease *bool
|
|
|
|
}
|
|
|
|
|
2021-04-06 17:09:30 +02:00
|
|
|
func (e *ApexExtractorProperties) prebuiltSrcs(ctx android.BaseModuleContext) []string {
|
2020-07-25 00:35:40 +02:00
|
|
|
var srcs []string
|
2021-04-06 17:09:30 +02:00
|
|
|
if e.Set != nil {
|
|
|
|
srcs = append(srcs, *e.Set)
|
2020-07-25 00:35:40 +02:00
|
|
|
}
|
|
|
|
|
2023-08-23 06:54:08 +02:00
|
|
|
sanitizers := ctx.Config().SanitizeDevice()
|
2020-07-25 00:35:40 +02:00
|
|
|
|
2021-04-06 17:09:30 +02: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 00:35:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return srcs
|
|
|
|
}
|
|
|
|
|
2021-04-06 17:09:30 +02:00
|
|
|
type ApexSetProperties struct {
|
|
|
|
ApexExtractorProperties
|
|
|
|
|
2021-06-15 12:34:01 +02:00
|
|
|
PrebuiltCommonProperties
|
2021-04-06 17:09:30 +02:00
|
|
|
}
|
|
|
|
|
2020-07-25 00:35:40 +02: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
|
|
|
|
}
|
|
|
|
|
2022-12-12 18:44:33 +01:00
|
|
|
func (a *ApexSet) OutputFiles(tag string) (android.Paths, error) {
|
|
|
|
switch tag {
|
|
|
|
case "":
|
|
|
|
return android.Paths{a.outputApex}, nil
|
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("unsupported module reference tag %q", tag)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-14 23:15:24 +02: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-06-15 12:34:01 +02:00
|
|
|
module.AddProperties(&module.properties)
|
|
|
|
module.initPrebuiltCommon(module, &module.properties.PrebuiltCommonProperties)
|
2021-04-06 17:09:30 +02:00
|
|
|
|
2020-05-14 23:15:24 +02:00
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
2021-05-05 15:13:27 +02:00
|
|
|
func createApexExtractorModule(ctx android.TopDownMutatorContext, name string, apexExtractorProperties *ApexExtractorProperties) {
|
2021-04-06 17:09:30 +02:00
|
|
|
props := struct {
|
|
|
|
Name *string
|
|
|
|
}{
|
|
|
|
Name: proptools.StringPtr(name),
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.CreateModule(privateApexExtractorModuleFactory,
|
|
|
|
&props,
|
|
|
|
apexExtractorProperties,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func apexExtractorModuleName(baseModuleName string) string {
|
|
|
|
return baseModuleName + ".apex.extractor"
|
|
|
|
}
|
|
|
|
|
2021-05-05 15:13:27 +02:00
|
|
|
var _ prebuiltApexModuleCreator = (*ApexSet)(nil)
|
|
|
|
|
|
|
|
// createPrebuiltApexModules creates modules necessary to export files from the apex set to other
|
|
|
|
// modules.
|
|
|
|
//
|
|
|
|
// This effectively does for apex_set what Prebuilt.createPrebuiltApexModules does for a
|
|
|
|
// prebuilt_apex except that instead of creating a selector module which selects one .apex file
|
|
|
|
// from those provided this creates an extractor module which extracts the appropriate .apex file
|
|
|
|
// from the zip file containing them.
|
|
|
|
func (a *ApexSet) createPrebuiltApexModules(ctx android.TopDownMutatorContext) {
|
2024-01-03 19:57:03 +01:00
|
|
|
apexExtractorModuleName := apexExtractorModuleName(a.Name())
|
2021-05-05 15:13:27 +02:00
|
|
|
createApexExtractorModule(ctx, apexExtractorModuleName, &a.properties.ApexExtractorProperties)
|
|
|
|
|
|
|
|
apexFileSource := ":" + apexExtractorModuleName
|
2024-01-03 19:57:03 +01:00
|
|
|
a.createDeapexerModuleIfNeeded(ctx, deapexerModuleName(a.Name()), apexFileSource)
|
2021-05-05 15:13:27 +02:00
|
|
|
|
|
|
|
// After passing the arch specific src properties to the creating the apex selector module
|
2021-05-05 17:58:08 +02:00
|
|
|
a.prebuiltCommonProperties.Selected_apex = proptools.StringPtr(apexFileSource)
|
2021-05-05 15:13:27 +02:00
|
|
|
}
|
|
|
|
|
2021-05-05 16:09:44 +02:00
|
|
|
func (a *ApexSet) ComponentDepsMutator(ctx android.BottomUpMutatorContext) {
|
|
|
|
a.prebuiltApexContentsDeps(ctx)
|
2021-04-06 17:00:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ ApexInfoMutator = (*ApexSet)(nil)
|
|
|
|
|
|
|
|
func (a *ApexSet) ApexInfoMutator(mctx android.TopDownMutatorContext) {
|
|
|
|
a.apexInfoMutator(mctx)
|
|
|
|
}
|
|
|
|
|
2020-05-14 23:15:24 +02:00
|
|
|
func (a *ApexSet) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2023-10-30 08:17:56 +01:00
|
|
|
a.apexKeysPath = writeApexKeys(ctx, a)
|
2020-05-14 23:15:24 +02:00
|
|
|
a.installFilename = a.InstallFilename()
|
2021-09-08 18:48:28 +02:00
|
|
|
if !strings.HasSuffix(a.installFilename, imageApexSuffix) && !strings.HasSuffix(a.installFilename, imageCapexSuffix) {
|
|
|
|
ctx.ModuleErrorf("filename should end in %s or %s for apex_set", imageApexSuffix, imageCapexSuffix)
|
2020-05-14 23:15:24 +02:00
|
|
|
}
|
|
|
|
|
2021-05-05 17:58:08 +02:00
|
|
|
inputApex := android.OptionalPathForModuleSrc(ctx, a.prebuiltCommonProperties.Selected_apex).Path()
|
2020-05-14 23:15:24 +02:00
|
|
|
a.outputApex = android.PathForModuleOut(ctx, a.installFilename)
|
2021-04-06 17:09:30 +02:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: android.Cp,
|
|
|
|
Input: inputApex,
|
|
|
|
Output: a.outputApex,
|
|
|
|
})
|
2020-07-16 14:38:56 +02:00
|
|
|
|
|
|
|
if a.prebuiltCommon.checkForceDisable(ctx) {
|
2020-12-16 19:20:23 +01:00
|
|
|
a.HideFromMake()
|
2020-07-16 14:38:56 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-12-06 20:40:24 +01:00
|
|
|
// dexpreopt any system server jars if present
|
|
|
|
a.dexpreoptSystemServerJars(ctx)
|
|
|
|
|
2023-12-13 01:06:32 +01:00
|
|
|
// provide info used for generating the boot image
|
|
|
|
a.provideApexExportsInfo(ctx)
|
|
|
|
|
2024-03-11 22:37:25 +01:00
|
|
|
a.providePrebuiltInfo(ctx)
|
|
|
|
|
2021-06-15 20:10:11 +02:00
|
|
|
// Save the files that need to be made available to Make.
|
|
|
|
a.initApexFilesForAndroidMk(ctx)
|
|
|
|
|
2020-05-14 23:15:24 +02:00
|
|
|
a.installDir = android.PathForModuleInstall(ctx, "apex")
|
|
|
|
if a.installable() {
|
2021-12-09 06:09:04 +01:00
|
|
|
a.installedFile = ctx.InstallFile(a.installDir, a.installFilename, a.outputApex)
|
2020-05-14 23:15:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// in case that apex_set replaces source apex (using prefer: prop)
|
2023-08-23 04:11:43 +02:00
|
|
|
a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
|
2020-05-14 23:15:24 +02:00
|
|
|
// or that apex_set overrides other apexes (using overrides: prop)
|
2021-06-15 12:34:01 +02:00
|
|
|
for _, overridden := range a.prebuiltCommonProperties.Overrides {
|
2023-08-23 04:11:43 +02:00
|
|
|
a.compatSymlinks = append(a.compatSymlinks, makeCompatSymlinks(overridden, ctx)...)
|
2020-05-14 23:15:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-15 12:34:01 +02:00
|
|
|
type systemExtContext struct {
|
|
|
|
android.ModuleContext
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*systemExtContext) SystemExtSpecific() bool {
|
|
|
|
return true
|
2020-05-14 23:15:24 +02:00
|
|
|
}
|