blob: ca2844244c3c951a307f943df35c8ebf0c12a0ad [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"
Alixbbfd5382022-06-09 18:52:05 +000034 "reflect"
Inseob Kim27408bf2021-04-06 21:00:17 +090035 "strings"
Jiyong Park76a42f52021-02-16 06:50:37 +090036
Jaewoong Jung4b79e982020-06-01 10:45:49 -070037 "github.com/google/blueprint/proptools"
38
39 "android/soong/android"
Rupert Shuttleworth378fc1b2021-07-28 08:03:16 -040040 "android/soong/bazel"
Spandan Das756d3402023-06-05 22:49:50 +000041 "android/soong/bazel/cquery"
Kiyoung Kimae11c232021-07-19 11:38:04 +090042 "android/soong/snapshot"
Liz Kammerd5d12d02023-09-05 09:18:50 -040043 "android/soong/ui/metrics/bp2build_metrics_proto"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070044)
45
46var pctx = android.NewPackageContext("android/soong/etc")
Jiyong Parkc678ad32018-04-10 13:07:10 +090047
Jaewoong Jungc3fcdb42019-02-13 05:50:33 -080048// TODO(jungw): Now that it handles more than the ones in etc/, consider renaming this file.
Jiyong Parkc678ad32018-04-10 13:07:10 +090049
50func init() {
Jaewoong Jung4b79e982020-06-01 10:45:49 -070051 pctx.Import("android/soong/android")
Jooyung Han0703fd82020-08-26 22:11:53 +090052 RegisterPrebuiltEtcBuildComponents(android.InitRegistrationContext)
Kiyoung Kimae11c232021-07-19 11:38:04 +090053 snapshot.RegisterSnapshotAction(generatePrebuiltSnapshot)
Jooyung Han0703fd82020-08-26 22:11:53 +090054}
Jaewoong Jung4b79e982020-06-01 10:45:49 -070055
Jooyung Han0703fd82020-08-26 22:11:53 +090056func RegisterPrebuiltEtcBuildComponents(ctx android.RegistrationContext) {
57 ctx.RegisterModuleType("prebuilt_etc", PrebuiltEtcFactory)
58 ctx.RegisterModuleType("prebuilt_etc_host", PrebuiltEtcHostFactory)
Miguel32b02802022-12-01 18:38:26 +000059 ctx.RegisterModuleType("prebuilt_etc_cacerts", PrebuiltEtcCaCertsFactory)
Inseob Kim27408bf2021-04-06 21:00:17 +090060 ctx.RegisterModuleType("prebuilt_root", PrebuiltRootFactory)
Liz Kammere9ecddc2022-01-04 17:27:52 -050061 ctx.RegisterModuleType("prebuilt_root_host", PrebuiltRootHostFactory)
Jooyung Han0703fd82020-08-26 22:11:53 +090062 ctx.RegisterModuleType("prebuilt_usr_share", PrebuiltUserShareFactory)
63 ctx.RegisterModuleType("prebuilt_usr_share_host", PrebuiltUserShareHostFactory)
64 ctx.RegisterModuleType("prebuilt_font", PrebuiltFontFactory)
65 ctx.RegisterModuleType("prebuilt_firmware", PrebuiltFirmwareFactory)
66 ctx.RegisterModuleType("prebuilt_dsp", PrebuiltDSPFactory)
Colin Cross83ebf232021-04-09 09:41:23 -070067 ctx.RegisterModuleType("prebuilt_rfsa", PrebuiltRFSAFactory)
Inseob Kim1e27a142021-05-06 11:46:11 +000068
69 ctx.RegisterModuleType("prebuilt_defaults", defaultsFactory)
Rupert Shuttleworth378fc1b2021-07-28 08:03:16 -040070
Jiyong Parkc678ad32018-04-10 13:07:10 +090071}
72
Paul Duffin1172fed2021-03-08 11:28:18 +000073var PrepareForTestWithPrebuiltEtc = android.FixtureRegisterWithContext(RegisterPrebuiltEtcBuildComponents)
74
Jiyong Parkc678ad32018-04-10 13:07:10 +090075type prebuiltEtcProperties struct {
Yo Chiang803c40d2020-11-16 20:32:51 +080076 // Source file of this prebuilt. Can reference a genrule type module with the ":module" syntax.
Colin Cross27b922f2019-03-04 22:35:41 -080077 Src *string `android:"path,arch_variant"`
Jiyong Parkc678ad32018-04-10 13:07:10 +090078
Yo Chiangf0e19fe2020-11-18 15:28:42 +080079 // Optional name for the installed file. If unspecified, name of the module is used as the file
80 // name.
Jiyong Park139a2e62018-10-26 21:49:39 +090081 Filename *string `android:"arch_variant"`
82
Yo Chiangf0e19fe2020-11-18 15:28:42 +080083 // When set to true, and filename property is not set, the name for the installed file
Jiyong Park1a7cf082018-11-13 11:59:12 +090084 // is the same as the file name of the source file.
85 Filename_from_src *bool `android:"arch_variant"`
86
Yifan Hong1b3348d2020-01-21 15:53:22 -080087 // Make this module available when building for ramdisk.
Yifan Hong39143a92020-10-26 12:43:12 -070088 // On device without a dedicated recovery partition, the module is only
89 // available after switching root into
90 // /first_stage_ramdisk. To expose the module before switching root, install
91 // the recovery variant instead.
Yifan Hong1b3348d2020-01-21 15:53:22 -080092 Ramdisk_available *bool
93
Yifan Hong60e0cfb2020-10-21 15:17:56 -070094 // Make this module available when building for vendor ramdisk.
Yifan Hong39143a92020-10-26 12:43:12 -070095 // On device without a dedicated recovery partition, the module is only
96 // available after switching root into
97 // /first_stage_ramdisk. To expose the module before switching root, install
98 // the recovery variant instead.
Yifan Hong60e0cfb2020-10-21 15:17:56 -070099 Vendor_ramdisk_available *bool
100
Inseob Kim08758f02021-04-08 21:13:22 +0900101 // Make this module available when building for debug ramdisk.
102 Debug_ramdisk_available *bool
103
Tao Bao0ba5c942018-08-14 22:20:22 -0700104 // Make this module available when building for recovery.
105 Recovery_available *bool
106
Jiyong Parkad9ce042018-10-31 22:49:57 +0900107 // Whether this module is directly installable to one of the partitions. Default: true.
108 Installable *bool
Yo Chiang3d64d492020-05-27 17:56:39 +0800109
110 // Install symlinks to the installed file.
111 Symlinks []string `android:"arch_variant"`
Jiyong Parkc678ad32018-04-10 13:07:10 +0900112}
113
Inseob Kim27408bf2021-04-06 21:00:17 +0900114type prebuiltSubdirProperties struct {
115 // Optional subdirectory under which this file is installed into, cannot be specified with
116 // relative_install_path, prefer relative_install_path.
117 Sub_dir *string `android:"arch_variant"`
118
119 // Optional subdirectory under which this file is installed into, cannot be specified with
120 // sub_dir.
121 Relative_install_path *string `android:"arch_variant"`
122}
123
Jooyung Han39edb6c2019-11-06 16:53:07 +0900124type PrebuiltEtcModule interface {
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700125 android.Module
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800126
127 // Returns the base install directory, such as "etc", "usr/share".
Jooyung Han0703fd82020-08-26 22:11:53 +0900128 BaseDir() string
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800129
130 // Returns the sub install directory relative to BaseDir().
Jooyung Han39edb6c2019-11-06 16:53:07 +0900131 SubDir() string
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800132
133 // Returns an android.OutputPath to the intermeidate file, which is the renamed prebuilt source
134 // file.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700135 OutputFile() android.OutputPath
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
Rupert Shuttleworth378fc1b2021-07-28 08:03:16 -0400141 android.BazelModuleBase
Jiyong Parkc678ad32018-04-10 13:07:10 +0900142
Kiyoung Kimae11c232021-07-19 11:38:04 +0900143 snapshot.VendorSnapshotModuleInterface
144 snapshot.RecoverySnapshotModuleInterface
145
Inseob Kim27408bf2021-04-06 21:00:17 +0900146 properties prebuiltEtcProperties
147 subdirProperties prebuiltSubdirProperties
Jiyong Parkc678ad32018-04-10 13:07:10 +0900148
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700149 sourceFilePath android.Path
150 outputFilePath android.OutputPath
Jaewoong Jungc3fcdb42019-02-13 05:50:33 -0800151 // The base install location, e.g. "etc" for prebuilt_etc, "usr/share" for prebuilt_usr_share.
Patrice Arruda057a8b12019-06-03 15:29:27 -0700152 installDirBase string
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800153 // The base install location when soc_specific property is set to true, e.g. "firmware" for
154 // prebuilt_firmware.
Patrice Arruda057a8b12019-06-03 15:29:27 -0700155 socInstallDirBase string
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700156 installDirPath android.InstallPath
157 additionalDependencies *android.Paths
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
348 if p.SocSpecific() && p.socInstallDirBase != "" {
349 installBaseDir = p.socInstallDirBase
350 }
351 p.installDirPath = android.PathForModuleInstall(ctx, installBaseDir, p.SubDir())
Jiyong Parkc43e0ac2018-10-04 20:27:15 +0900352
Spandan Das756d3402023-06-05 22:49:50 +0000353 // Call InstallFile even when uninstallable to make the module included in the package
354 ip := installProperties{
355 installable: p.Installable(),
356 filename: filename,
357 sourceFilePath: p.sourceFilePath,
358 symlinks: p.properties.Symlinks,
359 }
360 p.addInstallRules(ctx, ip)
361}
Jiyong Parkf9f68052020-09-29 20:15:08 +0900362
Spandan Das756d3402023-06-05 22:49:50 +0000363type installProperties struct {
364 installable bool
365 filename string
366 sourceFilePath android.Path
367 symlinks []string
368}
369
370// utility function to add install rules to the build graph.
371// Reduces code duplication between Soong and Mixed build analysis
372func (p *PrebuiltEtc) addInstallRules(ctx android.ModuleContext, ip installProperties) {
373 if !ip.installable {
Inseob Kim916901e2021-02-17 15:48:53 +0900374 p.SkipInstall()
375 }
376
Spandan Das756d3402023-06-05 22:49:50 +0000377 // Copy the file from src to a location in out/ with the correct `filename`
378 // This ensures that outputFilePath has the correct name for others to
379 // use, as the source file may have a different name.
380 p.outputFilePath = android.PathForModuleOut(ctx, ip.filename).OutputPath
381 ctx.Build(pctx, android.BuildParams{
382 Rule: android.Cp,
383 Output: p.outputFilePath,
384 Input: ip.sourceFilePath,
385 })
386
387 installPath := ctx.InstallFile(p.installDirPath, ip.filename, p.outputFilePath)
388 for _, sl := range ip.symlinks {
Inseob Kim916901e2021-02-17 15:48:53 +0900389 ctx.InstallSymlink(p.installDirPath, sl, installPath)
Jiyong Parkf9f68052020-09-29 20:15:08 +0900390 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900391}
392
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700393func (p *PrebuiltEtc) AndroidMkEntries() []android.AndroidMkEntries {
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700394 nameSuffix := ""
Yifan Hong1b3348d2020-01-21 15:53:22 -0800395 if p.inRamdisk() && !p.onlyInRamdisk() {
396 nameSuffix = ".ramdisk"
397 }
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700398 if p.inVendorRamdisk() && !p.onlyInVendorRamdisk() {
399 nameSuffix = ".vendor_ramdisk"
400 }
Inseob Kim08758f02021-04-08 21:13:22 +0900401 if p.inDebugRamdisk() && !p.onlyInDebugRamdisk() {
402 nameSuffix = ".debug_ramdisk"
403 }
Kiyoung Kimae11c232021-07-19 11:38:04 +0900404 if p.InRecovery() && !p.onlyInRecovery() {
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700405 nameSuffix = ".recovery"
406 }
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700407 return []android.AndroidMkEntries{android.AndroidMkEntries{
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700408 Class: "ETC",
409 SubName: nameSuffix,
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700410 OutputFile: android.OptionalPathForPath(p.outputFilePath),
411 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -0700412 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700413 entries.SetString("LOCAL_MODULE_TAGS", "optional")
Colin Crossc68db4b2021-11-11 18:59:15 -0800414 entries.SetString("LOCAL_MODULE_PATH", p.installDirPath.String())
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700415 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePath.Base())
Yo Chiang3d64d492020-05-27 17:56:39 +0800416 if len(p.properties.Symlinks) > 0 {
417 entries.AddStrings("LOCAL_MODULE_SYMLINKS", p.properties.Symlinks...)
418 }
Yo Chiang803c40d2020-11-16 20:32:51 +0800419 entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.Installable())
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700420 if p.additionalDependencies != nil {
Yo Chiang803c40d2020-11-16 20:32:51 +0800421 entries.AddStrings("LOCAL_ADDITIONAL_DEPENDENCIES", p.additionalDependencies.Strings()...)
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900422 }
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700423 },
Jiyong Parkc678ad32018-04-10 13:07:10 +0900424 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900425 }}
Jiyong Parkc678ad32018-04-10 13:07:10 +0900426}
427
Jooyung Hana0171822019-07-22 15:48:36 +0900428func InitPrebuiltEtcModule(p *PrebuiltEtc, dirBase string) {
429 p.installDirBase = dirBase
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900430 p.AddProperties(&p.properties)
Inseob Kim27408bf2021-04-06 21:00:17 +0900431 p.AddProperties(&p.subdirProperties)
432}
433
434func InitPrebuiltRootModule(p *PrebuiltEtc) {
435 p.installDirBase = "."
436 p.AddProperties(&p.properties)
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900437}
Jiyong Parkc678ad32018-04-10 13:07:10 +0900438
Patrice Arruda9e14b962019-03-11 15:58:50 -0700439// prebuilt_etc is for a prebuilt artifact that is installed in
440// <partition>/etc/<sub_dir> directory.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700441func PrebuiltEtcFactory() android.Module {
Jooyung Hana0171822019-07-22 15:48:36 +0900442 module := &PrebuiltEtc{}
443 InitPrebuiltEtcModule(module, "etc")
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900444 // This module is device-only
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700445 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Inseob Kim1e27a142021-05-06 11:46:11 +0000446 android.InitDefaultableModule(module)
Rupert Shuttleworth378fc1b2021-07-28 08:03:16 -0400447 android.InitBazelModule(module)
Inseob Kim1e27a142021-05-06 11:46:11 +0000448 return module
449}
450
451func defaultsFactory() android.Module {
452 return DefaultsFactory()
453}
454
455func DefaultsFactory(props ...interface{}) android.Module {
456 module := &Defaults{}
457
458 module.AddProperties(props...)
459 module.AddProperties(
460 &prebuiltEtcProperties{},
461 &prebuiltSubdirProperties{},
462 )
463
464 android.InitDefaultsModule(module)
465
Jiyong Parkc678ad32018-04-10 13:07:10 +0900466 return module
467}
Tao Bao0ba5c942018-08-14 22:20:22 -0700468
Patrice Arruda9e14b962019-03-11 15:58:50 -0700469// prebuilt_etc_host is for a host prebuilt artifact that is installed in
470// $(HOST_OUT)/etc/<sub_dir> directory.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700471func PrebuiltEtcHostFactory() android.Module {
Jooyung Hana0171822019-07-22 15:48:36 +0900472 module := &PrebuiltEtc{}
473 InitPrebuiltEtcModule(module, "etc")
Jaewoong Jung24788182019-02-04 14:34:10 -0800474 // This module is host-only
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700475 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100476 android.InitDefaultableModule(module)
Liz Kammera9234422021-12-22 15:32:18 -0500477 android.InitBazelModule(module)
Jaewoong Jung24788182019-02-04 14:34:10 -0800478 return module
479}
480
Miguel32b02802022-12-01 18:38:26 +0000481// prebuilt_etc_host is for a host prebuilt artifact that is installed in
482// <partition>/etc/<sub_dir> directory.
483func PrebuiltEtcCaCertsFactory() android.Module {
484 module := &PrebuiltEtc{}
485 InitPrebuiltEtcModule(module, "cacerts")
486 // This module is device-only
487 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
488 android.InitBazelModule(module)
489 return module
490}
491
Inseob Kim27408bf2021-04-06 21:00:17 +0900492// prebuilt_root is for a prebuilt artifact that is installed in
493// <partition>/ directory. Can't have any sub directories.
494func PrebuiltRootFactory() android.Module {
495 module := &PrebuiltEtc{}
496 InitPrebuiltRootModule(module)
497 // This module is device-only
498 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100499 android.InitDefaultableModule(module)
Inseob Kim27408bf2021-04-06 21:00:17 +0900500 return module
501}
502
Liz Kammere9ecddc2022-01-04 17:27:52 -0500503// prebuilt_root_host is for a host prebuilt artifact that is installed in $(HOST_OUT)/<sub_dir>
504// directory.
505func PrebuiltRootHostFactory() android.Module {
506 module := &PrebuiltEtc{}
507 InitPrebuiltEtcModule(module, ".")
508 // This module is host-only
509 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
510 android.InitDefaultableModule(module)
Zi Wang04054142023-10-10 14:49:18 -0700511 android.InitBazelModule(module)
Liz Kammere9ecddc2022-01-04 17:27:52 -0500512 return module
513}
514
Patrice Arruda9e14b962019-03-11 15:58:50 -0700515// prebuilt_usr_share is for a prebuilt artifact that is installed in
516// <partition>/usr/share/<sub_dir> directory.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700517func PrebuiltUserShareFactory() android.Module {
Jooyung Hana0171822019-07-22 15:48:36 +0900518 module := &PrebuiltEtc{}
519 InitPrebuiltEtcModule(module, "usr/share")
Jaewoong Jungc3fcdb42019-02-13 05:50:33 -0800520 // This module is device-only
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700521 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100522 android.InitDefaultableModule(module)
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxc78604e2022-02-28 18:22:59 -0500523 android.InitBazelModule(module)
Jaewoong Jungc3fcdb42019-02-13 05:50:33 -0800524 return module
525}
526
Patrice Arruda9e14b962019-03-11 15:58:50 -0700527// prebuild_usr_share_host is for a host prebuilt artifact that is installed in
528// $(HOST_OUT)/usr/share/<sub_dir> directory.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700529func PrebuiltUserShareHostFactory() android.Module {
Jooyung Hana0171822019-07-22 15:48:36 +0900530 module := &PrebuiltEtc{}
531 InitPrebuiltEtcModule(module, "usr/share")
Patrice Arruda300cef92019-02-22 15:47:57 -0800532 // This module is host-only
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700533 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100534 android.InitDefaultableModule(module)
Patrice Arruda300cef92019-02-22 15:47:57 -0800535 return module
536}
537
Patrice Arruda61583eb2019-05-14 08:20:45 -0700538// prebuilt_font installs a font in <partition>/fonts directory.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700539func PrebuiltFontFactory() android.Module {
Jooyung Hana0171822019-07-22 15:48:36 +0900540 module := &PrebuiltEtc{}
541 InitPrebuiltEtcModule(module, "fonts")
Patrice Arruda61583eb2019-05-14 08:20:45 -0700542 // This module is device-only
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700543 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100544 android.InitDefaultableModule(module)
Patrice Arruda61583eb2019-05-14 08:20:45 -0700545 return module
546}
Patrice Arruda057a8b12019-06-03 15:29:27 -0700547
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800548// prebuilt_firmware installs a firmware file to <partition>/etc/firmware directory for system
549// image.
550// If soc_specific property is set to true, the firmware file is installed to the
551// vendor <partition>/firmware directory for vendor image.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700552func PrebuiltFirmwareFactory() android.Module {
Jooyung Hana0171822019-07-22 15:48:36 +0900553 module := &PrebuiltEtc{}
554 module.socInstallDirBase = "firmware"
555 InitPrebuiltEtcModule(module, "etc/firmware")
Patrice Arruda057a8b12019-06-03 15:29:27 -0700556 // This module is device-only
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700557 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100558 android.InitDefaultableModule(module)
Patrice Arruda057a8b12019-06-03 15:29:27 -0700559 return module
560}
Patrice Arruda0f688002020-06-08 21:40:25 +0000561
562// prebuilt_dsp installs a DSP related file to <partition>/etc/dsp directory for system image.
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800563// If soc_specific property is set to true, the DSP related file is installed to the
564// vendor <partition>/dsp directory for vendor image.
Patrice Arruda0f688002020-06-08 21:40:25 +0000565func PrebuiltDSPFactory() android.Module {
566 module := &PrebuiltEtc{}
567 module.socInstallDirBase = "dsp"
568 InitPrebuiltEtcModule(module, "etc/dsp")
569 // This module is device-only
570 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100571 android.InitDefaultableModule(module)
Patrice Arruda0f688002020-06-08 21:40:25 +0000572 return module
573}
Colin Cross83ebf232021-04-09 09:41:23 -0700574
575// prebuilt_rfsa installs a firmware file that will be available through Qualcomm's RFSA
576// to the <partition>/lib/rfsa directory.
577func PrebuiltRFSAFactory() android.Module {
578 module := &PrebuiltEtc{}
579 // Ideally these would go in /vendor/dsp, but the /vendor/lib/rfsa paths are hardcoded in too
580 // many places outside of the application processor. They could be moved to /vendor/dsp once
581 // that is cleaned up.
582 InitPrebuiltEtcModule(module, "lib/rfsa")
583 // This module is device-only
584 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100585 android.InitDefaultableModule(module)
Colin Cross83ebf232021-04-09 09:41:23 -0700586 return module
587}
Kiyoung Kimae11c232021-07-19 11:38:04 +0900588
Kiyoung Kimae11c232021-07-19 11:38:04 +0900589// Copy file into the snapshot
590func copyFile(ctx android.SingletonContext, path android.Path, out string, fake bool) android.OutputPath {
591 if fake {
592 // Create empty file instead for the fake snapshot
593 return snapshot.WriteStringToFileRule(ctx, "", out)
594 } else {
595 return snapshot.CopyFileRule(pctx, ctx, path, out)
596 }
597}
598
599// Check if the module is target of the snapshot
600func isSnapshotAware(ctx android.SingletonContext, m *PrebuiltEtc, image snapshot.SnapshotImage) bool {
601 if !m.Enabled() {
602 return false
603 }
604
605 // Skip if the module is not included in the image
606 if !image.InImage(m)() {
607 return false
608 }
609
610 // When android/prebuilt.go selects between source and prebuilt, it sets
611 // HideFromMake on the other one to avoid duplicate install rules in make.
612 if m.IsHideFromMake() {
613 return false
614 }
615
616 // There are some prebuilt_etc module with multiple definition of same name.
617 // Check if the target would be included from the build
618 if !m.ExportedToMake() {
619 return false
620 }
621
622 // Skip if the module is in the predefined path list to skip
623 if image.IsProprietaryPath(ctx.ModuleDir(m), ctx.DeviceConfig()) {
624 return false
625 }
626
627 // Skip if the module should be excluded
628 if image.ExcludeFromSnapshot(m) || image.ExcludeFromDirectedSnapshot(ctx.DeviceConfig(), m.BaseModuleName()) {
629 return false
630 }
631
632 // Skip from other exceptional cases
633 if m.Target().Os.Class != android.Device {
634 return false
635 }
636 if m.Target().NativeBridge == android.NativeBridgeEnabled {
637 return false
638 }
639
640 return true
641}
642
Justin Yun1db97482023-04-11 18:20:07 +0900643func generatePrebuiltSnapshot(s snapshot.SnapshotSingleton, ctx android.SingletonContext, snapshotArchDir string) snapshot.SnapshotPaths {
Kiyoung Kimae11c232021-07-19 11:38:04 +0900644 /*
645 Snapshot zipped artifacts directory structure for etc modules:
646 {SNAPSHOT_ARCH}/
647 arch-{TARGET_ARCH}-{TARGET_ARCH_VARIANT}/
648 etc/
649 (prebuilt etc files)
650 arch-{TARGET_2ND_ARCH}-{TARGET_2ND_ARCH_VARIANT}/
651 etc/
652 (prebuilt etc files)
653 NOTICE_FILES/
654 (notice files)
655 */
656 var snapshotOutputs android.Paths
Justin Yun1db97482023-04-11 18:20:07 +0900657 var snapshotNotices android.Paths
Kiyoung Kimae11c232021-07-19 11:38:04 +0900658 installedNotices := make(map[string]bool)
659
660 ctx.VisitAllModules(func(module android.Module) {
661 m, ok := module.(*PrebuiltEtc)
662 if !ok {
663 return
664 }
665
666 if !isSnapshotAware(ctx, m, s.Image) {
667 return
668 }
669
670 targetArch := "arch-" + m.Target().Arch.ArchType.String()
671
672 snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, "etc", m.BaseModuleName())
673 snapshotOutputs = append(snapshotOutputs, copyFile(ctx, m.OutputFile(), snapshotLibOut, s.Fake))
674
Rob Seymour925aa092021-08-10 20:42:03 +0000675 prop := snapshot.SnapshotJsonFlags{}
Kiyoung Kimae11c232021-07-19 11:38:04 +0900676 propOut := snapshotLibOut + ".json"
Justin Yun1db97482023-04-11 18:20:07 +0900677 prop.InitBaseSnapshotProps(m)
Justin Yun8bd3afe2023-05-12 15:53:06 +0900678 prop.RelativeInstallPath = m.SubDir()
Kiyoung Kimae11c232021-07-19 11:38:04 +0900679
680 if m.properties.Filename != nil {
681 prop.Filename = *m.properties.Filename
682 }
683
684 j, err := json.Marshal(prop)
685 if err != nil {
686 ctx.Errorf("json marshal to %q failed: %#v", propOut, err)
687 return
688 }
689 snapshotOutputs = append(snapshotOutputs, snapshot.WriteStringToFileRule(ctx, string(j), propOut))
690
Justin Yun1db97482023-04-11 18:20:07 +0900691 for _, notice := range m.EffectiveLicenseFiles() {
692 if _, ok := installedNotices[notice.String()]; !ok {
693 installedNotices[notice.String()] = true
694 snapshotNotices = append(snapshotNotices, notice)
Kiyoung Kimae11c232021-07-19 11:38:04 +0900695 }
696 }
697
698 })
699
Justin Yun1db97482023-04-11 18:20:07 +0900700 return snapshot.SnapshotPaths{OutputFiles: snapshotOutputs, NoticeFiles: snapshotNotices}
Kiyoung Kimae11c232021-07-19 11:38:04 +0900701}
Rupert Shuttleworth378fc1b2021-07-28 08:03:16 -0400702
703// For Bazel / bp2build
704
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxc78604e2022-02-28 18:22:59 -0500705type bazelPrebuiltFileAttributes struct {
Alix993872a2022-06-15 17:42:14 +0000706 Src bazel.LabelAttribute
707 Filename bazel.LabelAttribute
708 Dir string
709 Installable bazel.BoolAttribute
710 Filename_from_src bazel.BoolAttribute
Rupert Shuttleworth378fc1b2021-07-28 08:03:16 -0400711}
712
Alix5918d642022-06-27 20:57:44 +0000713// Bp2buildHelper returns a bazelPrebuiltFileAttributes used for the conversion
714// of prebuilt_* modules. bazelPrebuiltFileAttributes has the common attributes
715// used by both prebuilt_etc_xml and other prebuilt_* moodules
Chris Parsons637458d2023-09-19 20:09:00 +0000716func (module *PrebuiltEtc) Bp2buildHelper(ctx android.Bp2buildMutatorContext) (*bazelPrebuiltFileAttributes, bool) {
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxc78604e2022-02-28 18:22:59 -0500717 var src bazel.LabelAttribute
Liz Kammerdff00ea2021-10-04 13:44:34 -0400718 for axis, configToProps := range module.GetArchVariantProperties(ctx, &prebuiltEtcProperties{}) {
719 for config, p := range configToProps {
720 props, ok := p.(*prebuiltEtcProperties)
721 if !ok {
722 continue
723 }
724 if props.Src != nil {
Liz Kammerd5d12d02023-09-05 09:18:50 -0400725 srcStr := proptools.String(props.Src)
726 if srcStr == ctx.ModuleName() {
727 ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_PROPERTY_UNSUPPORTED, "src == name")
728 return &bazelPrebuiltFileAttributes{}, false
729 }
730 label := android.BazelLabelForModuleSrcSingle(ctx, srcStr)
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxc78604e2022-02-28 18:22:59 -0500731 src.SetSelectValue(axis, config, label)
Liz Kammerdff00ea2021-10-04 13:44:34 -0400732 }
733 }
Liz Kammer9e2a5a72023-09-19 08:41:14 -0400734 productVarProperties, errs := android.ProductVariableProperties(ctx, ctx.Module())
735 for _, err := range errs {
736 ctx.ModuleErrorf("ProductVariableProperties error: %s", err)
737 }
738 for propName, productConfigProps := range productVarProperties {
Alixbbfd5382022-06-09 18:52:05 +0000739 for configProp, propVal := range productConfigProps {
740 if propName == "Src" {
741 props, ok := propVal.(*string)
742 if !ok {
743 ctx.PropertyErrorf(" Expected Property to have type string, but was %s\n", reflect.TypeOf(propVal).String())
744 continue
745 }
746 if props != nil {
747 label := android.BazelLabelForModuleSrcSingle(ctx, *props)
748 src.SetSelectValue(configProp.ConfigurationAxis(), configProp.SelectKey(), label)
749 }
750 }
751 }
752 }
Rupert Shuttleworth378fc1b2021-07-28 08:03:16 -0400753 }
754
755 var filename string
Alix993872a2022-06-15 17:42:14 +0000756 var filenameFromSrc bool
757 moduleProps := module.properties
758
759 if moduleProps.Filename != nil && *moduleProps.Filename != "" {
760 filename = *moduleProps.Filename
761 } else if moduleProps.Filename_from_src != nil && *moduleProps.Filename_from_src {
762 if moduleProps.Src != nil {
Zi Wang04054142023-10-10 14:49:18 -0700763 filename = android.BazelLabelForModuleSrcSingle(ctx, *moduleProps.Src).Label
Alix993872a2022-06-15 17:42:14 +0000764 }
765 filenameFromSrc = true
766 } else {
767 filename = ctx.ModuleName()
Rupert Shuttleworth378fc1b2021-07-28 08:03:16 -0400768 }
769
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxc78604e2022-02-28 18:22:59 -0500770 var dir = module.installDirBase
Zi Wang04054142023-10-10 14:49:18 -0700771 if module.SubDir() != "" {
772 dir = dir + "/" + module.SubDir()
Rupert Shuttleworth378fc1b2021-07-28 08:03:16 -0400773 }
774
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxc78604e2022-02-28 18:22:59 -0500775 var installable bazel.BoolAttribute
776 if install := module.properties.Installable; install != nil {
777 installable.Value = install
Rupert Shuttleworth378fc1b2021-07-28 08:03:16 -0400778 }
779
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxc78604e2022-02-28 18:22:59 -0500780 attrs := &bazelPrebuiltFileAttributes{
781 Src: src,
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxc78604e2022-02-28 18:22:59 -0500782 Dir: dir,
783 Installable: installable,
Rupert Shuttleworth378fc1b2021-07-28 08:03:16 -0400784 }
785
Alix993872a2022-06-15 17:42:14 +0000786 if filename != "" {
787 attrs.Filename = bazel.LabelAttribute{Value: &bazel.Label{Label: filename}}
788 } else if filenameFromSrc {
789 attrs.Filename_from_src = bazel.BoolAttribute{Value: moduleProps.Filename_from_src}
790 }
791
Liz Kammerd5d12d02023-09-05 09:18:50 -0400792 return attrs, true
Alix5918d642022-06-27 20:57:44 +0000793}
794
795// ConvertWithBp2build performs bp2build conversion of PrebuiltEtc
796// prebuilt_* modules (except prebuilt_etc_xml) are PrebuiltEtc,
797// which we treat as *PrebuiltFile*
Chris Parsons637458d2023-09-19 20:09:00 +0000798func (module *PrebuiltEtc) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) {
Alix5918d642022-06-27 20:57:44 +0000799 var dir = module.installDirBase
Zi Wang04054142023-10-10 14:49:18 -0700800 // prebuilt_file only supports "etc" or "usr/share" or "." as module installDirBase
801 if !(dir == "etc" || dir == "usr/share" || dir == ".") {
802 ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_TYPE_UNSUPPORTED, "")
Alix5918d642022-06-27 20:57:44 +0000803 return
804 }
805
Liz Kammerd5d12d02023-09-05 09:18:50 -0400806 attrs, convertible := module.Bp2buildHelper(ctx)
807 if !convertible {
808 return
809 }
Alix5918d642022-06-27 20:57:44 +0000810
Rupert Shuttleworth378fc1b2021-07-28 08:03:16 -0400811 props := bazel.BazelTargetModuleProperties{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxb81f77e2022-02-28 17:38:34 -0500812 Rule_class: "prebuilt_file",
813 Bzl_load_location: "//build/bazel/rules:prebuilt_file.bzl",
Rupert Shuttleworth378fc1b2021-07-28 08:03:16 -0400814 }
815
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux447f6c92021-08-31 20:30:36 +0000816 ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: module.Name()}, attrs)
Rupert Shuttleworth378fc1b2021-07-28 08:03:16 -0400817}
Spandan Das756d3402023-06-05 22:49:50 +0000818
819var _ android.MixedBuildBuildable = (*PrebuiltEtc)(nil)
820
821func (pe *PrebuiltEtc) IsMixedBuildSupported(ctx android.BaseModuleContext) bool {
822 return true
823}
824
825func (pe *PrebuiltEtc) QueueBazelCall(ctx android.BaseModuleContext) {
826 ctx.Config().BazelContext.QueueBazelRequest(
827 pe.GetBazelLabel(ctx, pe),
828 cquery.GetPrebuiltFileInfo,
829 android.GetConfigKey(ctx),
830 )
831}
832
833func (pe *PrebuiltEtc) ProcessBazelQueryResponse(ctx android.ModuleContext) {
834 bazelCtx := ctx.Config().BazelContext
835 pfi, err := bazelCtx.GetPrebuiltFileInfo(pe.GetBazelLabel(ctx, pe), android.GetConfigKey(ctx))
836 if err != nil {
837 ctx.ModuleErrorf(err.Error())
838 return
839 }
840
841 // Set properties for androidmk
842 pe.installDirPath = android.PathForModuleInstall(ctx, pfi.Dir)
843
844 // Installation rules
845 ip := installProperties{
846 installable: pfi.Installable,
847 filename: pfi.Filename,
848 sourceFilePath: android.PathForSource(ctx, pfi.Src),
849 // symlinks: pe.properties.Symlinks, // TODO: b/207489266 - Fully support all properties in prebuilt_file
850 }
851 pe.addInstallRules(ctx, ip)
852}