blob: 2dcf26eac5a4b2684081c78d38706df727083dd9 [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() {
Inseob Kimc42f2f22020-07-29 20:32:10 +090096 // scs and hwasan export both sanitized and unsanitized variants for static and header
Inseob Kim7f283f42020-06-01 21:53:49 +090097 // Always use unsanitized variants of them.
Tri Vo6eafc362021-04-01 11:29:09 -070098 for _, t := range []SanitizerType{scs, Hwasan} {
Ivan Lozanod7586b62021-04-01 09:49:36 -040099 if !sanitizable.Shared() && sanitizable.IsSanitizerEnabled(t) {
Inseob Kim7f283f42020-06-01 21:53:49 +0900100 return false
101 }
102 }
Inseob Kimc42f2f22020-07-29 20:32:10 +0900103 // cfi also exports both variants. But for static, we capture both.
Inseob Kimde5744a2020-12-02 13:14:28 +0900104 // This is because cfi static libraries can't be linked from non-cfi modules,
105 // and vice versa. This isn't the case for scs and hwasan sanitizers.
Ivan Lozanod7586b62021-04-01 09:49:36 -0400106 if !sanitizable.Static() && !sanitizable.Shared() && sanitizable.IsSanitizerEnabled(cfi) {
Inseob Kimc42f2f22020-07-29 20:32:10 +0900107 return false
108 }
Inseob Kim7f283f42020-06-01 21:53:49 +0900109 }
Ivan Lozanod7586b62021-04-01 09:49:36 -0400110 if sanitizable.Static() {
Kiyoung Kim48f37782021-07-07 12:42:39 +0900111 return sanitizable.OutputFile().Valid() && !isPrivate(image, m)
Inseob Kim8471cda2019-11-15 09:59:12 +0900112 }
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400113 if sanitizable.Shared() || sanitizable.Rlib() {
Ivan Lozanod7586b62021-04-01 09:49:36 -0400114 if !sanitizable.OutputFile().Valid() {
Bill Peckham7d3f0962020-06-29 16:49:15 -0700115 return false
116 }
Kiyoung Kim48f37782021-07-07 12:42:39 +0900117 if includeVndk(image) {
Ivan Lozanod7586b62021-04-01 09:49:36 -0400118 if !sanitizable.IsVndk() {
Jose Galmesf7294582020-11-13 12:07:36 -0800119 return true
120 }
Ivan Lozanod7586b62021-04-01 09:49:36 -0400121 return sanitizable.IsVndkExt()
Bill Peckham7d3f0962020-06-29 16:49:15 -0700122 }
Inseob Kim8471cda2019-11-15 09:59:12 +0900123 }
124 return true
125 }
126
Inseob Kim1042d292020-06-01 23:23:05 +0900127 // Binaries and Objects
Ivan Lozanod7586b62021-04-01 09:49:36 -0400128 if m.Binary() || m.Object() {
129 return m.OutputFile().Valid()
Inseob Kim8471cda2019-11-15 09:59:12 +0900130 }
Inseob Kim7f283f42020-06-01 21:53:49 +0900131
132 return false
Inseob Kim8471cda2019-11-15 09:59:12 +0900133}
134
Rob Seymour925aa092021-08-10 20:42:03 +0000135// Extend the snapshot.SnapshotJsonFlags to include cc specific fields.
Inseob Kimde5744a2020-12-02 13:14:28 +0900136type snapshotJsonFlags struct {
Rob Seymour925aa092021-08-10 20:42:03 +0000137 snapshot.SnapshotJsonFlags
Inseob Kimde5744a2020-12-02 13:14:28 +0900138 // library flags
139 ExportedDirs []string `json:",omitempty"`
140 ExportedSystemDirs []string `json:",omitempty"`
141 ExportedFlags []string `json:",omitempty"`
142 Sanitize string `json:",omitempty"`
143 SanitizeMinimalDep bool `json:",omitempty"`
144 SanitizeUbsanDep bool `json:",omitempty"`
145
146 // binary flags
Justin Yun5e035862021-06-29 20:50:37 +0900147 Symlinks []string `json:",omitempty"`
148 StaticExecutable bool `json:",omitempty"`
Jose Galmesc1a56bc2022-03-07 14:07:59 -0800149 InstallInRoot bool `json:",omitempty"`
Inseob Kimde5744a2020-12-02 13:14:28 +0900150
151 // dependencies
152 SharedLibs []string `json:",omitempty"`
Justin Yun5e035862021-06-29 20:50:37 +0900153 StaticLibs []string `json:",omitempty"`
Inseob Kimde5744a2020-12-02 13:14:28 +0900154 RuntimeLibs []string `json:",omitempty"`
Inseob Kimde5744a2020-12-02 13:14:28 +0900155
156 // extra config files
157 InitRc []string `json:",omitempty"`
158 VintfFragments []string `json:",omitempty"`
159}
160
Kiyoung Kim48f37782021-07-07 12:42:39 +0900161var ccSnapshotAction snapshot.GenerateSnapshotAction = func(s snapshot.SnapshotSingleton, ctx android.SingletonContext, snapshotArchDir string) android.Paths {
Inseob Kim8471cda2019-11-15 09:59:12 +0900162 /*
Kiyoung Kim48f37782021-07-07 12:42:39 +0900163 Vendor snapshot zipped artifacts directory structure for cc modules:
Inseob Kim8471cda2019-11-15 09:59:12 +0900164 {SNAPSHOT_ARCH}/
165 arch-{TARGET_ARCH}-{TARGET_ARCH_VARIANT}/
166 shared/
167 (.so shared libraries)
168 static/
169 (.a static libraries)
170 header/
171 (header only libraries)
172 binary/
173 (executable binaries)
Inseob Kim1042d292020-06-01 23:23:05 +0900174 object/
175 (.o object files)
Inseob Kim8471cda2019-11-15 09:59:12 +0900176 arch-{TARGET_2ND_ARCH}-{TARGET_2ND_ARCH_VARIANT}/
177 shared/
178 (.so shared libraries)
179 static/
180 (.a static libraries)
181 header/
182 (header only libraries)
183 binary/
184 (executable binaries)
Inseob Kim1042d292020-06-01 23:23:05 +0900185 object/
186 (.o object files)
Inseob Kim8471cda2019-11-15 09:59:12 +0900187 NOTICE_FILES/
188 (notice files, e.g. libbase.txt)
189 configs/
190 (config files, e.g. init.rc files, vintf_fragments.xml files, etc.)
191 include/
192 (header files of same directory structure with source tree)
193 */
194
Kiyoung Kim48f37782021-07-07 12:42:39 +0900195 var snapshotOutputs android.Paths
Inseob Kim8471cda2019-11-15 09:59:12 +0900196
197 includeDir := filepath.Join(snapshotArchDir, "include")
198 configsDir := filepath.Join(snapshotArchDir, "configs")
199 noticeDir := filepath.Join(snapshotArchDir, "NOTICE_FILES")
200
201 installedNotices := make(map[string]bool)
202 installedConfigs := make(map[string]bool)
203
204 var headers android.Paths
205
Jose Galmes0a942a02021-02-03 14:23:15 -0800206 copyFile := func(ctx android.SingletonContext, path android.Path, out string, fake bool) android.OutputPath {
207 if fake {
208 // All prebuilt binaries and headers are installed by copyFile function. This makes a fake
209 // snapshot just touch prebuilts and headers, rather than installing real files.
Kiyoung Kimae11c232021-07-19 11:38:04 +0900210 return snapshot.WriteStringToFileRule(ctx, "", out)
Jose Galmes0a942a02021-02-03 14:23:15 -0800211 } else {
Kiyoung Kimae11c232021-07-19 11:38:04 +0900212 return snapshot.CopyFileRule(pctx, ctx, path, out)
Inseob Kime9aec6a2021-01-05 20:03:22 +0900213 }
214 }
215
Inseob Kimde5744a2020-12-02 13:14:28 +0900216 // installSnapshot function copies prebuilt file (.so, .a, or executable) and json flag file.
217 // For executables, init_rc and vintf_fragments files are also copied.
Ivan Lozanod7586b62021-04-01 09:49:36 -0400218 installSnapshot := func(m LinkableInterface, fake bool) android.Paths {
Inseob Kim8471cda2019-11-15 09:59:12 +0900219 targetArch := "arch-" + m.Target().Arch.ArchType.String()
220 if m.Target().Arch.ArchVariant != "" {
221 targetArch += "-" + m.Target().Arch.ArchVariant
222 }
223
224 var ret android.Paths
225
Inseob Kimde5744a2020-12-02 13:14:28 +0900226 prop := snapshotJsonFlags{}
Inseob Kim8471cda2019-11-15 09:59:12 +0900227
228 // Common properties among snapshots.
229 prop.ModuleName = ctx.ModuleName(m)
Kiyoung Kim48f37782021-07-07 12:42:39 +0900230 if supportsVndkExt(s.Image) && m.IsVndkExt() {
Bill Peckham7d3f0962020-06-29 16:49:15 -0700231 // vndk exts are installed to /vendor/lib(64)?/vndk(-sp)?
Ivan Lozanod7586b62021-04-01 09:49:36 -0400232 if m.IsVndkSp() {
Bill Peckham7d3f0962020-06-29 16:49:15 -0700233 prop.RelativeInstallPath = "vndk-sp"
234 } else {
235 prop.RelativeInstallPath = "vndk"
236 }
237 } else {
238 prop.RelativeInstallPath = m.RelativeInstallPath()
239 }
Ivan Lozanod7586b62021-04-01 09:49:36 -0400240 prop.RuntimeLibs = m.SnapshotRuntimeLibs()
Inseob Kim8471cda2019-11-15 09:59:12 +0900241 prop.Required = m.RequiredModuleNames()
Inseob Kima1888ce2022-10-04 14:42:02 +0900242 if o, ok := m.(overridable); ok {
243 prop.Overrides = o.overriddenModules()
244 }
Inseob Kim8471cda2019-11-15 09:59:12 +0900245 for _, path := range m.InitRc() {
246 prop.InitRc = append(prop.InitRc, filepath.Join("configs", path.Base()))
247 }
248 for _, path := range m.VintfFragments() {
249 prop.VintfFragments = append(prop.VintfFragments, filepath.Join("configs", path.Base()))
250 }
251
252 // install config files. ignores any duplicates.
253 for _, path := range append(m.InitRc(), m.VintfFragments()...) {
254 out := filepath.Join(configsDir, path.Base())
255 if !installedConfigs[out] {
256 installedConfigs[out] = true
Jose Galmes0a942a02021-02-03 14:23:15 -0800257 ret = append(ret, copyFile(ctx, path, out, fake))
Inseob Kim8471cda2019-11-15 09:59:12 +0900258 }
259 }
260
261 var propOut string
262
Ivan Lozanod7586b62021-04-01 09:49:36 -0400263 if m.IsSnapshotLibrary() {
264 exporterInfo := ctx.ModuleProvider(m.Module(), FlagExporterInfoProvider).(FlagExporterInfo)
Inseob Kimc42f2f22020-07-29 20:32:10 +0900265
Inseob Kim8471cda2019-11-15 09:59:12 +0900266 // library flags
Colin Cross0de8a1e2020-09-18 14:15:30 -0700267 prop.ExportedFlags = exporterInfo.Flags
268 for _, dir := range exporterInfo.IncludeDirs {
Inseob Kim8471cda2019-11-15 09:59:12 +0900269 prop.ExportedDirs = append(prop.ExportedDirs, filepath.Join("include", dir.String()))
270 }
Colin Cross0de8a1e2020-09-18 14:15:30 -0700271 for _, dir := range exporterInfo.SystemIncludeDirs {
Inseob Kim8471cda2019-11-15 09:59:12 +0900272 prop.ExportedSystemDirs = append(prop.ExportedSystemDirs, filepath.Join("include", dir.String()))
273 }
Ivan Lozanod7586b62021-04-01 09:49:36 -0400274
Inseob Kim8471cda2019-11-15 09:59:12 +0900275 // shared libs dependencies aren't meaningful on static or header libs
Ivan Lozanod7586b62021-04-01 09:49:36 -0400276 if m.Shared() {
277 prop.SharedLibs = m.SnapshotSharedLibs()
Inseob Kim8471cda2019-11-15 09:59:12 +0900278 }
Justin Yun5e035862021-06-29 20:50:37 +0900279 // static libs dependencies are required to collect the NOTICE files.
280 prop.StaticLibs = m.SnapshotStaticLibs()
Ivan Lozanod7586b62021-04-01 09:49:36 -0400281 if sanitizable, ok := m.(PlatformSanitizeable); ok {
282 if sanitizable.Static() && sanitizable.SanitizePropDefined() {
283 prop.SanitizeMinimalDep = sanitizable.MinimalRuntimeDep() || sanitizable.MinimalRuntimeNeeded()
284 prop.SanitizeUbsanDep = sanitizable.UbsanRuntimeDep() || sanitizable.UbsanRuntimeNeeded()
285 }
Inseob Kim8471cda2019-11-15 09:59:12 +0900286 }
287
288 var libType string
Ivan Lozanod7586b62021-04-01 09:49:36 -0400289 if m.Static() {
Inseob Kim8471cda2019-11-15 09:59:12 +0900290 libType = "static"
Ivan Lozanod7586b62021-04-01 09:49:36 -0400291 } else if m.Shared() {
Inseob Kim8471cda2019-11-15 09:59:12 +0900292 libType = "shared"
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400293 } else if m.Rlib() {
294 libType = "rlib"
Inseob Kim8471cda2019-11-15 09:59:12 +0900295 } else {
296 libType = "header"
297 }
298
299 var stem string
300
301 // install .a or .so
302 if libType != "header" {
Ivan Lozanod7586b62021-04-01 09:49:36 -0400303 libPath := m.OutputFile().Path()
Inseob Kim8471cda2019-11-15 09:59:12 +0900304 stem = libPath.Base()
Ivan Lozanod7586b62021-04-01 09:49:36 -0400305 if sanitizable, ok := m.(PlatformSanitizeable); ok {
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400306 if (sanitizable.Static() || sanitizable.Rlib()) && sanitizable.SanitizePropDefined() && sanitizable.IsSanitizerEnabled(cfi) {
Ivan Lozanod7586b62021-04-01 09:49:36 -0400307 // both cfi and non-cfi variant for static libraries can exist.
308 // attach .cfi to distinguish between cfi and non-cfi.
309 // e.g. libbase.a -> libbase.cfi.a
310 ext := filepath.Ext(stem)
311 stem = strings.TrimSuffix(stem, ext) + ".cfi" + ext
312 prop.Sanitize = "cfi"
313 prop.ModuleName += ".cfi"
314 }
Inseob Kimc42f2f22020-07-29 20:32:10 +0900315 }
Inseob Kim8471cda2019-11-15 09:59:12 +0900316 snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, libType, stem)
Jose Galmes0a942a02021-02-03 14:23:15 -0800317 ret = append(ret, copyFile(ctx, libPath, snapshotLibOut, fake))
Inseob Kim8471cda2019-11-15 09:59:12 +0900318 } else {
319 stem = ctx.ModuleName(m)
320 }
321
322 propOut = filepath.Join(snapshotArchDir, targetArch, libType, stem+".json")
Ivan Lozanod7586b62021-04-01 09:49:36 -0400323 } else if m.Binary() {
Inseob Kim8471cda2019-11-15 09:59:12 +0900324 // binary flags
325 prop.Symlinks = m.Symlinks()
Justin Yun5e035862021-06-29 20:50:37 +0900326 prop.StaticExecutable = m.StaticExecutable()
Jose Galmesc1a56bc2022-03-07 14:07:59 -0800327 prop.InstallInRoot = m.InstallInRoot()
Ivan Lozanod7586b62021-04-01 09:49:36 -0400328 prop.SharedLibs = m.SnapshotSharedLibs()
Justin Yun5e035862021-06-29 20:50:37 +0900329 // static libs dependencies are required to collect the NOTICE files.
330 prop.StaticLibs = m.SnapshotStaticLibs()
Inseob Kim8471cda2019-11-15 09:59:12 +0900331 // install bin
Ivan Lozanod7586b62021-04-01 09:49:36 -0400332 binPath := m.OutputFile().Path()
Inseob Kim8471cda2019-11-15 09:59:12 +0900333 snapshotBinOut := filepath.Join(snapshotArchDir, targetArch, "binary", binPath.Base())
Jose Galmes0a942a02021-02-03 14:23:15 -0800334 ret = append(ret, copyFile(ctx, binPath, snapshotBinOut, fake))
Inseob Kim8471cda2019-11-15 09:59:12 +0900335 propOut = snapshotBinOut + ".json"
Ivan Lozanod7586b62021-04-01 09:49:36 -0400336 } else if m.Object() {
Inseob Kim1042d292020-06-01 23:23:05 +0900337 // object files aren't installed to the device, so their names can conflict.
338 // Use module name as stem.
Ivan Lozanod7586b62021-04-01 09:49:36 -0400339 objPath := m.OutputFile().Path()
Inseob Kim1042d292020-06-01 23:23:05 +0900340 snapshotObjOut := filepath.Join(snapshotArchDir, targetArch, "object",
341 ctx.ModuleName(m)+filepath.Ext(objPath.Base()))
Jose Galmes0a942a02021-02-03 14:23:15 -0800342 ret = append(ret, copyFile(ctx, objPath, snapshotObjOut, fake))
Inseob Kim1042d292020-06-01 23:23:05 +0900343 propOut = snapshotObjOut + ".json"
Inseob Kim7f283f42020-06-01 21:53:49 +0900344 } else {
345 ctx.Errorf("unknown module %q in vendor snapshot", m.String())
346 return nil
Inseob Kim8471cda2019-11-15 09:59:12 +0900347 }
348
349 j, err := json.Marshal(prop)
350 if err != nil {
351 ctx.Errorf("json marshal to %q failed: %#v", propOut, err)
352 return nil
353 }
Kiyoung Kimae11c232021-07-19 11:38:04 +0900354 ret = append(ret, snapshot.WriteStringToFileRule(ctx, string(j), propOut))
Inseob Kim8471cda2019-11-15 09:59:12 +0900355
356 return ret
357 }
358
359 ctx.VisitAllModules(func(module android.Module) {
Ivan Lozanod7586b62021-04-01 09:49:36 -0400360 m, ok := module.(LinkableInterface)
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900361 if !ok {
362 return
363 }
364
365 moduleDir := ctx.ModuleDir(module)
Kiyoung Kim48f37782021-07-07 12:42:39 +0900366 inProprietaryPath := s.Image.IsProprietaryPath(moduleDir, ctx.DeviceConfig())
Colin Cross56a83212020-09-15 18:30:11 -0700367 apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo)
Bill Peckham945441c2020-08-31 16:07:58 -0700368
Kiyoung Kim48f37782021-07-07 12:42:39 +0900369 if s.Image.ExcludeFromSnapshot(m) {
Jose Galmesf7294582020-11-13 12:07:36 -0800370 if inProprietaryPath {
Bill Peckham945441c2020-08-31 16:07:58 -0700371 // Error: exclude_from_vendor_snapshot applies
372 // to framework-path modules only.
373 ctx.Errorf("module %q in vendor proprietary path %q may not use \"exclude_from_vendor_snapshot: true\"", m.String(), moduleDir)
374 return
375 }
Bill Peckham945441c2020-08-31 16:07:58 -0700376 }
377
Kiyoung Kim48f37782021-07-07 12:42:39 +0900378 if !isSnapshotAware(ctx.DeviceConfig(), m, inProprietaryPath, apexInfo, s.Image) {
Inseob Kim8471cda2019-11-15 09:59:12 +0900379 return
380 }
381
Jose Galmes0a942a02021-02-03 14:23:15 -0800382 // If we are using directed snapshot and a module is not included in the
383 // list, we will still include the module as if it was a fake module.
384 // The reason is that soong needs all the dependencies to be present, even
385 // if they are not using during the build.
Kiyoung Kim48f37782021-07-07 12:42:39 +0900386 installAsFake := s.Fake
387 if s.Image.ExcludeFromDirectedSnapshot(ctx.DeviceConfig(), m.BaseModuleName()) {
Jose Galmes0a942a02021-02-03 14:23:15 -0800388 installAsFake = true
389 }
Inseob Kimde5744a2020-12-02 13:14:28 +0900390
Jose Galmes0a942a02021-02-03 14:23:15 -0800391 // installSnapshot installs prebuilts and json flag files
392 snapshotOutputs = append(snapshotOutputs, installSnapshot(m, installAsFake)...)
Inseob Kimde5744a2020-12-02 13:14:28 +0900393 // just gather headers and notice files here, because they are to be deduplicated
Ivan Lozanod7586b62021-04-01 09:49:36 -0400394 if m.IsSnapshotLibrary() {
395 headers = append(headers, m.SnapshotHeaders()...)
Inseob Kim8471cda2019-11-15 09:59:12 +0900396 }
397
Justin Yun885a7de2021-06-29 20:34:53 +0900398 if len(m.EffectiveLicenseFiles()) > 0 {
Inseob Kim8471cda2019-11-15 09:59:12 +0900399 noticeName := ctx.ModuleName(m) + ".txt"
400 noticeOut := filepath.Join(noticeDir, noticeName)
401 // skip already copied notice file
402 if !installedNotices[noticeOut] {
403 installedNotices[noticeOut] = true
Justin Yun885a7de2021-06-29 20:34:53 +0900404 snapshotOutputs = append(snapshotOutputs, combineNoticesRule(ctx, m.EffectiveLicenseFiles(), noticeOut))
Inseob Kim8471cda2019-11-15 09:59:12 +0900405 }
406 }
407 })
408
409 // install all headers after removing duplicates
410 for _, header := range android.FirstUniquePaths(headers) {
Kiyoung Kim48f37782021-07-07 12:42:39 +0900411 snapshotOutputs = append(snapshotOutputs, copyFile(ctx, header, filepath.Join(includeDir, header.String()), s.Fake))
Inseob Kim8471cda2019-11-15 09:59:12 +0900412 }
413
Kiyoung Kim48f37782021-07-07 12:42:39 +0900414 return snapshotOutputs
Inseob Kim8471cda2019-11-15 09:59:12 +0900415}
416
Kiyoung Kim48f37782021-07-07 12:42:39 +0900417func init() {
418 snapshot.RegisterSnapshotAction(ccSnapshotAction)
Inseob Kim8471cda2019-11-15 09:59:12 +0900419}