2019-11-15 01:59:12 +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
|
|
|
|
|
2020-12-02 05:14:28 +01:00
|
|
|
// This file contains utility types and functions for VNDK / vendor snapshot.
|
|
|
|
|
2019-11-15 01:59:12 +01:00
|
|
|
import (
|
|
|
|
"android/soong/android"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2021-05-20 19:01:32 +02:00
|
|
|
HeaderExts = []string{".h", ".hh", ".hpp", ".hxx", ".h++", ".inl", ".inc", ".ipp", ".h.generic"}
|
2019-11-15 01:59:12 +01:00
|
|
|
)
|
|
|
|
|
2021-04-01 15:49:36 +02:00
|
|
|
func (m *Module) IsSnapshotLibrary() bool {
|
|
|
|
if _, ok := m.linker.(snapshotLibraryInterface); ok {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Module) SnapshotHeaders() android.Paths {
|
|
|
|
if m.IsSnapshotLibrary() {
|
|
|
|
return m.linker.(snapshotLibraryInterface).snapshotHeaders()
|
|
|
|
}
|
|
|
|
return android.Paths{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Module) Dylib() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Module) Rlib() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Module) SnapshotRuntimeLibs() []string {
|
|
|
|
return m.Properties.SnapshotRuntimeLibs
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Module) SnapshotSharedLibs() []string {
|
|
|
|
return m.Properties.SnapshotSharedLibs
|
|
|
|
}
|
|
|
|
|
2020-12-02 05:14:28 +01:00
|
|
|
// snapshotLibraryInterface is an interface for libraries captured to VNDK / vendor snapshots.
|
2019-11-15 01:59:12 +01:00
|
|
|
type snapshotLibraryInterface interface {
|
|
|
|
libraryInterface
|
2020-12-02 05:14:28 +01:00
|
|
|
|
|
|
|
// collectHeadersForSnapshot is called in GenerateAndroidBuildActions for snapshot aware
|
|
|
|
// modules (See isSnapshotAware below).
|
|
|
|
// This function should gather all headers needed for snapshot.
|
2020-03-03 14:06:32 +01:00
|
|
|
collectHeadersForSnapshot(ctx android.ModuleContext)
|
2020-12-02 05:14:28 +01:00
|
|
|
|
|
|
|
// snapshotHeaders should return collected headers by collectHeadersForSnapshot.
|
|
|
|
// Calling snapshotHeaders before collectHeadersForSnapshot is an error.
|
2020-03-03 14:06:32 +01:00
|
|
|
snapshotHeaders() android.Paths
|
2019-11-15 01:59:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ snapshotLibraryInterface = (*prebuiltLibraryLinker)(nil)
|
|
|
|
var _ snapshotLibraryInterface = (*libraryDecorator)(nil)
|
|
|
|
|
2020-12-02 05:14:28 +01:00
|
|
|
// snapshotMap is a helper wrapper to a map from base module name to snapshot module name.
|
2020-01-22 03:11:29 +01:00
|
|
|
type snapshotMap struct {
|
|
|
|
snapshots map[string]string
|
|
|
|
}
|
|
|
|
|
|
|
|
func newSnapshotMap() *snapshotMap {
|
|
|
|
return &snapshotMap{
|
|
|
|
snapshots: make(map[string]string),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func snapshotMapKey(name string, arch android.ArchType) string {
|
|
|
|
return name + ":" + arch.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adds a snapshot name for given module name and architecture.
|
|
|
|
// e.g. add("libbase", X86, "libbase.vndk.29.x86")
|
|
|
|
func (s *snapshotMap) add(name string, arch android.ArchType, snapshot string) {
|
|
|
|
s.snapshots[snapshotMapKey(name, arch)] = snapshot
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns snapshot name for given module name and architecture, if found.
|
|
|
|
// e.g. get("libcutils", X86) => "libcutils.vndk.29.x86", true
|
|
|
|
func (s *snapshotMap) get(name string, arch android.ArchType) (snapshot string, found bool) {
|
|
|
|
snapshot, found = s.snapshots[snapshotMapKey(name, arch)]
|
|
|
|
return snapshot, found
|
|
|
|
}
|
|
|
|
|
2021-04-01 15:49:36 +02:00
|
|
|
// ShouldCollectHeadersForSnapshot determines if the module is a possible candidate for snapshot.
|
2020-12-02 05:14:28 +01:00
|
|
|
// If it's true, collectHeadersForSnapshot will be called in GenerateAndroidBuildActions.
|
2021-04-01 15:49:36 +02:00
|
|
|
func ShouldCollectHeadersForSnapshot(ctx android.ModuleContext, m LinkableInterface, apexInfo android.ApexInfo) bool {
|
2020-12-11 22:36:29 +01:00
|
|
|
if ctx.DeviceConfig().VndkVersion() != "current" &&
|
|
|
|
ctx.DeviceConfig().RecoverySnapshotVersion() != "current" {
|
|
|
|
return false
|
|
|
|
}
|
2021-04-01 15:49:36 +02:00
|
|
|
if _, ok := isVndkSnapshotAware(ctx.DeviceConfig(), m, apexInfo); ok {
|
2020-03-03 14:06:32 +01:00
|
|
|
return ctx.Config().VndkSnapshotBuildArtifacts()
|
2021-01-06 14:01:01 +01:00
|
|
|
}
|
|
|
|
|
2021-05-26 21:33:11 +02:00
|
|
|
for _, image := range []SnapshotImage{VendorSnapshotImageSingleton, recoverySnapshotImageSingleton} {
|
2021-02-24 19:49:43 +01:00
|
|
|
if isSnapshotAware(ctx.DeviceConfig(), m, image.isProprietaryPath(ctx.ModuleDir(), ctx.DeviceConfig()), apexInfo, image) {
|
2021-01-06 14:01:01 +01:00
|
|
|
return true
|
|
|
|
}
|
2019-11-15 01:59:12 +01:00
|
|
|
}
|
2020-03-03 14:06:32 +01:00
|
|
|
return false
|
2019-11-15 01:59:12 +01:00
|
|
|
}
|