blob: d2c29d631d6ed4d3bcceafe4247cff1187870e95 [file] [log] [blame]
Inseob Kim8471cda2019-11-15 09:59:12 +09001// 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.
14package cc
15
Inseob Kimde5744a2020-12-02 13:14:28 +090016// 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 Kim8471cda2019-11-15 09:59:12 +090020import (
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 Galmesf7294582020-11-13 12:07:36 -080031var vendorSnapshotSingleton = snapshotSingleton{
32 "vendor",
33 "SOONG_VENDOR_SNAPSHOT_ZIP",
34 android.OptionalPath{},
35 true,
Inseob Kimde5744a2020-12-02 13:14:28 +090036 vendorSnapshotImageSingleton,
Jose Galmesf7294582020-11-13 12:07:36 -080037}
38
39var recoverySnapshotSingleton = snapshotSingleton{
40 "recovery",
41 "SOONG_RECOVERY_SNAPSHOT_ZIP",
42 android.OptionalPath{},
43 false,
Inseob Kimde5744a2020-12-02 13:14:28 +090044 recoverySnapshotImageSingleton,
Inseob Kim8471cda2019-11-15 09:59:12 +090045}
46
47func VendorSnapshotSingleton() android.Singleton {
Jose Galmesf7294582020-11-13 12:07:36 -080048 return &vendorSnapshotSingleton
Inseob Kim8471cda2019-11-15 09:59:12 +090049}
50
Jose Galmesf7294582020-11-13 12:07:36 -080051func RecoverySnapshotSingleton() android.Singleton {
52 return &recoverySnapshotSingleton
53}
54
55type 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 Kimde5744a2020-12-02 13:14:28 +090072 image snapshotImage
Inseob Kim8471cda2019-11-15 09:59:12 +090073}
74
75var (
76 // Modules under following directories are ignored. They are OEM's and vendor's
Daniel Norman713387d2020-07-28 16:04:38 -070077 // proprietary modules(device/, kernel/, vendor/, and hardware/).
Inseob Kim8471cda2019-11-15 09:59:12 +090078 vendorProprietaryDirs = []string{
79 "device",
Daniel Norman713387d2020-07-28 16:04:38 -070080 "kernel",
Inseob Kim8471cda2019-11-15 09:59:12 +090081 "vendor",
82 "hardware",
83 }
84
Jose Galmesf7294582020-11-13 12:07:36 -080085 // Modules under following directories are ignored. They are OEM's and vendor's
86 // proprietary modules(device/, kernel/, vendor/, and hardware/).
Jose Galmesf7294582020-11-13 12:07:36 -080087 recoveryProprietaryDirs = []string{
88 "bootable/recovery",
89 "device",
90 "hardware",
91 "kernel",
92 "vendor",
93 }
94
Inseob Kim8471cda2019-11-15 09:59:12 +090095 // Modules under following directories are included as they are in AOSP,
Daniel Norman713387d2020-07-28 16:04:38 -070096 // although hardware/ and kernel/ are normally for vendor's own.
Inseob Kim8471cda2019-11-15 09:59:12 +090097 aospDirsUnderProprietary = []string{
Daniel Norman713387d2020-07-28 16:04:38 -070098 "kernel/configs",
99 "kernel/prebuilts",
100 "kernel/tests",
Inseob Kim8471cda2019-11-15 09:59:12 +0900101 "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.
110func isVendorProprietaryPath(dir string) bool {
Jose Galmesf7294582020-11-13 12:07:36 -0800111 return isProprietaryPath(dir, vendorProprietaryDirs)
112}
113
114func 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.
120func isProprietaryPath(dir string, proprietaryDirs []string) bool {
121 for _, p := range proprietaryDirs {
Inseob Kim8471cda2019-11-15 09:59:12 +0900122 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 Peckham945441c2020-08-31 16:07:58 -0700139func isVendorProprietaryModule(ctx android.BaseModuleContext) bool {
Bill Peckham945441c2020-08-31 16:07:58 -0700140 // Any module in a vendor proprietary path is a vendor proprietary
141 // module.
Bill Peckham945441c2020-08-31 16:07:58 -0700142 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 Peckham945441c2020-08-31 16:07:58 -0700150 if c, ok := ctx.Module().(*Module); ok {
151 if c.ExcludeFromVendorSnapshot() {
152 return true
153 }
154 }
155
156 return false
157}
158
Inseob Kim8471cda2019-11-15 09:59:12 +0900159// 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 Kimde5744a2020-12-02 13:14:28 +0900165func isVendorSnapshotAware(m *Module, inVendorProprietaryPath bool, apexInfo android.ApexInfo) bool {
166 return isSnapshotAware(m, inVendorProprietaryPath, apexInfo, vendorSnapshotImageSingleton)
Jose Galmesf7294582020-11-13 12:07:36 -0800167}
168
Inseob Kimde5744a2020-12-02 13:14:28 +0900169// 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.
174func isRecoverySnapshotAware(m *Module, inRecoveryProprietaryPath bool, apexInfo android.ApexInfo) bool {
175 return isSnapshotAware(m, inRecoveryProprietaryPath, apexInfo, recoverySnapshotImageSingleton)
Jose Galmesf7294582020-11-13 12:07:36 -0800176}
177
Inseob Kimde5744a2020-12-02 13:14:28 +0900178// Determines if the module is a candidate for snapshot.
179func isSnapshotAware(m *Module, inProprietaryPath bool, apexInfo android.ApexInfo, image snapshotImage) bool {
Inseob Kim7f283f42020-06-01 21:53:49 +0900180 if !m.Enabled() || m.Properties.HideFromMake {
Inseob Kim8471cda2019-11-15 09:59:12 +0900181 return false
182 }
Martin Stjernholm809d5182020-09-10 01:46:05 +0100183 // When android/prebuilt.go selects between source and prebuilt, it sets
Colin Crossa9c8c9f2020-12-16 10:20:23 -0800184 // HideFromMake on the other one to avoid duplicate install rules in make.
185 if m.IsHideFromMake() {
Martin Stjernholm809d5182020-09-10 01:46:05 +0100186 return false
187 }
Jose Galmesf7294582020-11-13 12:07:36 -0800188 // skip proprietary modules, but (for the vendor snapshot only)
189 // include all VNDK (static)
190 if inProprietaryPath && (!image.includeVndk() || !m.IsVndk()) {
Bill Peckham945441c2020-08-31 16:07:58 -0700191 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 Kim8471cda2019-11-15 09:59:12 +0900196 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 Kimde5744a2020-12-02 13:14:28 +0900204 // the module must be installed in target image
Jose Galmesf7294582020-11-13 12:07:36 -0800205 if !apexInfo.IsForPlatform() || m.isSnapshotPrebuilt() || !image.inImage(m)() {
Inseob Kim8471cda2019-11-15 09:59:12 +0900206 return false
207 }
Inseob Kim65ca36a2020-06-11 13:55:45 +0900208 // skip kernel_headers which always depend on vendor
209 if _, ok := m.linker.(*kernelHeadersDecorator); ok {
210 return false
211 }
Justin Yunf2664c62020-07-30 18:57:54 +0900212 // skip llndk_library and llndk_headers which are backward compatible
Colin Cross127bb8b2020-12-16 16:46:01 -0800213 if m.IsLlndk() {
214 return false
215 }
Justin Yunf2664c62020-07-30 18:57:54 +0900216 if _, ok := m.linker.(*llndkStubDecorator); ok {
217 return false
218 }
219 if _, ok := m.linker.(*llndkHeadersDecorator); ok {
220 return false
221 }
Inseob Kim8471cda2019-11-15 09:59:12 +0900222
223 // Libraries
224 if l, ok := m.linker.(snapshotLibraryInterface); ok {
Inseob Kim7f283f42020-06-01 21:53:49 +0900225 if m.sanitize != nil {
Inseob Kimc42f2f22020-07-29 20:32:10 +0900226 // scs and hwasan export both sanitized and unsanitized variants for static and header
Inseob Kim7f283f42020-06-01 21:53:49 +0900227 // Always use unsanitized variants of them.
Inseob Kimc42f2f22020-07-29 20:32:10 +0900228 for _, t := range []sanitizerType{scs, hwasan} {
Inseob Kim7f283f42020-06-01 21:53:49 +0900229 if !l.shared() && m.sanitize.isSanitizerEnabled(t) {
230 return false
231 }
232 }
Inseob Kimc42f2f22020-07-29 20:32:10 +0900233 // cfi also exports both variants. But for static, we capture both.
Inseob Kimde5744a2020-12-02 13:14:28 +0900234 // 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 Kimc42f2f22020-07-29 20:32:10 +0900236 if !l.static() && !l.shared() && m.sanitize.isSanitizerEnabled(cfi) {
237 return false
238 }
Inseob Kim7f283f42020-06-01 21:53:49 +0900239 }
Inseob Kim8471cda2019-11-15 09:59:12 +0900240 if l.static() {
Jose Galmesf7294582020-11-13 12:07:36 -0800241 return m.outputFile.Valid() && proptools.BoolDefault(image.available(m), true)
Inseob Kim8471cda2019-11-15 09:59:12 +0900242 }
243 if l.shared() {
Bill Peckham7d3f0962020-06-29 16:49:15 -0700244 if !m.outputFile.Valid() {
245 return false
246 }
Jose Galmesf7294582020-11-13 12:07:36 -0800247 if image.includeVndk() {
248 if !m.IsVndk() {
249 return true
250 }
Ivan Lozanof9e21722020-12-02 09:00:51 -0500251 return m.IsVndkExt()
Bill Peckham7d3f0962020-06-29 16:49:15 -0700252 }
Inseob Kim8471cda2019-11-15 09:59:12 +0900253 }
254 return true
255 }
256
Inseob Kim1042d292020-06-01 23:23:05 +0900257 // Binaries and Objects
258 if m.binary() || m.object() {
Jose Galmesf7294582020-11-13 12:07:36 -0800259 return m.outputFile.Valid() && proptools.BoolDefault(image.available(m), true)
Inseob Kim8471cda2019-11-15 09:59:12 +0900260 }
Inseob Kim7f283f42020-06-01 21:53:49 +0900261
262 return false
Inseob Kim8471cda2019-11-15 09:59:12 +0900263}
264
Inseob Kimde5744a2020-12-02 13:14:28 +0900265// 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.
267type 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 Galmesf7294582020-11-13 12:07:36 -0800292func (c *snapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) {
Inseob Kim8471cda2019-11-15 09:59:12 +0900293 // 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 Kim1042d292020-06-01 23:23:05 +0900312 object/
313 (.o object files)
Inseob Kim8471cda2019-11-15 09:59:12 +0900314 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 Kim1042d292020-06-01 23:23:05 +0900323 object/
324 (.o object files)
Inseob Kim8471cda2019-11-15 09:59:12 +0900325 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 Galmesf7294582020-11-13 12:07:36 -0800333 snapshotDir := c.name + "-snapshot"
Inseob Kim8471cda2019-11-15 09:59:12 +0900334 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 Kimde5744a2020-12-02 13:14:28 +0900345 // 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 Kim8471cda2019-11-15 09:59:12 +0900347 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 Kimde5744a2020-12-02 13:14:28 +0900355 prop := snapshotJsonFlags{}
Inseob Kim8471cda2019-11-15 09:59:12 +0900356
357 // Common properties among snapshots.
358 prop.ModuleName = ctx.ModuleName(m)
Ivan Lozanof9e21722020-12-02 09:00:51 -0500359 if c.supportsVndkExt && m.IsVndkExt() {
Bill Peckham7d3f0962020-06-29 16:49:15 -0700360 // 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 Kim8471cda2019-11-15 09:59:12 +0900369 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 Kimde5744a2020-12-02 13:14:28 +0900383 ret = append(ret, copyFileRule(ctx, path, out))
Inseob Kim8471cda2019-11-15 09:59:12 +0900384 }
385 }
386
387 var propOut string
388
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900389 if l, ok := m.linker.(snapshotLibraryInterface); ok {
Colin Cross0de8a1e2020-09-18 14:15:30 -0700390 exporterInfo := ctx.ModuleProvider(m, FlagExporterInfoProvider).(FlagExporterInfo)
Inseob Kimc42f2f22020-07-29 20:32:10 +0900391
Inseob Kim8471cda2019-11-15 09:59:12 +0900392 // library flags
Colin Cross0de8a1e2020-09-18 14:15:30 -0700393 prop.ExportedFlags = exporterInfo.Flags
394 for _, dir := range exporterInfo.IncludeDirs {
Inseob Kim8471cda2019-11-15 09:59:12 +0900395 prop.ExportedDirs = append(prop.ExportedDirs, filepath.Join("include", dir.String()))
396 }
Colin Cross0de8a1e2020-09-18 14:15:30 -0700397 for _, dir := range exporterInfo.SystemIncludeDirs {
Inseob Kim8471cda2019-11-15 09:59:12 +0900398 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 Kimc42f2f22020-07-29 20:32:10 +0900424 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 Kim8471cda2019-11-15 09:59:12 +0900433 snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, libType, stem)
Inseob Kimde5744a2020-12-02 13:14:28 +0900434 ret = append(ret, copyFileRule(ctx, libPath, snapshotLibOut))
Inseob Kim8471cda2019-11-15 09:59:12 +0900435 } else {
436 stem = ctx.ModuleName(m)
437 }
438
439 propOut = filepath.Join(snapshotArchDir, targetArch, libType, stem+".json")
Inseob Kim7f283f42020-06-01 21:53:49 +0900440 } else if m.binary() {
Inseob Kim8471cda2019-11-15 09:59:12 +0900441 // 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 Kimde5744a2020-12-02 13:14:28 +0900448 ret = append(ret, copyFileRule(ctx, binPath, snapshotBinOut))
Inseob Kim8471cda2019-11-15 09:59:12 +0900449 propOut = snapshotBinOut + ".json"
Inseob Kim1042d292020-06-01 23:23:05 +0900450 } 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 Kimde5744a2020-12-02 13:14:28 +0900456 ret = append(ret, copyFileRule(ctx, objPath, snapshotObjOut))
Inseob Kim1042d292020-06-01 23:23:05 +0900457 propOut = snapshotObjOut + ".json"
Inseob Kim7f283f42020-06-01 21:53:49 +0900458 } else {
459 ctx.Errorf("unknown module %q in vendor snapshot", m.String())
460 return nil
Inseob Kim8471cda2019-11-15 09:59:12 +0900461 }
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 Kimde5744a2020-12-02 13:14:28 +0900468 ret = append(ret, writeStringToFileRule(ctx, string(j), propOut))
Inseob Kim8471cda2019-11-15 09:59:12 +0900469
470 return ret
471 }
472
473 ctx.VisitAllModules(func(module android.Module) {
474 m, ok := module.(*Module)
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900475 if !ok {
476 return
477 }
478
479 moduleDir := ctx.ModuleDir(module)
Jose Galmesf7294582020-11-13 12:07:36 -0800480 inProprietaryPath := c.image.isProprietaryPath(moduleDir)
Colin Cross56a83212020-09-15 18:30:11 -0700481 apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo)
Bill Peckham945441c2020-08-31 16:07:58 -0700482
483 if m.ExcludeFromVendorSnapshot() {
Jose Galmesf7294582020-11-13 12:07:36 -0800484 if inProprietaryPath {
Bill Peckham945441c2020-08-31 16:07:58 -0700485 // 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 Galmesf7294582020-11-13 12:07:36 -0800490 if Bool(c.image.available(m)) {
Bill Peckham945441c2020-08-31 16:07:58 -0700491 // Error: may not combine "vendor_available:
492 // true" with "exclude_from_vendor_snapshot:
493 // true".
Jose Galmesf7294582020-11-13 12:07:36 -0800494 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 Peckham945441c2020-08-31 16:07:58 -0700499 return
500 }
501 }
502
Inseob Kimde5744a2020-12-02 13:14:28 +0900503 if !isSnapshotAware(m, inProprietaryPath, apexInfo, c.image) {
Inseob Kim8471cda2019-11-15 09:59:12 +0900504 return
505 }
506
Inseob Kimde5744a2020-12-02 13:14:28 +0900507 // installSnapshot installs prebuilts and json flag files
Inseob Kim8471cda2019-11-15 09:59:12 +0900508 snapshotOutputs = append(snapshotOutputs, installSnapshot(m)...)
Inseob Kimde5744a2020-12-02 13:14:28 +0900509
510 // just gather headers and notice files here, because they are to be deduplicated
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900511 if l, ok := m.linker.(snapshotLibraryInterface); ok {
512 headers = append(headers, l.snapshotHeaders()...)
Inseob Kim8471cda2019-11-15 09:59:12 +0900513 }
514
Bob Badoura75b0572020-02-18 20:21:55 -0800515 if len(m.NoticeFiles()) > 0 {
Inseob Kim8471cda2019-11-15 09:59:12 +0900516 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 Kimde5744a2020-12-02 13:14:28 +0900521 snapshotOutputs = append(snapshotOutputs, combineNoticesRule(
Bob Badoura75b0572020-02-18 20:21:55 -0800522 ctx, m.NoticeFiles(), noticeOut))
Inseob Kim8471cda2019-11-15 09:59:12 +0900523 }
524 }
525 })
526
527 // install all headers after removing duplicates
528 for _, header := range android.FirstUniquePaths(headers) {
Inseob Kimde5744a2020-12-02 13:14:28 +0900529 snapshotOutputs = append(snapshotOutputs, copyFileRule(
Inseob Kim8471cda2019-11-15 09:59:12 +0900530 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 Galmesf7294582020-11-13 12:07:36 -0800538 zipPath := android.PathForOutput(
539 ctx,
540 snapshotDir,
541 c.name+"-"+ctx.Config().DeviceName()+".zip")
Colin Crossf1a035e2020-11-16 17:32:30 -0800542 zipRule := android.NewRuleBuilder(pctx, ctx)
Inseob Kim8471cda2019-11-15 09:59:12 +0900543
544 // filenames in rspfile from FlagWithRspFileInputList might be single-quoted. Remove it with tr
Jose Galmesf7294582020-11-13 12:07:36 -0800545 snapshotOutputList := android.PathForOutput(
546 ctx,
547 snapshotDir,
548 c.name+"-"+ctx.Config().DeviceName()+"_list")
Inseob Kim8471cda2019-11-15 09:59:12 +0900549 zipRule.Command().
550 Text("tr").
551 FlagWithArg("-d ", "\\'").
552 FlagWithRspFileInputList("< ", snapshotOutputs).
553 FlagWithOutput("> ", snapshotOutputList)
554
555 zipRule.Temporary(snapshotOutputList)
556
557 zipRule.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -0800558 BuiltTool("soong_zip").
Inseob Kim8471cda2019-11-15 09:59:12 +0900559 FlagWithOutput("-o ", zipPath).
560 FlagWithArg("-C ", android.PathForOutput(ctx, snapshotDir).String()).
561 FlagWithInput("-l ", snapshotOutputList)
562
Colin Crossf1a035e2020-11-16 17:32:30 -0800563 zipRule.Build(zipPath.String(), c.name+" snapshot "+zipPath.String())
Inseob Kim8471cda2019-11-15 09:59:12 +0900564 zipRule.DeleteTemporaryFiles()
Jose Galmesf7294582020-11-13 12:07:36 -0800565 c.snapshotZipFile = android.OptionalPathForPath(zipPath)
Inseob Kim8471cda2019-11-15 09:59:12 +0900566}
567
Jose Galmesf7294582020-11-13 12:07:36 -0800568func (c *snapshotSingleton) MakeVars(ctx android.MakeVarsContext) {
569 ctx.Strict(
570 c.makeVar,
571 c.snapshotZipFile.String())
Inseob Kim8471cda2019-11-15 09:59:12 +0900572}