blob: 9ea337b8d6572682b3a0bfbd6ec129c2a9d6b3a1 [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//
Colin Crossd079e0b2022-08-16 10:27:33 -07007// http://www.apache.org/licenses/LICENSE-2.0
Inseob Kim8471cda2019-11-15 09:59:12 +09008//
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
16import (
17 "encoding/json"
18 "path/filepath"
Inseob Kim8471cda2019-11-15 09:59:12 +090019 "strings"
20
Inseob Kim8471cda2019-11-15 09:59:12 +090021 "android/soong/android"
Kiyoung Kim48f37782021-07-07 12:42:39 +090022 "android/soong/snapshot"
Inseob Kim8471cda2019-11-15 09:59:12 +090023)
24
Kiyoung Kim48f37782021-07-07 12:42:39 +090025// This file defines how to capture cc modules into snapshot package.
Inseob Kime9aec6a2021-01-05 20:03:22 +090026
Kiyoung Kim48f37782021-07-07 12:42:39 +090027// Checks if the target image would contain VNDK
28func includeVndk(image snapshot.SnapshotImage) bool {
29 if image.ImageName() == snapshot.VendorSnapshotImageName {
Bill Peckham945441c2020-08-31 16:07:58 -070030 return true
31 }
32
Bill Peckham945441c2020-08-31 16:07:58 -070033 return false
34}
35
Kiyoung Kim48f37782021-07-07 12:42:39 +090036// Check if the module is VNDK private
37func isPrivate(image snapshot.SnapshotImage, m LinkableInterface) bool {
38 if image.ImageName() == snapshot.VendorSnapshotImageName && m.IsVndkPrivate() {
Jose Galmes6f843bc2020-12-11 13:36:29 -080039 return true
40 }
41
Kiyoung Kim48f37782021-07-07 12:42:39 +090042 return false
43}
Jose Galmes6f843bc2020-12-11 13:36:29 -080044
Kiyoung Kim48f37782021-07-07 12:42:39 +090045// Checks if target image supports VNDK Ext
46func supportsVndkExt(image snapshot.SnapshotImage) bool {
47 if image.ImageName() == snapshot.VendorSnapshotImageName {
48 return true
Jose Galmes6f843bc2020-12-11 13:36:29 -080049 }
50
51 return false
52}
53
Inseob Kimde5744a2020-12-02 13:14:28 +090054// Determines if the module is a candidate for snapshot.
Kiyoung Kim48f37782021-07-07 12:42:39 +090055func isSnapshotAware(cfg android.DeviceConfig, m LinkableInterface, inProprietaryPath bool, apexInfo android.ApexInfo, image snapshot.SnapshotImage) bool {
Ivan Lozanod7586b62021-04-01 09:49:36 -040056 if !m.Enabled() || m.HiddenFromMake() {
Inseob Kim8471cda2019-11-15 09:59:12 +090057 return false
58 }
Martin Stjernholm809d5182020-09-10 01:46:05 +010059 // When android/prebuilt.go selects between source and prebuilt, it sets
Colin Crossa9c8c9f2020-12-16 10:20:23 -080060 // HideFromMake on the other one to avoid duplicate install rules in make.
61 if m.IsHideFromMake() {
Martin Stjernholm809d5182020-09-10 01:46:05 +010062 return false
63 }
Jose Galmesf7294582020-11-13 12:07:36 -080064 // skip proprietary modules, but (for the vendor snapshot only)
65 // include all VNDK (static)
Kiyoung Kim48f37782021-07-07 12:42:39 +090066 if inProprietaryPath && (!includeVndk(image) || !m.IsVndk()) {
Bill Peckham945441c2020-08-31 16:07:58 -070067 return false
68 }
69 // If the module would be included based on its path, check to see if
70 // the module is marked to be excluded. If so, skip it.
Kiyoung Kim48f37782021-07-07 12:42:39 +090071 if image.ExcludeFromSnapshot(m) {
Inseob Kim8471cda2019-11-15 09:59:12 +090072 return false
73 }
74 if m.Target().Os.Class != android.Device {
75 return false
76 }
77 if m.Target().NativeBridge == android.NativeBridgeEnabled {
78 return false
79 }
Inseob Kimde5744a2020-12-02 13:14:28 +090080 // the module must be installed in target image
Kiyoung Kim48f37782021-07-07 12:42:39 +090081 if !apexInfo.IsForPlatform() || m.IsSnapshotPrebuilt() || !image.InImage(m)() {
Inseob Kim8471cda2019-11-15 09:59:12 +090082 return false
83 }
Inseob Kim65ca36a2020-06-11 13:55:45 +090084 // skip kernel_headers which always depend on vendor
Ivan Lozanod7586b62021-04-01 09:49:36 -040085 if m.KernelHeadersDecorator() {
Inseob Kim65ca36a2020-06-11 13:55:45 +090086 return false
87 }
Ivan Lozanod7586b62021-04-01 09:49:36 -040088
Colin Cross127bb8b2020-12-16 16:46:01 -080089 if m.IsLlndk() {
90 return false
91 }
Inseob Kim8471cda2019-11-15 09:59:12 +090092
93 // Libraries
Ivan Lozanod7586b62021-04-01 09:49:36 -040094 if sanitizable, ok := m.(PlatformSanitizeable); ok && sanitizable.IsSnapshotLibrary() {
95 if sanitizable.SanitizePropDefined() {
Justin Yun8814fc52022-12-15 21:45:35 +090096 // scs exports both sanitized and unsanitized variants for static and header
97 // Always use unsanitized variant of it.
Ivan Lozano22823ee2023-07-31 18:01:26 +000098 if !sanitizable.Shared() && sanitizable.IsSanitizerEnabled(scs) {
Justin Yun8814fc52022-12-15 21:45:35 +090099 return false
Inseob Kim7f283f42020-06-01 21:53:49 +0900100 }
Justin Yun8814fc52022-12-15 21:45:35 +0900101 // cfi and hwasan also export both variants. But for static, we capture both.
Inseob Kimde5744a2020-12-02 13:14:28 +0900102 // This is because cfi static libraries can't be linked from non-cfi modules,
Justin Yun8814fc52022-12-15 21:45:35 +0900103 // and vice versa.
104 // hwasan is captured as well to support hwasan build.
105 if !sanitizable.Static() &&
106 !sanitizable.Shared() &&
107 (sanitizable.IsSanitizerEnabled(cfi) || sanitizable.IsSanitizerEnabled(Hwasan)) {
Inseob Kimc42f2f22020-07-29 20:32:10 +0900108 return false
109 }
Inseob Kim7f283f42020-06-01 21:53:49 +0900110 }
Ivan Lozanoadd122a2023-07-13 11:01:41 -0400111 if sanitizable.Static() || sanitizable.Rlib() {
Kiyoung Kim48f37782021-07-07 12:42:39 +0900112 return sanitizable.OutputFile().Valid() && !isPrivate(image, m)
Inseob Kim8471cda2019-11-15 09:59:12 +0900113 }
Ivan Lozanoadd122a2023-07-13 11:01:41 -0400114 if sanitizable.Shared() || sanitizable.Dylib() {
Ivan Lozanod7586b62021-04-01 09:49:36 -0400115 if !sanitizable.OutputFile().Valid() {
Bill Peckham7d3f0962020-06-29 16:49:15 -0700116 return false
117 }
Kiyoung Kim48f37782021-07-07 12:42:39 +0900118 if includeVndk(image) {
Ivan Lozanod7586b62021-04-01 09:49:36 -0400119 if !sanitizable.IsVndk() {
Jose Galmesf7294582020-11-13 12:07:36 -0800120 return true
121 }
Ivan Lozanod7586b62021-04-01 09:49:36 -0400122 return sanitizable.IsVndkExt()
Bill Peckham7d3f0962020-06-29 16:49:15 -0700123 }
Inseob Kim8471cda2019-11-15 09:59:12 +0900124 }
125 return true
126 }
127
Inseob Kim1042d292020-06-01 23:23:05 +0900128 // Binaries and Objects
Ivan Lozanod7586b62021-04-01 09:49:36 -0400129 if m.Binary() || m.Object() {
130 return m.OutputFile().Valid()
Inseob Kim8471cda2019-11-15 09:59:12 +0900131 }
Inseob Kim7f283f42020-06-01 21:53:49 +0900132
133 return false
Inseob Kim8471cda2019-11-15 09:59:12 +0900134}
135
Rob Seymour925aa092021-08-10 20:42:03 +0000136// Extend the snapshot.SnapshotJsonFlags to include cc specific fields.
Inseob Kimde5744a2020-12-02 13:14:28 +0900137type snapshotJsonFlags struct {
Rob Seymour925aa092021-08-10 20:42:03 +0000138 snapshot.SnapshotJsonFlags
Inseob Kimde5744a2020-12-02 13:14:28 +0900139 // library flags
140 ExportedDirs []string `json:",omitempty"`
141 ExportedSystemDirs []string `json:",omitempty"`
142 ExportedFlags []string `json:",omitempty"`
143 Sanitize string `json:",omitempty"`
144 SanitizeMinimalDep bool `json:",omitempty"`
145 SanitizeUbsanDep bool `json:",omitempty"`
146
147 // binary flags
Justin Yun5e035862021-06-29 20:50:37 +0900148 Symlinks []string `json:",omitempty"`
149 StaticExecutable bool `json:",omitempty"`
Jose Galmesc1a56bc2022-03-07 14:07:59 -0800150 InstallInRoot bool `json:",omitempty"`
Inseob Kimde5744a2020-12-02 13:14:28 +0900151
152 // dependencies
153 SharedLibs []string `json:",omitempty"`
Justin Yun5e035862021-06-29 20:50:37 +0900154 StaticLibs []string `json:",omitempty"`
Inseob Kimde5744a2020-12-02 13:14:28 +0900155 RuntimeLibs []string `json:",omitempty"`
Ivan Lozanoadd122a2023-07-13 11:01:41 -0400156 Dylibs []string `json:",omitempty"`
157 Rlibs []string `json:",omitempty"`
Inseob Kimde5744a2020-12-02 13:14:28 +0900158
159 // extra config files
160 InitRc []string `json:",omitempty"`
161 VintfFragments []string `json:",omitempty"`
Inseob Kim5860f822023-04-18 11:30:22 +0900162 MinSdkVersion string `json:",omitempty"`
Inseob Kimde5744a2020-12-02 13:14:28 +0900163}
164
Justin Yun1db97482023-04-11 18:20:07 +0900165var ccSnapshotAction snapshot.GenerateSnapshotAction = func(s snapshot.SnapshotSingleton, ctx android.SingletonContext, snapshotArchDir string) snapshot.SnapshotPaths {
Inseob Kim8471cda2019-11-15 09:59:12 +0900166 /*
Kiyoung Kim48f37782021-07-07 12:42:39 +0900167 Vendor snapshot zipped artifacts directory structure for cc modules:
Inseob Kim8471cda2019-11-15 09:59:12 +0900168 {SNAPSHOT_ARCH}/
169 arch-{TARGET_ARCH}-{TARGET_ARCH_VARIANT}/
170 shared/
171 (.so shared libraries)
172 static/
173 (.a static libraries)
174 header/
175 (header only libraries)
176 binary/
177 (executable binaries)
Inseob Kim1042d292020-06-01 23:23:05 +0900178 object/
179 (.o object files)
Inseob Kim8471cda2019-11-15 09:59:12 +0900180 arch-{TARGET_2ND_ARCH}-{TARGET_2ND_ARCH_VARIANT}/
181 shared/
182 (.so shared libraries)
183 static/
184 (.a static libraries)
185 header/
186 (header only libraries)
187 binary/
188 (executable binaries)
Inseob Kim1042d292020-06-01 23:23:05 +0900189 object/
190 (.o object files)
Inseob Kim8471cda2019-11-15 09:59:12 +0900191 NOTICE_FILES/
192 (notice files, e.g. libbase.txt)
193 configs/
194 (config files, e.g. init.rc files, vintf_fragments.xml files, etc.)
195 include/
196 (header files of same directory structure with source tree)
197 */
198
Kiyoung Kim48f37782021-07-07 12:42:39 +0900199 var snapshotOutputs android.Paths
Justin Yun1db97482023-04-11 18:20:07 +0900200 var snapshotNotices android.Paths
Inseob Kim8471cda2019-11-15 09:59:12 +0900201
202 includeDir := filepath.Join(snapshotArchDir, "include")
203 configsDir := filepath.Join(snapshotArchDir, "configs")
Inseob Kim8471cda2019-11-15 09:59:12 +0900204
205 installedNotices := make(map[string]bool)
206 installedConfigs := make(map[string]bool)
207
208 var headers android.Paths
209
Jose Galmes0a942a02021-02-03 14:23:15 -0800210 copyFile := func(ctx android.SingletonContext, path android.Path, out string, fake bool) android.OutputPath {
211 if fake {
212 // All prebuilt binaries and headers are installed by copyFile function. This makes a fake
213 // snapshot just touch prebuilts and headers, rather than installing real files.
Kiyoung Kimae11c232021-07-19 11:38:04 +0900214 return snapshot.WriteStringToFileRule(ctx, "", out)
Jose Galmes0a942a02021-02-03 14:23:15 -0800215 } else {
Kiyoung Kimae11c232021-07-19 11:38:04 +0900216 return snapshot.CopyFileRule(pctx, ctx, path, out)
Inseob Kime9aec6a2021-01-05 20:03:22 +0900217 }
218 }
219
Inseob Kimde5744a2020-12-02 13:14:28 +0900220 // installSnapshot function copies prebuilt file (.so, .a, or executable) and json flag file.
221 // For executables, init_rc and vintf_fragments files are also copied.
Ivan Lozanod7586b62021-04-01 09:49:36 -0400222 installSnapshot := func(m LinkableInterface, fake bool) android.Paths {
Inseob Kim8471cda2019-11-15 09:59:12 +0900223 targetArch := "arch-" + m.Target().Arch.ArchType.String()
224 if m.Target().Arch.ArchVariant != "" {
225 targetArch += "-" + m.Target().Arch.ArchVariant
226 }
227
228 var ret android.Paths
229
Inseob Kimde5744a2020-12-02 13:14:28 +0900230 prop := snapshotJsonFlags{}
Inseob Kim8471cda2019-11-15 09:59:12 +0900231
232 // Common properties among snapshots.
Justin Yun1db97482023-04-11 18:20:07 +0900233 prop.InitBaseSnapshotPropsWithName(m, ctx.ModuleName(m))
Kiyoung Kim48f37782021-07-07 12:42:39 +0900234 if supportsVndkExt(s.Image) && m.IsVndkExt() {
Bill Peckham7d3f0962020-06-29 16:49:15 -0700235 // vndk exts are installed to /vendor/lib(64)?/vndk(-sp)?
Ivan Lozanod7586b62021-04-01 09:49:36 -0400236 if m.IsVndkSp() {
Bill Peckham7d3f0962020-06-29 16:49:15 -0700237 prop.RelativeInstallPath = "vndk-sp"
238 } else {
239 prop.RelativeInstallPath = "vndk"
240 }
241 } else {
242 prop.RelativeInstallPath = m.RelativeInstallPath()
243 }
Ivan Lozanod7586b62021-04-01 09:49:36 -0400244 prop.RuntimeLibs = m.SnapshotRuntimeLibs()
Inseob Kim8471cda2019-11-15 09:59:12 +0900245 prop.Required = m.RequiredModuleNames()
Inseob Kima1888ce2022-10-04 14:42:02 +0900246 if o, ok := m.(overridable); ok {
247 prop.Overrides = o.overriddenModules()
248 }
Inseob Kim8471cda2019-11-15 09:59:12 +0900249 for _, path := range m.InitRc() {
250 prop.InitRc = append(prop.InitRc, filepath.Join("configs", path.Base()))
251 }
252 for _, path := range m.VintfFragments() {
253 prop.VintfFragments = append(prop.VintfFragments, filepath.Join("configs", path.Base()))
254 }
Justin Yun3cc78462023-05-08 21:06:59 +0900255 if m.IsPrebuilt() {
256 prop.MinSdkVersion = "apex_inherit"
257 } else {
258 prop.MinSdkVersion = m.MinSdkVersion()
259 }
Inseob Kim8471cda2019-11-15 09:59:12 +0900260
261 // install config files. ignores any duplicates.
262 for _, path := range append(m.InitRc(), m.VintfFragments()...) {
263 out := filepath.Join(configsDir, path.Base())
264 if !installedConfigs[out] {
265 installedConfigs[out] = true
Jose Galmes0a942a02021-02-03 14:23:15 -0800266 ret = append(ret, copyFile(ctx, path, out, fake))
Inseob Kim8471cda2019-11-15 09:59:12 +0900267 }
268 }
269
270 var propOut string
271
Ivan Lozanod7586b62021-04-01 09:49:36 -0400272 if m.IsSnapshotLibrary() {
273 exporterInfo := ctx.ModuleProvider(m.Module(), FlagExporterInfoProvider).(FlagExporterInfo)
Inseob Kimc42f2f22020-07-29 20:32:10 +0900274
Inseob Kim8471cda2019-11-15 09:59:12 +0900275 // library flags
Colin Cross0de8a1e2020-09-18 14:15:30 -0700276 prop.ExportedFlags = exporterInfo.Flags
277 for _, dir := range exporterInfo.IncludeDirs {
Inseob Kim8471cda2019-11-15 09:59:12 +0900278 prop.ExportedDirs = append(prop.ExportedDirs, filepath.Join("include", dir.String()))
279 }
Colin Cross0de8a1e2020-09-18 14:15:30 -0700280 for _, dir := range exporterInfo.SystemIncludeDirs {
Inseob Kim8471cda2019-11-15 09:59:12 +0900281 prop.ExportedSystemDirs = append(prop.ExportedSystemDirs, filepath.Join("include", dir.String()))
282 }
Ivan Lozanod7586b62021-04-01 09:49:36 -0400283
Inseob Kim8471cda2019-11-15 09:59:12 +0900284 // shared libs dependencies aren't meaningful on static or header libs
Ivan Lozanod7586b62021-04-01 09:49:36 -0400285 if m.Shared() {
286 prop.SharedLibs = m.SnapshotSharedLibs()
Inseob Kim8471cda2019-11-15 09:59:12 +0900287 }
Ivan Lozanoadd122a2023-07-13 11:01:41 -0400288
289 // dylibs collect both shared and dylib dependencies.
290 if m.Dylib() {
291 prop.SharedLibs = m.SnapshotSharedLibs()
292 prop.Dylibs = m.SnapshotDylibs()
293 }
294
295 // static and rlib libs dependencies are required to collect the NOTICE files.
Justin Yun5e035862021-06-29 20:50:37 +0900296 prop.StaticLibs = m.SnapshotStaticLibs()
Ivan Lozanoadd122a2023-07-13 11:01:41 -0400297 prop.Rlibs = m.SnapshotRlibs()
298
Ivan Lozanod7586b62021-04-01 09:49:36 -0400299 if sanitizable, ok := m.(PlatformSanitizeable); ok {
300 if sanitizable.Static() && sanitizable.SanitizePropDefined() {
301 prop.SanitizeMinimalDep = sanitizable.MinimalRuntimeDep() || sanitizable.MinimalRuntimeNeeded()
302 prop.SanitizeUbsanDep = sanitizable.UbsanRuntimeDep() || sanitizable.UbsanRuntimeNeeded()
303 }
Inseob Kim8471cda2019-11-15 09:59:12 +0900304 }
305
306 var libType string
Ivan Lozanod7586b62021-04-01 09:49:36 -0400307 if m.Static() {
Inseob Kim8471cda2019-11-15 09:59:12 +0900308 libType = "static"
Ivan Lozanod7586b62021-04-01 09:49:36 -0400309 } else if m.Shared() {
Inseob Kim8471cda2019-11-15 09:59:12 +0900310 libType = "shared"
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400311 } else if m.Rlib() {
312 libType = "rlib"
Ivan Lozanoadd122a2023-07-13 11:01:41 -0400313 } else if m.Dylib() {
314 libType = "dylib"
Inseob Kim8471cda2019-11-15 09:59:12 +0900315 } else {
316 libType = "header"
317 }
318
319 var stem string
320
Ivan Lozanoadd122a2023-07-13 11:01:41 -0400321 // install .a, .rlib, .dylib.so, or .so
Inseob Kim8471cda2019-11-15 09:59:12 +0900322 if libType != "header" {
Ivan Lozanod7586b62021-04-01 09:49:36 -0400323 libPath := m.OutputFile().Path()
Inseob Kim8471cda2019-11-15 09:59:12 +0900324 stem = libPath.Base()
Ivan Lozanod7586b62021-04-01 09:49:36 -0400325 if sanitizable, ok := m.(PlatformSanitizeable); ok {
Justin Yun8814fc52022-12-15 21:45:35 +0900326 if (sanitizable.Static() || sanitizable.Rlib()) && sanitizable.SanitizePropDefined() {
327 if sanitizable.IsSanitizerEnabled(cfi) {
328 // both cfi and non-cfi variant for static libraries can exist.
329 // attach .cfi to distinguish between cfi and non-cfi.
330 // e.g. libbase.a -> libbase.cfi.a
331 ext := filepath.Ext(stem)
332 stem = strings.TrimSuffix(stem, ext) + ".cfi" + ext
333 prop.Sanitize = "cfi"
334 prop.ModuleName += ".cfi"
335 } else if sanitizable.IsSanitizerEnabled(Hwasan) {
336 // Same for the hwasan
337 ext := filepath.Ext(stem)
338 stem = strings.TrimSuffix(stem, ext) + ".hwasan" + ext
339 prop.Sanitize = "hwasan"
340 prop.ModuleName += ".hwasan"
341 }
Ivan Lozanod7586b62021-04-01 09:49:36 -0400342 }
Inseob Kimc42f2f22020-07-29 20:32:10 +0900343 }
Ivan Lozanoadd122a2023-07-13 11:01:41 -0400344 if m.Rlib() && m.RlibStd() {
345 // rlibs produce both rlib-std and dylib-std variants
346 ext := filepath.Ext(stem)
347 stem = strings.TrimSuffix(stem, ext) + ".rlib-std" + ext
348 prop.ModuleName += ".rlib-std"
349 }
Justin Yun17d0ee22023-05-02 14:56:38 +0900350 snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, libType, m.RelativeInstallPath(), stem)
Jose Galmes0a942a02021-02-03 14:23:15 -0800351 ret = append(ret, copyFile(ctx, libPath, snapshotLibOut, fake))
Inseob Kim8471cda2019-11-15 09:59:12 +0900352 } else {
353 stem = ctx.ModuleName(m)
354 }
355
Justin Yun17d0ee22023-05-02 14:56:38 +0900356 propOut = filepath.Join(snapshotArchDir, targetArch, libType, m.RelativeInstallPath(), stem+".json")
Ivan Lozanod7586b62021-04-01 09:49:36 -0400357 } else if m.Binary() {
Inseob Kim8471cda2019-11-15 09:59:12 +0900358 // binary flags
359 prop.Symlinks = m.Symlinks()
Justin Yun5e035862021-06-29 20:50:37 +0900360 prop.StaticExecutable = m.StaticExecutable()
Jose Galmesc1a56bc2022-03-07 14:07:59 -0800361 prop.InstallInRoot = m.InstallInRoot()
Ivan Lozanod7586b62021-04-01 09:49:36 -0400362 prop.SharedLibs = m.SnapshotSharedLibs()
Ivan Lozanoadd122a2023-07-13 11:01:41 -0400363 prop.Dylibs = m.SnapshotDylibs()
364
365 // static and rlib dependencies are required to collect the NOTICE files.
Justin Yun5e035862021-06-29 20:50:37 +0900366 prop.StaticLibs = m.SnapshotStaticLibs()
Ivan Lozanoadd122a2023-07-13 11:01:41 -0400367 prop.Rlibs = m.SnapshotRlibs()
368
Inseob Kim8471cda2019-11-15 09:59:12 +0900369 // install bin
Ivan Lozanod7586b62021-04-01 09:49:36 -0400370 binPath := m.OutputFile().Path()
Inseob Kim8471cda2019-11-15 09:59:12 +0900371 snapshotBinOut := filepath.Join(snapshotArchDir, targetArch, "binary", binPath.Base())
Jose Galmes0a942a02021-02-03 14:23:15 -0800372 ret = append(ret, copyFile(ctx, binPath, snapshotBinOut, fake))
Inseob Kim8471cda2019-11-15 09:59:12 +0900373 propOut = snapshotBinOut + ".json"
Ivan Lozanod7586b62021-04-01 09:49:36 -0400374 } else if m.Object() {
Inseob Kim1042d292020-06-01 23:23:05 +0900375 // object files aren't installed to the device, so their names can conflict.
376 // Use module name as stem.
Ivan Lozanod7586b62021-04-01 09:49:36 -0400377 objPath := m.OutputFile().Path()
Inseob Kim1042d292020-06-01 23:23:05 +0900378 snapshotObjOut := filepath.Join(snapshotArchDir, targetArch, "object",
379 ctx.ModuleName(m)+filepath.Ext(objPath.Base()))
Jose Galmes0a942a02021-02-03 14:23:15 -0800380 ret = append(ret, copyFile(ctx, objPath, snapshotObjOut, fake))
Inseob Kim1042d292020-06-01 23:23:05 +0900381 propOut = snapshotObjOut + ".json"
Inseob Kim7f283f42020-06-01 21:53:49 +0900382 } else {
383 ctx.Errorf("unknown module %q in vendor snapshot", m.String())
384 return nil
Inseob Kim8471cda2019-11-15 09:59:12 +0900385 }
386
387 j, err := json.Marshal(prop)
388 if err != nil {
389 ctx.Errorf("json marshal to %q failed: %#v", propOut, err)
390 return nil
391 }
Kiyoung Kimae11c232021-07-19 11:38:04 +0900392 ret = append(ret, snapshot.WriteStringToFileRule(ctx, string(j), propOut))
Inseob Kim8471cda2019-11-15 09:59:12 +0900393
394 return ret
395 }
396
397 ctx.VisitAllModules(func(module android.Module) {
Ivan Lozanod7586b62021-04-01 09:49:36 -0400398 m, ok := module.(LinkableInterface)
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900399 if !ok {
400 return
401 }
402
403 moduleDir := ctx.ModuleDir(module)
Kiyoung Kim48f37782021-07-07 12:42:39 +0900404 inProprietaryPath := s.Image.IsProprietaryPath(moduleDir, ctx.DeviceConfig())
Colin Cross56a83212020-09-15 18:30:11 -0700405 apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo)
Bill Peckham945441c2020-08-31 16:07:58 -0700406
Kiyoung Kim48f37782021-07-07 12:42:39 +0900407 if s.Image.ExcludeFromSnapshot(m) {
Jose Galmesf7294582020-11-13 12:07:36 -0800408 if inProprietaryPath {
Bill Peckham945441c2020-08-31 16:07:58 -0700409 // Error: exclude_from_vendor_snapshot applies
410 // to framework-path modules only.
411 ctx.Errorf("module %q in vendor proprietary path %q may not use \"exclude_from_vendor_snapshot: true\"", m.String(), moduleDir)
412 return
413 }
Bill Peckham945441c2020-08-31 16:07:58 -0700414 }
415
Kiyoung Kim48f37782021-07-07 12:42:39 +0900416 if !isSnapshotAware(ctx.DeviceConfig(), m, inProprietaryPath, apexInfo, s.Image) {
Inseob Kim8471cda2019-11-15 09:59:12 +0900417 return
418 }
419
Jose Galmes0a942a02021-02-03 14:23:15 -0800420 // If we are using directed snapshot and a module is not included in the
421 // list, we will still include the module as if it was a fake module.
422 // The reason is that soong needs all the dependencies to be present, even
423 // if they are not using during the build.
Kiyoung Kim48f37782021-07-07 12:42:39 +0900424 installAsFake := s.Fake
425 if s.Image.ExcludeFromDirectedSnapshot(ctx.DeviceConfig(), m.BaseModuleName()) {
Jose Galmes0a942a02021-02-03 14:23:15 -0800426 installAsFake = true
427 }
Inseob Kimde5744a2020-12-02 13:14:28 +0900428
Jose Galmes0a942a02021-02-03 14:23:15 -0800429 // installSnapshot installs prebuilts and json flag files
430 snapshotOutputs = append(snapshotOutputs, installSnapshot(m, installAsFake)...)
Inseob Kimde5744a2020-12-02 13:14:28 +0900431 // just gather headers and notice files here, because they are to be deduplicated
Ivan Lozanod7586b62021-04-01 09:49:36 -0400432 if m.IsSnapshotLibrary() {
433 headers = append(headers, m.SnapshotHeaders()...)
Inseob Kim8471cda2019-11-15 09:59:12 +0900434 }
435
Justin Yun1db97482023-04-11 18:20:07 +0900436 for _, notice := range m.EffectiveLicenseFiles() {
437 if _, ok := installedNotices[notice.String()]; !ok {
438 installedNotices[notice.String()] = true
439 snapshotNotices = append(snapshotNotices, notice)
Inseob Kim8471cda2019-11-15 09:59:12 +0900440 }
441 }
442 })
443
444 // install all headers after removing duplicates
445 for _, header := range android.FirstUniquePaths(headers) {
Kiyoung Kim48f37782021-07-07 12:42:39 +0900446 snapshotOutputs = append(snapshotOutputs, copyFile(ctx, header, filepath.Join(includeDir, header.String()), s.Fake))
Inseob Kim8471cda2019-11-15 09:59:12 +0900447 }
448
Justin Yun1db97482023-04-11 18:20:07 +0900449 return snapshot.SnapshotPaths{OutputFiles: snapshotOutputs, NoticeFiles: snapshotNotices}
Inseob Kim8471cda2019-11-15 09:59:12 +0900450}
451
Kiyoung Kim48f37782021-07-07 12:42:39 +0900452func init() {
453 snapshot.RegisterSnapshotAction(ccSnapshotAction)
Inseob Kim8471cda2019-11-15 09:59:12 +0900454}