blob: de50ef50fd0b5b289d8cdfad72e12a4a729924a9 [file] [log] [blame]
Inseob Kim8471cda2019-11-15 09:59:12 +09001// Copyright 2020 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14package cc
15
Inseob Kimde5744a2020-12-02 13:14:28 +090016// This file contains utility types and functions for VNDK / vendor snapshot.
17
Inseob Kim8471cda2019-11-15 09:59:12 +090018import (
Inseob Kim8471cda2019-11-15 09:59:12 +090019 "android/soong/android"
20)
21
22var (
Ivan Lozanod67a6b02021-05-20 13:01:32 -040023 HeaderExts = []string{".h", ".hh", ".hpp", ".hxx", ".h++", ".inl", ".inc", ".ipp", ".h.generic"}
Inseob Kim8471cda2019-11-15 09:59:12 +090024)
25
Ivan Lozanod7586b62021-04-01 09:49:36 -040026func (m *Module) IsSnapshotLibrary() bool {
27 if _, ok := m.linker.(snapshotLibraryInterface); ok {
28 return true
29 }
30 return false
31}
32
33func (m *Module) SnapshotHeaders() android.Paths {
34 if m.IsSnapshotLibrary() {
35 return m.linker.(snapshotLibraryInterface).snapshotHeaders()
36 }
37 return android.Paths{}
38}
39
40func (m *Module) Dylib() bool {
41 return false
42}
43
44func (m *Module) Rlib() bool {
45 return false
46}
47
48func (m *Module) SnapshotRuntimeLibs() []string {
49 return m.Properties.SnapshotRuntimeLibs
50}
51
52func (m *Module) SnapshotSharedLibs() []string {
53 return m.Properties.SnapshotSharedLibs
54}
55
Justin Yun5e035862021-06-29 20:50:37 +090056func (m *Module) SnapshotStaticLibs() []string {
57 return m.Properties.SnapshotStaticLibs
58}
59
Inseob Kimde5744a2020-12-02 13:14:28 +090060// snapshotLibraryInterface is an interface for libraries captured to VNDK / vendor snapshots.
Inseob Kim8471cda2019-11-15 09:59:12 +090061type snapshotLibraryInterface interface {
Inseob Kim8471cda2019-11-15 09:59:12 +090062 libraryInterface
Inseob Kimde5744a2020-12-02 13:14:28 +090063
64 // collectHeadersForSnapshot is called in GenerateAndroidBuildActions for snapshot aware
65 // modules (See isSnapshotAware below).
66 // This function should gather all headers needed for snapshot.
Inseob Kimeda2e9c2020-03-03 22:06:32 +090067 collectHeadersForSnapshot(ctx android.ModuleContext)
Inseob Kimde5744a2020-12-02 13:14:28 +090068
69 // snapshotHeaders should return collected headers by collectHeadersForSnapshot.
70 // Calling snapshotHeaders before collectHeadersForSnapshot is an error.
Inseob Kimeda2e9c2020-03-03 22:06:32 +090071 snapshotHeaders() android.Paths
Inseob Kim8471cda2019-11-15 09:59:12 +090072}
73
74var _ snapshotLibraryInterface = (*prebuiltLibraryLinker)(nil)
75var _ snapshotLibraryInterface = (*libraryDecorator)(nil)
76
Inseob Kimde5744a2020-12-02 13:14:28 +090077// snapshotMap is a helper wrapper to a map from base module name to snapshot module name.
Inseob Kimeec88e12020-01-22 11:11:29 +090078type snapshotMap struct {
79 snapshots map[string]string
80}
81
82func newSnapshotMap() *snapshotMap {
83 return &snapshotMap{
84 snapshots: make(map[string]string),
85 }
86}
87
88func snapshotMapKey(name string, arch android.ArchType) string {
89 return name + ":" + arch.String()
90}
91
92// Adds a snapshot name for given module name and architecture.
93// e.g. add("libbase", X86, "libbase.vndk.29.x86")
94func (s *snapshotMap) add(name string, arch android.ArchType, snapshot string) {
95 s.snapshots[snapshotMapKey(name, arch)] = snapshot
96}
97
98// Returns snapshot name for given module name and architecture, if found.
99// e.g. get("libcutils", X86) => "libcutils.vndk.29.x86", true
100func (s *snapshotMap) get(name string, arch android.ArchType) (snapshot string, found bool) {
101 snapshot, found = s.snapshots[snapshotMapKey(name, arch)]
102 return snapshot, found
103}
104
Ivan Lozanod7586b62021-04-01 09:49:36 -0400105// ShouldCollectHeadersForSnapshot determines if the module is a possible candidate for snapshot.
Inseob Kimde5744a2020-12-02 13:14:28 +0900106// If it's true, collectHeadersForSnapshot will be called in GenerateAndroidBuildActions.
Ivan Lozanod7586b62021-04-01 09:49:36 -0400107func ShouldCollectHeadersForSnapshot(ctx android.ModuleContext, m LinkableInterface, apexInfo android.ApexInfo) bool {
Jose Galmes6f843bc2020-12-11 13:36:29 -0800108 if ctx.DeviceConfig().VndkVersion() != "current" &&
109 ctx.DeviceConfig().RecoverySnapshotVersion() != "current" {
110 return false
111 }
Ivan Lozanod7586b62021-04-01 09:49:36 -0400112 if _, ok := isVndkSnapshotAware(ctx.DeviceConfig(), m, apexInfo); ok {
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900113 return ctx.Config().VndkSnapshotBuildArtifacts()
Inseob Kim0c1ca4c2021-01-06 22:01:01 +0900114 }
115
Jose Galmesd7d99be2021-11-05 14:04:54 -0700116 for _, image := range []SnapshotImage{VendorSnapshotImageSingleton, RecoverySnapshotImageSingleton} {
Kiyoung Kim48f37782021-07-07 12:42:39 +0900117 if isSnapshotAware(ctx.DeviceConfig(), m, image.IsProprietaryPath(ctx.ModuleDir(), ctx.DeviceConfig()), apexInfo, image) {
Inseob Kim0c1ca4c2021-01-06 22:01:01 +0900118 return true
119 }
Inseob Kim8471cda2019-11-15 09:59:12 +0900120 }
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900121 return false
Inseob Kim8471cda2019-11-15 09:59:12 +0900122}