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