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