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 singletons to capture vendor and recovery snapshot. They consist of prebuilt |
| 17 | // modules under AOSP so older vendor and recovery can be built with a newer system in a single |
| 18 | // source tree. |
| 19 | |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 20 | import ( |
| 21 | "encoding/json" |
| 22 | "path/filepath" |
| 23 | "sort" |
| 24 | "strings" |
| 25 | |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 26 | "android/soong/android" |
| 27 | ) |
| 28 | |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 29 | var vendorSnapshotSingleton = snapshotSingleton{ |
| 30 | "vendor", |
| 31 | "SOONG_VENDOR_SNAPSHOT_ZIP", |
| 32 | android.OptionalPath{}, |
| 33 | true, |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 34 | vendorSnapshotImageSingleton, |
Inseob Kim | e9aec6a | 2021-01-05 20:03:22 +0900 | [diff] [blame] | 35 | false, /* fake */ |
| 36 | } |
| 37 | |
| 38 | var vendorFakeSnapshotSingleton = snapshotSingleton{ |
| 39 | "vendor", |
| 40 | "SOONG_VENDOR_FAKE_SNAPSHOT_ZIP", |
| 41 | android.OptionalPath{}, |
| 42 | true, |
| 43 | vendorSnapshotImageSingleton, |
| 44 | true, /* fake */ |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | var recoverySnapshotSingleton = snapshotSingleton{ |
| 48 | "recovery", |
| 49 | "SOONG_RECOVERY_SNAPSHOT_ZIP", |
| 50 | android.OptionalPath{}, |
| 51 | false, |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 52 | recoverySnapshotImageSingleton, |
Inseob Kim | e9aec6a | 2021-01-05 20:03:22 +0900 | [diff] [blame] | 53 | false, /* fake */ |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | func VendorSnapshotSingleton() android.Singleton { |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 57 | return &vendorSnapshotSingleton |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 58 | } |
| 59 | |
Inseob Kim | e9aec6a | 2021-01-05 20:03:22 +0900 | [diff] [blame] | 60 | func VendorFakeSnapshotSingleton() android.Singleton { |
| 61 | return &vendorFakeSnapshotSingleton |
| 62 | } |
| 63 | |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 64 | func RecoverySnapshotSingleton() android.Singleton { |
| 65 | return &recoverySnapshotSingleton |
| 66 | } |
| 67 | |
| 68 | type snapshotSingleton struct { |
| 69 | // Name, e.g., "vendor", "recovery", "ramdisk". |
| 70 | name string |
| 71 | |
| 72 | // Make variable that points to the snapshot file, e.g., |
| 73 | // "SOONG_RECOVERY_SNAPSHOT_ZIP". |
| 74 | makeVar string |
| 75 | |
| 76 | // Path to the snapshot zip file. |
| 77 | snapshotZipFile android.OptionalPath |
| 78 | |
| 79 | // Whether the image supports VNDK extension modules. |
| 80 | supportsVndkExt bool |
| 81 | |
| 82 | // Implementation of the image interface specific to the image |
| 83 | // associated with this snapshot (e.g., specific to the vendor image, |
| 84 | // recovery image, etc.). |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 85 | image snapshotImage |
Inseob Kim | e9aec6a | 2021-01-05 20:03:22 +0900 | [diff] [blame] | 86 | |
| 87 | // Whether this singleton is for fake snapshot or not. |
| 88 | // Fake snapshot is a snapshot whose prebuilt binaries and headers are empty. |
| 89 | // It is much faster to generate, and can be used to inspect dependencies. |
| 90 | fake bool |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | var ( |
| 94 | // Modules under following directories are ignored. They are OEM's and vendor's |
Daniel Norman | 713387d | 2020-07-28 16:04:38 -0700 | [diff] [blame] | 95 | // proprietary modules(device/, kernel/, vendor/, and hardware/). |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 96 | vendorProprietaryDirs = []string{ |
| 97 | "device", |
Daniel Norman | 713387d | 2020-07-28 16:04:38 -0700 | [diff] [blame] | 98 | "kernel", |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 99 | "vendor", |
| 100 | "hardware", |
| 101 | } |
| 102 | |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 103 | // Modules under following directories are ignored. They are OEM's and vendor's |
| 104 | // proprietary modules(device/, kernel/, vendor/, and hardware/). |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 105 | recoveryProprietaryDirs = []string{ |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 106 | "device", |
| 107 | "hardware", |
| 108 | "kernel", |
| 109 | "vendor", |
| 110 | } |
| 111 | |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 112 | // Modules under following directories are included as they are in AOSP, |
Daniel Norman | 713387d | 2020-07-28 16:04:38 -0700 | [diff] [blame] | 113 | // although hardware/ and kernel/ are normally for vendor's own. |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 114 | aospDirsUnderProprietary = []string{ |
Daniel Norman | 713387d | 2020-07-28 16:04:38 -0700 | [diff] [blame] | 115 | "kernel/configs", |
| 116 | "kernel/prebuilts", |
| 117 | "kernel/tests", |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 118 | "hardware/interfaces", |
| 119 | "hardware/libhardware", |
| 120 | "hardware/libhardware_legacy", |
| 121 | "hardware/ril", |
| 122 | } |
| 123 | ) |
| 124 | |
| 125 | // Determine if a dir under source tree is an SoC-owned proprietary directory, such as |
| 126 | // device/, vendor/, etc. |
| 127 | func isVendorProprietaryPath(dir string) bool { |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 128 | return isProprietaryPath(dir, vendorProprietaryDirs) |
| 129 | } |
| 130 | |
| 131 | func isRecoveryProprietaryPath(dir string) bool { |
| 132 | return isProprietaryPath(dir, recoveryProprietaryDirs) |
| 133 | } |
| 134 | |
| 135 | // Determine if a dir under source tree is an SoC-owned proprietary directory, such as |
| 136 | // device/, vendor/, etc. |
| 137 | func isProprietaryPath(dir string, proprietaryDirs []string) bool { |
| 138 | for _, p := range proprietaryDirs { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 139 | if strings.HasPrefix(dir, p) { |
| 140 | // filter out AOSP defined directories, e.g. hardware/interfaces/ |
| 141 | aosp := false |
| 142 | for _, p := range aospDirsUnderProprietary { |
| 143 | if strings.HasPrefix(dir, p) { |
| 144 | aosp = true |
| 145 | break |
| 146 | } |
| 147 | } |
| 148 | if !aosp { |
| 149 | return true |
| 150 | } |
| 151 | } |
| 152 | } |
| 153 | return false |
| 154 | } |
| 155 | |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 156 | func isVendorProprietaryModule(ctx android.BaseModuleContext) bool { |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 157 | // Any module in a vendor proprietary path is a vendor proprietary |
| 158 | // module. |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 159 | if isVendorProprietaryPath(ctx.ModuleDir()) { |
| 160 | return true |
| 161 | } |
| 162 | |
| 163 | // However if the module is not in a vendor proprietary path, it may |
| 164 | // still be a vendor proprietary module. This happens for cc modules |
| 165 | // that are excluded from the vendor snapshot, and it means that the |
| 166 | // vendor has assumed control of the framework-provided module. |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 167 | if c, ok := ctx.Module().(*Module); ok { |
| 168 | if c.ExcludeFromVendorSnapshot() { |
| 169 | return true |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | return false |
| 174 | } |
| 175 | |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 176 | func isRecoveryProprietaryModule(ctx android.BaseModuleContext) bool { |
| 177 | |
Justin Yun | e09ac17 | 2021-01-20 19:49:01 +0900 | [diff] [blame] | 178 | // Any module in a recovery proprietary path is a recovery proprietary |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 179 | // module. |
| 180 | if isRecoveryProprietaryPath(ctx.ModuleDir()) { |
| 181 | return true |
| 182 | } |
| 183 | |
Justin Yun | e09ac17 | 2021-01-20 19:49:01 +0900 | [diff] [blame] | 184 | // However if the module is not in a recovery proprietary path, it may |
| 185 | // still be a recovery proprietary module. This happens for cc modules |
| 186 | // that are excluded from the recovery snapshot, and it means that the |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 187 | // vendor has assumed control of the framework-provided module. |
| 188 | |
| 189 | if c, ok := ctx.Module().(*Module); ok { |
| 190 | if c.ExcludeFromRecoverySnapshot() { |
| 191 | return true |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | return false |
| 196 | } |
| 197 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 198 | // Determines if the module is a candidate for snapshot. |
Inseob Kim | 7cf1465 | 2021-01-06 23:06:52 +0900 | [diff] [blame] | 199 | func isSnapshotAware(cfg android.DeviceConfig, m *Module, inProprietaryPath bool, apexInfo android.ApexInfo, image snapshotImage) bool { |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 200 | if !m.Enabled() || m.Properties.HideFromMake { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 201 | return false |
| 202 | } |
Martin Stjernholm | 809d518 | 2020-09-10 01:46:05 +0100 | [diff] [blame] | 203 | // When android/prebuilt.go selects between source and prebuilt, it sets |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 204 | // HideFromMake on the other one to avoid duplicate install rules in make. |
| 205 | if m.IsHideFromMake() { |
Martin Stjernholm | 809d518 | 2020-09-10 01:46:05 +0100 | [diff] [blame] | 206 | return false |
| 207 | } |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 208 | // skip proprietary modules, but (for the vendor snapshot only) |
| 209 | // include all VNDK (static) |
| 210 | if inProprietaryPath && (!image.includeVndk() || !m.IsVndk()) { |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 211 | return false |
| 212 | } |
| 213 | // If the module would be included based on its path, check to see if |
| 214 | // the module is marked to be excluded. If so, skip it. |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 215 | if image.excludeFromSnapshot(m) { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 216 | return false |
| 217 | } |
| 218 | if m.Target().Os.Class != android.Device { |
| 219 | return false |
| 220 | } |
| 221 | if m.Target().NativeBridge == android.NativeBridgeEnabled { |
| 222 | return false |
| 223 | } |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 224 | // the module must be installed in target image |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 225 | if !apexInfo.IsForPlatform() || m.isSnapshotPrebuilt() || !image.inImage(m)() { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 226 | return false |
| 227 | } |
Inseob Kim | 65ca36a | 2020-06-11 13:55:45 +0900 | [diff] [blame] | 228 | // skip kernel_headers which always depend on vendor |
| 229 | if _, ok := m.linker.(*kernelHeadersDecorator); ok { |
| 230 | return false |
| 231 | } |
Justin Yun | f2664c6 | 2020-07-30 18:57:54 +0900 | [diff] [blame] | 232 | // skip llndk_library and llndk_headers which are backward compatible |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 233 | if m.IsLlndk() { |
| 234 | return false |
| 235 | } |
Justin Yun | f2664c6 | 2020-07-30 18:57:54 +0900 | [diff] [blame] | 236 | if _, ok := m.linker.(*llndkStubDecorator); ok { |
| 237 | return false |
| 238 | } |
| 239 | if _, ok := m.linker.(*llndkHeadersDecorator); ok { |
| 240 | return false |
| 241 | } |
Inseob Kim | 7cf1465 | 2021-01-06 23:06:52 +0900 | [diff] [blame] | 242 | // If we are using directed snapshot AND we have to exclude this module, skip this |
| 243 | if image.excludeFromDirectedSnapshot(cfg, m.BaseModuleName()) { |
| 244 | return false |
| 245 | } |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 246 | |
| 247 | // Libraries |
| 248 | if l, ok := m.linker.(snapshotLibraryInterface); ok { |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 249 | if m.sanitize != nil { |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 250 | // scs and hwasan export both sanitized and unsanitized variants for static and header |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 251 | // Always use unsanitized variants of them. |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 252 | for _, t := range []SanitizerType{scs, hwasan} { |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 253 | if !l.shared() && m.sanitize.isSanitizerEnabled(t) { |
| 254 | return false |
| 255 | } |
| 256 | } |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 257 | // cfi also exports both variants. But for static, we capture both. |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 258 | // This is because cfi static libraries can't be linked from non-cfi modules, |
| 259 | // and vice versa. This isn't the case for scs and hwasan sanitizers. |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 260 | if !l.static() && !l.shared() && m.sanitize.isSanitizerEnabled(cfi) { |
| 261 | return false |
| 262 | } |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 263 | } |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 264 | if l.static() { |
Justin Yun | e09ac17 | 2021-01-20 19:49:01 +0900 | [diff] [blame] | 265 | return m.outputFile.Valid() && !image.private(m) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 266 | } |
| 267 | if l.shared() { |
Bill Peckham | 7d3f096 | 2020-06-29 16:49:15 -0700 | [diff] [blame] | 268 | if !m.outputFile.Valid() { |
| 269 | return false |
| 270 | } |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 271 | if image.includeVndk() { |
| 272 | if !m.IsVndk() { |
| 273 | return true |
| 274 | } |
Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 275 | return m.IsVndkExt() |
Bill Peckham | 7d3f096 | 2020-06-29 16:49:15 -0700 | [diff] [blame] | 276 | } |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 277 | } |
| 278 | return true |
| 279 | } |
| 280 | |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 281 | // Binaries and Objects |
| 282 | if m.binary() || m.object() { |
Justin Yun | e09ac17 | 2021-01-20 19:49:01 +0900 | [diff] [blame] | 283 | return m.outputFile.Valid() |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 284 | } |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 285 | |
| 286 | return false |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 287 | } |
| 288 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 289 | // This is to be saved as .json files, which is for development/vendor_snapshot/update.py. |
| 290 | // These flags become Android.bp snapshot module properties. |
| 291 | type snapshotJsonFlags struct { |
| 292 | ModuleName string `json:",omitempty"` |
| 293 | RelativeInstallPath string `json:",omitempty"` |
Colin Cross | a889080 | 2021-01-22 14:06:33 -0800 | [diff] [blame^] | 294 | AndroidMkSuffix string `json:",omitempty"` |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 295 | |
| 296 | // library flags |
| 297 | ExportedDirs []string `json:",omitempty"` |
| 298 | ExportedSystemDirs []string `json:",omitempty"` |
| 299 | ExportedFlags []string `json:",omitempty"` |
| 300 | Sanitize string `json:",omitempty"` |
| 301 | SanitizeMinimalDep bool `json:",omitempty"` |
| 302 | SanitizeUbsanDep bool `json:",omitempty"` |
| 303 | |
| 304 | // binary flags |
| 305 | Symlinks []string `json:",omitempty"` |
| 306 | |
| 307 | // dependencies |
| 308 | SharedLibs []string `json:",omitempty"` |
| 309 | RuntimeLibs []string `json:",omitempty"` |
| 310 | Required []string `json:",omitempty"` |
| 311 | |
| 312 | // extra config files |
| 313 | InitRc []string `json:",omitempty"` |
| 314 | VintfFragments []string `json:",omitempty"` |
| 315 | } |
| 316 | |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 317 | func (c *snapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 318 | if !c.image.shouldGenerateSnapshot(ctx) { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 319 | return |
| 320 | } |
| 321 | |
| 322 | var snapshotOutputs android.Paths |
| 323 | |
| 324 | /* |
| 325 | Vendor snapshot zipped artifacts directory structure: |
| 326 | {SNAPSHOT_ARCH}/ |
| 327 | arch-{TARGET_ARCH}-{TARGET_ARCH_VARIANT}/ |
| 328 | shared/ |
| 329 | (.so shared libraries) |
| 330 | static/ |
| 331 | (.a static libraries) |
| 332 | header/ |
| 333 | (header only libraries) |
| 334 | binary/ |
| 335 | (executable binaries) |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 336 | object/ |
| 337 | (.o object files) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 338 | arch-{TARGET_2ND_ARCH}-{TARGET_2ND_ARCH_VARIANT}/ |
| 339 | shared/ |
| 340 | (.so shared libraries) |
| 341 | static/ |
| 342 | (.a static libraries) |
| 343 | header/ |
| 344 | (header only libraries) |
| 345 | binary/ |
| 346 | (executable binaries) |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 347 | object/ |
| 348 | (.o object files) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 349 | NOTICE_FILES/ |
| 350 | (notice files, e.g. libbase.txt) |
| 351 | configs/ |
| 352 | (config files, e.g. init.rc files, vintf_fragments.xml files, etc.) |
| 353 | include/ |
| 354 | (header files of same directory structure with source tree) |
| 355 | */ |
| 356 | |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 357 | snapshotDir := c.name + "-snapshot" |
Inseob Kim | e9aec6a | 2021-01-05 20:03:22 +0900 | [diff] [blame] | 358 | if c.fake { |
| 359 | // If this is a fake snapshot singleton, place all files under fake/ subdirectory to avoid |
| 360 | // collision with real snapshot files |
| 361 | snapshotDir = filepath.Join("fake", snapshotDir) |
| 362 | } |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 363 | snapshotArchDir := filepath.Join(snapshotDir, ctx.DeviceConfig().DeviceArch()) |
| 364 | |
| 365 | includeDir := filepath.Join(snapshotArchDir, "include") |
| 366 | configsDir := filepath.Join(snapshotArchDir, "configs") |
| 367 | noticeDir := filepath.Join(snapshotArchDir, "NOTICE_FILES") |
| 368 | |
| 369 | installedNotices := make(map[string]bool) |
| 370 | installedConfigs := make(map[string]bool) |
| 371 | |
| 372 | var headers android.Paths |
| 373 | |
Inseob Kim | e9aec6a | 2021-01-05 20:03:22 +0900 | [diff] [blame] | 374 | copyFile := copyFileRule |
| 375 | if c.fake { |
| 376 | // All prebuilt binaries and headers are installed by copyFile function. This makes a fake |
| 377 | // snapshot just touch prebuilts and headers, rather than installing real files. |
| 378 | copyFile = func(ctx android.SingletonContext, path android.Path, out string) android.OutputPath { |
| 379 | return writeStringToFileRule(ctx, "", out) |
| 380 | } |
| 381 | } |
| 382 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 383 | // installSnapshot function copies prebuilt file (.so, .a, or executable) and json flag file. |
| 384 | // For executables, init_rc and vintf_fragments files are also copied. |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 385 | installSnapshot := func(m *Module) android.Paths { |
| 386 | targetArch := "arch-" + m.Target().Arch.ArchType.String() |
| 387 | if m.Target().Arch.ArchVariant != "" { |
| 388 | targetArch += "-" + m.Target().Arch.ArchVariant |
| 389 | } |
| 390 | |
| 391 | var ret android.Paths |
| 392 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 393 | prop := snapshotJsonFlags{} |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 394 | |
| 395 | // Common properties among snapshots. |
| 396 | prop.ModuleName = ctx.ModuleName(m) |
Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 397 | if c.supportsVndkExt && m.IsVndkExt() { |
Bill Peckham | 7d3f096 | 2020-06-29 16:49:15 -0700 | [diff] [blame] | 398 | // vndk exts are installed to /vendor/lib(64)?/vndk(-sp)? |
| 399 | if m.isVndkSp() { |
| 400 | prop.RelativeInstallPath = "vndk-sp" |
| 401 | } else { |
| 402 | prop.RelativeInstallPath = "vndk" |
| 403 | } |
| 404 | } else { |
| 405 | prop.RelativeInstallPath = m.RelativeInstallPath() |
| 406 | } |
Colin Cross | a889080 | 2021-01-22 14:06:33 -0800 | [diff] [blame^] | 407 | prop.AndroidMkSuffix = m.Properties.SubName |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 408 | prop.RuntimeLibs = m.Properties.SnapshotRuntimeLibs |
| 409 | prop.Required = m.RequiredModuleNames() |
| 410 | for _, path := range m.InitRc() { |
| 411 | prop.InitRc = append(prop.InitRc, filepath.Join("configs", path.Base())) |
| 412 | } |
| 413 | for _, path := range m.VintfFragments() { |
| 414 | prop.VintfFragments = append(prop.VintfFragments, filepath.Join("configs", path.Base())) |
| 415 | } |
| 416 | |
| 417 | // install config files. ignores any duplicates. |
| 418 | for _, path := range append(m.InitRc(), m.VintfFragments()...) { |
| 419 | out := filepath.Join(configsDir, path.Base()) |
| 420 | if !installedConfigs[out] { |
| 421 | installedConfigs[out] = true |
Inseob Kim | e9aec6a | 2021-01-05 20:03:22 +0900 | [diff] [blame] | 422 | ret = append(ret, copyFile(ctx, path, out)) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 423 | } |
| 424 | } |
| 425 | |
| 426 | var propOut string |
| 427 | |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 428 | if l, ok := m.linker.(snapshotLibraryInterface); ok { |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 429 | exporterInfo := ctx.ModuleProvider(m, FlagExporterInfoProvider).(FlagExporterInfo) |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 430 | |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 431 | // library flags |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 432 | prop.ExportedFlags = exporterInfo.Flags |
| 433 | for _, dir := range exporterInfo.IncludeDirs { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 434 | prop.ExportedDirs = append(prop.ExportedDirs, filepath.Join("include", dir.String())) |
| 435 | } |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 436 | for _, dir := range exporterInfo.SystemIncludeDirs { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 437 | prop.ExportedSystemDirs = append(prop.ExportedSystemDirs, filepath.Join("include", dir.String())) |
| 438 | } |
| 439 | // shared libs dependencies aren't meaningful on static or header libs |
| 440 | if l.shared() { |
| 441 | prop.SharedLibs = m.Properties.SnapshotSharedLibs |
| 442 | } |
| 443 | if l.static() && m.sanitize != nil { |
| 444 | prop.SanitizeMinimalDep = m.sanitize.Properties.MinimalRuntimeDep || enableMinimalRuntime(m.sanitize) |
| 445 | prop.SanitizeUbsanDep = m.sanitize.Properties.UbsanRuntimeDep || enableUbsanRuntime(m.sanitize) |
| 446 | } |
| 447 | |
| 448 | var libType string |
| 449 | if l.static() { |
| 450 | libType = "static" |
| 451 | } else if l.shared() { |
| 452 | libType = "shared" |
| 453 | } else { |
| 454 | libType = "header" |
| 455 | } |
| 456 | |
| 457 | var stem string |
| 458 | |
| 459 | // install .a or .so |
| 460 | if libType != "header" { |
| 461 | libPath := m.outputFile.Path() |
| 462 | stem = libPath.Base() |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 463 | if l.static() && m.sanitize != nil && m.sanitize.isSanitizerEnabled(cfi) { |
| 464 | // both cfi and non-cfi variant for static libraries can exist. |
| 465 | // attach .cfi to distinguish between cfi and non-cfi. |
| 466 | // e.g. libbase.a -> libbase.cfi.a |
| 467 | ext := filepath.Ext(stem) |
| 468 | stem = strings.TrimSuffix(stem, ext) + ".cfi" + ext |
| 469 | prop.Sanitize = "cfi" |
| 470 | prop.ModuleName += ".cfi" |
| 471 | } |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 472 | snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, libType, stem) |
Inseob Kim | e9aec6a | 2021-01-05 20:03:22 +0900 | [diff] [blame] | 473 | ret = append(ret, copyFile(ctx, libPath, snapshotLibOut)) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 474 | } else { |
| 475 | stem = ctx.ModuleName(m) |
| 476 | } |
| 477 | |
| 478 | propOut = filepath.Join(snapshotArchDir, targetArch, libType, stem+".json") |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 479 | } else if m.binary() { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 480 | // binary flags |
| 481 | prop.Symlinks = m.Symlinks() |
| 482 | prop.SharedLibs = m.Properties.SnapshotSharedLibs |
| 483 | |
| 484 | // install bin |
| 485 | binPath := m.outputFile.Path() |
| 486 | snapshotBinOut := filepath.Join(snapshotArchDir, targetArch, "binary", binPath.Base()) |
Inseob Kim | e9aec6a | 2021-01-05 20:03:22 +0900 | [diff] [blame] | 487 | ret = append(ret, copyFile(ctx, binPath, snapshotBinOut)) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 488 | propOut = snapshotBinOut + ".json" |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 489 | } else if m.object() { |
| 490 | // object files aren't installed to the device, so their names can conflict. |
| 491 | // Use module name as stem. |
| 492 | objPath := m.outputFile.Path() |
| 493 | snapshotObjOut := filepath.Join(snapshotArchDir, targetArch, "object", |
| 494 | ctx.ModuleName(m)+filepath.Ext(objPath.Base())) |
Inseob Kim | e9aec6a | 2021-01-05 20:03:22 +0900 | [diff] [blame] | 495 | ret = append(ret, copyFile(ctx, objPath, snapshotObjOut)) |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 496 | propOut = snapshotObjOut + ".json" |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 497 | } else { |
| 498 | ctx.Errorf("unknown module %q in vendor snapshot", m.String()) |
| 499 | return nil |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | j, err := json.Marshal(prop) |
| 503 | if err != nil { |
| 504 | ctx.Errorf("json marshal to %q failed: %#v", propOut, err) |
| 505 | return nil |
| 506 | } |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 507 | ret = append(ret, writeStringToFileRule(ctx, string(j), propOut)) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 508 | |
| 509 | return ret |
| 510 | } |
| 511 | |
| 512 | ctx.VisitAllModules(func(module android.Module) { |
| 513 | m, ok := module.(*Module) |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 514 | if !ok { |
| 515 | return |
| 516 | } |
| 517 | |
| 518 | moduleDir := ctx.ModuleDir(module) |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 519 | inProprietaryPath := c.image.isProprietaryPath(moduleDir) |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 520 | apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo) |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 521 | |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 522 | if c.image.excludeFromSnapshot(m) { |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 523 | if inProprietaryPath { |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 524 | // Error: exclude_from_vendor_snapshot applies |
| 525 | // to framework-path modules only. |
| 526 | ctx.Errorf("module %q in vendor proprietary path %q may not use \"exclude_from_vendor_snapshot: true\"", m.String(), moduleDir) |
| 527 | return |
| 528 | } |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 529 | } |
| 530 | |
Inseob Kim | 7cf1465 | 2021-01-06 23:06:52 +0900 | [diff] [blame] | 531 | if !isSnapshotAware(ctx.DeviceConfig(), m, inProprietaryPath, apexInfo, c.image) { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 532 | return |
| 533 | } |
| 534 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 535 | // installSnapshot installs prebuilts and json flag files |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 536 | snapshotOutputs = append(snapshotOutputs, installSnapshot(m)...) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 537 | |
| 538 | // just gather headers and notice files here, because they are to be deduplicated |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 539 | if l, ok := m.linker.(snapshotLibraryInterface); ok { |
| 540 | headers = append(headers, l.snapshotHeaders()...) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 541 | } |
| 542 | |
Bob Badour | a75b057 | 2020-02-18 20:21:55 -0800 | [diff] [blame] | 543 | if len(m.NoticeFiles()) > 0 { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 544 | noticeName := ctx.ModuleName(m) + ".txt" |
| 545 | noticeOut := filepath.Join(noticeDir, noticeName) |
| 546 | // skip already copied notice file |
| 547 | if !installedNotices[noticeOut] { |
| 548 | installedNotices[noticeOut] = true |
Inseob Kim | e9aec6a | 2021-01-05 20:03:22 +0900 | [diff] [blame] | 549 | snapshotOutputs = append(snapshotOutputs, combineNoticesRule(ctx, m.NoticeFiles(), noticeOut)) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 550 | } |
| 551 | } |
| 552 | }) |
| 553 | |
| 554 | // install all headers after removing duplicates |
| 555 | for _, header := range android.FirstUniquePaths(headers) { |
Inseob Kim | e9aec6a | 2021-01-05 20:03:22 +0900 | [diff] [blame] | 556 | snapshotOutputs = append(snapshotOutputs, copyFile(ctx, header, filepath.Join(includeDir, header.String()))) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | // All artifacts are ready. Sort them to normalize ninja and then zip. |
| 560 | sort.Slice(snapshotOutputs, func(i, j int) bool { |
| 561 | return snapshotOutputs[i].String() < snapshotOutputs[j].String() |
| 562 | }) |
| 563 | |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 564 | zipPath := android.PathForOutput( |
| 565 | ctx, |
| 566 | snapshotDir, |
| 567 | c.name+"-"+ctx.Config().DeviceName()+".zip") |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 568 | zipRule := android.NewRuleBuilder(pctx, ctx) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 569 | |
| 570 | // filenames in rspfile from FlagWithRspFileInputList might be single-quoted. Remove it with tr |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 571 | snapshotOutputList := android.PathForOutput( |
| 572 | ctx, |
| 573 | snapshotDir, |
| 574 | c.name+"-"+ctx.Config().DeviceName()+"_list") |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 575 | zipRule.Command(). |
| 576 | Text("tr"). |
| 577 | FlagWithArg("-d ", "\\'"). |
| 578 | FlagWithRspFileInputList("< ", snapshotOutputs). |
| 579 | FlagWithOutput("> ", snapshotOutputList) |
| 580 | |
| 581 | zipRule.Temporary(snapshotOutputList) |
| 582 | |
| 583 | zipRule.Command(). |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 584 | BuiltTool("soong_zip"). |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 585 | FlagWithOutput("-o ", zipPath). |
| 586 | FlagWithArg("-C ", android.PathForOutput(ctx, snapshotDir).String()). |
| 587 | FlagWithInput("-l ", snapshotOutputList) |
| 588 | |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 589 | zipRule.Build(zipPath.String(), c.name+" snapshot "+zipPath.String()) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 590 | zipRule.DeleteTemporaryFiles() |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 591 | c.snapshotZipFile = android.OptionalPathForPath(zipPath) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 592 | } |
| 593 | |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 594 | func (c *snapshotSingleton) MakeVars(ctx android.MakeVarsContext) { |
| 595 | ctx.Strict( |
| 596 | c.makeVar, |
| 597 | c.snapshotZipFile.String()) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 598 | } |