Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 1 | // 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 | // |
Colin Cross | d079e0b | 2022-08-16 10:27:33 -0700 | [diff] [blame] | 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 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. |
| 14 | package cc |
| 15 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 16 | // This file contains utility types and functions for VNDK / vendor snapshot. |
| 17 | |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 18 | import ( |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 19 | "android/soong/android" |
| 20 | ) |
| 21 | |
| 22 | var ( |
Ivan Lozano | d67a6b0 | 2021-05-20 13:01:32 -0400 | [diff] [blame] | 23 | HeaderExts = []string{".h", ".hh", ".hpp", ".hxx", ".h++", ".inl", ".inc", ".ipp", ".h.generic"} |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 24 | ) |
| 25 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 26 | func (m *Module) IsSnapshotLibrary() bool { |
| 27 | if _, ok := m.linker.(snapshotLibraryInterface); ok { |
| 28 | return true |
| 29 | } |
| 30 | return false |
| 31 | } |
| 32 | |
| 33 | func (m *Module) SnapshotHeaders() android.Paths { |
| 34 | if m.IsSnapshotLibrary() { |
| 35 | return m.linker.(snapshotLibraryInterface).snapshotHeaders() |
| 36 | } |
| 37 | return android.Paths{} |
| 38 | } |
| 39 | |
| 40 | func (m *Module) Dylib() bool { |
| 41 | return false |
| 42 | } |
| 43 | |
| 44 | func (m *Module) Rlib() bool { |
| 45 | return false |
| 46 | } |
| 47 | |
| 48 | func (m *Module) SnapshotRuntimeLibs() []string { |
| 49 | return m.Properties.SnapshotRuntimeLibs |
| 50 | } |
| 51 | |
| 52 | func (m *Module) SnapshotSharedLibs() []string { |
| 53 | return m.Properties.SnapshotSharedLibs |
| 54 | } |
| 55 | |
Justin Yun | 5e03586 | 2021-06-29 20:50:37 +0900 | [diff] [blame] | 56 | func (m *Module) SnapshotStaticLibs() []string { |
| 57 | return m.Properties.SnapshotStaticLibs |
| 58 | } |
| 59 | |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 60 | func (m *Module) SnapshotRlibs() []string { |
| 61 | return []string{} |
| 62 | } |
| 63 | |
| 64 | func (m *Module) SnapshotDylibs() []string { |
| 65 | return []string{} |
| 66 | } |
| 67 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 68 | // snapshotLibraryInterface is an interface for libraries captured to VNDK / vendor snapshots. |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 69 | type snapshotLibraryInterface interface { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 70 | libraryInterface |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 71 | |
| 72 | // collectHeadersForSnapshot is called in GenerateAndroidBuildActions for snapshot aware |
| 73 | // modules (See isSnapshotAware below). |
| 74 | // This function should gather all headers needed for snapshot. |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 75 | collectHeadersForSnapshot(ctx android.ModuleContext) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 76 | |
| 77 | // snapshotHeaders should return collected headers by collectHeadersForSnapshot. |
| 78 | // Calling snapshotHeaders before collectHeadersForSnapshot is an error. |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 79 | snapshotHeaders() android.Paths |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | var _ snapshotLibraryInterface = (*prebuiltLibraryLinker)(nil) |
| 83 | var _ snapshotLibraryInterface = (*libraryDecorator)(nil) |
| 84 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 85 | // snapshotMap is a helper wrapper to a map from base module name to snapshot module name. |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 86 | type snapshotMap struct { |
| 87 | snapshots map[string]string |
| 88 | } |
| 89 | |
| 90 | func newSnapshotMap() *snapshotMap { |
| 91 | return &snapshotMap{ |
| 92 | snapshots: make(map[string]string), |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | func snapshotMapKey(name string, arch android.ArchType) string { |
| 97 | return name + ":" + arch.String() |
| 98 | } |
| 99 | |
| 100 | // Adds a snapshot name for given module name and architecture. |
| 101 | // e.g. add("libbase", X86, "libbase.vndk.29.x86") |
| 102 | func (s *snapshotMap) add(name string, arch android.ArchType, snapshot string) { |
| 103 | s.snapshots[snapshotMapKey(name, arch)] = snapshot |
| 104 | } |
| 105 | |
| 106 | // Returns snapshot name for given module name and architecture, if found. |
| 107 | // e.g. get("libcutils", X86) => "libcutils.vndk.29.x86", true |
| 108 | func (s *snapshotMap) get(name string, arch android.ArchType) (snapshot string, found bool) { |
| 109 | snapshot, found = s.snapshots[snapshotMapKey(name, arch)] |
| 110 | return snapshot, found |
| 111 | } |
| 112 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 113 | // ShouldCollectHeadersForSnapshot determines if the module is a possible candidate for snapshot. |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 114 | // If it's true, collectHeadersForSnapshot will be called in GenerateAndroidBuildActions. |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 115 | func ShouldCollectHeadersForSnapshot(ctx android.ModuleContext, m LinkableInterface, apexInfo android.ApexInfo) bool { |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 116 | if ctx.DeviceConfig().VndkVersion() != "current" && |
| 117 | ctx.DeviceConfig().RecoverySnapshotVersion() != "current" { |
| 118 | return false |
| 119 | } |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 120 | if _, ok := isVndkSnapshotAware(ctx.DeviceConfig(), m, apexInfo); ok { |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 121 | return ctx.Config().VndkSnapshotBuildArtifacts() |
Inseob Kim | 0c1ca4c | 2021-01-06 22:01:01 +0900 | [diff] [blame] | 122 | } |
| 123 | |
Jose Galmes | d7d99be | 2021-11-05 14:04:54 -0700 | [diff] [blame] | 124 | for _, image := range []SnapshotImage{VendorSnapshotImageSingleton, RecoverySnapshotImageSingleton} { |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 125 | if isSnapshotAware(ctx.DeviceConfig(), m, image.IsProprietaryPath(ctx.ModuleDir(), ctx.DeviceConfig()), apexInfo, image) { |
Inseob Kim | 0c1ca4c | 2021-01-06 22:01:01 +0900 | [diff] [blame] | 126 | return true |
| 127 | } |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 128 | } |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 129 | return false |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 130 | } |