blob: 66df1014553114215ca4015841d808f2d1f16bf5 [file] [log] [blame]
Jiyong Parkc678ad32018-04-10 13:07:10 +09001// Copyright 2016 Google Inc. All rights reserved.
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.
14
Jaewoong Jung4b79e982020-06-01 10:45:49 -070015package etc
Jiyong Parkc678ad32018-04-10 13:07:10 +090016
Yo Chiang803c40d2020-11-16 20:32:51 +080017// This file implements module types that install prebuilt artifacts.
18//
19// There exist two classes of prebuilt modules in the Android tree. The first class are the ones
20// based on `android.Prebuilt`, such as `cc_prebuilt_library` and `java_import`. This kind of
21// modules may exist both as prebuilts and source at the same time, though only one would be
22// installed and the other would be marked disabled. The `prebuilt_postdeps` mutator would select
23// the actual modules to be installed. More details in android/prebuilt.go.
24//
25// The second class is described in this file. Unlike `android.Prebuilt` based module types,
26// `prebuilt_etc` exist only as prebuilts and cannot have a same-named source module counterpart.
27// This makes the logic of `prebuilt_etc` to be much simpler as they don't need to go through the
28// various `prebuilt_*` mutators.
Jaewoong Jung4b79e982020-06-01 10:45:49 -070029
Yo Chiang803c40d2020-11-16 20:32:51 +080030import (
Kiyoung Kimae11c232021-07-19 11:38:04 +090031 "encoding/json"
Jiyong Park76a42f52021-02-16 06:50:37 +090032 "fmt"
Kiyoung Kimae11c232021-07-19 11:38:04 +090033 "path/filepath"
Inseob Kim27408bf2021-04-06 21:00:17 +090034 "strings"
Jiyong Park76a42f52021-02-16 06:50:37 +090035
Jaewoong Jung4b79e982020-06-01 10:45:49 -070036 "github.com/google/blueprint/proptools"
37
38 "android/soong/android"
Kiyoung Kimae11c232021-07-19 11:38:04 +090039 "android/soong/snapshot"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070040)
41
42var pctx = android.NewPackageContext("android/soong/etc")
Jiyong Parkc678ad32018-04-10 13:07:10 +090043
Jaewoong Jungc3fcdb42019-02-13 05:50:33 -080044// TODO(jungw): Now that it handles more than the ones in etc/, consider renaming this file.
Jiyong Parkc678ad32018-04-10 13:07:10 +090045
46func init() {
Jaewoong Jung4b79e982020-06-01 10:45:49 -070047 pctx.Import("android/soong/android")
Jooyung Han0703fd82020-08-26 22:11:53 +090048 RegisterPrebuiltEtcBuildComponents(android.InitRegistrationContext)
Kiyoung Kimae11c232021-07-19 11:38:04 +090049 snapshot.RegisterSnapshotAction(generatePrebuiltSnapshot)
Jooyung Han0703fd82020-08-26 22:11:53 +090050}
Jaewoong Jung4b79e982020-06-01 10:45:49 -070051
Jooyung Han0703fd82020-08-26 22:11:53 +090052func RegisterPrebuiltEtcBuildComponents(ctx android.RegistrationContext) {
53 ctx.RegisterModuleType("prebuilt_etc", PrebuiltEtcFactory)
54 ctx.RegisterModuleType("prebuilt_etc_host", PrebuiltEtcHostFactory)
Miguel32b02802022-12-01 18:38:26 +000055 ctx.RegisterModuleType("prebuilt_etc_cacerts", PrebuiltEtcCaCertsFactory)
Inseob Kim27408bf2021-04-06 21:00:17 +090056 ctx.RegisterModuleType("prebuilt_root", PrebuiltRootFactory)
Liz Kammere9ecddc2022-01-04 17:27:52 -050057 ctx.RegisterModuleType("prebuilt_root_host", PrebuiltRootHostFactory)
Jooyung Han0703fd82020-08-26 22:11:53 +090058 ctx.RegisterModuleType("prebuilt_usr_share", PrebuiltUserShareFactory)
59 ctx.RegisterModuleType("prebuilt_usr_share_host", PrebuiltUserShareHostFactory)
60 ctx.RegisterModuleType("prebuilt_font", PrebuiltFontFactory)
61 ctx.RegisterModuleType("prebuilt_firmware", PrebuiltFirmwareFactory)
62 ctx.RegisterModuleType("prebuilt_dsp", PrebuiltDSPFactory)
Colin Cross83ebf232021-04-09 09:41:23 -070063 ctx.RegisterModuleType("prebuilt_rfsa", PrebuiltRFSAFactory)
Colin Crossf17e2b52023-10-30 15:17:25 -070064 ctx.RegisterModuleType("prebuilt_renderscript_bitcode", PrebuiltRenderScriptBitcodeFactory)
Inseob Kim1e27a142021-05-06 11:46:11 +000065
66 ctx.RegisterModuleType("prebuilt_defaults", defaultsFactory)
Rupert Shuttleworth378fc1b2021-07-28 08:03:16 -040067
Jiyong Parkc678ad32018-04-10 13:07:10 +090068}
69
Paul Duffin1172fed2021-03-08 11:28:18 +000070var PrepareForTestWithPrebuiltEtc = android.FixtureRegisterWithContext(RegisterPrebuiltEtcBuildComponents)
71
Jiyong Parkc678ad32018-04-10 13:07:10 +090072type prebuiltEtcProperties struct {
Yo Chiang803c40d2020-11-16 20:32:51 +080073 // Source file of this prebuilt. Can reference a genrule type module with the ":module" syntax.
Colin Cross27b922f2019-03-04 22:35:41 -080074 Src *string `android:"path,arch_variant"`
Jiyong Parkc678ad32018-04-10 13:07:10 +090075
Yo Chiangf0e19fe2020-11-18 15:28:42 +080076 // Optional name for the installed file. If unspecified, name of the module is used as the file
77 // name.
Jiyong Park139a2e62018-10-26 21:49:39 +090078 Filename *string `android:"arch_variant"`
79
Yo Chiangf0e19fe2020-11-18 15:28:42 +080080 // When set to true, and filename property is not set, the name for the installed file
Jiyong Park1a7cf082018-11-13 11:59:12 +090081 // is the same as the file name of the source file.
82 Filename_from_src *bool `android:"arch_variant"`
83
Yifan Hong1b3348d2020-01-21 15:53:22 -080084 // Make this module available when building for ramdisk.
Yifan Hong39143a92020-10-26 12:43:12 -070085 // On device without a dedicated recovery partition, the module is only
86 // available after switching root into
87 // /first_stage_ramdisk. To expose the module before switching root, install
88 // the recovery variant instead.
Yifan Hong1b3348d2020-01-21 15:53:22 -080089 Ramdisk_available *bool
90
Yifan Hong60e0cfb2020-10-21 15:17:56 -070091 // Make this module available when building for vendor ramdisk.
Yifan Hong39143a92020-10-26 12:43:12 -070092 // On device without a dedicated recovery partition, the module is only
93 // available after switching root into
94 // /first_stage_ramdisk. To expose the module before switching root, install
95 // the recovery variant instead.
Yifan Hong60e0cfb2020-10-21 15:17:56 -070096 Vendor_ramdisk_available *bool
97
Inseob Kim08758f02021-04-08 21:13:22 +090098 // Make this module available when building for debug ramdisk.
99 Debug_ramdisk_available *bool
100
Tao Bao0ba5c942018-08-14 22:20:22 -0700101 // Make this module available when building for recovery.
102 Recovery_available *bool
103
Jiyong Parkad9ce042018-10-31 22:49:57 +0900104 // Whether this module is directly installable to one of the partitions. Default: true.
105 Installable *bool
Yo Chiang3d64d492020-05-27 17:56:39 +0800106
107 // Install symlinks to the installed file.
108 Symlinks []string `android:"arch_variant"`
Jiyong Parkc678ad32018-04-10 13:07:10 +0900109}
110
Inseob Kim27408bf2021-04-06 21:00:17 +0900111type prebuiltSubdirProperties struct {
112 // Optional subdirectory under which this file is installed into, cannot be specified with
113 // relative_install_path, prefer relative_install_path.
114 Sub_dir *string `android:"arch_variant"`
115
116 // Optional subdirectory under which this file is installed into, cannot be specified with
117 // sub_dir.
118 Relative_install_path *string `android:"arch_variant"`
119}
120
Jooyung Han39edb6c2019-11-06 16:53:07 +0900121type PrebuiltEtcModule interface {
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700122 android.Module
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800123
124 // Returns the base install directory, such as "etc", "usr/share".
Jooyung Han0703fd82020-08-26 22:11:53 +0900125 BaseDir() string
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800126
127 // Returns the sub install directory relative to BaseDir().
Jooyung Han39edb6c2019-11-06 16:53:07 +0900128 SubDir() string
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800129
130 // Returns an android.OutputPath to the intermeidate file, which is the renamed prebuilt source
131 // file.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700132 OutputFile() android.OutputPath
Jooyung Han39edb6c2019-11-06 16:53:07 +0900133}
134
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900135type PrebuiltEtc struct {
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700136 android.ModuleBase
Inseob Kim1e27a142021-05-06 11:46:11 +0000137 android.DefaultableModuleBase
Jiyong Parkc678ad32018-04-10 13:07:10 +0900138
Kiyoung Kimae11c232021-07-19 11:38:04 +0900139 snapshot.VendorSnapshotModuleInterface
140 snapshot.RecoverySnapshotModuleInterface
141
Inseob Kim27408bf2021-04-06 21:00:17 +0900142 properties prebuiltEtcProperties
143 subdirProperties prebuiltSubdirProperties
Jiyong Parkc678ad32018-04-10 13:07:10 +0900144
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700145 sourceFilePath android.Path
146 outputFilePath android.OutputPath
Jaewoong Jungc3fcdb42019-02-13 05:50:33 -0800147 // The base install location, e.g. "etc" for prebuilt_etc, "usr/share" for prebuilt_usr_share.
Colin Cross2f634572023-11-13 12:12:06 -0800148 installDirBase string
149 installDirBase64 string
150 installAvoidMultilibConflict bool
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800151 // The base install location when soc_specific property is set to true, e.g. "firmware" for
152 // prebuilt_firmware.
Patrice Arruda057a8b12019-06-03 15:29:27 -0700153 socInstallDirBase string
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700154 installDirPath android.InstallPath
155 additionalDependencies *android.Paths
Colin Crossf17e2b52023-10-30 15:17:25 -0700156
157 makeClass string
Jiyong Parkc678ad32018-04-10 13:07:10 +0900158}
159
Inseob Kim1e27a142021-05-06 11:46:11 +0000160type Defaults struct {
161 android.ModuleBase
162 android.DefaultsModuleBase
163}
164
Yifan Hong1b3348d2020-01-21 15:53:22 -0800165func (p *PrebuiltEtc) inRamdisk() bool {
166 return p.ModuleBase.InRamdisk() || p.ModuleBase.InstallInRamdisk()
167}
168
169func (p *PrebuiltEtc) onlyInRamdisk() bool {
170 return p.ModuleBase.InstallInRamdisk()
171}
172
173func (p *PrebuiltEtc) InstallInRamdisk() bool {
174 return p.inRamdisk()
175}
176
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700177func (p *PrebuiltEtc) inVendorRamdisk() bool {
178 return p.ModuleBase.InVendorRamdisk() || p.ModuleBase.InstallInVendorRamdisk()
179}
180
181func (p *PrebuiltEtc) onlyInVendorRamdisk() bool {
182 return p.ModuleBase.InstallInVendorRamdisk()
183}
184
185func (p *PrebuiltEtc) InstallInVendorRamdisk() bool {
186 return p.inVendorRamdisk()
187}
188
Inseob Kim08758f02021-04-08 21:13:22 +0900189func (p *PrebuiltEtc) inDebugRamdisk() bool {
190 return p.ModuleBase.InDebugRamdisk() || p.ModuleBase.InstallInDebugRamdisk()
191}
192
193func (p *PrebuiltEtc) onlyInDebugRamdisk() bool {
194 return p.ModuleBase.InstallInDebugRamdisk()
195}
196
197func (p *PrebuiltEtc) InstallInDebugRamdisk() bool {
198 return p.inDebugRamdisk()
199}
200
Kiyoung Kimae11c232021-07-19 11:38:04 +0900201func (p *PrebuiltEtc) InRecovery() bool {
Colin Cross7228ecd2019-11-18 16:00:16 -0800202 return p.ModuleBase.InRecovery() || p.ModuleBase.InstallInRecovery()
Tao Bao0ba5c942018-08-14 22:20:22 -0700203}
204
205func (p *PrebuiltEtc) onlyInRecovery() bool {
206 return p.ModuleBase.InstallInRecovery()
207}
208
209func (p *PrebuiltEtc) InstallInRecovery() bool {
Kiyoung Kimae11c232021-07-19 11:38:04 +0900210 return p.InRecovery()
Tao Bao0ba5c942018-08-14 22:20:22 -0700211}
212
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700213var _ android.ImageInterface = (*PrebuiltEtc)(nil)
Colin Cross7228ecd2019-11-18 16:00:16 -0800214
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700215func (p *PrebuiltEtc) ImageMutatorBegin(ctx android.BaseModuleContext) {}
Colin Cross7228ecd2019-11-18 16:00:16 -0800216
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700217func (p *PrebuiltEtc) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700218 return !p.ModuleBase.InstallInRecovery() && !p.ModuleBase.InstallInRamdisk() &&
Inseob Kim08758f02021-04-08 21:13:22 +0900219 !p.ModuleBase.InstallInVendorRamdisk() && !p.ModuleBase.InstallInDebugRamdisk()
Yifan Hong1b3348d2020-01-21 15:53:22 -0800220}
221
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700222func (p *PrebuiltEtc) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
223 return proptools.Bool(p.properties.Ramdisk_available) || p.ModuleBase.InstallInRamdisk()
Colin Cross7228ecd2019-11-18 16:00:16 -0800224}
225
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700226func (p *PrebuiltEtc) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
227 return proptools.Bool(p.properties.Vendor_ramdisk_available) || p.ModuleBase.InstallInVendorRamdisk()
228}
229
Inseob Kim08758f02021-04-08 21:13:22 +0900230func (p *PrebuiltEtc) DebugRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
231 return proptools.Bool(p.properties.Debug_ramdisk_available) || p.ModuleBase.InstallInDebugRamdisk()
232}
233
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700234func (p *PrebuiltEtc) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
235 return proptools.Bool(p.properties.Recovery_available) || p.ModuleBase.InstallInRecovery()
Colin Cross7228ecd2019-11-18 16:00:16 -0800236}
237
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700238func (p *PrebuiltEtc) ExtraImageVariations(ctx android.BaseModuleContext) []string {
Colin Cross7228ecd2019-11-18 16:00:16 -0800239 return nil
240}
241
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700242func (p *PrebuiltEtc) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) {
Colin Cross7228ecd2019-11-18 16:00:16 -0800243}
244
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700245func (p *PrebuiltEtc) SourceFilePath(ctx android.ModuleContext) android.Path {
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800246 return android.PathForModuleSrc(ctx, proptools.String(p.properties.Src))
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900247}
248
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700249func (p *PrebuiltEtc) InstallDirPath() android.InstallPath {
Jooyung Hana0171822019-07-22 15:48:36 +0900250 return p.installDirPath
251}
252
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900253// This allows other derivative modules (e.g. prebuilt_etc_xml) to perform
254// additional steps (like validating the src) before the file is installed.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700255func (p *PrebuiltEtc) SetAdditionalDependencies(paths android.Paths) {
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900256 p.additionalDependencies = &paths
257}
258
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700259func (p *PrebuiltEtc) OutputFile() android.OutputPath {
Jiyong Parkc43e0ac2018-10-04 20:27:15 +0900260 return p.outputFilePath
261}
262
Jiyong Park76a42f52021-02-16 06:50:37 +0900263var _ android.OutputFileProducer = (*PrebuiltEtc)(nil)
264
265func (p *PrebuiltEtc) OutputFiles(tag string) (android.Paths, error) {
266 switch tag {
267 case "":
268 return android.Paths{p.outputFilePath}, nil
269 default:
270 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
271 }
272}
273
Jiyong Parkc43e0ac2018-10-04 20:27:15 +0900274func (p *PrebuiltEtc) SubDir() string {
Inseob Kim27408bf2021-04-06 21:00:17 +0900275 if subDir := proptools.String(p.subdirProperties.Sub_dir); subDir != "" {
Liz Kammer0449a632020-06-26 10:12:36 -0700276 return subDir
277 }
Inseob Kim27408bf2021-04-06 21:00:17 +0900278 return proptools.String(p.subdirProperties.Relative_install_path)
Jiyong Parkc43e0ac2018-10-04 20:27:15 +0900279}
280
Jooyung Han0703fd82020-08-26 22:11:53 +0900281func (p *PrebuiltEtc) BaseDir() string {
Jooyung Han8e5685d2020-09-21 11:02:57 +0900282 return p.installDirBase
Jooyung Han0703fd82020-08-26 22:11:53 +0900283}
284
Jiyong Parkad9ce042018-10-31 22:49:57 +0900285func (p *PrebuiltEtc) Installable() bool {
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800286 return p.properties.Installable == nil || proptools.Bool(p.properties.Installable)
Jiyong Parkad9ce042018-10-31 22:49:57 +0900287}
288
Kiyoung Kimae11c232021-07-19 11:38:04 +0900289func (p *PrebuiltEtc) InVendor() bool {
290 return p.ModuleBase.InstallInVendor()
291}
292
293func (p *PrebuiltEtc) ExcludeFromVendorSnapshot() bool {
294 return false
295}
296
297func (p *PrebuiltEtc) ExcludeFromRecoverySnapshot() bool {
298 return false
299}
300
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700301func (p *PrebuiltEtc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800302 filename := proptools.String(p.properties.Filename)
303 filenameFromSrc := proptools.Bool(p.properties.Filename_from_src)
Colin Cross725eac62022-10-03 15:31:29 -0700304 if p.properties.Src != nil {
305 p.sourceFilePath = android.PathForModuleSrc(ctx, proptools.String(p.properties.Src))
306
307 // Determine the output file basename.
308 // If Filename is set, use the name specified by the property.
309 // If Filename_from_src is set, use the source file name.
310 // Otherwise use the module name.
311 if filename != "" {
312 if filenameFromSrc {
313 ctx.PropertyErrorf("filename_from_src", "filename is set. filename_from_src can't be true")
314 return
315 }
316 } else if filenameFromSrc {
317 filename = p.sourceFilePath.Base()
318 } else {
319 filename = ctx.ModuleName()
Jiyong Park1a7cf082018-11-13 11:59:12 +0900320 }
Colin Cross725eac62022-10-03 15:31:29 -0700321 } else if ctx.Config().AllowMissingDependencies() {
322 // If no srcs was set and AllowMissingDependencies is enabled then
323 // mark the module as missing dependencies and set a fake source path
324 // and file name.
325 ctx.AddMissingDependencies([]string{"MISSING_PREBUILT_SRC_FILE"})
326 p.sourceFilePath = android.PathForModuleSrc(ctx)
327 if filename == "" {
328 filename = ctx.ModuleName()
329 }
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800330 } else {
Colin Cross725eac62022-10-03 15:31:29 -0700331 ctx.PropertyErrorf("src", "missing prebuilt source file")
332 return
Jiyong Park139a2e62018-10-26 21:49:39 +0900333 }
Patrice Arruda057a8b12019-06-03 15:29:27 -0700334
Inseob Kim27408bf2021-04-06 21:00:17 +0900335 if strings.Contains(filename, "/") {
336 ctx.PropertyErrorf("filename", "filename cannot contain separator '/'")
337 return
338 }
339
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800340 // Check that `sub_dir` and `relative_install_path` are not set at the same time.
Inseob Kim27408bf2021-04-06 21:00:17 +0900341 if p.subdirProperties.Sub_dir != nil && p.subdirProperties.Relative_install_path != nil {
Liz Kammer0449a632020-06-26 10:12:36 -0700342 ctx.PropertyErrorf("sub_dir", "relative_install_path is set. Cannot set sub_dir")
343 }
344
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800345 // If soc install dir was specified and SOC specific is set, set the installDirPath to the
346 // specified socInstallDirBase.
Jooyung Han8e5685d2020-09-21 11:02:57 +0900347 installBaseDir := p.installDirBase
Colin Crossf17e2b52023-10-30 15:17:25 -0700348 if p.Target().Arch.ArchType.Multilib == "lib64" && p.installDirBase64 != "" {
349 installBaseDir = p.installDirBase64
350 }
Jooyung Han8e5685d2020-09-21 11:02:57 +0900351 if p.SocSpecific() && p.socInstallDirBase != "" {
352 installBaseDir = p.socInstallDirBase
353 }
Colin Cross2f634572023-11-13 12:12:06 -0800354 if p.installAvoidMultilibConflict && !ctx.Host() && ctx.Config().HasMultilibConflict(ctx.Arch().ArchType) {
355 installBaseDir = filepath.Join(installBaseDir, ctx.Arch().ArchType.String())
356 }
357
Jooyung Han8e5685d2020-09-21 11:02:57 +0900358 p.installDirPath = android.PathForModuleInstall(ctx, installBaseDir, p.SubDir())
Jiyong Parkc43e0ac2018-10-04 20:27:15 +0900359
Spandan Das756d3402023-06-05 22:49:50 +0000360 // Call InstallFile even when uninstallable to make the module included in the package
361 ip := installProperties{
362 installable: p.Installable(),
363 filename: filename,
364 sourceFilePath: p.sourceFilePath,
365 symlinks: p.properties.Symlinks,
366 }
367 p.addInstallRules(ctx, ip)
368}
Jiyong Parkf9f68052020-09-29 20:15:08 +0900369
Spandan Das756d3402023-06-05 22:49:50 +0000370type installProperties struct {
371 installable bool
372 filename string
373 sourceFilePath android.Path
374 symlinks []string
375}
376
377// utility function to add install rules to the build graph.
378// Reduces code duplication between Soong and Mixed build analysis
379func (p *PrebuiltEtc) addInstallRules(ctx android.ModuleContext, ip installProperties) {
380 if !ip.installable {
Inseob Kim916901e2021-02-17 15:48:53 +0900381 p.SkipInstall()
382 }
383
Spandan Das756d3402023-06-05 22:49:50 +0000384 // Copy the file from src to a location in out/ with the correct `filename`
385 // This ensures that outputFilePath has the correct name for others to
386 // use, as the source file may have a different name.
387 p.outputFilePath = android.PathForModuleOut(ctx, ip.filename).OutputPath
388 ctx.Build(pctx, android.BuildParams{
389 Rule: android.Cp,
390 Output: p.outputFilePath,
391 Input: ip.sourceFilePath,
392 })
393
394 installPath := ctx.InstallFile(p.installDirPath, ip.filename, p.outputFilePath)
395 for _, sl := range ip.symlinks {
Inseob Kim916901e2021-02-17 15:48:53 +0900396 ctx.InstallSymlink(p.installDirPath, sl, installPath)
Jiyong Parkf9f68052020-09-29 20:15:08 +0900397 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900398}
399
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700400func (p *PrebuiltEtc) AndroidMkEntries() []android.AndroidMkEntries {
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700401 nameSuffix := ""
Yifan Hong1b3348d2020-01-21 15:53:22 -0800402 if p.inRamdisk() && !p.onlyInRamdisk() {
403 nameSuffix = ".ramdisk"
404 }
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700405 if p.inVendorRamdisk() && !p.onlyInVendorRamdisk() {
406 nameSuffix = ".vendor_ramdisk"
407 }
Inseob Kim08758f02021-04-08 21:13:22 +0900408 if p.inDebugRamdisk() && !p.onlyInDebugRamdisk() {
409 nameSuffix = ".debug_ramdisk"
410 }
Kiyoung Kimae11c232021-07-19 11:38:04 +0900411 if p.InRecovery() && !p.onlyInRecovery() {
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700412 nameSuffix = ".recovery"
413 }
Colin Crossf17e2b52023-10-30 15:17:25 -0700414
415 class := p.makeClass
416 if class == "" {
417 class = "ETC"
418 }
419
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700420 return []android.AndroidMkEntries{android.AndroidMkEntries{
Colin Crossf17e2b52023-10-30 15:17:25 -0700421 Class: class,
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700422 SubName: nameSuffix,
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700423 OutputFile: android.OptionalPathForPath(p.outputFilePath),
424 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -0700425 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700426 entries.SetString("LOCAL_MODULE_TAGS", "optional")
Colin Crossc68db4b2021-11-11 18:59:15 -0800427 entries.SetString("LOCAL_MODULE_PATH", p.installDirPath.String())
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700428 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePath.Base())
Yo Chiang3d64d492020-05-27 17:56:39 +0800429 if len(p.properties.Symlinks) > 0 {
430 entries.AddStrings("LOCAL_MODULE_SYMLINKS", p.properties.Symlinks...)
431 }
Yo Chiang803c40d2020-11-16 20:32:51 +0800432 entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.Installable())
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700433 if p.additionalDependencies != nil {
Yo Chiang803c40d2020-11-16 20:32:51 +0800434 entries.AddStrings("LOCAL_ADDITIONAL_DEPENDENCIES", p.additionalDependencies.Strings()...)
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900435 }
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700436 },
Jiyong Parkc678ad32018-04-10 13:07:10 +0900437 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900438 }}
Jiyong Parkc678ad32018-04-10 13:07:10 +0900439}
440
Jooyung Hana0171822019-07-22 15:48:36 +0900441func InitPrebuiltEtcModule(p *PrebuiltEtc, dirBase string) {
442 p.installDirBase = dirBase
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900443 p.AddProperties(&p.properties)
Inseob Kim27408bf2021-04-06 21:00:17 +0900444 p.AddProperties(&p.subdirProperties)
445}
446
447func InitPrebuiltRootModule(p *PrebuiltEtc) {
448 p.installDirBase = "."
449 p.AddProperties(&p.properties)
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900450}
Jiyong Parkc678ad32018-04-10 13:07:10 +0900451
Patrice Arruda9e14b962019-03-11 15:58:50 -0700452// prebuilt_etc is for a prebuilt artifact that is installed in
453// <partition>/etc/<sub_dir> directory.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700454func PrebuiltEtcFactory() android.Module {
Jooyung Hana0171822019-07-22 15:48:36 +0900455 module := &PrebuiltEtc{}
456 InitPrebuiltEtcModule(module, "etc")
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900457 // This module is device-only
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700458 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Inseob Kim1e27a142021-05-06 11:46:11 +0000459 android.InitDefaultableModule(module)
460 return module
461}
462
463func defaultsFactory() android.Module {
464 return DefaultsFactory()
465}
466
467func DefaultsFactory(props ...interface{}) android.Module {
468 module := &Defaults{}
469
470 module.AddProperties(props...)
471 module.AddProperties(
472 &prebuiltEtcProperties{},
473 &prebuiltSubdirProperties{},
474 )
475
476 android.InitDefaultsModule(module)
477
Jiyong Parkc678ad32018-04-10 13:07:10 +0900478 return module
479}
Tao Bao0ba5c942018-08-14 22:20:22 -0700480
Patrice Arruda9e14b962019-03-11 15:58:50 -0700481// prebuilt_etc_host is for a host prebuilt artifact that is installed in
482// $(HOST_OUT)/etc/<sub_dir> directory.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700483func PrebuiltEtcHostFactory() android.Module {
Jooyung Hana0171822019-07-22 15:48:36 +0900484 module := &PrebuiltEtc{}
485 InitPrebuiltEtcModule(module, "etc")
Jaewoong Jung24788182019-02-04 14:34:10 -0800486 // This module is host-only
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700487 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100488 android.InitDefaultableModule(module)
Jaewoong Jung24788182019-02-04 14:34:10 -0800489 return module
490}
491
Miguel32b02802022-12-01 18:38:26 +0000492// prebuilt_etc_host is for a host prebuilt artifact that is installed in
493// <partition>/etc/<sub_dir> directory.
494func PrebuiltEtcCaCertsFactory() android.Module {
495 module := &PrebuiltEtc{}
496 InitPrebuiltEtcModule(module, "cacerts")
497 // This module is device-only
498 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Miguel32b02802022-12-01 18:38:26 +0000499 return module
500}
501
Inseob Kim27408bf2021-04-06 21:00:17 +0900502// prebuilt_root is for a prebuilt artifact that is installed in
503// <partition>/ directory. Can't have any sub directories.
504func PrebuiltRootFactory() android.Module {
505 module := &PrebuiltEtc{}
506 InitPrebuiltRootModule(module)
507 // This module is device-only
508 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100509 android.InitDefaultableModule(module)
Inseob Kim27408bf2021-04-06 21:00:17 +0900510 return module
511}
512
Liz Kammere9ecddc2022-01-04 17:27:52 -0500513// prebuilt_root_host is for a host prebuilt artifact that is installed in $(HOST_OUT)/<sub_dir>
514// directory.
515func PrebuiltRootHostFactory() android.Module {
516 module := &PrebuiltEtc{}
517 InitPrebuiltEtcModule(module, ".")
518 // This module is host-only
519 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
520 android.InitDefaultableModule(module)
521 return module
522}
523
Patrice Arruda9e14b962019-03-11 15:58:50 -0700524// prebuilt_usr_share is for a prebuilt artifact that is installed in
525// <partition>/usr/share/<sub_dir> directory.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700526func PrebuiltUserShareFactory() android.Module {
Jooyung Hana0171822019-07-22 15:48:36 +0900527 module := &PrebuiltEtc{}
528 InitPrebuiltEtcModule(module, "usr/share")
Jaewoong Jungc3fcdb42019-02-13 05:50:33 -0800529 // This module is device-only
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700530 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100531 android.InitDefaultableModule(module)
Jaewoong Jungc3fcdb42019-02-13 05:50:33 -0800532 return module
533}
534
Patrice Arruda9e14b962019-03-11 15:58:50 -0700535// prebuild_usr_share_host is for a host prebuilt artifact that is installed in
536// $(HOST_OUT)/usr/share/<sub_dir> directory.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700537func PrebuiltUserShareHostFactory() android.Module {
Jooyung Hana0171822019-07-22 15:48:36 +0900538 module := &PrebuiltEtc{}
539 InitPrebuiltEtcModule(module, "usr/share")
Patrice Arruda300cef92019-02-22 15:47:57 -0800540 // This module is host-only
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700541 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100542 android.InitDefaultableModule(module)
Patrice Arruda300cef92019-02-22 15:47:57 -0800543 return module
544}
545
Patrice Arruda61583eb2019-05-14 08:20:45 -0700546// prebuilt_font installs a font in <partition>/fonts directory.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700547func PrebuiltFontFactory() android.Module {
Jooyung Hana0171822019-07-22 15:48:36 +0900548 module := &PrebuiltEtc{}
549 InitPrebuiltEtcModule(module, "fonts")
Patrice Arruda61583eb2019-05-14 08:20:45 -0700550 // This module is device-only
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700551 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100552 android.InitDefaultableModule(module)
Patrice Arruda61583eb2019-05-14 08:20:45 -0700553 return module
554}
Patrice Arruda057a8b12019-06-03 15:29:27 -0700555
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800556// prebuilt_firmware installs a firmware file to <partition>/etc/firmware directory for system
557// image.
558// If soc_specific property is set to true, the firmware file is installed to the
559// vendor <partition>/firmware directory for vendor image.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700560func PrebuiltFirmwareFactory() android.Module {
Jooyung Hana0171822019-07-22 15:48:36 +0900561 module := &PrebuiltEtc{}
562 module.socInstallDirBase = "firmware"
563 InitPrebuiltEtcModule(module, "etc/firmware")
Patrice Arruda057a8b12019-06-03 15:29:27 -0700564 // This module is device-only
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700565 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100566 android.InitDefaultableModule(module)
Patrice Arruda057a8b12019-06-03 15:29:27 -0700567 return module
568}
Patrice Arruda0f688002020-06-08 21:40:25 +0000569
570// prebuilt_dsp installs a DSP related file to <partition>/etc/dsp directory for system image.
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800571// If soc_specific property is set to true, the DSP related file is installed to the
572// vendor <partition>/dsp directory for vendor image.
Patrice Arruda0f688002020-06-08 21:40:25 +0000573func PrebuiltDSPFactory() android.Module {
574 module := &PrebuiltEtc{}
575 module.socInstallDirBase = "dsp"
576 InitPrebuiltEtcModule(module, "etc/dsp")
577 // This module is device-only
578 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100579 android.InitDefaultableModule(module)
Patrice Arruda0f688002020-06-08 21:40:25 +0000580 return module
581}
Colin Cross83ebf232021-04-09 09:41:23 -0700582
Colin Crossf17e2b52023-10-30 15:17:25 -0700583// prebuilt_renderscript_bitcode installs a *.bc file into /system/lib or /system/lib64.
584func PrebuiltRenderScriptBitcodeFactory() android.Module {
585 module := &PrebuiltEtc{}
586 module.makeClass = "RENDERSCRIPT_BITCODE"
587 module.installDirBase64 = "lib64"
Colin Cross2f634572023-11-13 12:12:06 -0800588 module.installAvoidMultilibConflict = true
Colin Crossf17e2b52023-10-30 15:17:25 -0700589 InitPrebuiltEtcModule(module, "lib")
590 // This module is device-only
591 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibBoth)
592 android.InitDefaultableModule(module)
593 return module
594}
595
Colin Cross83ebf232021-04-09 09:41:23 -0700596// prebuilt_rfsa installs a firmware file that will be available through Qualcomm's RFSA
597// to the <partition>/lib/rfsa directory.
598func PrebuiltRFSAFactory() android.Module {
599 module := &PrebuiltEtc{}
600 // Ideally these would go in /vendor/dsp, but the /vendor/lib/rfsa paths are hardcoded in too
601 // many places outside of the application processor. They could be moved to /vendor/dsp once
602 // that is cleaned up.
603 InitPrebuiltEtcModule(module, "lib/rfsa")
604 // This module is device-only
605 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100606 android.InitDefaultableModule(module)
Colin Cross83ebf232021-04-09 09:41:23 -0700607 return module
608}
Kiyoung Kimae11c232021-07-19 11:38:04 +0900609
Kiyoung Kimae11c232021-07-19 11:38:04 +0900610// Copy file into the snapshot
611func copyFile(ctx android.SingletonContext, path android.Path, out string, fake bool) android.OutputPath {
612 if fake {
613 // Create empty file instead for the fake snapshot
614 return snapshot.WriteStringToFileRule(ctx, "", out)
615 } else {
616 return snapshot.CopyFileRule(pctx, ctx, path, out)
617 }
618}
619
620// Check if the module is target of the snapshot
621func isSnapshotAware(ctx android.SingletonContext, m *PrebuiltEtc, image snapshot.SnapshotImage) bool {
622 if !m.Enabled() {
623 return false
624 }
625
626 // Skip if the module is not included in the image
627 if !image.InImage(m)() {
628 return false
629 }
630
631 // When android/prebuilt.go selects between source and prebuilt, it sets
632 // HideFromMake on the other one to avoid duplicate install rules in make.
633 if m.IsHideFromMake() {
634 return false
635 }
636
637 // There are some prebuilt_etc module with multiple definition of same name.
638 // Check if the target would be included from the build
639 if !m.ExportedToMake() {
640 return false
641 }
642
643 // Skip if the module is in the predefined path list to skip
644 if image.IsProprietaryPath(ctx.ModuleDir(m), ctx.DeviceConfig()) {
645 return false
646 }
647
648 // Skip if the module should be excluded
649 if image.ExcludeFromSnapshot(m) || image.ExcludeFromDirectedSnapshot(ctx.DeviceConfig(), m.BaseModuleName()) {
650 return false
651 }
652
653 // Skip from other exceptional cases
654 if m.Target().Os.Class != android.Device {
655 return false
656 }
657 if m.Target().NativeBridge == android.NativeBridgeEnabled {
658 return false
659 }
660
661 return true
662}
663
Justin Yun1db97482023-04-11 18:20:07 +0900664func generatePrebuiltSnapshot(s snapshot.SnapshotSingleton, ctx android.SingletonContext, snapshotArchDir string) snapshot.SnapshotPaths {
Kiyoung Kimae11c232021-07-19 11:38:04 +0900665 /*
666 Snapshot zipped artifacts directory structure for etc modules:
667 {SNAPSHOT_ARCH}/
668 arch-{TARGET_ARCH}-{TARGET_ARCH_VARIANT}/
669 etc/
670 (prebuilt etc files)
671 arch-{TARGET_2ND_ARCH}-{TARGET_2ND_ARCH_VARIANT}/
672 etc/
673 (prebuilt etc files)
674 NOTICE_FILES/
675 (notice files)
676 */
677 var snapshotOutputs android.Paths
Justin Yun1db97482023-04-11 18:20:07 +0900678 var snapshotNotices android.Paths
Kiyoung Kimae11c232021-07-19 11:38:04 +0900679 installedNotices := make(map[string]bool)
680
681 ctx.VisitAllModules(func(module android.Module) {
682 m, ok := module.(*PrebuiltEtc)
683 if !ok {
684 return
685 }
686
687 if !isSnapshotAware(ctx, m, s.Image) {
688 return
689 }
690
691 targetArch := "arch-" + m.Target().Arch.ArchType.String()
692
693 snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, "etc", m.BaseModuleName())
694 snapshotOutputs = append(snapshotOutputs, copyFile(ctx, m.OutputFile(), snapshotLibOut, s.Fake))
695
Rob Seymour925aa092021-08-10 20:42:03 +0000696 prop := snapshot.SnapshotJsonFlags{}
Kiyoung Kimae11c232021-07-19 11:38:04 +0900697 propOut := snapshotLibOut + ".json"
Justin Yun1db97482023-04-11 18:20:07 +0900698 prop.InitBaseSnapshotProps(m)
Justin Yun8bd3afe2023-05-12 15:53:06 +0900699 prop.RelativeInstallPath = m.SubDir()
Kiyoung Kimae11c232021-07-19 11:38:04 +0900700
701 if m.properties.Filename != nil {
702 prop.Filename = *m.properties.Filename
703 }
704
705 j, err := json.Marshal(prop)
706 if err != nil {
707 ctx.Errorf("json marshal to %q failed: %#v", propOut, err)
708 return
709 }
710 snapshotOutputs = append(snapshotOutputs, snapshot.WriteStringToFileRule(ctx, string(j), propOut))
711
Justin Yun1db97482023-04-11 18:20:07 +0900712 for _, notice := range m.EffectiveLicenseFiles() {
713 if _, ok := installedNotices[notice.String()]; !ok {
714 installedNotices[notice.String()] = true
715 snapshotNotices = append(snapshotNotices, notice)
Kiyoung Kimae11c232021-07-19 11:38:04 +0900716 }
717 }
718
719 })
720
Justin Yun1db97482023-04-11 18:20:07 +0900721 return snapshot.SnapshotPaths{OutputFiles: snapshotOutputs, NoticeFiles: snapshotNotices}
Kiyoung Kimae11c232021-07-19 11:38:04 +0900722}