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 | |
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 | |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [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. |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 118 | if c, ok := ctx.Module().(*Module); ok { |
| 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 | |
| 140 | if c, ok := ctx.Module().(*Module); ok { |
| 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. |
Inseob Kim | 7cf1465 | 2021-01-06 23:06:52 +0900 | [diff] [blame] | 150 | 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] | 151 | if !m.Enabled() || m.Properties.HideFromMake { |
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 |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [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 |
| 180 | if _, ok := m.linker.(*kernelHeadersDecorator); ok { |
| 181 | return false |
| 182 | } |
Justin Yun | f2664c6 | 2020-07-30 18:57:54 +0900 | [diff] [blame] | 183 | // skip llndk_library and llndk_headers which are backward compatible |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 184 | if m.IsLlndk() { |
| 185 | return false |
| 186 | } |
Justin Yun | f2664c6 | 2020-07-30 18:57:54 +0900 | [diff] [blame] | 187 | if _, ok := m.linker.(*llndkStubDecorator); ok { |
| 188 | return false |
| 189 | } |
| 190 | if _, ok := m.linker.(*llndkHeadersDecorator); ok { |
| 191 | return false |
| 192 | } |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 193 | |
| 194 | // Libraries |
| 195 | if l, ok := m.linker.(snapshotLibraryInterface); ok { |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 196 | if m.sanitize != nil { |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 197 | // 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] | 198 | // Always use unsanitized variants of them. |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 199 | for _, t := range []SanitizerType{scs, hwasan} { |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 200 | if !l.shared() && m.sanitize.isSanitizerEnabled(t) { |
| 201 | return false |
| 202 | } |
| 203 | } |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 204 | // cfi also exports both variants. But for static, we capture both. |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 205 | // This is because cfi static libraries can't be linked from non-cfi modules, |
| 206 | // 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] | 207 | if !l.static() && !l.shared() && m.sanitize.isSanitizerEnabled(cfi) { |
| 208 | return false |
| 209 | } |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 210 | } |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 211 | if l.static() { |
Justin Yun | e09ac17 | 2021-01-20 19:49:01 +0900 | [diff] [blame] | 212 | return m.outputFile.Valid() && !image.private(m) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 213 | } |
| 214 | if l.shared() { |
Bill Peckham | 7d3f096 | 2020-06-29 16:49:15 -0700 | [diff] [blame] | 215 | if !m.outputFile.Valid() { |
| 216 | return false |
| 217 | } |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 218 | if image.includeVndk() { |
| 219 | if !m.IsVndk() { |
| 220 | return true |
| 221 | } |
Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 222 | return m.IsVndkExt() |
Bill Peckham | 7d3f096 | 2020-06-29 16:49:15 -0700 | [diff] [blame] | 223 | } |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 224 | } |
| 225 | return true |
| 226 | } |
| 227 | |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 228 | // Binaries and Objects |
| 229 | if m.binary() || m.object() { |
Justin Yun | e09ac17 | 2021-01-20 19:49:01 +0900 | [diff] [blame] | 230 | return m.outputFile.Valid() |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 231 | } |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 232 | |
| 233 | return false |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 234 | } |
| 235 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 236 | // This is to be saved as .json files, which is for development/vendor_snapshot/update.py. |
| 237 | // These flags become Android.bp snapshot module properties. |
| 238 | type snapshotJsonFlags struct { |
| 239 | ModuleName string `json:",omitempty"` |
| 240 | RelativeInstallPath string `json:",omitempty"` |
Colin Cross | a889080 | 2021-01-22 14:06:33 -0800 | [diff] [blame] | 241 | AndroidMkSuffix string `json:",omitempty"` |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 242 | |
| 243 | // library flags |
| 244 | ExportedDirs []string `json:",omitempty"` |
| 245 | ExportedSystemDirs []string `json:",omitempty"` |
| 246 | ExportedFlags []string `json:",omitempty"` |
| 247 | Sanitize string `json:",omitempty"` |
| 248 | SanitizeMinimalDep bool `json:",omitempty"` |
| 249 | SanitizeUbsanDep bool `json:",omitempty"` |
| 250 | |
| 251 | // binary flags |
| 252 | Symlinks []string `json:",omitempty"` |
| 253 | |
| 254 | // dependencies |
| 255 | SharedLibs []string `json:",omitempty"` |
| 256 | RuntimeLibs []string `json:",omitempty"` |
| 257 | Required []string `json:",omitempty"` |
| 258 | |
| 259 | // extra config files |
| 260 | InitRc []string `json:",omitempty"` |
| 261 | VintfFragments []string `json:",omitempty"` |
| 262 | } |
| 263 | |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 264 | func (c *snapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 265 | if !c.image.shouldGenerateSnapshot(ctx) { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 266 | return |
| 267 | } |
| 268 | |
| 269 | var snapshotOutputs android.Paths |
| 270 | |
| 271 | /* |
| 272 | Vendor snapshot zipped artifacts directory structure: |
| 273 | {SNAPSHOT_ARCH}/ |
| 274 | arch-{TARGET_ARCH}-{TARGET_ARCH_VARIANT}/ |
| 275 | shared/ |
| 276 | (.so shared libraries) |
| 277 | static/ |
| 278 | (.a static libraries) |
| 279 | header/ |
| 280 | (header only libraries) |
| 281 | binary/ |
| 282 | (executable binaries) |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 283 | object/ |
| 284 | (.o object files) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 285 | arch-{TARGET_2ND_ARCH}-{TARGET_2ND_ARCH_VARIANT}/ |
| 286 | shared/ |
| 287 | (.so shared libraries) |
| 288 | static/ |
| 289 | (.a static libraries) |
| 290 | header/ |
| 291 | (header only libraries) |
| 292 | binary/ |
| 293 | (executable binaries) |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 294 | object/ |
| 295 | (.o object files) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 296 | NOTICE_FILES/ |
| 297 | (notice files, e.g. libbase.txt) |
| 298 | configs/ |
| 299 | (config files, e.g. init.rc files, vintf_fragments.xml files, etc.) |
| 300 | include/ |
| 301 | (header files of same directory structure with source tree) |
| 302 | */ |
| 303 | |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 304 | snapshotDir := c.name + "-snapshot" |
Inseob Kim | e9aec6a | 2021-01-05 20:03:22 +0900 | [diff] [blame] | 305 | if c.fake { |
| 306 | // If this is a fake snapshot singleton, place all files under fake/ subdirectory to avoid |
| 307 | // collision with real snapshot files |
| 308 | snapshotDir = filepath.Join("fake", snapshotDir) |
| 309 | } |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 310 | snapshotArchDir := filepath.Join(snapshotDir, ctx.DeviceConfig().DeviceArch()) |
| 311 | |
| 312 | includeDir := filepath.Join(snapshotArchDir, "include") |
| 313 | configsDir := filepath.Join(snapshotArchDir, "configs") |
| 314 | noticeDir := filepath.Join(snapshotArchDir, "NOTICE_FILES") |
| 315 | |
| 316 | installedNotices := make(map[string]bool) |
| 317 | installedConfigs := make(map[string]bool) |
| 318 | |
| 319 | var headers android.Paths |
| 320 | |
Jose Galmes | 0a942a0 | 2021-02-03 14:23:15 -0800 | [diff] [blame] | 321 | copyFile := func(ctx android.SingletonContext, path android.Path, out string, fake bool) android.OutputPath { |
| 322 | if fake { |
| 323 | // All prebuilt binaries and headers are installed by copyFile function. This makes a fake |
| 324 | // snapshot just touch prebuilts and headers, rather than installing real files. |
Inseob Kim | e9aec6a | 2021-01-05 20:03:22 +0900 | [diff] [blame] | 325 | return writeStringToFileRule(ctx, "", out) |
Jose Galmes | 0a942a0 | 2021-02-03 14:23:15 -0800 | [diff] [blame] | 326 | } else { |
| 327 | return copyFileRule(ctx, path, out) |
Inseob Kim | e9aec6a | 2021-01-05 20:03:22 +0900 | [diff] [blame] | 328 | } |
| 329 | } |
| 330 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 331 | // installSnapshot function copies prebuilt file (.so, .a, or executable) and json flag file. |
| 332 | // For executables, init_rc and vintf_fragments files are also copied. |
Jose Galmes | 0a942a0 | 2021-02-03 14:23:15 -0800 | [diff] [blame] | 333 | installSnapshot := func(m *Module, fake bool) android.Paths { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 334 | targetArch := "arch-" + m.Target().Arch.ArchType.String() |
| 335 | if m.Target().Arch.ArchVariant != "" { |
| 336 | targetArch += "-" + m.Target().Arch.ArchVariant |
| 337 | } |
| 338 | |
| 339 | var ret android.Paths |
| 340 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 341 | prop := snapshotJsonFlags{} |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 342 | |
| 343 | // Common properties among snapshots. |
| 344 | prop.ModuleName = ctx.ModuleName(m) |
Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 345 | if c.supportsVndkExt && m.IsVndkExt() { |
Bill Peckham | 7d3f096 | 2020-06-29 16:49:15 -0700 | [diff] [blame] | 346 | // vndk exts are installed to /vendor/lib(64)?/vndk(-sp)? |
| 347 | if m.isVndkSp() { |
| 348 | prop.RelativeInstallPath = "vndk-sp" |
| 349 | } else { |
| 350 | prop.RelativeInstallPath = "vndk" |
| 351 | } |
| 352 | } else { |
| 353 | prop.RelativeInstallPath = m.RelativeInstallPath() |
| 354 | } |
Colin Cross | a889080 | 2021-01-22 14:06:33 -0800 | [diff] [blame] | 355 | prop.AndroidMkSuffix = m.Properties.SubName |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 356 | prop.RuntimeLibs = m.Properties.SnapshotRuntimeLibs |
| 357 | prop.Required = m.RequiredModuleNames() |
| 358 | for _, path := range m.InitRc() { |
| 359 | prop.InitRc = append(prop.InitRc, filepath.Join("configs", path.Base())) |
| 360 | } |
| 361 | for _, path := range m.VintfFragments() { |
| 362 | prop.VintfFragments = append(prop.VintfFragments, filepath.Join("configs", path.Base())) |
| 363 | } |
| 364 | |
| 365 | // install config files. ignores any duplicates. |
| 366 | for _, path := range append(m.InitRc(), m.VintfFragments()...) { |
| 367 | out := filepath.Join(configsDir, path.Base()) |
| 368 | if !installedConfigs[out] { |
| 369 | installedConfigs[out] = true |
Jose Galmes | 0a942a0 | 2021-02-03 14:23:15 -0800 | [diff] [blame] | 370 | ret = append(ret, copyFile(ctx, path, out, fake)) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 371 | } |
| 372 | } |
| 373 | |
| 374 | var propOut string |
| 375 | |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 376 | if l, ok := m.linker.(snapshotLibraryInterface); ok { |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 377 | exporterInfo := ctx.ModuleProvider(m, FlagExporterInfoProvider).(FlagExporterInfo) |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 378 | |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 379 | // library flags |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 380 | prop.ExportedFlags = exporterInfo.Flags |
| 381 | for _, dir := range exporterInfo.IncludeDirs { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 382 | prop.ExportedDirs = append(prop.ExportedDirs, filepath.Join("include", dir.String())) |
| 383 | } |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 384 | for _, dir := range exporterInfo.SystemIncludeDirs { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 385 | prop.ExportedSystemDirs = append(prop.ExportedSystemDirs, filepath.Join("include", dir.String())) |
| 386 | } |
| 387 | // shared libs dependencies aren't meaningful on static or header libs |
| 388 | if l.shared() { |
| 389 | prop.SharedLibs = m.Properties.SnapshotSharedLibs |
| 390 | } |
| 391 | if l.static() && m.sanitize != nil { |
| 392 | prop.SanitizeMinimalDep = m.sanitize.Properties.MinimalRuntimeDep || enableMinimalRuntime(m.sanitize) |
| 393 | prop.SanitizeUbsanDep = m.sanitize.Properties.UbsanRuntimeDep || enableUbsanRuntime(m.sanitize) |
| 394 | } |
| 395 | |
| 396 | var libType string |
| 397 | if l.static() { |
| 398 | libType = "static" |
| 399 | } else if l.shared() { |
| 400 | libType = "shared" |
| 401 | } else { |
| 402 | libType = "header" |
| 403 | } |
| 404 | |
| 405 | var stem string |
| 406 | |
| 407 | // install .a or .so |
| 408 | if libType != "header" { |
| 409 | libPath := m.outputFile.Path() |
| 410 | stem = libPath.Base() |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 411 | if l.static() && m.sanitize != nil && m.sanitize.isSanitizerEnabled(cfi) { |
| 412 | // both cfi and non-cfi variant for static libraries can exist. |
| 413 | // attach .cfi to distinguish between cfi and non-cfi. |
| 414 | // e.g. libbase.a -> libbase.cfi.a |
| 415 | ext := filepath.Ext(stem) |
| 416 | stem = strings.TrimSuffix(stem, ext) + ".cfi" + ext |
| 417 | prop.Sanitize = "cfi" |
| 418 | prop.ModuleName += ".cfi" |
| 419 | } |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 420 | snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, libType, stem) |
Jose Galmes | 0a942a0 | 2021-02-03 14:23:15 -0800 | [diff] [blame] | 421 | ret = append(ret, copyFile(ctx, libPath, snapshotLibOut, fake)) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 422 | } else { |
| 423 | stem = ctx.ModuleName(m) |
| 424 | } |
| 425 | |
| 426 | propOut = filepath.Join(snapshotArchDir, targetArch, libType, stem+".json") |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 427 | } else if m.binary() { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 428 | // binary flags |
| 429 | prop.Symlinks = m.Symlinks() |
| 430 | prop.SharedLibs = m.Properties.SnapshotSharedLibs |
| 431 | |
| 432 | // install bin |
| 433 | binPath := m.outputFile.Path() |
| 434 | snapshotBinOut := filepath.Join(snapshotArchDir, targetArch, "binary", binPath.Base()) |
Jose Galmes | 0a942a0 | 2021-02-03 14:23:15 -0800 | [diff] [blame] | 435 | ret = append(ret, copyFile(ctx, binPath, snapshotBinOut, fake)) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 436 | propOut = snapshotBinOut + ".json" |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 437 | } else if m.object() { |
| 438 | // object files aren't installed to the device, so their names can conflict. |
| 439 | // Use module name as stem. |
| 440 | objPath := m.outputFile.Path() |
| 441 | snapshotObjOut := filepath.Join(snapshotArchDir, targetArch, "object", |
| 442 | ctx.ModuleName(m)+filepath.Ext(objPath.Base())) |
Jose Galmes | 0a942a0 | 2021-02-03 14:23:15 -0800 | [diff] [blame] | 443 | ret = append(ret, copyFile(ctx, objPath, snapshotObjOut, fake)) |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 444 | propOut = snapshotObjOut + ".json" |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 445 | } else { |
| 446 | ctx.Errorf("unknown module %q in vendor snapshot", m.String()) |
| 447 | return nil |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | j, err := json.Marshal(prop) |
| 451 | if err != nil { |
| 452 | ctx.Errorf("json marshal to %q failed: %#v", propOut, err) |
| 453 | return nil |
| 454 | } |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 455 | ret = append(ret, writeStringToFileRule(ctx, string(j), propOut)) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 456 | |
| 457 | return ret |
| 458 | } |
| 459 | |
| 460 | ctx.VisitAllModules(func(module android.Module) { |
| 461 | m, ok := module.(*Module) |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 462 | if !ok { |
| 463 | return |
| 464 | } |
| 465 | |
| 466 | moduleDir := ctx.ModuleDir(module) |
Justin DeMartino | 383bfb3 | 2021-02-24 10:49:43 -0800 | [diff] [blame] | 467 | inProprietaryPath := c.image.isProprietaryPath(moduleDir, ctx.DeviceConfig()) |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 468 | apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo) |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 469 | |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 470 | if c.image.excludeFromSnapshot(m) { |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 471 | if inProprietaryPath { |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 472 | // Error: exclude_from_vendor_snapshot applies |
| 473 | // to framework-path modules only. |
| 474 | ctx.Errorf("module %q in vendor proprietary path %q may not use \"exclude_from_vendor_snapshot: true\"", m.String(), moduleDir) |
| 475 | return |
| 476 | } |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 477 | } |
| 478 | |
Inseob Kim | 7cf1465 | 2021-01-06 23:06:52 +0900 | [diff] [blame] | 479 | if !isSnapshotAware(ctx.DeviceConfig(), m, inProprietaryPath, apexInfo, c.image) { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 480 | return |
| 481 | } |
| 482 | |
Jose Galmes | 0a942a0 | 2021-02-03 14:23:15 -0800 | [diff] [blame] | 483 | // If we are using directed snapshot and a module is not included in the |
| 484 | // list, we will still include the module as if it was a fake module. |
| 485 | // The reason is that soong needs all the dependencies to be present, even |
| 486 | // if they are not using during the build. |
| 487 | installAsFake := c.fake |
| 488 | if c.image.excludeFromDirectedSnapshot(ctx.DeviceConfig(), m.BaseModuleName()) { |
| 489 | installAsFake = true |
| 490 | } |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 491 | |
Jose Galmes | 0a942a0 | 2021-02-03 14:23:15 -0800 | [diff] [blame] | 492 | // installSnapshot installs prebuilts and json flag files |
| 493 | snapshotOutputs = append(snapshotOutputs, installSnapshot(m, installAsFake)...) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 494 | // 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] | 495 | if l, ok := m.linker.(snapshotLibraryInterface); ok { |
| 496 | headers = append(headers, l.snapshotHeaders()...) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 497 | } |
| 498 | |
Bob Badour | a75b057 | 2020-02-18 20:21:55 -0800 | [diff] [blame] | 499 | if len(m.NoticeFiles()) > 0 { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 500 | noticeName := ctx.ModuleName(m) + ".txt" |
| 501 | noticeOut := filepath.Join(noticeDir, noticeName) |
| 502 | // skip already copied notice file |
| 503 | if !installedNotices[noticeOut] { |
| 504 | installedNotices[noticeOut] = true |
Inseob Kim | e9aec6a | 2021-01-05 20:03:22 +0900 | [diff] [blame] | 505 | snapshotOutputs = append(snapshotOutputs, combineNoticesRule(ctx, m.NoticeFiles(), noticeOut)) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 506 | } |
| 507 | } |
| 508 | }) |
| 509 | |
| 510 | // install all headers after removing duplicates |
| 511 | for _, header := range android.FirstUniquePaths(headers) { |
Jose Galmes | 0a942a0 | 2021-02-03 14:23:15 -0800 | [diff] [blame] | 512 | 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] | 513 | } |
| 514 | |
| 515 | // All artifacts are ready. Sort them to normalize ninja and then zip. |
| 516 | sort.Slice(snapshotOutputs, func(i, j int) bool { |
| 517 | return snapshotOutputs[i].String() < snapshotOutputs[j].String() |
| 518 | }) |
| 519 | |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 520 | zipPath := android.PathForOutput( |
| 521 | ctx, |
| 522 | snapshotDir, |
| 523 | c.name+"-"+ctx.Config().DeviceName()+".zip") |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 524 | zipRule := android.NewRuleBuilder(pctx, ctx) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 525 | |
| 526 | // 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] | 527 | snapshotOutputList := android.PathForOutput( |
| 528 | ctx, |
| 529 | snapshotDir, |
| 530 | c.name+"-"+ctx.Config().DeviceName()+"_list") |
Colin Cross | 70c4741 | 2021-03-12 17:48:14 -0800 | [diff] [blame^] | 531 | rspFile := snapshotOutputList.ReplaceExtension(ctx, "rsp") |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 532 | zipRule.Command(). |
| 533 | Text("tr"). |
| 534 | FlagWithArg("-d ", "\\'"). |
Colin Cross | 70c4741 | 2021-03-12 17:48:14 -0800 | [diff] [blame^] | 535 | FlagWithRspFileInputList("< ", rspFile, snapshotOutputs). |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 536 | FlagWithOutput("> ", snapshotOutputList) |
| 537 | |
| 538 | zipRule.Temporary(snapshotOutputList) |
| 539 | |
| 540 | zipRule.Command(). |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 541 | BuiltTool("soong_zip"). |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 542 | FlagWithOutput("-o ", zipPath). |
| 543 | FlagWithArg("-C ", android.PathForOutput(ctx, snapshotDir).String()). |
| 544 | FlagWithInput("-l ", snapshotOutputList) |
| 545 | |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 546 | zipRule.Build(zipPath.String(), c.name+" snapshot "+zipPath.String()) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 547 | zipRule.DeleteTemporaryFiles() |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 548 | c.snapshotZipFile = android.OptionalPathForPath(zipPath) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 549 | } |
| 550 | |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 551 | func (c *snapshotSingleton) MakeVars(ctx android.MakeVarsContext) { |
| 552 | ctx.Strict( |
| 553 | c.makeVar, |
| 554 | c.snapshotZipFile.String()) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 555 | } |