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