2020-12-02 05:14:28 +01:00
|
|
|
// Copyright 2020 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 cc
|
|
|
|
|
|
|
|
// This file defines snapshot prebuilt modules, e.g. vendor snapshot and recovery snapshot. Such
|
|
|
|
// snapshot modules will override original source modules with setting BOARD_VNDK_VERSION, with
|
|
|
|
// snapshot mutators and snapshot information maps which are also defined in this file.
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"android/soong/android"
|
2021-07-07 05:42:39 +02:00
|
|
|
"android/soong/snapshot"
|
2020-12-11 22:36:29 +01:00
|
|
|
|
2021-01-12 02:31:17 +01:00
|
|
|
"github.com/google/blueprint"
|
2020-12-02 05:14:28 +01:00
|
|
|
)
|
|
|
|
|
2021-07-07 05:42:39 +02:00
|
|
|
// This interface overrides snapshot.SnapshotImage to implement cc module specific functions
|
2021-05-26 21:33:11 +02:00
|
|
|
type SnapshotImage interface {
|
2021-07-07 05:42:39 +02:00
|
|
|
snapshot.SnapshotImage
|
2021-01-12 02:31:17 +01:00
|
|
|
|
|
|
|
// The image variant name for this snapshot image.
|
|
|
|
// For example, recovery snapshot image will return "recovery", and vendor snapshot image will
|
|
|
|
// return "vendor." + version.
|
|
|
|
imageVariantName(cfg android.DeviceConfig) string
|
|
|
|
|
|
|
|
// The variant suffix for snapshot modules. For example, vendor snapshot modules will have
|
|
|
|
// ".vendor" as their suffix.
|
|
|
|
moduleNameSuffix() string
|
2020-12-02 05:14:28 +01:00
|
|
|
}
|
|
|
|
|
2021-07-07 05:42:39 +02:00
|
|
|
type vendorSnapshotImage struct {
|
|
|
|
*snapshot.VendorSnapshotImage
|
2020-12-02 05:14:28 +01:00
|
|
|
}
|
|
|
|
|
2021-07-07 05:42:39 +02:00
|
|
|
type recoverySnapshotImage struct {
|
|
|
|
*snapshot.RecoverySnapshotImage
|
2020-12-02 05:14:28 +01:00
|
|
|
}
|
|
|
|
|
2021-07-07 05:42:39 +02:00
|
|
|
func (vendorSnapshotImage) imageVariantName(cfg android.DeviceConfig) string {
|
|
|
|
return VendorVariationPrefix + cfg.VndkVersion()
|
2020-12-02 05:14:28 +01:00
|
|
|
}
|
|
|
|
|
2021-07-07 05:42:39 +02:00
|
|
|
func (vendorSnapshotImage) moduleNameSuffix() string {
|
|
|
|
return VendorSuffix
|
2020-12-11 22:36:29 +01:00
|
|
|
}
|
|
|
|
|
2021-07-07 05:42:39 +02:00
|
|
|
func (recoverySnapshotImage) imageVariantName(cfg android.DeviceConfig) string {
|
|
|
|
return android.RecoveryVariation
|
2020-12-11 22:36:29 +01:00
|
|
|
}
|
|
|
|
|
2021-07-07 05:42:39 +02:00
|
|
|
func (recoverySnapshotImage) moduleNameSuffix() string {
|
2021-02-11 21:31:46 +01:00
|
|
|
return RecoverySuffix
|
2021-01-06 15:06:52 +01:00
|
|
|
}
|
|
|
|
|
2021-07-07 05:42:39 +02:00
|
|
|
// Override existing vendor and recovery snapshot for cc module specific extra functions
|
|
|
|
var VendorSnapshotImageSingleton vendorSnapshotImage = vendorSnapshotImage{&snapshot.VendorSnapshotImageSingleton}
|
2021-11-05 22:04:54 +01:00
|
|
|
var RecoverySnapshotImageSingleton recoverySnapshotImage = recoverySnapshotImage{&snapshot.RecoverySnapshotImageSingleton}
|
2021-01-12 02:31:17 +01:00
|
|
|
|
2021-07-07 05:42:39 +02:00
|
|
|
func RegisterVendorSnapshotModules(ctx android.RegistrationContext) {
|
|
|
|
ctx.RegisterModuleType("vendor_snapshot", vendorSnapshotFactory)
|
|
|
|
ctx.RegisterModuleType("vendor_snapshot_shared", VendorSnapshotSharedFactory)
|
|
|
|
ctx.RegisterModuleType("vendor_snapshot_static", VendorSnapshotStaticFactory)
|
|
|
|
ctx.RegisterModuleType("vendor_snapshot_header", VendorSnapshotHeaderFactory)
|
|
|
|
ctx.RegisterModuleType("vendor_snapshot_binary", VendorSnapshotBinaryFactory)
|
|
|
|
ctx.RegisterModuleType("vendor_snapshot_object", VendorSnapshotObjectFactory)
|
2021-01-12 02:31:17 +01:00
|
|
|
}
|
|
|
|
|
2021-07-07 05:42:39 +02:00
|
|
|
func RegisterRecoverySnapshotModules(ctx android.RegistrationContext) {
|
2021-01-12 02:31:17 +01:00
|
|
|
ctx.RegisterModuleType("recovery_snapshot", recoverySnapshotFactory)
|
|
|
|
ctx.RegisterModuleType("recovery_snapshot_shared", RecoverySnapshotSharedFactory)
|
|
|
|
ctx.RegisterModuleType("recovery_snapshot_static", RecoverySnapshotStaticFactory)
|
|
|
|
ctx.RegisterModuleType("recovery_snapshot_header", RecoverySnapshotHeaderFactory)
|
|
|
|
ctx.RegisterModuleType("recovery_snapshot_binary", RecoverySnapshotBinaryFactory)
|
|
|
|
ctx.RegisterModuleType("recovery_snapshot_object", RecoverySnapshotObjectFactory)
|
2020-12-02 05:14:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2021-07-07 05:42:39 +02:00
|
|
|
RegisterVendorSnapshotModules(android.InitRegistrationContext)
|
|
|
|
RegisterRecoverySnapshotModules(android.InitRegistrationContext)
|
2021-07-13 04:36:24 +02:00
|
|
|
android.RegisterMakeVarsProvider(pctx, snapshotMakeVarsProvider)
|
2020-12-02 05:14:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
2021-01-12 02:31:17 +01:00
|
|
|
snapshotHeaderSuffix = "_header."
|
2021-05-26 21:33:11 +02:00
|
|
|
SnapshotSharedSuffix = "_shared."
|
|
|
|
SnapshotStaticSuffix = "_static."
|
2021-01-12 02:31:17 +01:00
|
|
|
snapshotBinarySuffix = "_binary."
|
|
|
|
snapshotObjectSuffix = "_object."
|
2021-06-01 21:09:53 +02:00
|
|
|
SnapshotRlibSuffix = "_rlib."
|
2020-12-02 05:14:28 +01:00
|
|
|
)
|
|
|
|
|
2021-01-12 02:31:17 +01:00
|
|
|
type SnapshotProperties struct {
|
|
|
|
Header_libs []string `android:"arch_variant"`
|
|
|
|
Static_libs []string `android:"arch_variant"`
|
|
|
|
Shared_libs []string `android:"arch_variant"`
|
2021-06-01 21:09:53 +02:00
|
|
|
Rlibs []string `android:"arch_variant"`
|
2021-01-12 02:31:17 +01:00
|
|
|
Vndk_libs []string `android:"arch_variant"`
|
|
|
|
Binaries []string `android:"arch_variant"`
|
|
|
|
Objects []string `android:"arch_variant"`
|
2020-12-02 05:14:28 +01:00
|
|
|
}
|
2021-07-07 05:42:39 +02:00
|
|
|
type snapshotModule struct {
|
2021-01-12 02:31:17 +01:00
|
|
|
android.ModuleBase
|
|
|
|
|
|
|
|
properties SnapshotProperties
|
|
|
|
|
2021-05-26 21:33:11 +02:00
|
|
|
baseSnapshot BaseSnapshotDecorator
|
2021-01-12 02:31:17 +01:00
|
|
|
|
2021-05-26 21:33:11 +02:00
|
|
|
image SnapshotImage
|
2020-12-02 05:14:28 +01:00
|
|
|
}
|
|
|
|
|
2021-07-07 05:42:39 +02:00
|
|
|
func (s *snapshotModule) ImageMutatorBegin(ctx android.BaseModuleContext) {
|
2021-01-12 02:31:17 +01:00
|
|
|
cfg := ctx.DeviceConfig()
|
2021-07-07 05:42:39 +02:00
|
|
|
if !s.image.IsUsingSnapshot(cfg) || s.image.TargetSnapshotVersion(cfg) != s.baseSnapshot.Version() {
|
2021-01-12 02:31:17 +01:00
|
|
|
s.Disable()
|
|
|
|
}
|
2020-12-02 05:14:28 +01:00
|
|
|
}
|
|
|
|
|
2021-07-07 05:42:39 +02:00
|
|
|
func (s *snapshotModule) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
|
2021-01-12 02:31:17 +01:00
|
|
|
return false
|
2020-12-02 05:14:28 +01:00
|
|
|
}
|
|
|
|
|
2021-07-07 05:42:39 +02:00
|
|
|
func (s *snapshotModule) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
|
2021-01-12 02:31:17 +01:00
|
|
|
return false
|
2020-12-02 05:14:28 +01:00
|
|
|
}
|
|
|
|
|
2021-07-07 05:42:39 +02:00
|
|
|
func (s *snapshotModule) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
|
2021-01-12 02:31:17 +01:00
|
|
|
return false
|
2020-12-02 05:14:28 +01:00
|
|
|
}
|
|
|
|
|
2021-07-07 05:42:39 +02:00
|
|
|
func (s *snapshotModule) DebugRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
|
2021-04-08 14:13:22 +02:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-07-07 05:42:39 +02:00
|
|
|
func (s *snapshotModule) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
|
2021-01-12 02:31:17 +01:00
|
|
|
return false
|
2020-12-11 22:36:29 +01:00
|
|
|
}
|
|
|
|
|
2021-07-07 05:42:39 +02:00
|
|
|
func (s *snapshotModule) ExtraImageVariations(ctx android.BaseModuleContext) []string {
|
2021-01-12 02:31:17 +01:00
|
|
|
return []string{s.image.imageVariantName(ctx.DeviceConfig())}
|
2020-12-11 22:36:29 +01:00
|
|
|
}
|
|
|
|
|
2021-07-07 05:42:39 +02:00
|
|
|
func (s *snapshotModule) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) {
|
2020-12-11 22:36:29 +01:00
|
|
|
}
|
|
|
|
|
2021-07-07 05:42:39 +02:00
|
|
|
func (s *snapshotModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2021-01-12 02:31:17 +01:00
|
|
|
// Nothing, the snapshot module is only used to forward dependency information in DepsMutator.
|
2020-12-11 22:36:29 +01:00
|
|
|
}
|
|
|
|
|
2021-02-26 06:00:03 +01:00
|
|
|
func getSnapshotNameSuffix(moduleSuffix, version, arch string) string {
|
|
|
|
versionSuffix := version
|
|
|
|
if arch != "" {
|
|
|
|
versionSuffix += "." + arch
|
|
|
|
}
|
|
|
|
return moduleSuffix + versionSuffix
|
|
|
|
}
|
2021-01-12 02:31:17 +01:00
|
|
|
|
2021-07-07 05:42:39 +02:00
|
|
|
func (s *snapshotModule) DepsMutator(ctx android.BottomUpMutatorContext) {
|
2021-02-26 06:00:03 +01:00
|
|
|
collectSnapshotMap := func(names []string, snapshotSuffix, moduleSuffix string) map[string]string {
|
2021-02-25 10:21:27 +01:00
|
|
|
snapshotMap := make(map[string]string)
|
2021-01-12 02:31:17 +01:00
|
|
|
for _, name := range names {
|
2021-02-25 10:21:27 +01:00
|
|
|
snapshotMap[name] = name +
|
2021-02-26 06:00:03 +01:00
|
|
|
getSnapshotNameSuffix(snapshotSuffix+moduleSuffix,
|
2021-05-26 21:33:11 +02:00
|
|
|
s.baseSnapshot.Version(),
|
2021-04-07 04:48:10 +02:00
|
|
|
ctx.DeviceConfig().Arches()[0].ArchType.String())
|
2021-01-12 02:31:17 +01:00
|
|
|
}
|
|
|
|
return snapshotMap
|
|
|
|
}
|
|
|
|
|
|
|
|
snapshotSuffix := s.image.moduleNameSuffix()
|
2021-02-26 06:00:03 +01:00
|
|
|
headers := collectSnapshotMap(s.properties.Header_libs, snapshotSuffix, snapshotHeaderSuffix)
|
|
|
|
binaries := collectSnapshotMap(s.properties.Binaries, snapshotSuffix, snapshotBinarySuffix)
|
|
|
|
objects := collectSnapshotMap(s.properties.Objects, snapshotSuffix, snapshotObjectSuffix)
|
2021-05-26 21:33:11 +02:00
|
|
|
staticLibs := collectSnapshotMap(s.properties.Static_libs, snapshotSuffix, SnapshotStaticSuffix)
|
|
|
|
sharedLibs := collectSnapshotMap(s.properties.Shared_libs, snapshotSuffix, SnapshotSharedSuffix)
|
2021-06-01 21:09:53 +02:00
|
|
|
rlibs := collectSnapshotMap(s.properties.Rlibs, snapshotSuffix, SnapshotRlibSuffix)
|
2021-02-26 06:00:03 +01:00
|
|
|
vndkLibs := collectSnapshotMap(s.properties.Vndk_libs, "", vndkSuffix)
|
2021-01-12 02:31:17 +01:00
|
|
|
for k, v := range vndkLibs {
|
|
|
|
sharedLibs[k] = v
|
|
|
|
}
|
2021-02-26 06:00:03 +01:00
|
|
|
|
2021-01-12 02:31:17 +01:00
|
|
|
ctx.SetProvider(SnapshotInfoProvider, SnapshotInfo{
|
|
|
|
HeaderLibs: headers,
|
|
|
|
Binaries: binaries,
|
|
|
|
Objects: objects,
|
|
|
|
StaticLibs: staticLibs,
|
|
|
|
SharedLibs: sharedLibs,
|
2021-06-01 21:09:53 +02:00
|
|
|
Rlibs: rlibs,
|
2021-01-12 02:31:17 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
type SnapshotInfo struct {
|
2021-06-01 21:09:53 +02:00
|
|
|
HeaderLibs, Binaries, Objects, StaticLibs, SharedLibs, Rlibs map[string]string
|
2021-01-12 02:31:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var SnapshotInfoProvider = blueprint.NewMutatorProvider(SnapshotInfo{}, "deps")
|
|
|
|
|
2021-07-07 05:42:39 +02:00
|
|
|
var _ android.ImageInterface = (*snapshotModule)(nil)
|
2021-01-12 02:31:17 +01:00
|
|
|
|
2021-07-13 04:36:24 +02:00
|
|
|
func snapshotMakeVarsProvider(ctx android.MakeVarsContext) {
|
|
|
|
snapshotSet := map[string]struct{}{}
|
|
|
|
ctx.VisitAllModules(func(m android.Module) {
|
2021-07-07 05:42:39 +02:00
|
|
|
if s, ok := m.(*snapshotModule); ok {
|
2021-07-13 04:36:24 +02:00
|
|
|
if _, ok := snapshotSet[s.Name()]; ok {
|
|
|
|
// arch variant generates duplicated modules
|
|
|
|
// skip this as we only need to know the path of the module.
|
|
|
|
return
|
|
|
|
}
|
|
|
|
snapshotSet[s.Name()] = struct{}{}
|
|
|
|
imageNameVersion := strings.Split(s.image.imageVariantName(ctx.DeviceConfig()), ".")
|
|
|
|
ctx.Strict(
|
|
|
|
strings.Join([]string{strings.ToUpper(imageNameVersion[0]), s.baseSnapshot.Version(), "SNAPSHOT_DIR"}, "_"),
|
|
|
|
ctx.ModuleDir(s))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-01-12 02:31:17 +01:00
|
|
|
func vendorSnapshotFactory() android.Module {
|
2021-05-20 19:01:32 +02:00
|
|
|
return snapshotFactory(VendorSnapshotImageSingleton)
|
2021-01-12 02:31:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func recoverySnapshotFactory() android.Module {
|
2021-11-05 22:04:54 +01:00
|
|
|
return snapshotFactory(RecoverySnapshotImageSingleton)
|
2021-01-12 02:31:17 +01:00
|
|
|
}
|
|
|
|
|
2021-05-26 21:33:11 +02:00
|
|
|
func snapshotFactory(image SnapshotImage) android.Module {
|
2021-07-07 05:42:39 +02:00
|
|
|
snapshotModule := &snapshotModule{}
|
|
|
|
snapshotModule.image = image
|
|
|
|
snapshotModule.AddProperties(
|
|
|
|
&snapshotModule.properties,
|
|
|
|
&snapshotModule.baseSnapshot.baseProperties)
|
|
|
|
android.InitAndroidArchModule(snapshotModule, android.DeviceSupported, android.MultilibBoth)
|
|
|
|
return snapshotModule
|
2021-01-12 02:31:17 +01:00
|
|
|
}
|
|
|
|
|
2021-05-26 21:33:11 +02:00
|
|
|
type BaseSnapshotDecoratorProperties struct {
|
2020-12-02 05:14:28 +01:00
|
|
|
// snapshot version.
|
|
|
|
Version string
|
|
|
|
|
|
|
|
// Target arch name of the snapshot (e.g. 'arm64' for variant 'aosp_arm64')
|
|
|
|
Target_arch string
|
2020-12-11 22:36:29 +01:00
|
|
|
|
2021-01-22 23:06:33 +01:00
|
|
|
// Suffix to be added to the module name when exporting to Android.mk, e.g. ".vendor".
|
2021-04-05 06:37:02 +02:00
|
|
|
Androidmk_suffix string `blueprint:"mutated"`
|
2021-01-22 23:06:33 +01:00
|
|
|
|
2020-12-11 22:36:29 +01:00
|
|
|
// Suffix to be added to the module name, e.g., vendor_shared,
|
|
|
|
// recovery_shared, etc.
|
2021-01-12 02:31:17 +01:00
|
|
|
ModuleSuffix string `blueprint:"mutated"`
|
2020-12-02 05:14:28 +01:00
|
|
|
}
|
|
|
|
|
2021-05-26 21:33:11 +02:00
|
|
|
// BaseSnapshotDecorator provides common basic functions for all snapshot modules, such as snapshot
|
2020-12-02 05:14:28 +01:00
|
|
|
// version, snapshot arch, etc. It also adds a special suffix to Soong module name, so it doesn't
|
|
|
|
// collide with source modules. e.g. the following example module,
|
|
|
|
//
|
|
|
|
// vendor_snapshot_static {
|
|
|
|
// name: "libbase",
|
|
|
|
// arch: "arm64",
|
|
|
|
// version: 30,
|
|
|
|
// ...
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// will be seen as "libbase.vendor_static.30.arm64" by Soong.
|
2021-05-26 21:33:11 +02:00
|
|
|
type BaseSnapshotDecorator struct {
|
|
|
|
baseProperties BaseSnapshotDecoratorProperties
|
2021-07-07 05:42:39 +02:00
|
|
|
Image SnapshotImage
|
2020-12-02 05:14:28 +01:00
|
|
|
}
|
|
|
|
|
2021-05-26 21:33:11 +02:00
|
|
|
func (p *BaseSnapshotDecorator) Name(name string) string {
|
2020-12-02 05:14:28 +01:00
|
|
|
return name + p.NameSuffix()
|
|
|
|
}
|
|
|
|
|
2021-05-26 21:33:11 +02:00
|
|
|
func (p *BaseSnapshotDecorator) NameSuffix() string {
|
|
|
|
return getSnapshotNameSuffix(p.moduleSuffix(), p.Version(), p.Arch())
|
2020-12-02 05:14:28 +01:00
|
|
|
}
|
|
|
|
|
2021-05-26 21:33:11 +02:00
|
|
|
func (p *BaseSnapshotDecorator) Version() string {
|
2020-12-02 05:14:28 +01:00
|
|
|
return p.baseProperties.Version
|
|
|
|
}
|
|
|
|
|
2021-05-26 21:33:11 +02:00
|
|
|
func (p *BaseSnapshotDecorator) Arch() string {
|
2020-12-02 05:14:28 +01:00
|
|
|
return p.baseProperties.Target_arch
|
|
|
|
}
|
|
|
|
|
2021-05-26 21:33:11 +02:00
|
|
|
func (p *BaseSnapshotDecorator) moduleSuffix() string {
|
2021-01-12 02:31:17 +01:00
|
|
|
return p.baseProperties.ModuleSuffix
|
2020-12-11 22:36:29 +01:00
|
|
|
}
|
|
|
|
|
2021-05-26 21:33:11 +02:00
|
|
|
func (p *BaseSnapshotDecorator) IsSnapshotPrebuilt() bool {
|
2020-12-02 05:14:28 +01:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-05-26 21:33:11 +02:00
|
|
|
func (p *BaseSnapshotDecorator) SnapshotAndroidMkSuffix() string {
|
2021-01-22 23:06:33 +01:00
|
|
|
return p.baseProperties.Androidmk_suffix
|
|
|
|
}
|
|
|
|
|
2021-05-26 21:33:11 +02:00
|
|
|
func (p *BaseSnapshotDecorator) SetSnapshotAndroidMkSuffix(ctx android.ModuleContext, variant string) {
|
2021-05-27 06:16:52 +02:00
|
|
|
// If there are any 2 or more variations among {core, product, vendor, recovery}
|
|
|
|
// we have to add the androidmk suffix to avoid duplicate modules with the same
|
|
|
|
// name.
|
|
|
|
variations := append(ctx.Target().Variations(), blueprint.Variation{
|
2021-05-20 20:54:21 +02:00
|
|
|
Mutator: "image",
|
|
|
|
Variation: android.CoreVariation})
|
|
|
|
|
2021-05-26 21:33:11 +02:00
|
|
|
if ctx.OtherModuleFarDependencyVariantExists(variations, ctx.Module().(LinkableInterface).BaseModuleName()) {
|
2021-07-07 05:42:39 +02:00
|
|
|
p.baseProperties.Androidmk_suffix = p.Image.moduleNameSuffix()
|
2021-05-20 20:54:21 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-05-27 06:16:52 +02:00
|
|
|
variations = append(ctx.Target().Variations(), blueprint.Variation{
|
2021-05-20 20:54:21 +02:00
|
|
|
Mutator: "image",
|
|
|
|
Variation: ProductVariationPrefix + ctx.DeviceConfig().PlatformVndkVersion()})
|
|
|
|
|
2021-05-26 21:33:11 +02:00
|
|
|
if ctx.OtherModuleFarDependencyVariantExists(variations, ctx.Module().(LinkableInterface).BaseModuleName()) {
|
2021-07-07 05:42:39 +02:00
|
|
|
p.baseProperties.Androidmk_suffix = p.Image.moduleNameSuffix()
|
2021-05-20 20:54:21 +02:00
|
|
|
return
|
2021-04-05 06:37:02 +02:00
|
|
|
}
|
2021-05-20 20:54:21 +02:00
|
|
|
|
2021-11-05 22:04:54 +01:00
|
|
|
images := []SnapshotImage{VendorSnapshotImageSingleton, RecoverySnapshotImageSingleton}
|
2021-05-27 06:16:52 +02:00
|
|
|
|
|
|
|
for _, image := range images {
|
2021-07-07 05:42:39 +02:00
|
|
|
if p.Image == image {
|
2021-05-27 06:16:52 +02:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
variations = append(ctx.Target().Variations(), blueprint.Variation{
|
|
|
|
Mutator: "image",
|
|
|
|
Variation: image.imageVariantName(ctx.DeviceConfig())})
|
|
|
|
|
|
|
|
if ctx.OtherModuleFarDependencyVariantExists(variations,
|
2021-05-26 21:33:11 +02:00
|
|
|
ctx.Module().(LinkableInterface).BaseModuleName()+
|
2021-05-27 06:16:52 +02:00
|
|
|
getSnapshotNameSuffix(
|
|
|
|
image.moduleNameSuffix()+variant,
|
2021-05-26 21:33:11 +02:00
|
|
|
p.Version(),
|
2021-05-27 06:16:52 +02:00
|
|
|
ctx.DeviceConfig().Arches()[0].ArchType.String())) {
|
2021-07-07 05:42:39 +02:00
|
|
|
p.baseProperties.Androidmk_suffix = p.Image.moduleNameSuffix()
|
2021-05-27 06:16:52 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-20 20:54:21 +02:00
|
|
|
p.baseProperties.Androidmk_suffix = ""
|
2021-04-05 06:37:02 +02:00
|
|
|
}
|
|
|
|
|
2020-12-02 05:14:28 +01:00
|
|
|
// Call this with a module suffix after creating a snapshot module, such as
|
|
|
|
// vendorSnapshotSharedSuffix, recoverySnapshotBinarySuffix, etc.
|
2021-05-26 21:33:11 +02:00
|
|
|
func (p *BaseSnapshotDecorator) Init(m LinkableInterface, image SnapshotImage, moduleSuffix string) {
|
2021-07-07 05:42:39 +02:00
|
|
|
p.Image = image
|
2021-04-05 06:37:02 +02:00
|
|
|
p.baseProperties.ModuleSuffix = image.moduleNameSuffix() + moduleSuffix
|
2020-12-02 05:14:28 +01:00
|
|
|
m.AddProperties(&p.baseProperties)
|
|
|
|
android.AddLoadHook(m, func(ctx android.LoadHookContext) {
|
|
|
|
vendorSnapshotLoadHook(ctx, p)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// vendorSnapshotLoadHook disables snapshots if it's not BOARD_VNDK_VERSION.
|
|
|
|
// As vendor snapshot is only for vendor, such modules won't be used at all.
|
2021-05-26 21:33:11 +02:00
|
|
|
func vendorSnapshotLoadHook(ctx android.LoadHookContext, p *BaseSnapshotDecorator) {
|
|
|
|
if p.Version() != ctx.DeviceConfig().VndkVersion() {
|
2020-12-02 05:14:28 +01:00
|
|
|
ctx.Module().Disable()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Module definitions for snapshots of libraries (shared, static, header).
|
|
|
|
//
|
|
|
|
// Modules (vendor|recovery)_snapshot_(shared|static|header) are defined here. Shared libraries and
|
|
|
|
// static libraries have their prebuilt library files (.so for shared, .a for static) as their src,
|
|
|
|
// which can be installed or linked against. Also they export flags needed when linked, such as
|
|
|
|
// include directories, c flags, sanitize dependency information, etc.
|
|
|
|
//
|
|
|
|
// These modules are auto-generated by development/vendor_snapshot/update.py.
|
2021-05-26 21:33:11 +02:00
|
|
|
type SnapshotLibraryProperties struct {
|
2020-12-02 05:14:28 +01:00
|
|
|
// Prebuilt file for each arch.
|
|
|
|
Src *string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// list of directories that will be added to the include path (using -I).
|
|
|
|
Export_include_dirs []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// list of directories that will be added to the system path (using -isystem).
|
|
|
|
Export_system_include_dirs []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// list of flags that will be used for any module that links against this module.
|
|
|
|
Export_flags []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// Whether this prebuilt needs to depend on sanitize ubsan runtime or not.
|
|
|
|
Sanitize_ubsan_dep *bool `android:"arch_variant"`
|
|
|
|
|
|
|
|
// Whether this prebuilt needs to depend on sanitize minimal runtime or not.
|
|
|
|
Sanitize_minimal_dep *bool `android:"arch_variant"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type snapshotSanitizer interface {
|
2020-12-14 17:27:52 +01:00
|
|
|
isSanitizerEnabled(t SanitizerType) bool
|
|
|
|
setSanitizerVariation(t SanitizerType, enabled bool)
|
2020-12-02 05:14:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type snapshotLibraryDecorator struct {
|
2021-05-26 21:33:11 +02:00
|
|
|
BaseSnapshotDecorator
|
2020-12-02 05:14:28 +01:00
|
|
|
*libraryDecorator
|
2021-05-26 21:33:11 +02:00
|
|
|
properties SnapshotLibraryProperties
|
2020-12-02 05:14:28 +01:00
|
|
|
sanitizerProperties struct {
|
|
|
|
CfiEnabled bool `blueprint:"mutated"`
|
|
|
|
|
|
|
|
// Library flags for cfi variant.
|
2021-05-26 21:33:11 +02:00
|
|
|
Cfi SnapshotLibraryProperties `android:"arch_variant"`
|
2020-12-02 05:14:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *snapshotLibraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
|
|
|
|
p.libraryDecorator.libName = strings.TrimSuffix(ctx.ModuleName(), p.NameSuffix())
|
|
|
|
return p.libraryDecorator.linkerFlags(ctx, flags)
|
|
|
|
}
|
|
|
|
|
2021-05-26 21:33:11 +02:00
|
|
|
func (p *snapshotLibraryDecorator) MatchesWithDevice(config android.DeviceConfig) bool {
|
2020-12-02 05:14:28 +01:00
|
|
|
arches := config.Arches()
|
2021-05-26 21:33:11 +02:00
|
|
|
if len(arches) == 0 || arches[0].ArchType.String() != p.Arch() {
|
2020-12-02 05:14:28 +01:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
if !p.header() && p.properties.Src == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// cc modules' link functions are to link compiled objects into final binaries.
|
|
|
|
// As snapshots are prebuilts, this just returns the prebuilt binary after doing things which are
|
|
|
|
// done by normal library decorator, e.g. exporting flags.
|
|
|
|
func (p *snapshotLibraryDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path {
|
2021-05-27 06:16:52 +02:00
|
|
|
var variant string
|
|
|
|
if p.shared() {
|
2021-05-26 21:33:11 +02:00
|
|
|
variant = SnapshotSharedSuffix
|
2021-05-27 06:16:52 +02:00
|
|
|
} else if p.static() {
|
2021-05-26 21:33:11 +02:00
|
|
|
variant = SnapshotStaticSuffix
|
2021-05-27 06:16:52 +02:00
|
|
|
} else {
|
|
|
|
variant = snapshotHeaderSuffix
|
|
|
|
}
|
|
|
|
|
2021-05-26 21:33:11 +02:00
|
|
|
p.SetSnapshotAndroidMkSuffix(ctx, variant)
|
2021-04-05 06:37:02 +02:00
|
|
|
|
2020-12-02 05:14:28 +01:00
|
|
|
if p.header() {
|
|
|
|
return p.libraryDecorator.link(ctx, flags, deps, objs)
|
|
|
|
}
|
|
|
|
|
|
|
|
if p.sanitizerProperties.CfiEnabled {
|
|
|
|
p.properties = p.sanitizerProperties.Cfi
|
|
|
|
}
|
|
|
|
|
2021-05-26 21:33:11 +02:00
|
|
|
if !p.MatchesWithDevice(ctx.DeviceConfig()) {
|
2020-12-02 05:14:28 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-04-12 14:09:59 +02:00
|
|
|
// Flags specified directly to this module.
|
2020-12-02 05:14:28 +01:00
|
|
|
p.libraryDecorator.reexportDirs(android.PathsForModuleSrc(ctx, p.properties.Export_include_dirs)...)
|
|
|
|
p.libraryDecorator.reexportSystemDirs(android.PathsForModuleSrc(ctx, p.properties.Export_system_include_dirs)...)
|
|
|
|
p.libraryDecorator.reexportFlags(p.properties.Export_flags...)
|
|
|
|
|
2021-04-12 14:09:59 +02:00
|
|
|
// Flags reexported from dependencies. (e.g. vndk_prebuilt_shared)
|
|
|
|
p.libraryDecorator.reexportDirs(deps.ReexportedDirs...)
|
|
|
|
p.libraryDecorator.reexportSystemDirs(deps.ReexportedSystemDirs...)
|
|
|
|
p.libraryDecorator.reexportFlags(deps.ReexportedFlags...)
|
|
|
|
p.libraryDecorator.reexportDeps(deps.ReexportedDeps...)
|
|
|
|
p.libraryDecorator.addExportedGeneratedHeaders(deps.ReexportedGeneratedHeaders...)
|
|
|
|
|
2020-12-02 05:14:28 +01:00
|
|
|
in := android.PathForModuleSrc(ctx, *p.properties.Src)
|
|
|
|
p.unstrippedOutputFile = in
|
|
|
|
|
|
|
|
if p.shared() {
|
|
|
|
libName := in.Base()
|
|
|
|
|
|
|
|
// Optimize out relinking against shared libraries whose interface hasn't changed by
|
|
|
|
// depending on a table of contents file instead of the library itself.
|
|
|
|
tocFile := android.PathForModuleOut(ctx, libName+".toc")
|
|
|
|
p.tocFile = android.OptionalPathForPath(tocFile)
|
2021-11-03 20:30:18 +01:00
|
|
|
TransformSharedObjectToToc(ctx, in, tocFile)
|
2020-12-02 05:14:28 +01:00
|
|
|
|
|
|
|
ctx.SetProvider(SharedLibraryInfoProvider, SharedLibraryInfo{
|
2021-06-08 21:37:09 +02:00
|
|
|
SharedLibrary: in,
|
|
|
|
Target: ctx.Target(),
|
2020-12-02 05:14:28 +01:00
|
|
|
|
|
|
|
TableOfContents: p.tocFile,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
if p.static() {
|
|
|
|
depSet := android.NewDepSetBuilder(android.TOPOLOGICAL).Direct(in).Build()
|
|
|
|
ctx.SetProvider(StaticLibraryInfoProvider, StaticLibraryInfo{
|
|
|
|
StaticLibrary: in,
|
|
|
|
|
|
|
|
TransitiveStaticLibrariesForOrdering: depSet,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
p.libraryDecorator.flagExporter.setProvider(ctx)
|
|
|
|
|
|
|
|
return in
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *snapshotLibraryDecorator) install(ctx ModuleContext, file android.Path) {
|
2022-01-21 10:12:48 +01:00
|
|
|
if p.MatchesWithDevice(ctx.DeviceConfig()) && p.shared() {
|
2020-12-02 05:14:28 +01:00
|
|
|
p.baseInstaller.install(ctx, file)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *snapshotLibraryDecorator) nativeCoverage() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-12-14 17:27:52 +01:00
|
|
|
func (p *snapshotLibraryDecorator) isSanitizerEnabled(t SanitizerType) bool {
|
2020-12-02 05:14:28 +01:00
|
|
|
switch t {
|
|
|
|
case cfi:
|
|
|
|
return p.sanitizerProperties.Cfi.Src != nil
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-14 17:27:52 +01:00
|
|
|
func (p *snapshotLibraryDecorator) setSanitizerVariation(t SanitizerType, enabled bool) {
|
2020-12-02 05:14:28 +01:00
|
|
|
if !enabled {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
switch t {
|
|
|
|
case cfi:
|
|
|
|
p.sanitizerProperties.CfiEnabled = true
|
|
|
|
default:
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-26 21:33:11 +02:00
|
|
|
func snapshotLibraryFactory(image SnapshotImage, moduleSuffix string) (*Module, *snapshotLibraryDecorator) {
|
2020-12-02 05:14:28 +01:00
|
|
|
module, library := NewLibrary(android.DeviceSupported)
|
|
|
|
|
|
|
|
module.stl = nil
|
|
|
|
module.sanitize = nil
|
|
|
|
library.disableStripping()
|
|
|
|
|
|
|
|
prebuilt := &snapshotLibraryDecorator{
|
|
|
|
libraryDecorator: library,
|
|
|
|
}
|
|
|
|
|
|
|
|
prebuilt.baseLinker.Properties.No_libcrt = BoolPtr(true)
|
|
|
|
prebuilt.baseLinker.Properties.Nocrt = BoolPtr(true)
|
|
|
|
|
|
|
|
// Prevent default system libs (libc, libm, and libdl) from being linked
|
|
|
|
if prebuilt.baseLinker.Properties.System_shared_libs == nil {
|
|
|
|
prebuilt.baseLinker.Properties.System_shared_libs = []string{}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.compiler = nil
|
|
|
|
module.linker = prebuilt
|
|
|
|
module.installer = prebuilt
|
|
|
|
|
2021-05-26 21:33:11 +02:00
|
|
|
prebuilt.Init(module, image, moduleSuffix)
|
2020-12-02 05:14:28 +01:00
|
|
|
module.AddProperties(
|
|
|
|
&prebuilt.properties,
|
|
|
|
&prebuilt.sanitizerProperties,
|
|
|
|
)
|
|
|
|
|
|
|
|
return module, prebuilt
|
|
|
|
}
|
|
|
|
|
|
|
|
// vendor_snapshot_shared is a special prebuilt shared library which is auto-generated by
|
|
|
|
// development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_shared
|
|
|
|
// overrides the vendor variant of the cc shared library with the same name, if BOARD_VNDK_VERSION
|
|
|
|
// is set.
|
|
|
|
func VendorSnapshotSharedFactory() android.Module {
|
2021-05-26 21:33:11 +02:00
|
|
|
module, prebuilt := snapshotLibraryFactory(VendorSnapshotImageSingleton, SnapshotSharedSuffix)
|
2020-12-02 05:14:28 +01:00
|
|
|
prebuilt.libraryDecorator.BuildOnlyShared()
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
|
|
|
// recovery_snapshot_shared is a special prebuilt shared library which is auto-generated by
|
|
|
|
// development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_shared
|
|
|
|
// overrides the recovery variant of the cc shared library with the same name, if BOARD_VNDK_VERSION
|
|
|
|
// is set.
|
|
|
|
func RecoverySnapshotSharedFactory() android.Module {
|
2021-11-05 22:04:54 +01:00
|
|
|
module, prebuilt := snapshotLibraryFactory(RecoverySnapshotImageSingleton, SnapshotSharedSuffix)
|
2020-12-02 05:14:28 +01:00
|
|
|
prebuilt.libraryDecorator.BuildOnlyShared()
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
|
|
|
// vendor_snapshot_static is a special prebuilt static library which is auto-generated by
|
|
|
|
// development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_static
|
|
|
|
// overrides the vendor variant of the cc static library with the same name, if BOARD_VNDK_VERSION
|
|
|
|
// is set.
|
|
|
|
func VendorSnapshotStaticFactory() android.Module {
|
2021-05-26 21:33:11 +02:00
|
|
|
module, prebuilt := snapshotLibraryFactory(VendorSnapshotImageSingleton, SnapshotStaticSuffix)
|
2020-12-02 05:14:28 +01:00
|
|
|
prebuilt.libraryDecorator.BuildOnlyStatic()
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
|
|
|
// recovery_snapshot_static is a special prebuilt static library which is auto-generated by
|
|
|
|
// development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_static
|
|
|
|
// overrides the recovery variant of the cc static library with the same name, if BOARD_VNDK_VERSION
|
|
|
|
// is set.
|
|
|
|
func RecoverySnapshotStaticFactory() android.Module {
|
2021-11-05 22:04:54 +01:00
|
|
|
module, prebuilt := snapshotLibraryFactory(RecoverySnapshotImageSingleton, SnapshotStaticSuffix)
|
2020-12-02 05:14:28 +01:00
|
|
|
prebuilt.libraryDecorator.BuildOnlyStatic()
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
|
|
|
// vendor_snapshot_header is a special header library which is auto-generated by
|
|
|
|
// development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_header
|
|
|
|
// overrides the vendor variant of the cc header library with the same name, if BOARD_VNDK_VERSION
|
|
|
|
// is set.
|
|
|
|
func VendorSnapshotHeaderFactory() android.Module {
|
2021-05-20 19:01:32 +02:00
|
|
|
module, prebuilt := snapshotLibraryFactory(VendorSnapshotImageSingleton, snapshotHeaderSuffix)
|
2020-12-02 05:14:28 +01:00
|
|
|
prebuilt.libraryDecorator.HeaderOnly()
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
|
|
|
// recovery_snapshot_header is a special header library which is auto-generated by
|
|
|
|
// development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_header
|
|
|
|
// overrides the recovery variant of the cc header library with the same name, if BOARD_VNDK_VERSION
|
|
|
|
// is set.
|
|
|
|
func RecoverySnapshotHeaderFactory() android.Module {
|
2021-11-05 22:04:54 +01:00
|
|
|
module, prebuilt := snapshotLibraryFactory(RecoverySnapshotImageSingleton, snapshotHeaderSuffix)
|
2020-12-02 05:14:28 +01:00
|
|
|
prebuilt.libraryDecorator.HeaderOnly()
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ snapshotSanitizer = (*snapshotLibraryDecorator)(nil)
|
|
|
|
|
|
|
|
//
|
|
|
|
// Module definitions for snapshots of executable binaries.
|
|
|
|
//
|
|
|
|
// Modules (vendor|recovery)_snapshot_binary are defined here. They have their prebuilt executable
|
|
|
|
// binaries (e.g. toybox, sh) as their src, which can be installed.
|
|
|
|
//
|
|
|
|
// These modules are auto-generated by development/vendor_snapshot/update.py.
|
|
|
|
type snapshotBinaryProperties struct {
|
|
|
|
// Prebuilt file for each arch.
|
|
|
|
Src *string `android:"arch_variant"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type snapshotBinaryDecorator struct {
|
2021-05-26 21:33:11 +02:00
|
|
|
BaseSnapshotDecorator
|
2020-12-02 05:14:28 +01:00
|
|
|
*binaryDecorator
|
2021-01-22 23:06:33 +01:00
|
|
|
properties snapshotBinaryProperties
|
2020-12-02 05:14:28 +01:00
|
|
|
}
|
|
|
|
|
2021-05-26 21:33:11 +02:00
|
|
|
func (p *snapshotBinaryDecorator) MatchesWithDevice(config android.DeviceConfig) bool {
|
|
|
|
if config.DeviceArch() != p.Arch() {
|
2020-12-02 05:14:28 +01:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
if p.properties.Src == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// cc modules' link functions are to link compiled objects into final binaries.
|
|
|
|
// As snapshots are prebuilts, this just returns the prebuilt binary
|
|
|
|
func (p *snapshotBinaryDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path {
|
2021-05-26 21:33:11 +02:00
|
|
|
p.SetSnapshotAndroidMkSuffix(ctx, snapshotBinarySuffix)
|
2021-04-05 06:37:02 +02:00
|
|
|
|
2021-05-26 21:33:11 +02:00
|
|
|
if !p.MatchesWithDevice(ctx.DeviceConfig()) {
|
2020-12-02 05:14:28 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
in := android.PathForModuleSrc(ctx, *p.properties.Src)
|
|
|
|
p.unstrippedOutputFile = in
|
|
|
|
binName := in.Base()
|
|
|
|
|
|
|
|
// use cpExecutable to make it executable
|
|
|
|
outputFile := android.PathForModuleOut(ctx, binName)
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: android.CpExecutable,
|
|
|
|
Description: "prebuilt",
|
|
|
|
Output: outputFile,
|
|
|
|
Input: in,
|
|
|
|
})
|
|
|
|
|
|
|
|
return outputFile
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *snapshotBinaryDecorator) nativeCoverage() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// vendor_snapshot_binary is a special prebuilt executable binary which is auto-generated by
|
|
|
|
// development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_binary
|
|
|
|
// overrides the vendor variant of the cc binary with the same name, if BOARD_VNDK_VERSION is set.
|
|
|
|
func VendorSnapshotBinaryFactory() android.Module {
|
2021-05-20 19:01:32 +02:00
|
|
|
return snapshotBinaryFactory(VendorSnapshotImageSingleton, snapshotBinarySuffix)
|
2020-12-02 05:14:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// recovery_snapshot_binary is a special prebuilt executable binary which is auto-generated by
|
|
|
|
// development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_binary
|
|
|
|
// overrides the recovery variant of the cc binary with the same name, if BOARD_VNDK_VERSION is set.
|
|
|
|
func RecoverySnapshotBinaryFactory() android.Module {
|
2021-11-05 22:04:54 +01:00
|
|
|
return snapshotBinaryFactory(RecoverySnapshotImageSingleton, snapshotBinarySuffix)
|
2020-12-02 05:14:28 +01:00
|
|
|
}
|
|
|
|
|
2021-05-26 21:33:11 +02:00
|
|
|
func snapshotBinaryFactory(image SnapshotImage, moduleSuffix string) android.Module {
|
2020-12-02 05:14:28 +01:00
|
|
|
module, binary := NewBinary(android.DeviceSupported)
|
|
|
|
binary.baseLinker.Properties.No_libcrt = BoolPtr(true)
|
|
|
|
binary.baseLinker.Properties.Nocrt = BoolPtr(true)
|
|
|
|
|
|
|
|
// Prevent default system libs (libc, libm, and libdl) from being linked
|
|
|
|
if binary.baseLinker.Properties.System_shared_libs == nil {
|
|
|
|
binary.baseLinker.Properties.System_shared_libs = []string{}
|
|
|
|
}
|
|
|
|
|
|
|
|
prebuilt := &snapshotBinaryDecorator{
|
|
|
|
binaryDecorator: binary,
|
|
|
|
}
|
|
|
|
|
|
|
|
module.compiler = nil
|
|
|
|
module.sanitize = nil
|
|
|
|
module.stl = nil
|
|
|
|
module.linker = prebuilt
|
|
|
|
|
2021-05-26 21:33:11 +02:00
|
|
|
prebuilt.Init(module, image, moduleSuffix)
|
2020-12-02 05:14:28 +01:00
|
|
|
module.AddProperties(&prebuilt.properties)
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Module definitions for snapshots of object files (*.o).
|
|
|
|
//
|
|
|
|
// Modules (vendor|recovery)_snapshot_object are defined here. They have their prebuilt object
|
|
|
|
// files (*.o) as their src.
|
|
|
|
//
|
|
|
|
// These modules are auto-generated by development/vendor_snapshot/update.py.
|
|
|
|
type vendorSnapshotObjectProperties struct {
|
|
|
|
// Prebuilt file for each arch.
|
|
|
|
Src *string `android:"arch_variant"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type snapshotObjectLinker struct {
|
2021-05-26 21:33:11 +02:00
|
|
|
BaseSnapshotDecorator
|
2020-12-02 05:14:28 +01:00
|
|
|
objectLinker
|
2021-01-22 23:06:33 +01:00
|
|
|
properties vendorSnapshotObjectProperties
|
2020-12-02 05:14:28 +01:00
|
|
|
}
|
|
|
|
|
2021-05-26 21:33:11 +02:00
|
|
|
func (p *snapshotObjectLinker) MatchesWithDevice(config android.DeviceConfig) bool {
|
|
|
|
if config.DeviceArch() != p.Arch() {
|
2020-12-02 05:14:28 +01:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
if p.properties.Src == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// cc modules' link functions are to link compiled objects into final binaries.
|
|
|
|
// As snapshots are prebuilts, this just returns the prebuilt binary
|
|
|
|
func (p *snapshotObjectLinker) link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path {
|
2021-05-26 21:33:11 +02:00
|
|
|
p.SetSnapshotAndroidMkSuffix(ctx, snapshotObjectSuffix)
|
2021-04-05 06:37:02 +02:00
|
|
|
|
2021-05-26 21:33:11 +02:00
|
|
|
if !p.MatchesWithDevice(ctx.DeviceConfig()) {
|
2020-12-02 05:14:28 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return android.PathForModuleSrc(ctx, *p.properties.Src)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *snapshotObjectLinker) nativeCoverage() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// vendor_snapshot_object is a special prebuilt compiled object file which is auto-generated by
|
|
|
|
// development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_object
|
|
|
|
// overrides the vendor variant of the cc object with the same name, if BOARD_VNDK_VERSION is set.
|
|
|
|
func VendorSnapshotObjectFactory() android.Module {
|
2021-06-25 23:21:04 +02:00
|
|
|
module := newObject(android.DeviceSupported)
|
2020-12-02 05:14:28 +01:00
|
|
|
|
|
|
|
prebuilt := &snapshotObjectLinker{
|
|
|
|
objectLinker: objectLinker{
|
|
|
|
baseLinker: NewBaseLinker(nil),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
module.linker = prebuilt
|
|
|
|
|
2021-05-26 21:33:11 +02:00
|
|
|
prebuilt.Init(module, VendorSnapshotImageSingleton, snapshotObjectSuffix)
|
2020-12-02 05:14:28 +01:00
|
|
|
module.AddProperties(&prebuilt.properties)
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
|
|
|
// recovery_snapshot_object is a special prebuilt compiled object file which is auto-generated by
|
|
|
|
// development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_object
|
|
|
|
// overrides the recovery variant of the cc object with the same name, if BOARD_VNDK_VERSION is set.
|
|
|
|
func RecoverySnapshotObjectFactory() android.Module {
|
2021-06-25 23:21:04 +02:00
|
|
|
module := newObject(android.DeviceSupported)
|
2020-12-02 05:14:28 +01:00
|
|
|
|
|
|
|
prebuilt := &snapshotObjectLinker{
|
|
|
|
objectLinker: objectLinker{
|
|
|
|
baseLinker: NewBaseLinker(nil),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
module.linker = prebuilt
|
|
|
|
|
2021-11-05 22:04:54 +01:00
|
|
|
prebuilt.Init(module, RecoverySnapshotImageSingleton, snapshotObjectSuffix)
|
2020-12-02 05:14:28 +01:00
|
|
|
module.AddProperties(&prebuilt.properties)
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2021-05-26 21:33:11 +02:00
|
|
|
type SnapshotInterface interface {
|
|
|
|
MatchesWithDevice(config android.DeviceConfig) bool
|
|
|
|
IsSnapshotPrebuilt() bool
|
|
|
|
Version() string
|
|
|
|
SnapshotAndroidMkSuffix() string
|
2020-12-02 05:14:28 +01:00
|
|
|
}
|
|
|
|
|
2021-05-26 21:33:11 +02:00
|
|
|
var _ SnapshotInterface = (*vndkPrebuiltLibraryDecorator)(nil)
|
|
|
|
var _ SnapshotInterface = (*snapshotLibraryDecorator)(nil)
|
|
|
|
var _ SnapshotInterface = (*snapshotBinaryDecorator)(nil)
|
|
|
|
var _ SnapshotInterface = (*snapshotObjectLinker)(nil)
|