blob: 25960ab965c22b2af4bebde4cac8f10fffb41b41 [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
184 // SkipInstall on the other one to avoid duplicate install rules in make.
185 if m.IsSkipInstall() {
186 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
213 if _, ok := m.linker.(*llndkStubDecorator); ok {
214 return false
215 }
216 if _, ok := m.linker.(*llndkHeadersDecorator); ok {
217 return false
218 }
Inseob Kim8471cda2019-11-15 09:59:12 +0900219
220 // Libraries
221 if l, ok := m.linker.(snapshotLibraryInterface); ok {
Inseob Kim7f283f42020-06-01 21:53:49 +0900222 if m.sanitize != nil {
Inseob Kimc42f2f22020-07-29 20:32:10 +0900223 // scs and hwasan export both sanitized and unsanitized variants for static and header
Inseob Kim7f283f42020-06-01 21:53:49 +0900224 // Always use unsanitized variants of them.
Inseob Kimc42f2f22020-07-29 20:32:10 +0900225 for _, t := range []sanitizerType{scs, hwasan} {
Inseob Kim7f283f42020-06-01 21:53:49 +0900226 if !l.shared() && m.sanitize.isSanitizerEnabled(t) {
227 return false
228 }
229 }
Inseob Kimc42f2f22020-07-29 20:32:10 +0900230 // cfi also exports both variants. But for static, we capture both.
Inseob Kimde5744a2020-12-02 13:14:28 +0900231 // 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 Kimc42f2f22020-07-29 20:32:10 +0900233 if !l.static() && !l.shared() && m.sanitize.isSanitizerEnabled(cfi) {
234 return false
235 }
Inseob Kim7f283f42020-06-01 21:53:49 +0900236 }
Inseob Kim8471cda2019-11-15 09:59:12 +0900237 if l.static() {
Jose Galmesf7294582020-11-13 12:07:36 -0800238 return m.outputFile.Valid() && proptools.BoolDefault(image.available(m), true)
Inseob Kim8471cda2019-11-15 09:59:12 +0900239 }
240 if l.shared() {
Bill Peckham7d3f0962020-06-29 16:49:15 -0700241 if !m.outputFile.Valid() {
242 return false
243 }
Jose Galmesf7294582020-11-13 12:07:36 -0800244 if image.includeVndk() {
245 if !m.IsVndk() {
246 return true
247 }
248 return m.isVndkExt()
Bill Peckham7d3f0962020-06-29 16:49:15 -0700249 }
Inseob Kim8471cda2019-11-15 09:59:12 +0900250 }
251 return true
252 }
253
Inseob Kim1042d292020-06-01 23:23:05 +0900254 // Binaries and Objects
255 if m.binary() || m.object() {
Jose Galmesf7294582020-11-13 12:07:36 -0800256 return m.outputFile.Valid() && proptools.BoolDefault(image.available(m), true)
Inseob Kim8471cda2019-11-15 09:59:12 +0900257 }
Inseob Kim7f283f42020-06-01 21:53:49 +0900258
259 return false
Inseob Kim8471cda2019-11-15 09:59:12 +0900260}
261
Inseob Kimde5744a2020-12-02 13:14:28 +0900262// 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.
264type 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 Galmesf7294582020-11-13 12:07:36 -0800289func (c *snapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) {
Inseob Kim8471cda2019-11-15 09:59:12 +0900290 // 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 Kim1042d292020-06-01 23:23:05 +0900309 object/
310 (.o object files)
Inseob Kim8471cda2019-11-15 09:59:12 +0900311 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 Kim1042d292020-06-01 23:23:05 +0900320 object/
321 (.o object files)
Inseob Kim8471cda2019-11-15 09:59:12 +0900322 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 Galmesf7294582020-11-13 12:07:36 -0800330 snapshotDir := c.name + "-snapshot"
Inseob Kim8471cda2019-11-15 09:59:12 +0900331 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 Kimde5744a2020-12-02 13:14:28 +0900342 // 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 Kim8471cda2019-11-15 09:59:12 +0900344 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 Kimde5744a2020-12-02 13:14:28 +0900352 prop := snapshotJsonFlags{}
Inseob Kim8471cda2019-11-15 09:59:12 +0900353
354 // Common properties among snapshots.
355 prop.ModuleName = ctx.ModuleName(m)
Jose Galmesf7294582020-11-13 12:07:36 -0800356 if c.supportsVndkExt && m.isVndkExt() {
Bill Peckham7d3f0962020-06-29 16:49:15 -0700357 // 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 Kim8471cda2019-11-15 09:59:12 +0900366 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 Kimde5744a2020-12-02 13:14:28 +0900380 ret = append(ret, copyFileRule(ctx, path, out))
Inseob Kim8471cda2019-11-15 09:59:12 +0900381 }
382 }
383
384 var propOut string
385
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900386 if l, ok := m.linker.(snapshotLibraryInterface); ok {
Colin Cross0de8a1e2020-09-18 14:15:30 -0700387 exporterInfo := ctx.ModuleProvider(m, FlagExporterInfoProvider).(FlagExporterInfo)
Inseob Kimc42f2f22020-07-29 20:32:10 +0900388
Inseob Kim8471cda2019-11-15 09:59:12 +0900389 // library flags
Colin Cross0de8a1e2020-09-18 14:15:30 -0700390 prop.ExportedFlags = exporterInfo.Flags
391 for _, dir := range exporterInfo.IncludeDirs {
Inseob Kim8471cda2019-11-15 09:59:12 +0900392 prop.ExportedDirs = append(prop.ExportedDirs, filepath.Join("include", dir.String()))
393 }
Colin Cross0de8a1e2020-09-18 14:15:30 -0700394 for _, dir := range exporterInfo.SystemIncludeDirs {
Inseob Kim8471cda2019-11-15 09:59:12 +0900395 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 Kimc42f2f22020-07-29 20:32:10 +0900421 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 Kim8471cda2019-11-15 09:59:12 +0900430 snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, libType, stem)
Inseob Kimde5744a2020-12-02 13:14:28 +0900431 ret = append(ret, copyFileRule(ctx, libPath, snapshotLibOut))
Inseob Kim8471cda2019-11-15 09:59:12 +0900432 } else {
433 stem = ctx.ModuleName(m)
434 }
435
436 propOut = filepath.Join(snapshotArchDir, targetArch, libType, stem+".json")
Inseob Kim7f283f42020-06-01 21:53:49 +0900437 } else if m.binary() {
Inseob Kim8471cda2019-11-15 09:59:12 +0900438 // 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 Kimde5744a2020-12-02 13:14:28 +0900445 ret = append(ret, copyFileRule(ctx, binPath, snapshotBinOut))
Inseob Kim8471cda2019-11-15 09:59:12 +0900446 propOut = snapshotBinOut + ".json"
Inseob Kim1042d292020-06-01 23:23:05 +0900447 } 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 Kimde5744a2020-12-02 13:14:28 +0900453 ret = append(ret, copyFileRule(ctx, objPath, snapshotObjOut))
Inseob Kim1042d292020-06-01 23:23:05 +0900454 propOut = snapshotObjOut + ".json"
Inseob Kim7f283f42020-06-01 21:53:49 +0900455 } else {
456 ctx.Errorf("unknown module %q in vendor snapshot", m.String())
457 return nil
Inseob Kim8471cda2019-11-15 09:59:12 +0900458 }
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 Kimde5744a2020-12-02 13:14:28 +0900465 ret = append(ret, writeStringToFileRule(ctx, string(j), propOut))
Inseob Kim8471cda2019-11-15 09:59:12 +0900466
467 return ret
468 }
469
470 ctx.VisitAllModules(func(module android.Module) {
471 m, ok := module.(*Module)
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900472 if !ok {
473 return
474 }
475
476 moduleDir := ctx.ModuleDir(module)
Jose Galmesf7294582020-11-13 12:07:36 -0800477 inProprietaryPath := c.image.isProprietaryPath(moduleDir)
Colin Cross56a83212020-09-15 18:30:11 -0700478 apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo)
Bill Peckham945441c2020-08-31 16:07:58 -0700479
480 if m.ExcludeFromVendorSnapshot() {
Jose Galmesf7294582020-11-13 12:07:36 -0800481 if inProprietaryPath {
Bill Peckham945441c2020-08-31 16:07:58 -0700482 // 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 Galmesf7294582020-11-13 12:07:36 -0800487 if Bool(c.image.available(m)) {
Bill Peckham945441c2020-08-31 16:07:58 -0700488 // Error: may not combine "vendor_available:
489 // true" with "exclude_from_vendor_snapshot:
490 // true".
Jose Galmesf7294582020-11-13 12:07:36 -0800491 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 Peckham945441c2020-08-31 16:07:58 -0700496 return
497 }
498 }
499
Inseob Kimde5744a2020-12-02 13:14:28 +0900500 if !isSnapshotAware(m, inProprietaryPath, apexInfo, c.image) {
Inseob Kim8471cda2019-11-15 09:59:12 +0900501 return
502 }
503
Inseob Kimde5744a2020-12-02 13:14:28 +0900504 // installSnapshot installs prebuilts and json flag files
Inseob Kim8471cda2019-11-15 09:59:12 +0900505 snapshotOutputs = append(snapshotOutputs, installSnapshot(m)...)
Inseob Kimde5744a2020-12-02 13:14:28 +0900506
507 // just gather headers and notice files here, because they are to be deduplicated
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900508 if l, ok := m.linker.(snapshotLibraryInterface); ok {
509 headers = append(headers, l.snapshotHeaders()...)
Inseob Kim8471cda2019-11-15 09:59:12 +0900510 }
511
Bob Badoura75b0572020-02-18 20:21:55 -0800512 if len(m.NoticeFiles()) > 0 {
Inseob Kim8471cda2019-11-15 09:59:12 +0900513 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 Kimde5744a2020-12-02 13:14:28 +0900518 snapshotOutputs = append(snapshotOutputs, combineNoticesRule(
Bob Badoura75b0572020-02-18 20:21:55 -0800519 ctx, m.NoticeFiles(), noticeOut))
Inseob Kim8471cda2019-11-15 09:59:12 +0900520 }
521 }
522 })
523
524 // install all headers after removing duplicates
525 for _, header := range android.FirstUniquePaths(headers) {
Inseob Kimde5744a2020-12-02 13:14:28 +0900526 snapshotOutputs = append(snapshotOutputs, copyFileRule(
Inseob Kim8471cda2019-11-15 09:59:12 +0900527 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 Galmesf7294582020-11-13 12:07:36 -0800535 zipPath := android.PathForOutput(
536 ctx,
537 snapshotDir,
538 c.name+"-"+ctx.Config().DeviceName()+".zip")
Colin Crossf1a035e2020-11-16 17:32:30 -0800539 zipRule := android.NewRuleBuilder(pctx, ctx)
Inseob Kim8471cda2019-11-15 09:59:12 +0900540
541 // filenames in rspfile from FlagWithRspFileInputList might be single-quoted. Remove it with tr
Jose Galmesf7294582020-11-13 12:07:36 -0800542 snapshotOutputList := android.PathForOutput(
543 ctx,
544 snapshotDir,
545 c.name+"-"+ctx.Config().DeviceName()+"_list")
Inseob Kim8471cda2019-11-15 09:59:12 +0900546 zipRule.Command().
547 Text("tr").
548 FlagWithArg("-d ", "\\'").
549 FlagWithRspFileInputList("< ", snapshotOutputs).
550 FlagWithOutput("> ", snapshotOutputList)
551
552 zipRule.Temporary(snapshotOutputList)
553
554 zipRule.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -0800555 BuiltTool("soong_zip").
Inseob Kim8471cda2019-11-15 09:59:12 +0900556 FlagWithOutput("-o ", zipPath).
557 FlagWithArg("-C ", android.PathForOutput(ctx, snapshotDir).String()).
558 FlagWithInput("-l ", snapshotOutputList)
559
Colin Crossf1a035e2020-11-16 17:32:30 -0800560 zipRule.Build(zipPath.String(), c.name+" snapshot "+zipPath.String())
Inseob Kim8471cda2019-11-15 09:59:12 +0900561 zipRule.DeleteTemporaryFiles()
Jose Galmesf7294582020-11-13 12:07:36 -0800562 c.snapshotZipFile = android.OptionalPathForPath(zipPath)
Inseob Kim8471cda2019-11-15 09:59:12 +0900563}
564
Jose Galmesf7294582020-11-13 12:07:36 -0800565func (c *snapshotSingleton) MakeVars(ctx android.MakeVarsContext) {
566 ctx.Strict(
567 c.makeVar,
568 c.snapshotZipFile.String())
Inseob Kim8471cda2019-11-15 09:59:12 +0900569}