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 | |
| 16 | import ( |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 17 | "android/soong/android" |
| 18 | ) |
| 19 | |
| 20 | var ( |
| 21 | headerExts = []string{".h", ".hh", ".hpp", ".hxx", ".h++", ".inl", ".inc", ".ipp", ".h.generic"} |
| 22 | ) |
| 23 | |
| 24 | type snapshotLibraryInterface interface { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 25 | libraryInterface |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 26 | collectHeadersForSnapshot(ctx android.ModuleContext) |
| 27 | snapshotHeaders() android.Paths |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | var _ snapshotLibraryInterface = (*prebuiltLibraryLinker)(nil) |
| 31 | var _ snapshotLibraryInterface = (*libraryDecorator)(nil) |
| 32 | |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 33 | type snapshotMap struct { |
| 34 | snapshots map[string]string |
| 35 | } |
| 36 | |
| 37 | func newSnapshotMap() *snapshotMap { |
| 38 | return &snapshotMap{ |
| 39 | snapshots: make(map[string]string), |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | func snapshotMapKey(name string, arch android.ArchType) string { |
| 44 | return name + ":" + arch.String() |
| 45 | } |
| 46 | |
| 47 | // Adds a snapshot name for given module name and architecture. |
| 48 | // e.g. add("libbase", X86, "libbase.vndk.29.x86") |
| 49 | func (s *snapshotMap) add(name string, arch android.ArchType, snapshot string) { |
| 50 | s.snapshots[snapshotMapKey(name, arch)] = snapshot |
| 51 | } |
| 52 | |
| 53 | // Returns snapshot name for given module name and architecture, if found. |
| 54 | // e.g. get("libcutils", X86) => "libcutils.vndk.29.x86", true |
| 55 | func (s *snapshotMap) get(name string, arch android.ArchType) (snapshot string, found bool) { |
| 56 | snapshot, found = s.snapshots[snapshotMapKey(name, arch)] |
| 57 | return snapshot, found |
| 58 | } |
| 59 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 60 | func isSnapshotAware(ctx android.ModuleContext, m *Module, apexInfo android.ApexInfo) bool { |
| 61 | if _, _, ok := isVndkSnapshotLibrary(ctx.DeviceConfig(), m, apexInfo); ok { |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 62 | return ctx.Config().VndkSnapshotBuildArtifacts() |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 63 | } else if isVendorSnapshotModule(m, isVendorProprietaryPath(ctx.ModuleDir()), apexInfo) { |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 64 | return true |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 65 | } |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 66 | return false |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | func copyFile(ctx android.SingletonContext, path android.Path, out string) android.OutputPath { |
| 70 | outPath := android.PathForOutput(ctx, out) |
| 71 | ctx.Build(pctx, android.BuildParams{ |
| 72 | Rule: android.Cp, |
| 73 | Input: path, |
| 74 | Output: outPath, |
| 75 | Description: "Cp " + out, |
| 76 | Args: map[string]string{ |
| 77 | "cpFlags": "-f -L", |
| 78 | }, |
| 79 | }) |
| 80 | return outPath |
| 81 | } |
| 82 | |
Bob Badour | a75b057 | 2020-02-18 20:21:55 -0800 | [diff] [blame] | 83 | func combineNotices(ctx android.SingletonContext, paths android.Paths, out string) android.OutputPath { |
| 84 | outPath := android.PathForOutput(ctx, out) |
| 85 | ctx.Build(pctx, android.BuildParams{ |
| 86 | Rule: android.Cat, |
| 87 | Inputs: paths, |
| 88 | Output: outPath, |
| 89 | Description: "combine notices for " + out, |
| 90 | }) |
| 91 | return outPath |
| 92 | } |
| 93 | |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 94 | func writeStringToFile(ctx android.SingletonContext, content, out string) android.OutputPath { |
| 95 | outPath := android.PathForOutput(ctx, out) |
| 96 | ctx.Build(pctx, android.BuildParams{ |
| 97 | Rule: android.WriteFile, |
| 98 | Output: outPath, |
| 99 | Description: "WriteFile " + out, |
| 100 | Args: map[string]string{ |
| 101 | "content": content, |
| 102 | }, |
| 103 | }) |
| 104 | return outPath |
| 105 | } |