blob: 2f68ccad176128c53b6260417b5d2a1c29c4f03e [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
Inseob Kim8471cda2019-11-15 09:59:12 +090026 "android/soong/android"
27)
28
Jose Galmesf7294582020-11-13 12:07:36 -080029var vendorSnapshotSingleton = snapshotSingleton{
30 "vendor",
31 "SOONG_VENDOR_SNAPSHOT_ZIP",
32 android.OptionalPath{},
33 true,
Inseob Kimde5744a2020-12-02 13:14:28 +090034 vendorSnapshotImageSingleton,
Inseob Kime9aec6a2021-01-05 20:03:22 +090035 false, /* fake */
36}
37
38var vendorFakeSnapshotSingleton = snapshotSingleton{
39 "vendor",
40 "SOONG_VENDOR_FAKE_SNAPSHOT_ZIP",
41 android.OptionalPath{},
42 true,
43 vendorSnapshotImageSingleton,
44 true, /* fake */
Jose Galmesf7294582020-11-13 12:07:36 -080045}
46
47var recoverySnapshotSingleton = snapshotSingleton{
48 "recovery",
49 "SOONG_RECOVERY_SNAPSHOT_ZIP",
50 android.OptionalPath{},
51 false,
Inseob Kimde5744a2020-12-02 13:14:28 +090052 recoverySnapshotImageSingleton,
Inseob Kime9aec6a2021-01-05 20:03:22 +090053 false, /* fake */
Inseob Kim8471cda2019-11-15 09:59:12 +090054}
55
56func VendorSnapshotSingleton() android.Singleton {
Jose Galmesf7294582020-11-13 12:07:36 -080057 return &vendorSnapshotSingleton
Inseob Kim8471cda2019-11-15 09:59:12 +090058}
59
Inseob Kime9aec6a2021-01-05 20:03:22 +090060func VendorFakeSnapshotSingleton() android.Singleton {
61 return &vendorFakeSnapshotSingleton
62}
63
Jose Galmesf7294582020-11-13 12:07:36 -080064func RecoverySnapshotSingleton() android.Singleton {
65 return &recoverySnapshotSingleton
66}
67
68type snapshotSingleton struct {
69 // Name, e.g., "vendor", "recovery", "ramdisk".
70 name string
71
72 // Make variable that points to the snapshot file, e.g.,
73 // "SOONG_RECOVERY_SNAPSHOT_ZIP".
74 makeVar string
75
76 // Path to the snapshot zip file.
77 snapshotZipFile android.OptionalPath
78
79 // Whether the image supports VNDK extension modules.
80 supportsVndkExt bool
81
82 // Implementation of the image interface specific to the image
83 // associated with this snapshot (e.g., specific to the vendor image,
84 // recovery image, etc.).
Inseob Kimde5744a2020-12-02 13:14:28 +090085 image snapshotImage
Inseob Kime9aec6a2021-01-05 20:03:22 +090086
87 // Whether this singleton is for fake snapshot or not.
88 // Fake snapshot is a snapshot whose prebuilt binaries and headers are empty.
89 // It is much faster to generate, and can be used to inspect dependencies.
90 fake bool
Inseob Kim8471cda2019-11-15 09:59:12 +090091}
92
Justin DeMartino383bfb32021-02-24 10:49:43 -080093// Determine if a dir under source tree is an SoC-owned proprietary directory based
94// on vendor snapshot configuration
95// Examples: device/, vendor/
96func isVendorProprietaryPath(dir string, deviceConfig android.DeviceConfig) bool {
97 return VendorSnapshotSingleton().(*snapshotSingleton).image.isProprietaryPath(dir, deviceConfig)
Jose Galmesf7294582020-11-13 12:07:36 -080098}
99
Justin DeMartino383bfb32021-02-24 10:49:43 -0800100// Determine if a dir under source tree is an SoC-owned proprietary directory based
101// on recovery snapshot configuration
102// Examples: device/, vendor/
103func isRecoveryProprietaryPath(dir string, deviceConfig android.DeviceConfig) bool {
104 return RecoverySnapshotSingleton().(*snapshotSingleton).image.isProprietaryPath(dir, deviceConfig)
Inseob Kim8471cda2019-11-15 09:59:12 +0900105}
106
Bill Peckham945441c2020-08-31 16:07:58 -0700107func isVendorProprietaryModule(ctx android.BaseModuleContext) bool {
Bill Peckham945441c2020-08-31 16:07:58 -0700108 // Any module in a vendor proprietary path is a vendor proprietary
109 // module.
Justin DeMartino383bfb32021-02-24 10:49:43 -0800110 if isVendorProprietaryPath(ctx.ModuleDir(), ctx.DeviceConfig()) {
Bill Peckham945441c2020-08-31 16:07:58 -0700111 return true
112 }
113
114 // However if the module is not in a vendor proprietary path, it may
115 // still be a vendor proprietary module. This happens for cc modules
116 // that are excluded from the vendor snapshot, and it means that the
117 // vendor has assumed control of the framework-provided module.
Bill Peckham945441c2020-08-31 16:07:58 -0700118 if c, ok := ctx.Module().(*Module); ok {
119 if c.ExcludeFromVendorSnapshot() {
120 return true
121 }
122 }
123
124 return false
125}
126
Jose Galmes6f843bc2020-12-11 13:36:29 -0800127func isRecoveryProprietaryModule(ctx android.BaseModuleContext) bool {
128
Justin Yune09ac172021-01-20 19:49:01 +0900129 // Any module in a recovery proprietary path is a recovery proprietary
Jose Galmes6f843bc2020-12-11 13:36:29 -0800130 // module.
Justin DeMartino383bfb32021-02-24 10:49:43 -0800131 if isRecoveryProprietaryPath(ctx.ModuleDir(), ctx.DeviceConfig()) {
Jose Galmes6f843bc2020-12-11 13:36:29 -0800132 return true
133 }
134
Justin Yune09ac172021-01-20 19:49:01 +0900135 // However if the module is not in a recovery proprietary path, it may
136 // still be a recovery proprietary module. This happens for cc modules
137 // that are excluded from the recovery snapshot, and it means that the
Jose Galmes6f843bc2020-12-11 13:36:29 -0800138 // vendor has assumed control of the framework-provided module.
139
140 if c, ok := ctx.Module().(*Module); ok {
141 if c.ExcludeFromRecoverySnapshot() {
142 return true
143 }
144 }
145
146 return false
147}
148
Inseob Kimde5744a2020-12-02 13:14:28 +0900149// Determines if the module is a candidate for snapshot.
Inseob Kim7cf14652021-01-06 23:06:52 +0900150func isSnapshotAware(cfg android.DeviceConfig, m *Module, inProprietaryPath bool, apexInfo android.ApexInfo, image snapshotImage) bool {
Inseob Kim7f283f42020-06-01 21:53:49 +0900151 if !m.Enabled() || m.Properties.HideFromMake {
Inseob Kim8471cda2019-11-15 09:59:12 +0900152 return false
153 }
Martin Stjernholm809d5182020-09-10 01:46:05 +0100154 // When android/prebuilt.go selects between source and prebuilt, it sets
Colin Crossa9c8c9f2020-12-16 10:20:23 -0800155 // HideFromMake on the other one to avoid duplicate install rules in make.
156 if m.IsHideFromMake() {
Martin Stjernholm809d5182020-09-10 01:46:05 +0100157 return false
158 }
Jose Galmesf7294582020-11-13 12:07:36 -0800159 // skip proprietary modules, but (for the vendor snapshot only)
160 // include all VNDK (static)
161 if inProprietaryPath && (!image.includeVndk() || !m.IsVndk()) {
Bill Peckham945441c2020-08-31 16:07:58 -0700162 return false
163 }
164 // If the module would be included based on its path, check to see if
165 // the module is marked to be excluded. If so, skip it.
Jose Galmes6f843bc2020-12-11 13:36:29 -0800166 if image.excludeFromSnapshot(m) {
Inseob Kim8471cda2019-11-15 09:59:12 +0900167 return false
168 }
169 if m.Target().Os.Class != android.Device {
170 return false
171 }
172 if m.Target().NativeBridge == android.NativeBridgeEnabled {
173 return false
174 }
Inseob Kimde5744a2020-12-02 13:14:28 +0900175 // the module must be installed in target image
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400176 if !apexInfo.IsForPlatform() || m.IsSnapshotPrebuilt() || !image.inImage(m)() {
Inseob Kim8471cda2019-11-15 09:59:12 +0900177 return false
178 }
Inseob Kim65ca36a2020-06-11 13:55:45 +0900179 // skip kernel_headers which always depend on vendor
180 if _, ok := m.linker.(*kernelHeadersDecorator); ok {
181 return false
182 }
Justin Yunf2664c62020-07-30 18:57:54 +0900183 // skip llndk_library and llndk_headers which are backward compatible
Colin Cross127bb8b2020-12-16 16:46:01 -0800184 if m.IsLlndk() {
185 return false
186 }
Justin Yunf2664c62020-07-30 18:57:54 +0900187 if _, ok := m.linker.(*llndkStubDecorator); ok {
188 return false
189 }
190 if _, ok := m.linker.(*llndkHeadersDecorator); ok {
191 return false
192 }
Inseob Kim8471cda2019-11-15 09:59:12 +0900193
194 // Libraries
195 if l, ok := m.linker.(snapshotLibraryInterface); ok {
Inseob Kim7f283f42020-06-01 21:53:49 +0900196 if m.sanitize != nil {
Inseob Kimc42f2f22020-07-29 20:32:10 +0900197 // scs and hwasan export both sanitized and unsanitized variants for static and header
Inseob Kim7f283f42020-06-01 21:53:49 +0900198 // Always use unsanitized variants of them.
Tri Vo6eafc362021-04-01 11:29:09 -0700199 for _, t := range []SanitizerType{scs, Hwasan} {
Inseob Kim7f283f42020-06-01 21:53:49 +0900200 if !l.shared() && m.sanitize.isSanitizerEnabled(t) {
201 return false
202 }
203 }
Inseob Kimc42f2f22020-07-29 20:32:10 +0900204 // cfi also exports both variants. But for static, we capture both.
Inseob Kimde5744a2020-12-02 13:14:28 +0900205 // This is because cfi static libraries can't be linked from non-cfi modules,
206 // and vice versa. This isn't the case for scs and hwasan sanitizers.
Inseob Kimc42f2f22020-07-29 20:32:10 +0900207 if !l.static() && !l.shared() && m.sanitize.isSanitizerEnabled(cfi) {
208 return false
209 }
Inseob Kim7f283f42020-06-01 21:53:49 +0900210 }
Inseob Kim8471cda2019-11-15 09:59:12 +0900211 if l.static() {
Justin Yune09ac172021-01-20 19:49:01 +0900212 return m.outputFile.Valid() && !image.private(m)
Inseob Kim8471cda2019-11-15 09:59:12 +0900213 }
214 if l.shared() {
Bill Peckham7d3f0962020-06-29 16:49:15 -0700215 if !m.outputFile.Valid() {
216 return false
217 }
Jose Galmesf7294582020-11-13 12:07:36 -0800218 if image.includeVndk() {
219 if !m.IsVndk() {
220 return true
221 }
Ivan Lozanof9e21722020-12-02 09:00:51 -0500222 return m.IsVndkExt()
Bill Peckham7d3f0962020-06-29 16:49:15 -0700223 }
Inseob Kim8471cda2019-11-15 09:59:12 +0900224 }
225 return true
226 }
227
Inseob Kim1042d292020-06-01 23:23:05 +0900228 // Binaries and Objects
229 if m.binary() || m.object() {
Justin Yune09ac172021-01-20 19:49:01 +0900230 return m.outputFile.Valid()
Inseob Kim8471cda2019-11-15 09:59:12 +0900231 }
Inseob Kim7f283f42020-06-01 21:53:49 +0900232
233 return false
Inseob Kim8471cda2019-11-15 09:59:12 +0900234}
235
Inseob Kimde5744a2020-12-02 13:14:28 +0900236// This is to be saved as .json files, which is for development/vendor_snapshot/update.py.
237// These flags become Android.bp snapshot module properties.
238type snapshotJsonFlags struct {
239 ModuleName string `json:",omitempty"`
240 RelativeInstallPath string `json:",omitempty"`
241
242 // library flags
243 ExportedDirs []string `json:",omitempty"`
244 ExportedSystemDirs []string `json:",omitempty"`
245 ExportedFlags []string `json:",omitempty"`
246 Sanitize string `json:",omitempty"`
247 SanitizeMinimalDep bool `json:",omitempty"`
248 SanitizeUbsanDep bool `json:",omitempty"`
249
250 // binary flags
251 Symlinks []string `json:",omitempty"`
252
253 // dependencies
254 SharedLibs []string `json:",omitempty"`
255 RuntimeLibs []string `json:",omitempty"`
256 Required []string `json:",omitempty"`
257
258 // extra config files
259 InitRc []string `json:",omitempty"`
260 VintfFragments []string `json:",omitempty"`
261}
262
Jose Galmesf7294582020-11-13 12:07:36 -0800263func (c *snapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) {
Jose Galmes6f843bc2020-12-11 13:36:29 -0800264 if !c.image.shouldGenerateSnapshot(ctx) {
Inseob Kim8471cda2019-11-15 09:59:12 +0900265 return
266 }
267
268 var snapshotOutputs android.Paths
269
270 /*
271 Vendor snapshot zipped artifacts directory structure:
272 {SNAPSHOT_ARCH}/
273 arch-{TARGET_ARCH}-{TARGET_ARCH_VARIANT}/
274 shared/
275 (.so shared libraries)
276 static/
277 (.a static libraries)
278 header/
279 (header only libraries)
280 binary/
281 (executable binaries)
Inseob Kim1042d292020-06-01 23:23:05 +0900282 object/
283 (.o object files)
Inseob Kim8471cda2019-11-15 09:59:12 +0900284 arch-{TARGET_2ND_ARCH}-{TARGET_2ND_ARCH_VARIANT}/
285 shared/
286 (.so shared libraries)
287 static/
288 (.a static libraries)
289 header/
290 (header only libraries)
291 binary/
292 (executable binaries)
Inseob Kim1042d292020-06-01 23:23:05 +0900293 object/
294 (.o object files)
Inseob Kim8471cda2019-11-15 09:59:12 +0900295 NOTICE_FILES/
296 (notice files, e.g. libbase.txt)
297 configs/
298 (config files, e.g. init.rc files, vintf_fragments.xml files, etc.)
299 include/
300 (header files of same directory structure with source tree)
301 */
302
Jose Galmesf7294582020-11-13 12:07:36 -0800303 snapshotDir := c.name + "-snapshot"
Inseob Kime9aec6a2021-01-05 20:03:22 +0900304 if c.fake {
305 // If this is a fake snapshot singleton, place all files under fake/ subdirectory to avoid
306 // collision with real snapshot files
307 snapshotDir = filepath.Join("fake", snapshotDir)
308 }
Inseob Kim8471cda2019-11-15 09:59:12 +0900309 snapshotArchDir := filepath.Join(snapshotDir, ctx.DeviceConfig().DeviceArch())
310
311 includeDir := filepath.Join(snapshotArchDir, "include")
312 configsDir := filepath.Join(snapshotArchDir, "configs")
313 noticeDir := filepath.Join(snapshotArchDir, "NOTICE_FILES")
314
315 installedNotices := make(map[string]bool)
316 installedConfigs := make(map[string]bool)
317
318 var headers android.Paths
319
Jose Galmes0a942a02021-02-03 14:23:15 -0800320 copyFile := func(ctx android.SingletonContext, path android.Path, out string, fake bool) android.OutputPath {
321 if fake {
322 // All prebuilt binaries and headers are installed by copyFile function. This makes a fake
323 // snapshot just touch prebuilts and headers, rather than installing real files.
Inseob Kime9aec6a2021-01-05 20:03:22 +0900324 return writeStringToFileRule(ctx, "", out)
Jose Galmes0a942a02021-02-03 14:23:15 -0800325 } else {
326 return copyFileRule(ctx, path, out)
Inseob Kime9aec6a2021-01-05 20:03:22 +0900327 }
328 }
329
Inseob Kimde5744a2020-12-02 13:14:28 +0900330 // installSnapshot function copies prebuilt file (.so, .a, or executable) and json flag file.
331 // For executables, init_rc and vintf_fragments files are also copied.
Jose Galmes0a942a02021-02-03 14:23:15 -0800332 installSnapshot := func(m *Module, fake bool) android.Paths {
Inseob Kim8471cda2019-11-15 09:59:12 +0900333 targetArch := "arch-" + m.Target().Arch.ArchType.String()
334 if m.Target().Arch.ArchVariant != "" {
335 targetArch += "-" + m.Target().Arch.ArchVariant
336 }
337
338 var ret android.Paths
339
Inseob Kimde5744a2020-12-02 13:14:28 +0900340 prop := snapshotJsonFlags{}
Inseob Kim8471cda2019-11-15 09:59:12 +0900341
342 // Common properties among snapshots.
343 prop.ModuleName = ctx.ModuleName(m)
Ivan Lozanof9e21722020-12-02 09:00:51 -0500344 if c.supportsVndkExt && m.IsVndkExt() {
Bill Peckham7d3f0962020-06-29 16:49:15 -0700345 // vndk exts are installed to /vendor/lib(64)?/vndk(-sp)?
346 if m.isVndkSp() {
347 prop.RelativeInstallPath = "vndk-sp"
348 } else {
349 prop.RelativeInstallPath = "vndk"
350 }
351 } else {
352 prop.RelativeInstallPath = m.RelativeInstallPath()
353 }
Inseob Kim8471cda2019-11-15 09:59:12 +0900354 prop.RuntimeLibs = m.Properties.SnapshotRuntimeLibs
355 prop.Required = m.RequiredModuleNames()
356 for _, path := range m.InitRc() {
357 prop.InitRc = append(prop.InitRc, filepath.Join("configs", path.Base()))
358 }
359 for _, path := range m.VintfFragments() {
360 prop.VintfFragments = append(prop.VintfFragments, filepath.Join("configs", path.Base()))
361 }
362
363 // install config files. ignores any duplicates.
364 for _, path := range append(m.InitRc(), m.VintfFragments()...) {
365 out := filepath.Join(configsDir, path.Base())
366 if !installedConfigs[out] {
367 installedConfigs[out] = true
Jose Galmes0a942a02021-02-03 14:23:15 -0800368 ret = append(ret, copyFile(ctx, path, out, fake))
Inseob Kim8471cda2019-11-15 09:59:12 +0900369 }
370 }
371
372 var propOut string
373
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900374 if l, ok := m.linker.(snapshotLibraryInterface); ok {
Colin Cross0de8a1e2020-09-18 14:15:30 -0700375 exporterInfo := ctx.ModuleProvider(m, FlagExporterInfoProvider).(FlagExporterInfo)
Inseob Kimc42f2f22020-07-29 20:32:10 +0900376
Inseob Kim8471cda2019-11-15 09:59:12 +0900377 // library flags
Colin Cross0de8a1e2020-09-18 14:15:30 -0700378 prop.ExportedFlags = exporterInfo.Flags
379 for _, dir := range exporterInfo.IncludeDirs {
Inseob Kim8471cda2019-11-15 09:59:12 +0900380 prop.ExportedDirs = append(prop.ExportedDirs, filepath.Join("include", dir.String()))
381 }
Colin Cross0de8a1e2020-09-18 14:15:30 -0700382 for _, dir := range exporterInfo.SystemIncludeDirs {
Inseob Kim8471cda2019-11-15 09:59:12 +0900383 prop.ExportedSystemDirs = append(prop.ExportedSystemDirs, filepath.Join("include", dir.String()))
384 }
385 // shared libs dependencies aren't meaningful on static or header libs
386 if l.shared() {
387 prop.SharedLibs = m.Properties.SnapshotSharedLibs
388 }
389 if l.static() && m.sanitize != nil {
390 prop.SanitizeMinimalDep = m.sanitize.Properties.MinimalRuntimeDep || enableMinimalRuntime(m.sanitize)
391 prop.SanitizeUbsanDep = m.sanitize.Properties.UbsanRuntimeDep || enableUbsanRuntime(m.sanitize)
392 }
393
394 var libType string
395 if l.static() {
396 libType = "static"
397 } else if l.shared() {
398 libType = "shared"
399 } else {
400 libType = "header"
401 }
402
403 var stem string
404
405 // install .a or .so
406 if libType != "header" {
407 libPath := m.outputFile.Path()
408 stem = libPath.Base()
Inseob Kimc42f2f22020-07-29 20:32:10 +0900409 if l.static() && m.sanitize != nil && m.sanitize.isSanitizerEnabled(cfi) {
410 // both cfi and non-cfi variant for static libraries can exist.
411 // attach .cfi to distinguish between cfi and non-cfi.
412 // e.g. libbase.a -> libbase.cfi.a
413 ext := filepath.Ext(stem)
414 stem = strings.TrimSuffix(stem, ext) + ".cfi" + ext
415 prop.Sanitize = "cfi"
416 prop.ModuleName += ".cfi"
417 }
Inseob Kim8471cda2019-11-15 09:59:12 +0900418 snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, libType, stem)
Jose Galmes0a942a02021-02-03 14:23:15 -0800419 ret = append(ret, copyFile(ctx, libPath, snapshotLibOut, fake))
Inseob Kim8471cda2019-11-15 09:59:12 +0900420 } else {
421 stem = ctx.ModuleName(m)
422 }
423
424 propOut = filepath.Join(snapshotArchDir, targetArch, libType, stem+".json")
Inseob Kim7f283f42020-06-01 21:53:49 +0900425 } else if m.binary() {
Inseob Kim8471cda2019-11-15 09:59:12 +0900426 // binary flags
427 prop.Symlinks = m.Symlinks()
428 prop.SharedLibs = m.Properties.SnapshotSharedLibs
429
430 // install bin
431 binPath := m.outputFile.Path()
432 snapshotBinOut := filepath.Join(snapshotArchDir, targetArch, "binary", binPath.Base())
Jose Galmes0a942a02021-02-03 14:23:15 -0800433 ret = append(ret, copyFile(ctx, binPath, snapshotBinOut, fake))
Inseob Kim8471cda2019-11-15 09:59:12 +0900434 propOut = snapshotBinOut + ".json"
Inseob Kim1042d292020-06-01 23:23:05 +0900435 } else if m.object() {
436 // object files aren't installed to the device, so their names can conflict.
437 // Use module name as stem.
438 objPath := m.outputFile.Path()
439 snapshotObjOut := filepath.Join(snapshotArchDir, targetArch, "object",
440 ctx.ModuleName(m)+filepath.Ext(objPath.Base()))
Jose Galmes0a942a02021-02-03 14:23:15 -0800441 ret = append(ret, copyFile(ctx, objPath, snapshotObjOut, fake))
Inseob Kim1042d292020-06-01 23:23:05 +0900442 propOut = snapshotObjOut + ".json"
Inseob Kim7f283f42020-06-01 21:53:49 +0900443 } else {
444 ctx.Errorf("unknown module %q in vendor snapshot", m.String())
445 return nil
Inseob Kim8471cda2019-11-15 09:59:12 +0900446 }
447
448 j, err := json.Marshal(prop)
449 if err != nil {
450 ctx.Errorf("json marshal to %q failed: %#v", propOut, err)
451 return nil
452 }
Inseob Kimde5744a2020-12-02 13:14:28 +0900453 ret = append(ret, writeStringToFileRule(ctx, string(j), propOut))
Inseob Kim8471cda2019-11-15 09:59:12 +0900454
455 return ret
456 }
457
458 ctx.VisitAllModules(func(module android.Module) {
459 m, ok := module.(*Module)
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900460 if !ok {
461 return
462 }
463
464 moduleDir := ctx.ModuleDir(module)
Justin DeMartino383bfb32021-02-24 10:49:43 -0800465 inProprietaryPath := c.image.isProprietaryPath(moduleDir, ctx.DeviceConfig())
Colin Cross56a83212020-09-15 18:30:11 -0700466 apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo)
Bill Peckham945441c2020-08-31 16:07:58 -0700467
Jose Galmes6f843bc2020-12-11 13:36:29 -0800468 if c.image.excludeFromSnapshot(m) {
Jose Galmesf7294582020-11-13 12:07:36 -0800469 if inProprietaryPath {
Bill Peckham945441c2020-08-31 16:07:58 -0700470 // Error: exclude_from_vendor_snapshot applies
471 // to framework-path modules only.
472 ctx.Errorf("module %q in vendor proprietary path %q may not use \"exclude_from_vendor_snapshot: true\"", m.String(), moduleDir)
473 return
474 }
Bill Peckham945441c2020-08-31 16:07:58 -0700475 }
476
Inseob Kim7cf14652021-01-06 23:06:52 +0900477 if !isSnapshotAware(ctx.DeviceConfig(), m, inProprietaryPath, apexInfo, c.image) {
Inseob Kim8471cda2019-11-15 09:59:12 +0900478 return
479 }
480
Jose Galmes0a942a02021-02-03 14:23:15 -0800481 // If we are using directed snapshot and a module is not included in the
482 // list, we will still include the module as if it was a fake module.
483 // The reason is that soong needs all the dependencies to be present, even
484 // if they are not using during the build.
485 installAsFake := c.fake
486 if c.image.excludeFromDirectedSnapshot(ctx.DeviceConfig(), m.BaseModuleName()) {
487 installAsFake = true
488 }
Inseob Kimde5744a2020-12-02 13:14:28 +0900489
Jose Galmes0a942a02021-02-03 14:23:15 -0800490 // installSnapshot installs prebuilts and json flag files
491 snapshotOutputs = append(snapshotOutputs, installSnapshot(m, installAsFake)...)
Inseob Kimde5744a2020-12-02 13:14:28 +0900492 // just gather headers and notice files here, because they are to be deduplicated
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900493 if l, ok := m.linker.(snapshotLibraryInterface); ok {
494 headers = append(headers, l.snapshotHeaders()...)
Inseob Kim8471cda2019-11-15 09:59:12 +0900495 }
496
Bob Badoura75b0572020-02-18 20:21:55 -0800497 if len(m.NoticeFiles()) > 0 {
Inseob Kim8471cda2019-11-15 09:59:12 +0900498 noticeName := ctx.ModuleName(m) + ".txt"
499 noticeOut := filepath.Join(noticeDir, noticeName)
500 // skip already copied notice file
501 if !installedNotices[noticeOut] {
502 installedNotices[noticeOut] = true
Inseob Kime9aec6a2021-01-05 20:03:22 +0900503 snapshotOutputs = append(snapshotOutputs, combineNoticesRule(ctx, m.NoticeFiles(), noticeOut))
Inseob Kim8471cda2019-11-15 09:59:12 +0900504 }
505 }
506 })
507
508 // install all headers after removing duplicates
509 for _, header := range android.FirstUniquePaths(headers) {
Jose Galmes0a942a02021-02-03 14:23:15 -0800510 snapshotOutputs = append(snapshotOutputs, copyFile(ctx, header, filepath.Join(includeDir, header.String()), c.fake))
Inseob Kim8471cda2019-11-15 09:59:12 +0900511 }
512
513 // All artifacts are ready. Sort them to normalize ninja and then zip.
514 sort.Slice(snapshotOutputs, func(i, j int) bool {
515 return snapshotOutputs[i].String() < snapshotOutputs[j].String()
516 })
517
Jose Galmesf7294582020-11-13 12:07:36 -0800518 zipPath := android.PathForOutput(
519 ctx,
520 snapshotDir,
521 c.name+"-"+ctx.Config().DeviceName()+".zip")
Colin Crossf1a035e2020-11-16 17:32:30 -0800522 zipRule := android.NewRuleBuilder(pctx, ctx)
Inseob Kim8471cda2019-11-15 09:59:12 +0900523
524 // filenames in rspfile from FlagWithRspFileInputList might be single-quoted. Remove it with tr
Jose Galmesf7294582020-11-13 12:07:36 -0800525 snapshotOutputList := android.PathForOutput(
526 ctx,
527 snapshotDir,
528 c.name+"-"+ctx.Config().DeviceName()+"_list")
Colin Cross70c47412021-03-12 17:48:14 -0800529 rspFile := snapshotOutputList.ReplaceExtension(ctx, "rsp")
Inseob Kim8471cda2019-11-15 09:59:12 +0900530 zipRule.Command().
531 Text("tr").
532 FlagWithArg("-d ", "\\'").
Colin Cross70c47412021-03-12 17:48:14 -0800533 FlagWithRspFileInputList("< ", rspFile, snapshotOutputs).
Inseob Kim8471cda2019-11-15 09:59:12 +0900534 FlagWithOutput("> ", snapshotOutputList)
535
536 zipRule.Temporary(snapshotOutputList)
537
538 zipRule.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -0800539 BuiltTool("soong_zip").
Inseob Kim8471cda2019-11-15 09:59:12 +0900540 FlagWithOutput("-o ", zipPath).
541 FlagWithArg("-C ", android.PathForOutput(ctx, snapshotDir).String()).
542 FlagWithInput("-l ", snapshotOutputList)
543
Colin Crossf1a035e2020-11-16 17:32:30 -0800544 zipRule.Build(zipPath.String(), c.name+" snapshot "+zipPath.String())
Inseob Kim8471cda2019-11-15 09:59:12 +0900545 zipRule.DeleteTemporaryFiles()
Jose Galmesf7294582020-11-13 12:07:36 -0800546 c.snapshotZipFile = android.OptionalPathForPath(zipPath)
Inseob Kim8471cda2019-11-15 09:59:12 +0900547}
548
Jose Galmesf7294582020-11-13 12:07:36 -0800549func (c *snapshotSingleton) MakeVars(ctx android.MakeVarsContext) {
550 ctx.Strict(
551 c.makeVar,
552 c.snapshotZipFile.String())
Inseob Kim8471cda2019-11-15 09:59:12 +0900553}