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, |
Ivan Lozano | d67a6b0 | 2021-05-20 13:01:32 -0400 | [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, |
Ivan Lozano | d67a6b0 | 2021-05-20 13:01:32 -0400 | [diff] [blame] | 43 | VendorSnapshotImageSingleton, |
Inseob Kim | e9aec6a | 2021-01-05 20:03:22 +0900 | [diff] [blame] | 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.). |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [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 | |
Justin DeMartino | 383bfb3 | 2021-02-24 10:49:43 -0800 | [diff] [blame] | 93 | // Determine if a dir under source tree is an SoC-owned proprietary directory based |
| 94 | // on vendor snapshot configuration |
| 95 | // Examples: device/, vendor/ |
| 96 | func isVendorProprietaryPath(dir string, deviceConfig android.DeviceConfig) bool { |
| 97 | return VendorSnapshotSingleton().(*snapshotSingleton).image.isProprietaryPath(dir, deviceConfig) |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 98 | } |
| 99 | |
Justin DeMartino | 383bfb3 | 2021-02-24 10:49:43 -0800 | [diff] [blame] | 100 | // Determine if a dir under source tree is an SoC-owned proprietary directory based |
| 101 | // on recovery snapshot configuration |
| 102 | // Examples: device/, vendor/ |
| 103 | func isRecoveryProprietaryPath(dir string, deviceConfig android.DeviceConfig) bool { |
| 104 | return RecoverySnapshotSingleton().(*snapshotSingleton).image.isProprietaryPath(dir, deviceConfig) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 105 | } |
| 106 | |
Ivan Lozano | d67a6b0 | 2021-05-20 13:01:32 -0400 | [diff] [blame] | 107 | func IsVendorProprietaryModule(ctx android.BaseModuleContext) bool { |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 108 | // Any module in a vendor proprietary path is a vendor proprietary |
| 109 | // module. |
Justin DeMartino | 383bfb3 | 2021-02-24 10:49:43 -0800 | [diff] [blame] | 110 | if isVendorProprietaryPath(ctx.ModuleDir(), ctx.DeviceConfig()) { |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 111 | return true |
| 112 | } |
| 113 | |
| 114 | // However if the module is not in a vendor proprietary path, it may |
| 115 | // still be a vendor proprietary module. This happens for cc modules |
| 116 | // that are excluded from the vendor snapshot, and it means that the |
| 117 | // vendor has assumed control of the framework-provided module. |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 118 | if c, ok := ctx.Module().(LinkableInterface); ok { |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 119 | if c.ExcludeFromVendorSnapshot() { |
| 120 | return true |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | return false |
| 125 | } |
| 126 | |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 127 | func isRecoveryProprietaryModule(ctx android.BaseModuleContext) bool { |
| 128 | |
Justin Yun | e09ac17 | 2021-01-20 19:49:01 +0900 | [diff] [blame] | 129 | // Any module in a recovery proprietary path is a recovery proprietary |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 130 | // module. |
Justin DeMartino | 383bfb3 | 2021-02-24 10:49:43 -0800 | [diff] [blame] | 131 | if isRecoveryProprietaryPath(ctx.ModuleDir(), ctx.DeviceConfig()) { |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 132 | return true |
| 133 | } |
| 134 | |
Justin Yun | e09ac17 | 2021-01-20 19:49:01 +0900 | [diff] [blame] | 135 | // However if the module is not in a recovery proprietary path, it may |
| 136 | // still be a recovery proprietary module. This happens for cc modules |
| 137 | // that are excluded from the recovery snapshot, and it means that the |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 138 | // vendor has assumed control of the framework-provided module. |
| 139 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 140 | if c, ok := ctx.Module().(LinkableInterface); ok { |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 141 | if c.ExcludeFromRecoverySnapshot() { |
| 142 | return true |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | return false |
| 147 | } |
| 148 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 149 | // Determines if the module is a candidate for snapshot. |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 150 | func isSnapshotAware(cfg android.DeviceConfig, m LinkableInterface, inProprietaryPath bool, apexInfo android.ApexInfo, image SnapshotImage) bool { |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 151 | if !m.Enabled() || m.HiddenFromMake() { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 152 | return false |
| 153 | } |
Martin Stjernholm | 809d518 | 2020-09-10 01:46:05 +0100 | [diff] [blame] | 154 | // When android/prebuilt.go selects between source and prebuilt, it sets |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 155 | // HideFromMake on the other one to avoid duplicate install rules in make. |
| 156 | if m.IsHideFromMake() { |
Martin Stjernholm | 809d518 | 2020-09-10 01:46:05 +0100 | [diff] [blame] | 157 | return false |
| 158 | } |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 159 | // skip proprietary modules, but (for the vendor snapshot only) |
| 160 | // include all VNDK (static) |
| 161 | if inProprietaryPath && (!image.includeVndk() || !m.IsVndk()) { |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 162 | return false |
| 163 | } |
| 164 | // If the module would be included based on its path, check to see if |
| 165 | // the module is marked to be excluded. If so, skip it. |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 166 | if image.excludeFromSnapshot(m) { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 167 | return false |
| 168 | } |
| 169 | if m.Target().Os.Class != android.Device { |
| 170 | return false |
| 171 | } |
| 172 | if m.Target().NativeBridge == android.NativeBridgeEnabled { |
| 173 | return false |
| 174 | } |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 175 | // the module must be installed in target image |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 176 | if !apexInfo.IsForPlatform() || m.IsSnapshotPrebuilt() || !image.inImage(m)() { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 177 | return false |
| 178 | } |
Inseob Kim | 65ca36a | 2020-06-11 13:55:45 +0900 | [diff] [blame] | 179 | // skip kernel_headers which always depend on vendor |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 180 | if m.KernelHeadersDecorator() { |
Inseob Kim | 65ca36a | 2020-06-11 13:55:45 +0900 | [diff] [blame] | 181 | return false |
| 182 | } |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 183 | |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 184 | if m.IsLlndk() { |
| 185 | return false |
| 186 | } |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 187 | |
| 188 | // Libraries |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 189 | if sanitizable, ok := m.(PlatformSanitizeable); ok && sanitizable.IsSnapshotLibrary() { |
| 190 | if sanitizable.SanitizePropDefined() { |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 191 | // 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] | 192 | // Always use unsanitized variants of them. |
Tri Vo | 6eafc36 | 2021-04-01 11:29:09 -0700 | [diff] [blame] | 193 | for _, t := range []SanitizerType{scs, Hwasan} { |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 194 | if !sanitizable.Shared() && sanitizable.IsSanitizerEnabled(t) { |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 195 | return false |
| 196 | } |
| 197 | } |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 198 | // cfi also exports both variants. But for static, we capture both. |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 199 | // This is because cfi static libraries can't be linked from non-cfi modules, |
| 200 | // and vice versa. This isn't the case for scs and hwasan sanitizers. |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 201 | if !sanitizable.Static() && !sanitizable.Shared() && sanitizable.IsSanitizerEnabled(cfi) { |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 202 | return false |
| 203 | } |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 204 | } |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 205 | if sanitizable.Static() { |
| 206 | return sanitizable.OutputFile().Valid() && !image.private(m) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 207 | } |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 208 | if sanitizable.Shared() || sanitizable.Rlib() { |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 209 | if !sanitizable.OutputFile().Valid() { |
Bill Peckham | 7d3f096 | 2020-06-29 16:49:15 -0700 | [diff] [blame] | 210 | return false |
| 211 | } |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 212 | if image.includeVndk() { |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 213 | if !sanitizable.IsVndk() { |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 214 | return true |
| 215 | } |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 216 | return sanitizable.IsVndkExt() |
Bill Peckham | 7d3f096 | 2020-06-29 16:49:15 -0700 | [diff] [blame] | 217 | } |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 218 | } |
| 219 | return true |
| 220 | } |
| 221 | |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 222 | // Binaries and Objects |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 223 | if m.Binary() || m.Object() { |
| 224 | return m.OutputFile().Valid() |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 225 | } |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 226 | |
| 227 | return false |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 228 | } |
| 229 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 230 | // This is to be saved as .json files, which is for development/vendor_snapshot/update.py. |
| 231 | // These flags become Android.bp snapshot module properties. |
| 232 | type snapshotJsonFlags struct { |
| 233 | ModuleName string `json:",omitempty"` |
| 234 | RelativeInstallPath string `json:",omitempty"` |
| 235 | |
| 236 | // library flags |
| 237 | ExportedDirs []string `json:",omitempty"` |
| 238 | ExportedSystemDirs []string `json:",omitempty"` |
| 239 | ExportedFlags []string `json:",omitempty"` |
| 240 | Sanitize string `json:",omitempty"` |
| 241 | SanitizeMinimalDep bool `json:",omitempty"` |
| 242 | SanitizeUbsanDep bool `json:",omitempty"` |
| 243 | |
| 244 | // binary flags |
Justin Yun | 5e03586 | 2021-06-29 20:50:37 +0900 | [diff] [blame] | 245 | Symlinks []string `json:",omitempty"` |
| 246 | StaticExecutable bool `json:",omitempty"` |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 247 | |
| 248 | // dependencies |
| 249 | SharedLibs []string `json:",omitempty"` |
Justin Yun | 5e03586 | 2021-06-29 20:50:37 +0900 | [diff] [blame] | 250 | StaticLibs []string `json:",omitempty"` |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 251 | RuntimeLibs []string `json:",omitempty"` |
| 252 | Required []string `json:",omitempty"` |
| 253 | |
| 254 | // extra config files |
| 255 | InitRc []string `json:",omitempty"` |
| 256 | VintfFragments []string `json:",omitempty"` |
| 257 | } |
| 258 | |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 259 | func (c *snapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 260 | if !c.image.shouldGenerateSnapshot(ctx) { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 261 | return |
| 262 | } |
| 263 | |
| 264 | var snapshotOutputs android.Paths |
| 265 | |
| 266 | /* |
| 267 | Vendor snapshot zipped artifacts directory structure: |
| 268 | {SNAPSHOT_ARCH}/ |
| 269 | arch-{TARGET_ARCH}-{TARGET_ARCH_VARIANT}/ |
| 270 | shared/ |
| 271 | (.so shared libraries) |
| 272 | static/ |
| 273 | (.a static libraries) |
| 274 | header/ |
| 275 | (header only libraries) |
| 276 | binary/ |
| 277 | (executable binaries) |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 278 | object/ |
| 279 | (.o object files) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 280 | arch-{TARGET_2ND_ARCH}-{TARGET_2ND_ARCH_VARIANT}/ |
| 281 | shared/ |
| 282 | (.so shared libraries) |
| 283 | static/ |
| 284 | (.a static libraries) |
| 285 | header/ |
| 286 | (header only libraries) |
| 287 | binary/ |
| 288 | (executable binaries) |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 289 | object/ |
| 290 | (.o object files) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 291 | NOTICE_FILES/ |
| 292 | (notice files, e.g. libbase.txt) |
| 293 | configs/ |
| 294 | (config files, e.g. init.rc files, vintf_fragments.xml files, etc.) |
| 295 | include/ |
| 296 | (header files of same directory structure with source tree) |
| 297 | */ |
| 298 | |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 299 | snapshotDir := c.name + "-snapshot" |
Inseob Kim | e9aec6a | 2021-01-05 20:03:22 +0900 | [diff] [blame] | 300 | if c.fake { |
| 301 | // If this is a fake snapshot singleton, place all files under fake/ subdirectory to avoid |
| 302 | // collision with real snapshot files |
| 303 | snapshotDir = filepath.Join("fake", snapshotDir) |
| 304 | } |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 305 | snapshotArchDir := filepath.Join(snapshotDir, ctx.DeviceConfig().DeviceArch()) |
| 306 | |
| 307 | includeDir := filepath.Join(snapshotArchDir, "include") |
| 308 | configsDir := filepath.Join(snapshotArchDir, "configs") |
| 309 | noticeDir := filepath.Join(snapshotArchDir, "NOTICE_FILES") |
| 310 | |
| 311 | installedNotices := make(map[string]bool) |
| 312 | installedConfigs := make(map[string]bool) |
| 313 | |
| 314 | var headers android.Paths |
| 315 | |
Jose Galmes | 0a942a0 | 2021-02-03 14:23:15 -0800 | [diff] [blame] | 316 | copyFile := func(ctx android.SingletonContext, path android.Path, out string, fake bool) android.OutputPath { |
| 317 | if fake { |
| 318 | // All prebuilt binaries and headers are installed by copyFile function. This makes a fake |
| 319 | // snapshot just touch prebuilts and headers, rather than installing real files. |
Inseob Kim | e9aec6a | 2021-01-05 20:03:22 +0900 | [diff] [blame] | 320 | return writeStringToFileRule(ctx, "", out) |
Jose Galmes | 0a942a0 | 2021-02-03 14:23:15 -0800 | [diff] [blame] | 321 | } else { |
| 322 | return copyFileRule(ctx, path, out) |
Inseob Kim | e9aec6a | 2021-01-05 20:03:22 +0900 | [diff] [blame] | 323 | } |
| 324 | } |
| 325 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 326 | // installSnapshot function copies prebuilt file (.so, .a, or executable) and json flag file. |
| 327 | // For executables, init_rc and vintf_fragments files are also copied. |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 328 | installSnapshot := func(m LinkableInterface, fake bool) android.Paths { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 329 | targetArch := "arch-" + m.Target().Arch.ArchType.String() |
| 330 | if m.Target().Arch.ArchVariant != "" { |
| 331 | targetArch += "-" + m.Target().Arch.ArchVariant |
| 332 | } |
| 333 | |
| 334 | var ret android.Paths |
| 335 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 336 | prop := snapshotJsonFlags{} |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 337 | |
| 338 | // Common properties among snapshots. |
| 339 | prop.ModuleName = ctx.ModuleName(m) |
Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 340 | if c.supportsVndkExt && m.IsVndkExt() { |
Bill Peckham | 7d3f096 | 2020-06-29 16:49:15 -0700 | [diff] [blame] | 341 | // vndk exts are installed to /vendor/lib(64)?/vndk(-sp)? |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 342 | if m.IsVndkSp() { |
Bill Peckham | 7d3f096 | 2020-06-29 16:49:15 -0700 | [diff] [blame] | 343 | prop.RelativeInstallPath = "vndk-sp" |
| 344 | } else { |
| 345 | prop.RelativeInstallPath = "vndk" |
| 346 | } |
| 347 | } else { |
| 348 | prop.RelativeInstallPath = m.RelativeInstallPath() |
| 349 | } |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 350 | prop.RuntimeLibs = m.SnapshotRuntimeLibs() |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 351 | prop.Required = m.RequiredModuleNames() |
| 352 | for _, path := range m.InitRc() { |
| 353 | prop.InitRc = append(prop.InitRc, filepath.Join("configs", path.Base())) |
| 354 | } |
| 355 | for _, path := range m.VintfFragments() { |
| 356 | prop.VintfFragments = append(prop.VintfFragments, filepath.Join("configs", path.Base())) |
| 357 | } |
| 358 | |
| 359 | // install config files. ignores any duplicates. |
| 360 | for _, path := range append(m.InitRc(), m.VintfFragments()...) { |
| 361 | out := filepath.Join(configsDir, path.Base()) |
| 362 | if !installedConfigs[out] { |
| 363 | installedConfigs[out] = true |
Jose Galmes | 0a942a0 | 2021-02-03 14:23:15 -0800 | [diff] [blame] | 364 | ret = append(ret, copyFile(ctx, path, out, fake)) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 365 | } |
| 366 | } |
| 367 | |
| 368 | var propOut string |
| 369 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 370 | if m.IsSnapshotLibrary() { |
| 371 | exporterInfo := ctx.ModuleProvider(m.Module(), FlagExporterInfoProvider).(FlagExporterInfo) |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 372 | |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 373 | // library flags |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 374 | prop.ExportedFlags = exporterInfo.Flags |
| 375 | for _, dir := range exporterInfo.IncludeDirs { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 376 | prop.ExportedDirs = append(prop.ExportedDirs, filepath.Join("include", dir.String())) |
| 377 | } |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 378 | for _, dir := range exporterInfo.SystemIncludeDirs { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 379 | prop.ExportedSystemDirs = append(prop.ExportedSystemDirs, filepath.Join("include", dir.String())) |
| 380 | } |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 381 | |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 382 | // shared libs dependencies aren't meaningful on static or header libs |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 383 | if m.Shared() { |
| 384 | prop.SharedLibs = m.SnapshotSharedLibs() |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 385 | } |
Justin Yun | 5e03586 | 2021-06-29 20:50:37 +0900 | [diff] [blame] | 386 | // static libs dependencies are required to collect the NOTICE files. |
| 387 | prop.StaticLibs = m.SnapshotStaticLibs() |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 388 | if sanitizable, ok := m.(PlatformSanitizeable); ok { |
| 389 | if sanitizable.Static() && sanitizable.SanitizePropDefined() { |
| 390 | prop.SanitizeMinimalDep = sanitizable.MinimalRuntimeDep() || sanitizable.MinimalRuntimeNeeded() |
| 391 | prop.SanitizeUbsanDep = sanitizable.UbsanRuntimeDep() || sanitizable.UbsanRuntimeNeeded() |
| 392 | } |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | var libType string |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 396 | if m.Static() { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 397 | libType = "static" |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 398 | } else if m.Shared() { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 399 | libType = "shared" |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 400 | } else if m.Rlib() { |
| 401 | libType = "rlib" |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 402 | } else { |
| 403 | libType = "header" |
| 404 | } |
| 405 | |
| 406 | var stem string |
| 407 | |
| 408 | // install .a or .so |
| 409 | if libType != "header" { |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 410 | libPath := m.OutputFile().Path() |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 411 | stem = libPath.Base() |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 412 | if sanitizable, ok := m.(PlatformSanitizeable); ok { |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 413 | if (sanitizable.Static() || sanitizable.Rlib()) && sanitizable.SanitizePropDefined() && sanitizable.IsSanitizerEnabled(cfi) { |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 414 | // both cfi and non-cfi variant for static libraries can exist. |
| 415 | // attach .cfi to distinguish between cfi and non-cfi. |
| 416 | // e.g. libbase.a -> libbase.cfi.a |
| 417 | ext := filepath.Ext(stem) |
| 418 | stem = strings.TrimSuffix(stem, ext) + ".cfi" + ext |
| 419 | prop.Sanitize = "cfi" |
| 420 | prop.ModuleName += ".cfi" |
| 421 | } |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 422 | } |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 423 | snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, libType, stem) |
Jose Galmes | 0a942a0 | 2021-02-03 14:23:15 -0800 | [diff] [blame] | 424 | ret = append(ret, copyFile(ctx, libPath, snapshotLibOut, fake)) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 425 | } else { |
| 426 | stem = ctx.ModuleName(m) |
| 427 | } |
| 428 | |
| 429 | propOut = filepath.Join(snapshotArchDir, targetArch, libType, stem+".json") |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 430 | } else if m.Binary() { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 431 | // binary flags |
| 432 | prop.Symlinks = m.Symlinks() |
Justin Yun | 5e03586 | 2021-06-29 20:50:37 +0900 | [diff] [blame] | 433 | prop.StaticExecutable = m.StaticExecutable() |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 434 | prop.SharedLibs = m.SnapshotSharedLibs() |
Justin Yun | 5e03586 | 2021-06-29 20:50:37 +0900 | [diff] [blame] | 435 | // static libs dependencies are required to collect the NOTICE files. |
| 436 | prop.StaticLibs = m.SnapshotStaticLibs() |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 437 | // install bin |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 438 | binPath := m.OutputFile().Path() |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 439 | snapshotBinOut := filepath.Join(snapshotArchDir, targetArch, "binary", binPath.Base()) |
Jose Galmes | 0a942a0 | 2021-02-03 14:23:15 -0800 | [diff] [blame] | 440 | ret = append(ret, copyFile(ctx, binPath, snapshotBinOut, fake)) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 441 | propOut = snapshotBinOut + ".json" |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 442 | } else if m.Object() { |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 443 | // object files aren't installed to the device, so their names can conflict. |
| 444 | // Use module name as stem. |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 445 | objPath := m.OutputFile().Path() |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 446 | snapshotObjOut := filepath.Join(snapshotArchDir, targetArch, "object", |
| 447 | ctx.ModuleName(m)+filepath.Ext(objPath.Base())) |
Jose Galmes | 0a942a0 | 2021-02-03 14:23:15 -0800 | [diff] [blame] | 448 | ret = append(ret, copyFile(ctx, objPath, snapshotObjOut, fake)) |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 449 | propOut = snapshotObjOut + ".json" |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 450 | } else { |
| 451 | ctx.Errorf("unknown module %q in vendor snapshot", m.String()) |
| 452 | return nil |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | j, err := json.Marshal(prop) |
| 456 | if err != nil { |
| 457 | ctx.Errorf("json marshal to %q failed: %#v", propOut, err) |
| 458 | return nil |
| 459 | } |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 460 | ret = append(ret, writeStringToFileRule(ctx, string(j), propOut)) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 461 | |
| 462 | return ret |
| 463 | } |
| 464 | |
| 465 | ctx.VisitAllModules(func(module android.Module) { |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 466 | m, ok := module.(LinkableInterface) |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 467 | if !ok { |
| 468 | return |
| 469 | } |
| 470 | |
| 471 | moduleDir := ctx.ModuleDir(module) |
Justin DeMartino | 383bfb3 | 2021-02-24 10:49:43 -0800 | [diff] [blame] | 472 | inProprietaryPath := c.image.isProprietaryPath(moduleDir, ctx.DeviceConfig()) |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 473 | apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo) |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 474 | |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 475 | if c.image.excludeFromSnapshot(m) { |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 476 | if inProprietaryPath { |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 477 | // Error: exclude_from_vendor_snapshot applies |
| 478 | // to framework-path modules only. |
| 479 | ctx.Errorf("module %q in vendor proprietary path %q may not use \"exclude_from_vendor_snapshot: true\"", m.String(), moduleDir) |
| 480 | return |
| 481 | } |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 482 | } |
| 483 | |
Inseob Kim | 7cf1465 | 2021-01-06 23:06:52 +0900 | [diff] [blame] | 484 | if !isSnapshotAware(ctx.DeviceConfig(), m, inProprietaryPath, apexInfo, c.image) { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 485 | return |
| 486 | } |
| 487 | |
Jose Galmes | 0a942a0 | 2021-02-03 14:23:15 -0800 | [diff] [blame] | 488 | // If we are using directed snapshot and a module is not included in the |
| 489 | // list, we will still include the module as if it was a fake module. |
| 490 | // The reason is that soong needs all the dependencies to be present, even |
| 491 | // if they are not using during the build. |
| 492 | installAsFake := c.fake |
| 493 | if c.image.excludeFromDirectedSnapshot(ctx.DeviceConfig(), m.BaseModuleName()) { |
| 494 | installAsFake = true |
| 495 | } |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 496 | |
Jose Galmes | 0a942a0 | 2021-02-03 14:23:15 -0800 | [diff] [blame] | 497 | // installSnapshot installs prebuilts and json flag files |
| 498 | snapshotOutputs = append(snapshotOutputs, installSnapshot(m, installAsFake)...) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 499 | // just gather headers and notice files here, because they are to be deduplicated |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 500 | if m.IsSnapshotLibrary() { |
| 501 | headers = append(headers, m.SnapshotHeaders()...) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 502 | } |
| 503 | |
Justin Yun | 885a7de | 2021-06-29 20:34:53 +0900 | [diff] [blame^] | 504 | if len(m.EffectiveLicenseFiles()) > 0 { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 505 | noticeName := ctx.ModuleName(m) + ".txt" |
| 506 | noticeOut := filepath.Join(noticeDir, noticeName) |
| 507 | // skip already copied notice file |
| 508 | if !installedNotices[noticeOut] { |
| 509 | installedNotices[noticeOut] = true |
Justin Yun | 885a7de | 2021-06-29 20:34:53 +0900 | [diff] [blame^] | 510 | snapshotOutputs = append(snapshotOutputs, combineNoticesRule(ctx, m.EffectiveLicenseFiles(), noticeOut)) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 511 | } |
| 512 | } |
| 513 | }) |
| 514 | |
| 515 | // install all headers after removing duplicates |
| 516 | for _, header := range android.FirstUniquePaths(headers) { |
Jose Galmes | 0a942a0 | 2021-02-03 14:23:15 -0800 | [diff] [blame] | 517 | snapshotOutputs = append(snapshotOutputs, copyFile(ctx, header, filepath.Join(includeDir, header.String()), c.fake)) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | // All artifacts are ready. Sort them to normalize ninja and then zip. |
| 521 | sort.Slice(snapshotOutputs, func(i, j int) bool { |
| 522 | return snapshotOutputs[i].String() < snapshotOutputs[j].String() |
| 523 | }) |
| 524 | |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 525 | zipPath := android.PathForOutput( |
| 526 | ctx, |
| 527 | snapshotDir, |
| 528 | c.name+"-"+ctx.Config().DeviceName()+".zip") |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 529 | zipRule := android.NewRuleBuilder(pctx, ctx) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 530 | |
| 531 | // 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] | 532 | snapshotOutputList := android.PathForOutput( |
| 533 | ctx, |
| 534 | snapshotDir, |
| 535 | c.name+"-"+ctx.Config().DeviceName()+"_list") |
Colin Cross | 70c4741 | 2021-03-12 17:48:14 -0800 | [diff] [blame] | 536 | rspFile := snapshotOutputList.ReplaceExtension(ctx, "rsp") |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 537 | zipRule.Command(). |
| 538 | Text("tr"). |
| 539 | FlagWithArg("-d ", "\\'"). |
Colin Cross | 70c4741 | 2021-03-12 17:48:14 -0800 | [diff] [blame] | 540 | FlagWithRspFileInputList("< ", rspFile, snapshotOutputs). |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 541 | FlagWithOutput("> ", snapshotOutputList) |
| 542 | |
| 543 | zipRule.Temporary(snapshotOutputList) |
| 544 | |
| 545 | zipRule.Command(). |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 546 | BuiltTool("soong_zip"). |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 547 | FlagWithOutput("-o ", zipPath). |
| 548 | FlagWithArg("-C ", android.PathForOutput(ctx, snapshotDir).String()). |
| 549 | FlagWithInput("-l ", snapshotOutputList) |
| 550 | |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 551 | zipRule.Build(zipPath.String(), c.name+" snapshot "+zipPath.String()) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 552 | zipRule.DeleteTemporaryFiles() |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 553 | c.snapshotZipFile = android.OptionalPathForPath(zipPath) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 554 | } |
| 555 | |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 556 | func (c *snapshotSingleton) MakeVars(ctx android.MakeVarsContext) { |
| 557 | ctx.Strict( |
| 558 | c.makeVar, |
| 559 | c.snapshotZipFile.String()) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 560 | } |