blob: c1a0b9c60e8a6a6f913f44420c4c6b849a844236 [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)
Kevin93f7cd82024-05-02 12:37:59 +020062 ctx.RegisterModuleType("prebuilt_overlay", PrebuiltOverlayFactory)
Jooyung Han0703fd82020-08-26 22:11:53 +090063 ctx.RegisterModuleType("prebuilt_firmware", PrebuiltFirmwareFactory)
64 ctx.RegisterModuleType("prebuilt_dsp", PrebuiltDSPFactory)
Colin Cross83ebf232021-04-09 09:41:23 -070065 ctx.RegisterModuleType("prebuilt_rfsa", PrebuiltRFSAFactory)
Colin Crossf17e2b52023-10-30 15:17:25 -070066 ctx.RegisterModuleType("prebuilt_renderscript_bitcode", PrebuiltRenderScriptBitcodeFactory)
Inseob Kim1e27a142021-05-06 11:46:11 +000067
68 ctx.RegisterModuleType("prebuilt_defaults", defaultsFactory)
Rupert Shuttleworth378fc1b2021-07-28 08:03:16 -040069
Jiyong Parkc678ad32018-04-10 13:07:10 +090070}
71
Paul Duffin1172fed2021-03-08 11:28:18 +000072var PrepareForTestWithPrebuiltEtc = android.FixtureRegisterWithContext(RegisterPrebuiltEtcBuildComponents)
73
Jiyong Parkc678ad32018-04-10 13:07:10 +090074type prebuiltEtcProperties struct {
Yo Chiang803c40d2020-11-16 20:32:51 +080075 // Source file of this prebuilt. Can reference a genrule type module with the ":module" syntax.
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +110076 // Mutually exclusive with srcs.
Cole Faustfdec8722024-05-22 11:38:29 -070077 Src proptools.Configurable[string] `android:"path,arch_variant,replace_instead_of_append"`
Jiyong Parkc678ad32018-04-10 13:07:10 +090078
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +110079 // Source files of this prebuilt. Can reference a genrule type module with the ":module" syntax.
80 // Mutually exclusive with src. When used, filename_from_src is set to true.
Cole Faustfdec8722024-05-22 11:38:29 -070081 Srcs proptools.Configurable[[]string] `android:"path,arch_variant"`
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +110082
Yo Chiangf0e19fe2020-11-18 15:28:42 +080083 // 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 +110084 // name. Only available when using a single source (src).
Jiyong Park139a2e62018-10-26 21:49:39 +090085 Filename *string `android:"arch_variant"`
86
Yo Chiangf0e19fe2020-11-18 15:28:42 +080087 // When set to true, and filename property is not set, the name for the installed file
Jiyong Park1a7cf082018-11-13 11:59:12 +090088 // is the same as the file name of the source file.
89 Filename_from_src *bool `android:"arch_variant"`
90
Yifan Hong1b3348d2020-01-21 15:53:22 -080091 // Make this module available when building for 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 Hong1b3348d2020-01-21 15:53:22 -080096 Ramdisk_available *bool
97
Yifan Hong60e0cfb2020-10-21 15:17:56 -070098 // Make this module available when building for vendor ramdisk.
Yifan Hong39143a92020-10-26 12:43:12 -070099 // On device without a dedicated recovery partition, the module is only
100 // available after switching root into
101 // /first_stage_ramdisk. To expose the module before switching root, install
102 // the recovery variant instead.
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700103 Vendor_ramdisk_available *bool
104
Inseob Kim08758f02021-04-08 21:13:22 +0900105 // Make this module available when building for debug ramdisk.
106 Debug_ramdisk_available *bool
107
Tao Bao0ba5c942018-08-14 22:20:22 -0700108 // Make this module available when building for recovery.
109 Recovery_available *bool
110
Jiyong Parkad9ce042018-10-31 22:49:57 +0900111 // Whether this module is directly installable to one of the partitions. Default: true.
112 Installable *bool
Yo Chiang3d64d492020-05-27 17:56:39 +0800113
114 // Install symlinks to the installed file.
115 Symlinks []string `android:"arch_variant"`
Jiyong Parkc678ad32018-04-10 13:07:10 +0900116}
117
Inseob Kim27408bf2021-04-06 21:00:17 +0900118type prebuiltSubdirProperties struct {
119 // Optional subdirectory under which this file is installed into, cannot be specified with
120 // relative_install_path, prefer relative_install_path.
121 Sub_dir *string `android:"arch_variant"`
122
123 // Optional subdirectory under which this file is installed into, cannot be specified with
124 // sub_dir.
125 Relative_install_path *string `android:"arch_variant"`
126}
127
Jooyung Han39edb6c2019-11-06 16:53:07 +0900128type PrebuiltEtcModule interface {
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700129 android.Module
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800130
131 // Returns the base install directory, such as "etc", "usr/share".
Jooyung Han0703fd82020-08-26 22:11:53 +0900132 BaseDir() string
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800133
134 // Returns the sub install directory relative to BaseDir().
Jooyung Han39edb6c2019-11-06 16:53:07 +0900135 SubDir() string
Jooyung Han39edb6c2019-11-06 16:53:07 +0900136}
137
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900138type PrebuiltEtc struct {
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700139 android.ModuleBase
Inseob Kim1e27a142021-05-06 11:46:11 +0000140 android.DefaultableModuleBase
Jiyong Parkc678ad32018-04-10 13:07:10 +0900141
Inseob Kim27408bf2021-04-06 21:00:17 +0900142 properties prebuiltEtcProperties
143 subdirProperties prebuiltSubdirProperties
Jiyong Parkc678ad32018-04-10 13:07:10 +0900144
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100145 sourceFilePaths android.Paths
146 outputFilePaths android.OutputPaths
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
Cole Faustfdec8722024-05-22 11:38:29 -0700157 usedSrcsProperty bool
158
Colin Crossf17e2b52023-10-30 15:17:25 -0700159 makeClass string
Jiyong Parkc678ad32018-04-10 13:07:10 +0900160}
161
Inseob Kim1e27a142021-05-06 11:46:11 +0000162type Defaults struct {
163 android.ModuleBase
164 android.DefaultsModuleBase
165}
166
Yifan Hong1b3348d2020-01-21 15:53:22 -0800167func (p *PrebuiltEtc) inRamdisk() bool {
168 return p.ModuleBase.InRamdisk() || p.ModuleBase.InstallInRamdisk()
169}
170
171func (p *PrebuiltEtc) onlyInRamdisk() bool {
172 return p.ModuleBase.InstallInRamdisk()
173}
174
175func (p *PrebuiltEtc) InstallInRamdisk() bool {
176 return p.inRamdisk()
177}
178
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700179func (p *PrebuiltEtc) inVendorRamdisk() bool {
180 return p.ModuleBase.InVendorRamdisk() || p.ModuleBase.InstallInVendorRamdisk()
181}
182
183func (p *PrebuiltEtc) onlyInVendorRamdisk() bool {
184 return p.ModuleBase.InstallInVendorRamdisk()
185}
186
187func (p *PrebuiltEtc) InstallInVendorRamdisk() bool {
188 return p.inVendorRamdisk()
189}
190
Inseob Kim08758f02021-04-08 21:13:22 +0900191func (p *PrebuiltEtc) inDebugRamdisk() bool {
192 return p.ModuleBase.InDebugRamdisk() || p.ModuleBase.InstallInDebugRamdisk()
193}
194
195func (p *PrebuiltEtc) onlyInDebugRamdisk() bool {
196 return p.ModuleBase.InstallInDebugRamdisk()
197}
198
199func (p *PrebuiltEtc) InstallInDebugRamdisk() bool {
200 return p.inDebugRamdisk()
201}
202
Kiyoung Kimae11c232021-07-19 11:38:04 +0900203func (p *PrebuiltEtc) InRecovery() bool {
Colin Cross7228ecd2019-11-18 16:00:16 -0800204 return p.ModuleBase.InRecovery() || p.ModuleBase.InstallInRecovery()
Tao Bao0ba5c942018-08-14 22:20:22 -0700205}
206
207func (p *PrebuiltEtc) onlyInRecovery() bool {
208 return p.ModuleBase.InstallInRecovery()
209}
210
211func (p *PrebuiltEtc) InstallInRecovery() bool {
Kiyoung Kimae11c232021-07-19 11:38:04 +0900212 return p.InRecovery()
Tao Bao0ba5c942018-08-14 22:20:22 -0700213}
214
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700215var _ android.ImageInterface = (*PrebuiltEtc)(nil)
Colin Cross7228ecd2019-11-18 16:00:16 -0800216
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700217func (p *PrebuiltEtc) ImageMutatorBegin(ctx android.BaseModuleContext) {}
Colin Cross7228ecd2019-11-18 16:00:16 -0800218
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700219func (p *PrebuiltEtc) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700220 return !p.ModuleBase.InstallInRecovery() && !p.ModuleBase.InstallInRamdisk() &&
Inseob Kim08758f02021-04-08 21:13:22 +0900221 !p.ModuleBase.InstallInVendorRamdisk() && !p.ModuleBase.InstallInDebugRamdisk()
Yifan Hong1b3348d2020-01-21 15:53:22 -0800222}
223
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700224func (p *PrebuiltEtc) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
225 return proptools.Bool(p.properties.Ramdisk_available) || p.ModuleBase.InstallInRamdisk()
Colin Cross7228ecd2019-11-18 16:00:16 -0800226}
227
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700228func (p *PrebuiltEtc) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
229 return proptools.Bool(p.properties.Vendor_ramdisk_available) || p.ModuleBase.InstallInVendorRamdisk()
230}
231
Inseob Kim08758f02021-04-08 21:13:22 +0900232func (p *PrebuiltEtc) DebugRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
233 return proptools.Bool(p.properties.Debug_ramdisk_available) || p.ModuleBase.InstallInDebugRamdisk()
234}
235
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700236func (p *PrebuiltEtc) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
237 return proptools.Bool(p.properties.Recovery_available) || p.ModuleBase.InstallInRecovery()
Colin Cross7228ecd2019-11-18 16:00:16 -0800238}
239
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700240func (p *PrebuiltEtc) ExtraImageVariations(ctx android.BaseModuleContext) []string {
Colin Cross7228ecd2019-11-18 16:00:16 -0800241 return nil
242}
243
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700244func (p *PrebuiltEtc) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) {
Colin Cross7228ecd2019-11-18 16:00:16 -0800245}
246
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700247func (p *PrebuiltEtc) SourceFilePath(ctx android.ModuleContext) android.Path {
Cole Faustfdec8722024-05-22 11:38:29 -0700248 if len(p.properties.Srcs.GetOrDefault(ctx, nil)) > 0 {
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100249 panic(fmt.Errorf("SourceFilePath not available on multi-source prebuilt %q", p.Name()))
250 }
Cole Faustfdec8722024-05-22 11:38:29 -0700251 return android.PathForModuleSrc(ctx, p.properties.Src.GetOrDefault(ctx, ""))
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900252}
253
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700254func (p *PrebuiltEtc) InstallDirPath() android.InstallPath {
Jooyung Hana0171822019-07-22 15:48:36 +0900255 return p.installDirPath
256}
257
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900258// This allows other derivative modules (e.g. prebuilt_etc_xml) to perform
259// additional steps (like validating the src) before the file is installed.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700260func (p *PrebuiltEtc) SetAdditionalDependencies(paths android.Paths) {
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900261 p.additionalDependencies = &paths
262}
263
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700264func (p *PrebuiltEtc) OutputFile() android.OutputPath {
Cole Faustfdec8722024-05-22 11:38:29 -0700265 if p.usedSrcsProperty {
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100266 panic(fmt.Errorf("OutputFile not available on multi-source prebuilt %q", p.Name()))
267 }
268 return p.outputFilePaths[0]
Jiyong Parkc43e0ac2018-10-04 20:27:15 +0900269}
270
Jiyong Park76a42f52021-02-16 06:50:37 +0900271var _ android.OutputFileProducer = (*PrebuiltEtc)(nil)
272
273func (p *PrebuiltEtc) OutputFiles(tag string) (android.Paths, error) {
274 switch tag {
275 case "":
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100276 return p.outputFilePaths.Paths(), nil
Jiyong Park76a42f52021-02-16 06:50:37 +0900277 default:
278 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
279 }
280}
281
Jiyong Parkc43e0ac2018-10-04 20:27:15 +0900282func (p *PrebuiltEtc) SubDir() string {
Inseob Kim27408bf2021-04-06 21:00:17 +0900283 if subDir := proptools.String(p.subdirProperties.Sub_dir); subDir != "" {
Liz Kammer0449a632020-06-26 10:12:36 -0700284 return subDir
285 }
Inseob Kim27408bf2021-04-06 21:00:17 +0900286 return proptools.String(p.subdirProperties.Relative_install_path)
Jiyong Parkc43e0ac2018-10-04 20:27:15 +0900287}
288
Jooyung Han0703fd82020-08-26 22:11:53 +0900289func (p *PrebuiltEtc) BaseDir() string {
Jooyung Han8e5685d2020-09-21 11:02:57 +0900290 return p.installDirBase
Jooyung Han0703fd82020-08-26 22:11:53 +0900291}
292
Jiyong Parkad9ce042018-10-31 22:49:57 +0900293func (p *PrebuiltEtc) Installable() bool {
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800294 return p.properties.Installable == nil || proptools.Bool(p.properties.Installable)
Jiyong Parkad9ce042018-10-31 22:49:57 +0900295}
296
Kiyoung Kimae11c232021-07-19 11:38:04 +0900297func (p *PrebuiltEtc) InVendor() bool {
298 return p.ModuleBase.InstallInVendor()
299}
300
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100301func (p *PrebuiltEtc) installBaseDir(ctx android.ModuleContext) string {
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800302 // If soc install dir was specified and SOC specific is set, set the installDirPath to the
303 // specified socInstallDirBase.
Jooyung Han8e5685d2020-09-21 11:02:57 +0900304 installBaseDir := p.installDirBase
Colin Crossf17e2b52023-10-30 15:17:25 -0700305 if p.Target().Arch.ArchType.Multilib == "lib64" && p.installDirBase64 != "" {
306 installBaseDir = p.installDirBase64
307 }
Jooyung Han8e5685d2020-09-21 11:02:57 +0900308 if p.SocSpecific() && p.socInstallDirBase != "" {
309 installBaseDir = p.socInstallDirBase
310 }
Colin Cross2f634572023-11-13 12:12:06 -0800311 if p.installAvoidMultilibConflict && !ctx.Host() && ctx.Config().HasMultilibConflict(ctx.Arch().ArchType) {
312 installBaseDir = filepath.Join(installBaseDir, ctx.Arch().ArchType.String())
313 }
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100314 return installBaseDir
315}
Colin Cross2f634572023-11-13 12:12:06 -0800316
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100317func (p *PrebuiltEtc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
318 var installs []installProperties
Jiyong Parkc43e0ac2018-10-04 20:27:15 +0900319
Cole Faustfdec8722024-05-22 11:38:29 -0700320 srcProperty := p.properties.Src.Get(ctx)
321 srcsProperty := p.properties.Srcs.GetOrDefault(ctx, nil)
322 if srcProperty.IsPresent() && len(srcsProperty) > 0 {
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100323 ctx.PropertyErrorf("src", "src is set. Cannot set srcs")
Spandan Das756d3402023-06-05 22:49:50 +0000324 }
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100325
326 // Check that `sub_dir` and `relative_install_path` are not set at the same time.
327 if p.subdirProperties.Sub_dir != nil && p.subdirProperties.Relative_install_path != nil {
328 ctx.PropertyErrorf("sub_dir", "relative_install_path is set. Cannot set sub_dir")
329 }
330 p.installDirPath = android.PathForModuleInstall(ctx, p.installBaseDir(ctx), p.SubDir())
331
332 filename := proptools.String(p.properties.Filename)
333 filenameFromSrc := proptools.Bool(p.properties.Filename_from_src)
Cole Faustfdec8722024-05-22 11:38:29 -0700334 if srcProperty.IsPresent() {
335 p.sourceFilePaths = android.PathsForModuleSrc(ctx, []string{srcProperty.Get()})
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100336 // If the source was not found, set a fake source path to
337 // support AllowMissingDependencies executions.
338 if len(p.sourceFilePaths) == 0 {
339 p.sourceFilePaths = android.Paths{android.PathForModuleSrc(ctx)}
340 }
341
342 // Determine the output file basename.
343 // If Filename is set, use the name specified by the property.
344 // If Filename_from_src is set, use the source file name.
345 // Otherwise use the module name.
346 if filename != "" {
347 if filenameFromSrc {
348 ctx.PropertyErrorf("filename_from_src", "filename is set. filename_from_src can't be true")
349 return
350 }
351 } else if filenameFromSrc {
352 filename = p.sourceFilePaths[0].Base()
353 } else {
354 filename = ctx.ModuleName()
355 }
356 if strings.Contains(filename, "/") {
357 ctx.PropertyErrorf("filename", "filename cannot contain separator '/'")
358 return
359 }
360 p.outputFilePaths = android.OutputPaths{android.PathForModuleOut(ctx, filename).OutputPath}
361
362 ip := installProperties{
363 filename: filename,
364 sourceFilePath: p.sourceFilePaths[0],
365 outputFilePath: p.outputFilePaths[0],
366 installDirPath: p.installDirPath,
367 symlinks: p.properties.Symlinks,
368 }
369 installs = append(installs, ip)
Cole Faustfdec8722024-05-22 11:38:29 -0700370 } else if len(srcsProperty) > 0 {
371 p.usedSrcsProperty = true
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100372 if filename != "" {
373 ctx.PropertyErrorf("filename", "filename cannot be set when using srcs")
374 }
375 if len(p.properties.Symlinks) > 0 {
376 ctx.PropertyErrorf("symlinks", "symlinks cannot be set when using srcs")
377 }
378 if p.properties.Filename_from_src != nil {
379 ctx.PropertyErrorf("filename_from_src", "filename_from_src is implicitly set to true when using srcs")
380 }
Cole Faustfdec8722024-05-22 11:38:29 -0700381 p.sourceFilePaths = android.PathsForModuleSrc(ctx, srcsProperty)
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100382 for _, src := range p.sourceFilePaths {
383 filename := src.Base()
384 output := android.PathForModuleOut(ctx, filename).OutputPath
385 ip := installProperties{
386 filename: filename,
387 sourceFilePath: src,
388 outputFilePath: output,
389 installDirPath: p.installDirPath,
390 }
391 p.outputFilePaths = append(p.outputFilePaths, output)
392 installs = append(installs, ip)
393 }
394 } else if ctx.Config().AllowMissingDependencies() {
395 // If no srcs was set and AllowMissingDependencies is enabled then
396 // mark the module as missing dependencies and set a fake source path
397 // and file name.
398 ctx.AddMissingDependencies([]string{"MISSING_PREBUILT_SRC_FILE"})
399 p.sourceFilePaths = android.Paths{android.PathForModuleSrc(ctx)}
400 if filename == "" {
401 filename = ctx.ModuleName()
402 }
403 p.outputFilePaths = android.OutputPaths{android.PathForModuleOut(ctx, filename).OutputPath}
404 ip := installProperties{
405 filename: filename,
406 sourceFilePath: p.sourceFilePaths[0],
407 outputFilePath: p.outputFilePaths[0],
408 installDirPath: p.installDirPath,
409 }
410 installs = append(installs, ip)
411 } else {
412 ctx.PropertyErrorf("src", "missing prebuilt source file")
413 return
414 }
415
416 // Call InstallFile even when uninstallable to make the module included in the package.
417 if !p.Installable() {
418 p.SkipInstall()
419 }
420 for _, ip := range installs {
421 ip.addInstallRules(ctx)
422 }
Spandan Das756d3402023-06-05 22:49:50 +0000423}
Jiyong Parkf9f68052020-09-29 20:15:08 +0900424
Spandan Das756d3402023-06-05 22:49:50 +0000425type installProperties struct {
Spandan Das756d3402023-06-05 22:49:50 +0000426 filename string
427 sourceFilePath android.Path
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100428 outputFilePath android.OutputPath
429 installDirPath android.InstallPath
Spandan Das756d3402023-06-05 22:49:50 +0000430 symlinks []string
431}
432
433// utility function to add install rules to the build graph.
434// Reduces code duplication between Soong and Mixed build analysis
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100435func (ip *installProperties) addInstallRules(ctx android.ModuleContext) {
Spandan Das756d3402023-06-05 22:49:50 +0000436 // Copy the file from src to a location in out/ with the correct `filename`
437 // This ensures that outputFilePath has the correct name for others to
438 // use, as the source file may have a different name.
Spandan Das756d3402023-06-05 22:49:50 +0000439 ctx.Build(pctx, android.BuildParams{
440 Rule: android.Cp,
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100441 Output: ip.outputFilePath,
Spandan Das756d3402023-06-05 22:49:50 +0000442 Input: ip.sourceFilePath,
443 })
444
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100445 installPath := ctx.InstallFile(ip.installDirPath, ip.filename, ip.outputFilePath)
Spandan Das756d3402023-06-05 22:49:50 +0000446 for _, sl := range ip.symlinks {
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100447 ctx.InstallSymlink(ip.installDirPath, sl, installPath)
Jiyong Parkf9f68052020-09-29 20:15:08 +0900448 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900449}
450
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700451func (p *PrebuiltEtc) AndroidMkEntries() []android.AndroidMkEntries {
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700452 nameSuffix := ""
Yifan Hong1b3348d2020-01-21 15:53:22 -0800453 if p.inRamdisk() && !p.onlyInRamdisk() {
454 nameSuffix = ".ramdisk"
455 }
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700456 if p.inVendorRamdisk() && !p.onlyInVendorRamdisk() {
457 nameSuffix = ".vendor_ramdisk"
458 }
Inseob Kim08758f02021-04-08 21:13:22 +0900459 if p.inDebugRamdisk() && !p.onlyInDebugRamdisk() {
460 nameSuffix = ".debug_ramdisk"
461 }
Kiyoung Kimae11c232021-07-19 11:38:04 +0900462 if p.InRecovery() && !p.onlyInRecovery() {
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700463 nameSuffix = ".recovery"
464 }
Colin Crossf17e2b52023-10-30 15:17:25 -0700465
466 class := p.makeClass
467 if class == "" {
468 class = "ETC"
469 }
470
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100471 return []android.AndroidMkEntries{{
Colin Crossf17e2b52023-10-30 15:17:25 -0700472 Class: class,
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700473 SubName: nameSuffix,
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100474 OutputFile: android.OptionalPathForPath(p.outputFilePaths[0]),
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700475 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -0700476 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700477 entries.SetString("LOCAL_MODULE_TAGS", "optional")
Colin Crossc68db4b2021-11-11 18:59:15 -0800478 entries.SetString("LOCAL_MODULE_PATH", p.installDirPath.String())
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100479 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePaths[0].Base())
Yo Chiang3d64d492020-05-27 17:56:39 +0800480 if len(p.properties.Symlinks) > 0 {
481 entries.AddStrings("LOCAL_MODULE_SYMLINKS", p.properties.Symlinks...)
482 }
Yo Chiang803c40d2020-11-16 20:32:51 +0800483 entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.Installable())
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700484 if p.additionalDependencies != nil {
Yo Chiang803c40d2020-11-16 20:32:51 +0800485 entries.AddStrings("LOCAL_ADDITIONAL_DEPENDENCIES", p.additionalDependencies.Strings()...)
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900486 }
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700487 },
Jiyong Parkc678ad32018-04-10 13:07:10 +0900488 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900489 }}
Jiyong Parkc678ad32018-04-10 13:07:10 +0900490}
491
LaMont Jonesafe7baf2024-01-09 22:47:39 +0000492func (p *PrebuiltEtc) AndroidModuleBase() *android.ModuleBase {
493 return &p.ModuleBase
494}
495
Jooyung Hana0171822019-07-22 15:48:36 +0900496func InitPrebuiltEtcModule(p *PrebuiltEtc, dirBase string) {
497 p.installDirBase = dirBase
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900498 p.AddProperties(&p.properties)
Inseob Kim27408bf2021-04-06 21:00:17 +0900499 p.AddProperties(&p.subdirProperties)
500}
501
502func InitPrebuiltRootModule(p *PrebuiltEtc) {
503 p.installDirBase = "."
504 p.AddProperties(&p.properties)
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900505}
Jiyong Parkc678ad32018-04-10 13:07:10 +0900506
Patrice Arruda9e14b962019-03-11 15:58:50 -0700507// prebuilt_etc is for a prebuilt artifact that is installed in
508// <partition>/etc/<sub_dir> directory.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700509func PrebuiltEtcFactory() android.Module {
Jooyung Hana0171822019-07-22 15:48:36 +0900510 module := &PrebuiltEtc{}
511 InitPrebuiltEtcModule(module, "etc")
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900512 // This module is device-only
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700513 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Inseob Kim1e27a142021-05-06 11:46:11 +0000514 android.InitDefaultableModule(module)
515 return module
516}
517
518func defaultsFactory() android.Module {
519 return DefaultsFactory()
520}
521
522func DefaultsFactory(props ...interface{}) android.Module {
523 module := &Defaults{}
524
525 module.AddProperties(props...)
526 module.AddProperties(
527 &prebuiltEtcProperties{},
528 &prebuiltSubdirProperties{},
529 )
530
531 android.InitDefaultsModule(module)
532
Jiyong Parkc678ad32018-04-10 13:07:10 +0900533 return module
534}
Tao Bao0ba5c942018-08-14 22:20:22 -0700535
Patrice Arruda9e14b962019-03-11 15:58:50 -0700536// prebuilt_etc_host is for a host prebuilt artifact that is installed in
537// $(HOST_OUT)/etc/<sub_dir> directory.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700538func PrebuiltEtcHostFactory() android.Module {
Jooyung Hana0171822019-07-22 15:48:36 +0900539 module := &PrebuiltEtc{}
540 InitPrebuiltEtcModule(module, "etc")
Jaewoong Jung24788182019-02-04 14:34:10 -0800541 // This module is host-only
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700542 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100543 android.InitDefaultableModule(module)
Jaewoong Jung24788182019-02-04 14:34:10 -0800544 return module
545}
546
Miguel32b02802022-12-01 18:38:26 +0000547// prebuilt_etc_host is for a host prebuilt artifact that is installed in
548// <partition>/etc/<sub_dir> directory.
549func PrebuiltEtcCaCertsFactory() android.Module {
550 module := &PrebuiltEtc{}
551 InitPrebuiltEtcModule(module, "cacerts")
552 // This module is device-only
553 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Miguel32b02802022-12-01 18:38:26 +0000554 return module
555}
556
Inseob Kim27408bf2021-04-06 21:00:17 +0900557// prebuilt_root is for a prebuilt artifact that is installed in
558// <partition>/ directory. Can't have any sub directories.
559func PrebuiltRootFactory() android.Module {
560 module := &PrebuiltEtc{}
561 InitPrebuiltRootModule(module)
562 // This module is device-only
563 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100564 android.InitDefaultableModule(module)
Inseob Kim27408bf2021-04-06 21:00:17 +0900565 return module
566}
567
Liz Kammere9ecddc2022-01-04 17:27:52 -0500568// prebuilt_root_host is for a host prebuilt artifact that is installed in $(HOST_OUT)/<sub_dir>
569// directory.
570func PrebuiltRootHostFactory() android.Module {
571 module := &PrebuiltEtc{}
572 InitPrebuiltEtcModule(module, ".")
573 // This module is host-only
574 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
575 android.InitDefaultableModule(module)
576 return module
577}
578
Patrice Arruda9e14b962019-03-11 15:58:50 -0700579// prebuilt_usr_share is for a prebuilt artifact that is installed in
580// <partition>/usr/share/<sub_dir> directory.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700581func PrebuiltUserShareFactory() android.Module {
Jooyung Hana0171822019-07-22 15:48:36 +0900582 module := &PrebuiltEtc{}
583 InitPrebuiltEtcModule(module, "usr/share")
Jaewoong Jungc3fcdb42019-02-13 05:50:33 -0800584 // This module is device-only
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700585 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100586 android.InitDefaultableModule(module)
Jaewoong Jungc3fcdb42019-02-13 05:50:33 -0800587 return module
588}
589
Patrice Arruda9e14b962019-03-11 15:58:50 -0700590// prebuild_usr_share_host is for a host prebuilt artifact that is installed in
591// $(HOST_OUT)/usr/share/<sub_dir> directory.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700592func PrebuiltUserShareHostFactory() android.Module {
Jooyung Hana0171822019-07-22 15:48:36 +0900593 module := &PrebuiltEtc{}
594 InitPrebuiltEtcModule(module, "usr/share")
Patrice Arruda300cef92019-02-22 15:47:57 -0800595 // This module is host-only
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700596 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100597 android.InitDefaultableModule(module)
Patrice Arruda300cef92019-02-22 15:47:57 -0800598 return module
599}
600
yangbill63c5e192024-03-27 09:02:12 +0000601// prebuilt_usr_hyphendata is for a prebuilt artifact that is installed in
602// <partition>/usr/hyphen-data/<sub_dir> directory.
603func PrebuiltUserHyphenDataFactory() android.Module {
604 module := &PrebuiltEtc{}
605 InitPrebuiltEtcModule(module, "usr/hyphen-data")
606 // This module is device-only
607 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
608 android.InitDefaultableModule(module)
609 return module
610}
611
yangbill85527e62024-04-30 08:24:50 +0000612// prebuilt_usr_keylayout is for a prebuilt artifact that is installed in
613// <partition>/usr/keylayout/<sub_dir> directory.
614func PrebuiltUserKeyLayoutFactory() android.Module {
615 module := &PrebuiltEtc{}
616 InitPrebuiltEtcModule(module, "usr/keylayout")
617 // This module is device-only
618 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
619 android.InitDefaultableModule(module)
620 return module
621}
622
623// prebuilt_usr_keychars is for a prebuilt artifact that is installed in
624// <partition>/usr/keychars/<sub_dir> directory.
625func PrebuiltUserKeyCharsFactory() android.Module {
626 module := &PrebuiltEtc{}
627 InitPrebuiltEtcModule(module, "usr/keychars")
628 // This module is device-only
629 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
630 android.InitDefaultableModule(module)
631 return module
632}
633
634// prebuilt_usr_idc is for a prebuilt artifact that is installed in
635// <partition>/usr/idc/<sub_dir> directory.
636func PrebuiltUserIdcFactory() android.Module {
637 module := &PrebuiltEtc{}
638 InitPrebuiltEtcModule(module, "usr/idc")
639 // This module is device-only
640 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
641 android.InitDefaultableModule(module)
642 return module
643}
644
Patrice Arruda61583eb2019-05-14 08:20:45 -0700645// prebuilt_font installs a font in <partition>/fonts directory.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700646func PrebuiltFontFactory() android.Module {
Jooyung Hana0171822019-07-22 15:48:36 +0900647 module := &PrebuiltEtc{}
648 InitPrebuiltEtcModule(module, "fonts")
Patrice Arruda61583eb2019-05-14 08:20:45 -0700649 // This module is device-only
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700650 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100651 android.InitDefaultableModule(module)
Patrice Arruda61583eb2019-05-14 08:20:45 -0700652 return module
653}
Patrice Arruda057a8b12019-06-03 15:29:27 -0700654
Kevin93f7cd82024-05-02 12:37:59 +0200655// prebuilt_overlay is for a prebuilt artifact in <partition>/overlay directory.
656func PrebuiltOverlayFactory() android.Module {
657 module := &PrebuiltEtc{}
658 InitPrebuiltEtcModule(module, "overlay")
659 // This module is device-only
660 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
661 return module
662}
663
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800664// prebuilt_firmware installs a firmware file to <partition>/etc/firmware directory for system
665// image.
666// If soc_specific property is set to true, the firmware file is installed to the
667// vendor <partition>/firmware directory for vendor image.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700668func PrebuiltFirmwareFactory() android.Module {
Jooyung Hana0171822019-07-22 15:48:36 +0900669 module := &PrebuiltEtc{}
670 module.socInstallDirBase = "firmware"
671 InitPrebuiltEtcModule(module, "etc/firmware")
Patrice Arruda057a8b12019-06-03 15:29:27 -0700672 // This module is device-only
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700673 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100674 android.InitDefaultableModule(module)
Patrice Arruda057a8b12019-06-03 15:29:27 -0700675 return module
676}
Patrice Arruda0f688002020-06-08 21:40:25 +0000677
678// prebuilt_dsp installs a DSP related file to <partition>/etc/dsp directory for system image.
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800679// If soc_specific property is set to true, the DSP related file is installed to the
680// vendor <partition>/dsp directory for vendor image.
Patrice Arruda0f688002020-06-08 21:40:25 +0000681func PrebuiltDSPFactory() android.Module {
682 module := &PrebuiltEtc{}
683 module.socInstallDirBase = "dsp"
684 InitPrebuiltEtcModule(module, "etc/dsp")
685 // This module is device-only
686 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100687 android.InitDefaultableModule(module)
Patrice Arruda0f688002020-06-08 21:40:25 +0000688 return module
689}
Colin Cross83ebf232021-04-09 09:41:23 -0700690
Colin Crossf17e2b52023-10-30 15:17:25 -0700691// prebuilt_renderscript_bitcode installs a *.bc file into /system/lib or /system/lib64.
692func PrebuiltRenderScriptBitcodeFactory() android.Module {
693 module := &PrebuiltEtc{}
694 module.makeClass = "RENDERSCRIPT_BITCODE"
695 module.installDirBase64 = "lib64"
Colin Cross2f634572023-11-13 12:12:06 -0800696 module.installAvoidMultilibConflict = true
Colin Crossf17e2b52023-10-30 15:17:25 -0700697 InitPrebuiltEtcModule(module, "lib")
698 // This module is device-only
699 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibBoth)
700 android.InitDefaultableModule(module)
701 return module
702}
703
Colin Cross83ebf232021-04-09 09:41:23 -0700704// prebuilt_rfsa installs a firmware file that will be available through Qualcomm's RFSA
705// to the <partition>/lib/rfsa directory.
706func PrebuiltRFSAFactory() android.Module {
707 module := &PrebuiltEtc{}
708 // Ideally these would go in /vendor/dsp, but the /vendor/lib/rfsa paths are hardcoded in too
709 // many places outside of the application processor. They could be moved to /vendor/dsp once
710 // that is cleaned up.
711 InitPrebuiltEtcModule(module, "lib/rfsa")
712 // This module is device-only
713 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100714 android.InitDefaultableModule(module)
Colin Cross83ebf232021-04-09 09:41:23 -0700715 return module
716}