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 | // |
| 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. |
| 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 ( |
| 23 | headerExts = []string{".h", ".hh", ".hpp", ".hxx", ".h++", ".inl", ".inc", ".ipp", ".h.generic"} |
| 24 | ) |
| 25 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 26 | // snapshotLibraryInterface is an interface for libraries captured to VNDK / vendor snapshots. |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 27 | type snapshotLibraryInterface interface { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 28 | libraryInterface |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 29 | |
| 30 | // collectHeadersForSnapshot is called in GenerateAndroidBuildActions for snapshot aware |
| 31 | // modules (See isSnapshotAware below). |
| 32 | // This function should gather all headers needed for snapshot. |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 33 | collectHeadersForSnapshot(ctx android.ModuleContext) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 34 | |
| 35 | // snapshotHeaders should return collected headers by collectHeadersForSnapshot. |
| 36 | // Calling snapshotHeaders before collectHeadersForSnapshot is an error. |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 37 | snapshotHeaders() android.Paths |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | var _ snapshotLibraryInterface = (*prebuiltLibraryLinker)(nil) |
| 41 | var _ snapshotLibraryInterface = (*libraryDecorator)(nil) |
| 42 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 43 | // 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] | 44 | type snapshotMap struct { |
| 45 | snapshots map[string]string |
| 46 | } |
| 47 | |
| 48 | func newSnapshotMap() *snapshotMap { |
| 49 | return &snapshotMap{ |
| 50 | snapshots: make(map[string]string), |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | func snapshotMapKey(name string, arch android.ArchType) string { |
| 55 | return name + ":" + arch.String() |
| 56 | } |
| 57 | |
| 58 | // Adds a snapshot name for given module name and architecture. |
| 59 | // e.g. add("libbase", X86, "libbase.vndk.29.x86") |
| 60 | func (s *snapshotMap) add(name string, arch android.ArchType, snapshot string) { |
| 61 | s.snapshots[snapshotMapKey(name, arch)] = snapshot |
| 62 | } |
| 63 | |
| 64 | // Returns snapshot name for given module name and architecture, if found. |
| 65 | // e.g. get("libcutils", X86) => "libcutils.vndk.29.x86", true |
| 66 | func (s *snapshotMap) get(name string, arch android.ArchType) (snapshot string, found bool) { |
| 67 | snapshot, found = s.snapshots[snapshotMapKey(name, arch)] |
| 68 | return snapshot, found |
| 69 | } |
| 70 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 71 | // shouldCollectHeadersForSnapshot determines if the module is a possible candidate for snapshot. |
| 72 | // If it's true, collectHeadersForSnapshot will be called in GenerateAndroidBuildActions. |
| 73 | func shouldCollectHeadersForSnapshot(ctx android.ModuleContext, m *Module, apexInfo android.ApexInfo) bool { |
| 74 | if _, _, ok := isVndkSnapshotAware(ctx.DeviceConfig(), m, apexInfo); ok { |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 75 | return ctx.Config().VndkSnapshotBuildArtifacts() |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 76 | } else if isVendorSnapshotAware(m, isVendorProprietaryPath(ctx.ModuleDir()), apexInfo) || |
| 77 | isRecoverySnapshotAware(m, isRecoveryProprietaryPath(ctx.ModuleDir()), apexInfo) { |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 78 | return true |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 79 | } |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 80 | return false |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 81 | } |