blob: 6ab3b8890f2d71132765c66e02baea3cdaf2a67f [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 (
Jiyong Park76a42f52021-02-16 06:50:37 +090031 "fmt"
Kiyoung Kimae11c232021-07-19 11:38:04 +090032 "path/filepath"
Inseob Kim27408bf2021-04-06 21:00:17 +090033 "strings"
Jiyong Park76a42f52021-02-16 06:50:37 +090034
Jaewoong Jung4b79e982020-06-01 10:45:49 -070035 "github.com/google/blueprint/proptools"
36
37 "android/soong/android"
38)
39
40var pctx = android.NewPackageContext("android/soong/etc")
Jiyong Parkc678ad32018-04-10 13:07:10 +090041
Jaewoong Jungc3fcdb42019-02-13 05:50:33 -080042// TODO(jungw): Now that it handles more than the ones in etc/, consider renaming this file.
Jiyong Parkc678ad32018-04-10 13:07:10 +090043
44func init() {
Jaewoong Jung4b79e982020-06-01 10:45:49 -070045 pctx.Import("android/soong/android")
Jooyung Han0703fd82020-08-26 22:11:53 +090046 RegisterPrebuiltEtcBuildComponents(android.InitRegistrationContext)
47}
Jaewoong Jung4b79e982020-06-01 10:45:49 -070048
Jooyung Han0703fd82020-08-26 22:11:53 +090049func RegisterPrebuiltEtcBuildComponents(ctx android.RegistrationContext) {
50 ctx.RegisterModuleType("prebuilt_etc", PrebuiltEtcFactory)
51 ctx.RegisterModuleType("prebuilt_etc_host", PrebuiltEtcHostFactory)
Miguel32b02802022-12-01 18:38:26 +000052 ctx.RegisterModuleType("prebuilt_etc_cacerts", PrebuiltEtcCaCertsFactory)
Inseob Kim27408bf2021-04-06 21:00:17 +090053 ctx.RegisterModuleType("prebuilt_root", PrebuiltRootFactory)
Liz Kammere9ecddc2022-01-04 17:27:52 -050054 ctx.RegisterModuleType("prebuilt_root_host", PrebuiltRootHostFactory)
Jooyung Han0703fd82020-08-26 22:11:53 +090055 ctx.RegisterModuleType("prebuilt_usr_share", PrebuiltUserShareFactory)
56 ctx.RegisterModuleType("prebuilt_usr_share_host", PrebuiltUserShareHostFactory)
yangbill63c5e192024-03-27 09:02:12 +000057 ctx.RegisterModuleType("prebuilt_usr_hyphendata", PrebuiltUserHyphenDataFactory)
yangbill85527e62024-04-30 08:24:50 +000058 ctx.RegisterModuleType("prebuilt_usr_keylayout", PrebuiltUserKeyLayoutFactory)
59 ctx.RegisterModuleType("prebuilt_usr_keychars", PrebuiltUserKeyCharsFactory)
60 ctx.RegisterModuleType("prebuilt_usr_idc", PrebuiltUserIdcFactory)
Jooyung Han0703fd82020-08-26 22:11:53 +090061 ctx.RegisterModuleType("prebuilt_font", PrebuiltFontFactory)
62 ctx.RegisterModuleType("prebuilt_firmware", PrebuiltFirmwareFactory)
63 ctx.RegisterModuleType("prebuilt_dsp", PrebuiltDSPFactory)
Colin Cross83ebf232021-04-09 09:41:23 -070064 ctx.RegisterModuleType("prebuilt_rfsa", PrebuiltRFSAFactory)
Colin Crossf17e2b52023-10-30 15:17:25 -070065 ctx.RegisterModuleType("prebuilt_renderscript_bitcode", PrebuiltRenderScriptBitcodeFactory)
Inseob Kim1e27a142021-05-06 11:46:11 +000066
67 ctx.RegisterModuleType("prebuilt_defaults", defaultsFactory)
Rupert Shuttleworth378fc1b2021-07-28 08:03:16 -040068
Jiyong Parkc678ad32018-04-10 13:07:10 +090069}
70
Paul Duffin1172fed2021-03-08 11:28:18 +000071var PrepareForTestWithPrebuiltEtc = android.FixtureRegisterWithContext(RegisterPrebuiltEtcBuildComponents)
72
Jiyong Parkc678ad32018-04-10 13:07:10 +090073type prebuiltEtcProperties struct {
Yo Chiang803c40d2020-11-16 20:32:51 +080074 // Source file of this prebuilt. Can reference a genrule type module with the ":module" syntax.
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +110075 // Mutually exclusive with srcs.
Colin Cross27b922f2019-03-04 22:35:41 -080076 Src *string `android:"path,arch_variant"`
Jiyong Parkc678ad32018-04-10 13:07:10 +090077
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +110078 // Source files of this prebuilt. Can reference a genrule type module with the ":module" syntax.
79 // Mutually exclusive with src. When used, filename_from_src is set to true.
80 Srcs []string `android:"path,arch_variant"`
81
Yo Chiangf0e19fe2020-11-18 15:28:42 +080082 // Optional name for the installed file. If unspecified, name of the module is used as the file
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +110083 // name. Only available when using a single source (src).
Jiyong Park139a2e62018-10-26 21:49:39 +090084 Filename *string `android:"arch_variant"`
85
Yo Chiangf0e19fe2020-11-18 15:28:42 +080086 // When set to true, and filename property is not set, the name for the installed file
Jiyong Park1a7cf082018-11-13 11:59:12 +090087 // is the same as the file name of the source file.
88 Filename_from_src *bool `android:"arch_variant"`
89
Yifan Hong1b3348d2020-01-21 15:53:22 -080090 // Make this module available when building for ramdisk.
Yifan Hong39143a92020-10-26 12:43:12 -070091 // On device without a dedicated recovery partition, the module is only
92 // available after switching root into
93 // /first_stage_ramdisk. To expose the module before switching root, install
94 // the recovery variant instead.
Yifan Hong1b3348d2020-01-21 15:53:22 -080095 Ramdisk_available *bool
96
Yifan Hong60e0cfb2020-10-21 15:17:56 -070097 // Make this module available when building for vendor ramdisk.
Yifan Hong39143a92020-10-26 12:43:12 -070098 // On device without a dedicated recovery partition, the module is only
99 // available after switching root into
100 // /first_stage_ramdisk. To expose the module before switching root, install
101 // the recovery variant instead.
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700102 Vendor_ramdisk_available *bool
103
Inseob Kim08758f02021-04-08 21:13:22 +0900104 // Make this module available when building for debug ramdisk.
105 Debug_ramdisk_available *bool
106
Tao Bao0ba5c942018-08-14 22:20:22 -0700107 // Make this module available when building for recovery.
108 Recovery_available *bool
109
Jiyong Parkad9ce042018-10-31 22:49:57 +0900110 // Whether this module is directly installable to one of the partitions. Default: true.
111 Installable *bool
Yo Chiang3d64d492020-05-27 17:56:39 +0800112
113 // Install symlinks to the installed file.
114 Symlinks []string `android:"arch_variant"`
Jiyong Parkc678ad32018-04-10 13:07:10 +0900115}
116
Inseob Kim27408bf2021-04-06 21:00:17 +0900117type prebuiltSubdirProperties struct {
118 // Optional subdirectory under which this file is installed into, cannot be specified with
119 // relative_install_path, prefer relative_install_path.
120 Sub_dir *string `android:"arch_variant"`
121
122 // Optional subdirectory under which this file is installed into, cannot be specified with
123 // sub_dir.
124 Relative_install_path *string `android:"arch_variant"`
125}
126
Jooyung Han39edb6c2019-11-06 16:53:07 +0900127type PrebuiltEtcModule interface {
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700128 android.Module
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800129
130 // Returns the base install directory, such as "etc", "usr/share".
Jooyung Han0703fd82020-08-26 22:11:53 +0900131 BaseDir() string
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800132
133 // Returns the sub install directory relative to BaseDir().
Jooyung Han39edb6c2019-11-06 16:53:07 +0900134 SubDir() string
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800135
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100136 // Returns an android.OutputPath to the intermediate file, which is the renamed prebuilt source
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800137 // file.
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100138 OutputFiles(tag string) (android.Paths, error)
Jooyung Han39edb6c2019-11-06 16:53:07 +0900139}
140
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900141type PrebuiltEtc struct {
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700142 android.ModuleBase
Inseob Kim1e27a142021-05-06 11:46:11 +0000143 android.DefaultableModuleBase
Jiyong Parkc678ad32018-04-10 13:07:10 +0900144
Inseob Kim27408bf2021-04-06 21:00:17 +0900145 properties prebuiltEtcProperties
146 subdirProperties prebuiltSubdirProperties
Jiyong Parkc678ad32018-04-10 13:07:10 +0900147
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100148 sourceFilePaths android.Paths
149 outputFilePaths android.OutputPaths
Jaewoong Jungc3fcdb42019-02-13 05:50:33 -0800150 // The base install location, e.g. "etc" for prebuilt_etc, "usr/share" for prebuilt_usr_share.
Colin Cross2f634572023-11-13 12:12:06 -0800151 installDirBase string
152 installDirBase64 string
153 installAvoidMultilibConflict bool
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800154 // The base install location when soc_specific property is set to true, e.g. "firmware" for
155 // prebuilt_firmware.
Patrice Arruda057a8b12019-06-03 15:29:27 -0700156 socInstallDirBase string
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700157 installDirPath android.InstallPath
158 additionalDependencies *android.Paths
Colin Crossf17e2b52023-10-30 15:17:25 -0700159
160 makeClass string
Jiyong Parkc678ad32018-04-10 13:07:10 +0900161}
162
Inseob Kim1e27a142021-05-06 11:46:11 +0000163type Defaults struct {
164 android.ModuleBase
165 android.DefaultsModuleBase
166}
167
Yifan Hong1b3348d2020-01-21 15:53:22 -0800168func (p *PrebuiltEtc) inRamdisk() bool {
169 return p.ModuleBase.InRamdisk() || p.ModuleBase.InstallInRamdisk()
170}
171
172func (p *PrebuiltEtc) onlyInRamdisk() bool {
173 return p.ModuleBase.InstallInRamdisk()
174}
175
176func (p *PrebuiltEtc) InstallInRamdisk() bool {
177 return p.inRamdisk()
178}
179
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700180func (p *PrebuiltEtc) inVendorRamdisk() bool {
181 return p.ModuleBase.InVendorRamdisk() || p.ModuleBase.InstallInVendorRamdisk()
182}
183
184func (p *PrebuiltEtc) onlyInVendorRamdisk() bool {
185 return p.ModuleBase.InstallInVendorRamdisk()
186}
187
188func (p *PrebuiltEtc) InstallInVendorRamdisk() bool {
189 return p.inVendorRamdisk()
190}
191
Inseob Kim08758f02021-04-08 21:13:22 +0900192func (p *PrebuiltEtc) inDebugRamdisk() bool {
193 return p.ModuleBase.InDebugRamdisk() || p.ModuleBase.InstallInDebugRamdisk()
194}
195
196func (p *PrebuiltEtc) onlyInDebugRamdisk() bool {
197 return p.ModuleBase.InstallInDebugRamdisk()
198}
199
200func (p *PrebuiltEtc) InstallInDebugRamdisk() bool {
201 return p.inDebugRamdisk()
202}
203
Kiyoung Kimae11c232021-07-19 11:38:04 +0900204func (p *PrebuiltEtc) InRecovery() bool {
Colin Cross7228ecd2019-11-18 16:00:16 -0800205 return p.ModuleBase.InRecovery() || p.ModuleBase.InstallInRecovery()
Tao Bao0ba5c942018-08-14 22:20:22 -0700206}
207
208func (p *PrebuiltEtc) onlyInRecovery() bool {
209 return p.ModuleBase.InstallInRecovery()
210}
211
212func (p *PrebuiltEtc) InstallInRecovery() bool {
Kiyoung Kimae11c232021-07-19 11:38:04 +0900213 return p.InRecovery()
Tao Bao0ba5c942018-08-14 22:20:22 -0700214}
215
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700216var _ android.ImageInterface = (*PrebuiltEtc)(nil)
Colin Cross7228ecd2019-11-18 16:00:16 -0800217
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700218func (p *PrebuiltEtc) ImageMutatorBegin(ctx android.BaseModuleContext) {}
Colin Cross7228ecd2019-11-18 16:00:16 -0800219
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700220func (p *PrebuiltEtc) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700221 return !p.ModuleBase.InstallInRecovery() && !p.ModuleBase.InstallInRamdisk() &&
Inseob Kim08758f02021-04-08 21:13:22 +0900222 !p.ModuleBase.InstallInVendorRamdisk() && !p.ModuleBase.InstallInDebugRamdisk()
Yifan Hong1b3348d2020-01-21 15:53:22 -0800223}
224
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700225func (p *PrebuiltEtc) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
226 return proptools.Bool(p.properties.Ramdisk_available) || p.ModuleBase.InstallInRamdisk()
Colin Cross7228ecd2019-11-18 16:00:16 -0800227}
228
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700229func (p *PrebuiltEtc) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
230 return proptools.Bool(p.properties.Vendor_ramdisk_available) || p.ModuleBase.InstallInVendorRamdisk()
231}
232
Inseob Kim08758f02021-04-08 21:13:22 +0900233func (p *PrebuiltEtc) DebugRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
234 return proptools.Bool(p.properties.Debug_ramdisk_available) || p.ModuleBase.InstallInDebugRamdisk()
235}
236
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700237func (p *PrebuiltEtc) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
238 return proptools.Bool(p.properties.Recovery_available) || p.ModuleBase.InstallInRecovery()
Colin Cross7228ecd2019-11-18 16:00:16 -0800239}
240
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700241func (p *PrebuiltEtc) ExtraImageVariations(ctx android.BaseModuleContext) []string {
Colin Cross7228ecd2019-11-18 16:00:16 -0800242 return nil
243}
244
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700245func (p *PrebuiltEtc) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) {
Colin Cross7228ecd2019-11-18 16:00:16 -0800246}
247
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700248func (p *PrebuiltEtc) SourceFilePath(ctx android.ModuleContext) android.Path {
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100249 if len(p.properties.Srcs) > 0 {
250 panic(fmt.Errorf("SourceFilePath not available on multi-source prebuilt %q", p.Name()))
251 }
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800252 return android.PathForModuleSrc(ctx, proptools.String(p.properties.Src))
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900253}
254
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700255func (p *PrebuiltEtc) InstallDirPath() android.InstallPath {
Jooyung Hana0171822019-07-22 15:48:36 +0900256 return p.installDirPath
257}
258
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900259// This allows other derivative modules (e.g. prebuilt_etc_xml) to perform
260// additional steps (like validating the src) before the file is installed.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700261func (p *PrebuiltEtc) SetAdditionalDependencies(paths android.Paths) {
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900262 p.additionalDependencies = &paths
263}
264
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700265func (p *PrebuiltEtc) OutputFile() android.OutputPath {
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100266 if len(p.properties.Srcs) > 0 {
267 panic(fmt.Errorf("OutputFile not available on multi-source prebuilt %q", p.Name()))
268 }
269 return p.outputFilePaths[0]
Jiyong Parkc43e0ac2018-10-04 20:27:15 +0900270}
271
Jiyong Park76a42f52021-02-16 06:50:37 +0900272var _ android.OutputFileProducer = (*PrebuiltEtc)(nil)
273
274func (p *PrebuiltEtc) OutputFiles(tag string) (android.Paths, error) {
275 switch tag {
276 case "":
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100277 return p.outputFilePaths.Paths(), nil
Jiyong Park76a42f52021-02-16 06:50:37 +0900278 default:
279 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
280 }
281}
282
Jiyong Parkc43e0ac2018-10-04 20:27:15 +0900283func (p *PrebuiltEtc) SubDir() string {
Inseob Kim27408bf2021-04-06 21:00:17 +0900284 if subDir := proptools.String(p.subdirProperties.Sub_dir); subDir != "" {
Liz Kammer0449a632020-06-26 10:12:36 -0700285 return subDir
286 }
Inseob Kim27408bf2021-04-06 21:00:17 +0900287 return proptools.String(p.subdirProperties.Relative_install_path)
Jiyong Parkc43e0ac2018-10-04 20:27:15 +0900288}
289
Jooyung Han0703fd82020-08-26 22:11:53 +0900290func (p *PrebuiltEtc) BaseDir() string {
Jooyung Han8e5685d2020-09-21 11:02:57 +0900291 return p.installDirBase
Jooyung Han0703fd82020-08-26 22:11:53 +0900292}
293
Jiyong Parkad9ce042018-10-31 22:49:57 +0900294func (p *PrebuiltEtc) Installable() bool {
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800295 return p.properties.Installable == nil || proptools.Bool(p.properties.Installable)
Jiyong Parkad9ce042018-10-31 22:49:57 +0900296}
297
Kiyoung Kimae11c232021-07-19 11:38:04 +0900298func (p *PrebuiltEtc) InVendor() bool {
299 return p.ModuleBase.InstallInVendor()
300}
301
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100302func (p *PrebuiltEtc) installBaseDir(ctx android.ModuleContext) string {
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800303 // If soc install dir was specified and SOC specific is set, set the installDirPath to the
304 // specified socInstallDirBase.
Jooyung Han8e5685d2020-09-21 11:02:57 +0900305 installBaseDir := p.installDirBase
Colin Crossf17e2b52023-10-30 15:17:25 -0700306 if p.Target().Arch.ArchType.Multilib == "lib64" && p.installDirBase64 != "" {
307 installBaseDir = p.installDirBase64
308 }
Jooyung Han8e5685d2020-09-21 11:02:57 +0900309 if p.SocSpecific() && p.socInstallDirBase != "" {
310 installBaseDir = p.socInstallDirBase
311 }
Colin Cross2f634572023-11-13 12:12:06 -0800312 if p.installAvoidMultilibConflict && !ctx.Host() && ctx.Config().HasMultilibConflict(ctx.Arch().ArchType) {
313 installBaseDir = filepath.Join(installBaseDir, ctx.Arch().ArchType.String())
314 }
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100315 return installBaseDir
316}
Colin Cross2f634572023-11-13 12:12:06 -0800317
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100318func (p *PrebuiltEtc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
319 var installs []installProperties
Jiyong Parkc43e0ac2018-10-04 20:27:15 +0900320
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100321 if p.properties.Src != nil && len(p.properties.Srcs) > 0 {
322 ctx.PropertyErrorf("src", "src is set. Cannot set srcs")
Spandan Das756d3402023-06-05 22:49:50 +0000323 }
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100324
325 // Check that `sub_dir` and `relative_install_path` are not set at the same time.
326 if p.subdirProperties.Sub_dir != nil && p.subdirProperties.Relative_install_path != nil {
327 ctx.PropertyErrorf("sub_dir", "relative_install_path is set. Cannot set sub_dir")
328 }
329 p.installDirPath = android.PathForModuleInstall(ctx, p.installBaseDir(ctx), p.SubDir())
330
331 filename := proptools.String(p.properties.Filename)
332 filenameFromSrc := proptools.Bool(p.properties.Filename_from_src)
333 if p.properties.Src != nil {
334 p.sourceFilePaths = android.PathsForModuleSrc(ctx, []string{proptools.String(p.properties.Src)})
335 // If the source was not found, set a fake source path to
336 // support AllowMissingDependencies executions.
337 if len(p.sourceFilePaths) == 0 {
338 p.sourceFilePaths = android.Paths{android.PathForModuleSrc(ctx)}
339 }
340
341 // Determine the output file basename.
342 // If Filename is set, use the name specified by the property.
343 // If Filename_from_src is set, use the source file name.
344 // Otherwise use the module name.
345 if filename != "" {
346 if filenameFromSrc {
347 ctx.PropertyErrorf("filename_from_src", "filename is set. filename_from_src can't be true")
348 return
349 }
350 } else if filenameFromSrc {
351 filename = p.sourceFilePaths[0].Base()
352 } else {
353 filename = ctx.ModuleName()
354 }
355 if strings.Contains(filename, "/") {
356 ctx.PropertyErrorf("filename", "filename cannot contain separator '/'")
357 return
358 }
359 p.outputFilePaths = android.OutputPaths{android.PathForModuleOut(ctx, filename).OutputPath}
360
361 ip := installProperties{
362 filename: filename,
363 sourceFilePath: p.sourceFilePaths[0],
364 outputFilePath: p.outputFilePaths[0],
365 installDirPath: p.installDirPath,
366 symlinks: p.properties.Symlinks,
367 }
368 installs = append(installs, ip)
369 } else if len(p.properties.Srcs) > 0 {
370 if filename != "" {
371 ctx.PropertyErrorf("filename", "filename cannot be set when using srcs")
372 }
373 if len(p.properties.Symlinks) > 0 {
374 ctx.PropertyErrorf("symlinks", "symlinks cannot be set when using srcs")
375 }
376 if p.properties.Filename_from_src != nil {
377 ctx.PropertyErrorf("filename_from_src", "filename_from_src is implicitly set to true when using srcs")
378 }
379 p.sourceFilePaths = android.PathsForModuleSrc(ctx, p.properties.Srcs)
380 for _, src := range p.sourceFilePaths {
381 filename := src.Base()
382 output := android.PathForModuleOut(ctx, filename).OutputPath
383 ip := installProperties{
384 filename: filename,
385 sourceFilePath: src,
386 outputFilePath: output,
387 installDirPath: p.installDirPath,
388 }
389 p.outputFilePaths = append(p.outputFilePaths, output)
390 installs = append(installs, ip)
391 }
392 } else if ctx.Config().AllowMissingDependencies() {
393 // If no srcs was set and AllowMissingDependencies is enabled then
394 // mark the module as missing dependencies and set a fake source path
395 // and file name.
396 ctx.AddMissingDependencies([]string{"MISSING_PREBUILT_SRC_FILE"})
397 p.sourceFilePaths = android.Paths{android.PathForModuleSrc(ctx)}
398 if filename == "" {
399 filename = ctx.ModuleName()
400 }
401 p.outputFilePaths = android.OutputPaths{android.PathForModuleOut(ctx, filename).OutputPath}
402 ip := installProperties{
403 filename: filename,
404 sourceFilePath: p.sourceFilePaths[0],
405 outputFilePath: p.outputFilePaths[0],
406 installDirPath: p.installDirPath,
407 }
408 installs = append(installs, ip)
409 } else {
410 ctx.PropertyErrorf("src", "missing prebuilt source file")
411 return
412 }
413
414 // Call InstallFile even when uninstallable to make the module included in the package.
415 if !p.Installable() {
416 p.SkipInstall()
417 }
418 for _, ip := range installs {
419 ip.addInstallRules(ctx)
420 }
Spandan Das756d3402023-06-05 22:49:50 +0000421}
Jiyong Parkf9f68052020-09-29 20:15:08 +0900422
Spandan Das756d3402023-06-05 22:49:50 +0000423type installProperties struct {
Spandan Das756d3402023-06-05 22:49:50 +0000424 filename string
425 sourceFilePath android.Path
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100426 outputFilePath android.OutputPath
427 installDirPath android.InstallPath
Spandan Das756d3402023-06-05 22:49:50 +0000428 symlinks []string
429}
430
431// utility function to add install rules to the build graph.
432// Reduces code duplication between Soong and Mixed build analysis
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100433func (ip *installProperties) addInstallRules(ctx android.ModuleContext) {
Spandan Das756d3402023-06-05 22:49:50 +0000434 // Copy the file from src to a location in out/ with the correct `filename`
435 // This ensures that outputFilePath has the correct name for others to
436 // use, as the source file may have a different name.
Spandan Das756d3402023-06-05 22:49:50 +0000437 ctx.Build(pctx, android.BuildParams{
438 Rule: android.Cp,
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100439 Output: ip.outputFilePath,
Spandan Das756d3402023-06-05 22:49:50 +0000440 Input: ip.sourceFilePath,
441 })
442
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100443 installPath := ctx.InstallFile(ip.installDirPath, ip.filename, ip.outputFilePath)
Spandan Das756d3402023-06-05 22:49:50 +0000444 for _, sl := range ip.symlinks {
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100445 ctx.InstallSymlink(ip.installDirPath, sl, installPath)
Jiyong Parkf9f68052020-09-29 20:15:08 +0900446 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900447}
448
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700449func (p *PrebuiltEtc) AndroidMkEntries() []android.AndroidMkEntries {
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700450 nameSuffix := ""
Yifan Hong1b3348d2020-01-21 15:53:22 -0800451 if p.inRamdisk() && !p.onlyInRamdisk() {
452 nameSuffix = ".ramdisk"
453 }
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700454 if p.inVendorRamdisk() && !p.onlyInVendorRamdisk() {
455 nameSuffix = ".vendor_ramdisk"
456 }
Inseob Kim08758f02021-04-08 21:13:22 +0900457 if p.inDebugRamdisk() && !p.onlyInDebugRamdisk() {
458 nameSuffix = ".debug_ramdisk"
459 }
Kiyoung Kimae11c232021-07-19 11:38:04 +0900460 if p.InRecovery() && !p.onlyInRecovery() {
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700461 nameSuffix = ".recovery"
462 }
Colin Crossf17e2b52023-10-30 15:17:25 -0700463
464 class := p.makeClass
465 if class == "" {
466 class = "ETC"
467 }
468
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100469 return []android.AndroidMkEntries{{
Colin Crossf17e2b52023-10-30 15:17:25 -0700470 Class: class,
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700471 SubName: nameSuffix,
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100472 OutputFile: android.OptionalPathForPath(p.outputFilePaths[0]),
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700473 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -0700474 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700475 entries.SetString("LOCAL_MODULE_TAGS", "optional")
Colin Crossc68db4b2021-11-11 18:59:15 -0800476 entries.SetString("LOCAL_MODULE_PATH", p.installDirPath.String())
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100477 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePaths[0].Base())
Yo Chiang3d64d492020-05-27 17:56:39 +0800478 if len(p.properties.Symlinks) > 0 {
479 entries.AddStrings("LOCAL_MODULE_SYMLINKS", p.properties.Symlinks...)
480 }
Yo Chiang803c40d2020-11-16 20:32:51 +0800481 entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.Installable())
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700482 if p.additionalDependencies != nil {
Yo Chiang803c40d2020-11-16 20:32:51 +0800483 entries.AddStrings("LOCAL_ADDITIONAL_DEPENDENCIES", p.additionalDependencies.Strings()...)
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900484 }
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700485 },
Jiyong Parkc678ad32018-04-10 13:07:10 +0900486 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900487 }}
Jiyong Parkc678ad32018-04-10 13:07:10 +0900488}
489
LaMont Jonesafe7baf2024-01-09 22:47:39 +0000490func (p *PrebuiltEtc) AndroidModuleBase() *android.ModuleBase {
491 return &p.ModuleBase
492}
493
Jooyung Hana0171822019-07-22 15:48:36 +0900494func InitPrebuiltEtcModule(p *PrebuiltEtc, dirBase string) {
495 p.installDirBase = dirBase
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900496 p.AddProperties(&p.properties)
Inseob Kim27408bf2021-04-06 21:00:17 +0900497 p.AddProperties(&p.subdirProperties)
498}
499
500func InitPrebuiltRootModule(p *PrebuiltEtc) {
501 p.installDirBase = "."
502 p.AddProperties(&p.properties)
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900503}
Jiyong Parkc678ad32018-04-10 13:07:10 +0900504
Patrice Arruda9e14b962019-03-11 15:58:50 -0700505// prebuilt_etc is for a prebuilt artifact that is installed in
506// <partition>/etc/<sub_dir> directory.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700507func PrebuiltEtcFactory() android.Module {
Jooyung Hana0171822019-07-22 15:48:36 +0900508 module := &PrebuiltEtc{}
509 InitPrebuiltEtcModule(module, "etc")
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900510 // This module is device-only
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700511 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Inseob Kim1e27a142021-05-06 11:46:11 +0000512 android.InitDefaultableModule(module)
513 return module
514}
515
516func defaultsFactory() android.Module {
517 return DefaultsFactory()
518}
519
520func DefaultsFactory(props ...interface{}) android.Module {
521 module := &Defaults{}
522
523 module.AddProperties(props...)
524 module.AddProperties(
525 &prebuiltEtcProperties{},
526 &prebuiltSubdirProperties{},
527 )
528
529 android.InitDefaultsModule(module)
530
Jiyong Parkc678ad32018-04-10 13:07:10 +0900531 return module
532}
Tao Bao0ba5c942018-08-14 22:20:22 -0700533
Patrice Arruda9e14b962019-03-11 15:58:50 -0700534// prebuilt_etc_host is for a host prebuilt artifact that is installed in
535// $(HOST_OUT)/etc/<sub_dir> directory.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700536func PrebuiltEtcHostFactory() android.Module {
Jooyung Hana0171822019-07-22 15:48:36 +0900537 module := &PrebuiltEtc{}
538 InitPrebuiltEtcModule(module, "etc")
Jaewoong Jung24788182019-02-04 14:34:10 -0800539 // This module is host-only
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700540 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100541 android.InitDefaultableModule(module)
Jaewoong Jung24788182019-02-04 14:34:10 -0800542 return module
543}
544
Miguel32b02802022-12-01 18:38:26 +0000545// prebuilt_etc_host is for a host prebuilt artifact that is installed in
546// <partition>/etc/<sub_dir> directory.
547func PrebuiltEtcCaCertsFactory() android.Module {
548 module := &PrebuiltEtc{}
549 InitPrebuiltEtcModule(module, "cacerts")
550 // This module is device-only
551 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Miguel32b02802022-12-01 18:38:26 +0000552 return module
553}
554
Inseob Kim27408bf2021-04-06 21:00:17 +0900555// prebuilt_root is for a prebuilt artifact that is installed in
556// <partition>/ directory. Can't have any sub directories.
557func PrebuiltRootFactory() android.Module {
558 module := &PrebuiltEtc{}
559 InitPrebuiltRootModule(module)
560 // This module is device-only
561 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100562 android.InitDefaultableModule(module)
Inseob Kim27408bf2021-04-06 21:00:17 +0900563 return module
564}
565
Liz Kammere9ecddc2022-01-04 17:27:52 -0500566// prebuilt_root_host is for a host prebuilt artifact that is installed in $(HOST_OUT)/<sub_dir>
567// directory.
568func PrebuiltRootHostFactory() android.Module {
569 module := &PrebuiltEtc{}
570 InitPrebuiltEtcModule(module, ".")
571 // This module is host-only
572 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
573 android.InitDefaultableModule(module)
574 return module
575}
576
Patrice Arruda9e14b962019-03-11 15:58:50 -0700577// prebuilt_usr_share is for a prebuilt artifact that is installed in
578// <partition>/usr/share/<sub_dir> directory.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700579func PrebuiltUserShareFactory() android.Module {
Jooyung Hana0171822019-07-22 15:48:36 +0900580 module := &PrebuiltEtc{}
581 InitPrebuiltEtcModule(module, "usr/share")
Jaewoong Jungc3fcdb42019-02-13 05:50:33 -0800582 // This module is device-only
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700583 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100584 android.InitDefaultableModule(module)
Jaewoong Jungc3fcdb42019-02-13 05:50:33 -0800585 return module
586}
587
Patrice Arruda9e14b962019-03-11 15:58:50 -0700588// prebuild_usr_share_host is for a host prebuilt artifact that is installed in
589// $(HOST_OUT)/usr/share/<sub_dir> directory.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700590func PrebuiltUserShareHostFactory() android.Module {
Jooyung Hana0171822019-07-22 15:48:36 +0900591 module := &PrebuiltEtc{}
592 InitPrebuiltEtcModule(module, "usr/share")
Patrice Arruda300cef92019-02-22 15:47:57 -0800593 // This module is host-only
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700594 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100595 android.InitDefaultableModule(module)
Patrice Arruda300cef92019-02-22 15:47:57 -0800596 return module
597}
598
yangbill63c5e192024-03-27 09:02:12 +0000599// prebuilt_usr_hyphendata is for a prebuilt artifact that is installed in
600// <partition>/usr/hyphen-data/<sub_dir> directory.
601func PrebuiltUserHyphenDataFactory() android.Module {
602 module := &PrebuiltEtc{}
603 InitPrebuiltEtcModule(module, "usr/hyphen-data")
604 // This module is device-only
605 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
606 android.InitDefaultableModule(module)
607 return module
608}
609
yangbill85527e62024-04-30 08:24:50 +0000610// prebuilt_usr_keylayout is for a prebuilt artifact that is installed in
611// <partition>/usr/keylayout/<sub_dir> directory.
612func PrebuiltUserKeyLayoutFactory() android.Module {
613 module := &PrebuiltEtc{}
614 InitPrebuiltEtcModule(module, "usr/keylayout")
615 // This module is device-only
616 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
617 android.InitDefaultableModule(module)
618 return module
619}
620
621// prebuilt_usr_keychars is for a prebuilt artifact that is installed in
622// <partition>/usr/keychars/<sub_dir> directory.
623func PrebuiltUserKeyCharsFactory() android.Module {
624 module := &PrebuiltEtc{}
625 InitPrebuiltEtcModule(module, "usr/keychars")
626 // This module is device-only
627 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
628 android.InitDefaultableModule(module)
629 return module
630}
631
632// prebuilt_usr_idc is for a prebuilt artifact that is installed in
633// <partition>/usr/idc/<sub_dir> directory.
634func PrebuiltUserIdcFactory() android.Module {
635 module := &PrebuiltEtc{}
636 InitPrebuiltEtcModule(module, "usr/idc")
637 // This module is device-only
638 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
639 android.InitDefaultableModule(module)
640 return module
641}
642
Patrice Arruda61583eb2019-05-14 08:20:45 -0700643// prebuilt_font installs a font in <partition>/fonts directory.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700644func PrebuiltFontFactory() android.Module {
Jooyung Hana0171822019-07-22 15:48:36 +0900645 module := &PrebuiltEtc{}
646 InitPrebuiltEtcModule(module, "fonts")
Patrice Arruda61583eb2019-05-14 08:20:45 -0700647 // This module is device-only
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700648 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100649 android.InitDefaultableModule(module)
Patrice Arruda61583eb2019-05-14 08:20:45 -0700650 return module
651}
Patrice Arruda057a8b12019-06-03 15:29:27 -0700652
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800653// prebuilt_firmware installs a firmware file to <partition>/etc/firmware directory for system
654// image.
655// If soc_specific property is set to true, the firmware file is installed to the
656// vendor <partition>/firmware directory for vendor image.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700657func PrebuiltFirmwareFactory() android.Module {
Jooyung Hana0171822019-07-22 15:48:36 +0900658 module := &PrebuiltEtc{}
659 module.socInstallDirBase = "firmware"
660 InitPrebuiltEtcModule(module, "etc/firmware")
Patrice Arruda057a8b12019-06-03 15:29:27 -0700661 // This module is device-only
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700662 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100663 android.InitDefaultableModule(module)
Patrice Arruda057a8b12019-06-03 15:29:27 -0700664 return module
665}
Patrice Arruda0f688002020-06-08 21:40:25 +0000666
667// prebuilt_dsp installs a DSP related file to <partition>/etc/dsp directory for system image.
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800668// If soc_specific property is set to true, the DSP related file is installed to the
669// vendor <partition>/dsp directory for vendor image.
Patrice Arruda0f688002020-06-08 21:40:25 +0000670func PrebuiltDSPFactory() android.Module {
671 module := &PrebuiltEtc{}
672 module.socInstallDirBase = "dsp"
673 InitPrebuiltEtcModule(module, "etc/dsp")
674 // This module is device-only
675 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100676 android.InitDefaultableModule(module)
Patrice Arruda0f688002020-06-08 21:40:25 +0000677 return module
678}
Colin Cross83ebf232021-04-09 09:41:23 -0700679
Colin Crossf17e2b52023-10-30 15:17:25 -0700680// prebuilt_renderscript_bitcode installs a *.bc file into /system/lib or /system/lib64.
681func PrebuiltRenderScriptBitcodeFactory() android.Module {
682 module := &PrebuiltEtc{}
683 module.makeClass = "RENDERSCRIPT_BITCODE"
684 module.installDirBase64 = "lib64"
Colin Cross2f634572023-11-13 12:12:06 -0800685 module.installAvoidMultilibConflict = true
Colin Crossf17e2b52023-10-30 15:17:25 -0700686 InitPrebuiltEtcModule(module, "lib")
687 // This module is device-only
688 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibBoth)
689 android.InitDefaultableModule(module)
690 return module
691}
692
Colin Cross83ebf232021-04-09 09:41:23 -0700693// prebuilt_rfsa installs a firmware file that will be available through Qualcomm's RFSA
694// to the <partition>/lib/rfsa directory.
695func PrebuiltRFSAFactory() android.Module {
696 module := &PrebuiltEtc{}
697 // Ideally these would go in /vendor/dsp, but the /vendor/lib/rfsa paths are hardcoded in too
698 // many places outside of the application processor. They could be moved to /vendor/dsp once
699 // that is cleaned up.
700 InitPrebuiltEtcModule(module, "lib/rfsa")
701 // This module is device-only
702 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100703 android.InitDefaultableModule(module)
Colin Cross83ebf232021-04-09 09:41:23 -0700704 return module
705}