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