blob: 370a4235b603062f2edcb2acd98ae6cbad67376a [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"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070043)
44
45var pctx = android.NewPackageContext("android/soong/etc")
Jiyong Parkc678ad32018-04-10 13:07:10 +090046
Jaewoong Jungc3fcdb42019-02-13 05:50:33 -080047// TODO(jungw): Now that it handles more than the ones in etc/, consider renaming this file.
Jiyong Parkc678ad32018-04-10 13:07:10 +090048
49func init() {
Jaewoong Jung4b79e982020-06-01 10:45:49 -070050 pctx.Import("android/soong/android")
Jooyung Han0703fd82020-08-26 22:11:53 +090051 RegisterPrebuiltEtcBuildComponents(android.InitRegistrationContext)
Kiyoung Kimae11c232021-07-19 11:38:04 +090052 snapshot.RegisterSnapshotAction(generatePrebuiltSnapshot)
Jooyung Han0703fd82020-08-26 22:11:53 +090053}
Jaewoong Jung4b79e982020-06-01 10:45:49 -070054
Jooyung Han0703fd82020-08-26 22:11:53 +090055func RegisterPrebuiltEtcBuildComponents(ctx android.RegistrationContext) {
56 ctx.RegisterModuleType("prebuilt_etc", PrebuiltEtcFactory)
57 ctx.RegisterModuleType("prebuilt_etc_host", PrebuiltEtcHostFactory)
Miguel32b02802022-12-01 18:38:26 +000058 ctx.RegisterModuleType("prebuilt_etc_cacerts", PrebuiltEtcCaCertsFactory)
Inseob Kim27408bf2021-04-06 21:00:17 +090059 ctx.RegisterModuleType("prebuilt_root", PrebuiltRootFactory)
Liz Kammere9ecddc2022-01-04 17:27:52 -050060 ctx.RegisterModuleType("prebuilt_root_host", PrebuiltRootHostFactory)
Jooyung Han0703fd82020-08-26 22:11:53 +090061 ctx.RegisterModuleType("prebuilt_usr_share", PrebuiltUserShareFactory)
62 ctx.RegisterModuleType("prebuilt_usr_share_host", PrebuiltUserShareHostFactory)
63 ctx.RegisterModuleType("prebuilt_font", PrebuiltFontFactory)
64 ctx.RegisterModuleType("prebuilt_firmware", PrebuiltFirmwareFactory)
65 ctx.RegisterModuleType("prebuilt_dsp", PrebuiltDSPFactory)
Colin Cross83ebf232021-04-09 09:41:23 -070066 ctx.RegisterModuleType("prebuilt_rfsa", PrebuiltRFSAFactory)
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.
Colin Cross27b922f2019-03-04 22:35:41 -080076 Src *string `android:"path,arch_variant"`
Jiyong Parkc678ad32018-04-10 13:07:10 +090077
Yo Chiangf0e19fe2020-11-18 15:28:42 +080078 // Optional name for the installed file. If unspecified, name of the module is used as the file
79 // name.
Jiyong Park139a2e62018-10-26 21:49:39 +090080 Filename *string `android:"arch_variant"`
81
Yo Chiangf0e19fe2020-11-18 15:28:42 +080082 // When set to true, and filename property is not set, the name for the installed file
Jiyong Park1a7cf082018-11-13 11:59:12 +090083 // is the same as the file name of the source file.
84 Filename_from_src *bool `android:"arch_variant"`
85
Yifan Hong1b3348d2020-01-21 15:53:22 -080086 // Make this module available when building for ramdisk.
Yifan Hong39143a92020-10-26 12:43:12 -070087 // On device without a dedicated recovery partition, the module is only
88 // available after switching root into
89 // /first_stage_ramdisk. To expose the module before switching root, install
90 // the recovery variant instead.
Yifan Hong1b3348d2020-01-21 15:53:22 -080091 Ramdisk_available *bool
92
Yifan Hong60e0cfb2020-10-21 15:17:56 -070093 // Make this module available when building for vendor ramdisk.
Yifan Hong39143a92020-10-26 12:43:12 -070094 // On device without a dedicated recovery partition, the module is only
95 // available after switching root into
96 // /first_stage_ramdisk. To expose the module before switching root, install
97 // the recovery variant instead.
Yifan Hong60e0cfb2020-10-21 15:17:56 -070098 Vendor_ramdisk_available *bool
99
Inseob Kim08758f02021-04-08 21:13:22 +0900100 // Make this module available when building for debug ramdisk.
101 Debug_ramdisk_available *bool
102
Tao Bao0ba5c942018-08-14 22:20:22 -0700103 // Make this module available when building for recovery.
104 Recovery_available *bool
105
Jiyong Parkad9ce042018-10-31 22:49:57 +0900106 // Whether this module is directly installable to one of the partitions. Default: true.
107 Installable *bool
Yo Chiang3d64d492020-05-27 17:56:39 +0800108
109 // Install symlinks to the installed file.
110 Symlinks []string `android:"arch_variant"`
Jiyong Parkc678ad32018-04-10 13:07:10 +0900111}
112
Inseob Kim27408bf2021-04-06 21:00:17 +0900113type prebuiltSubdirProperties struct {
114 // Optional subdirectory under which this file is installed into, cannot be specified with
115 // relative_install_path, prefer relative_install_path.
116 Sub_dir *string `android:"arch_variant"`
117
118 // Optional subdirectory under which this file is installed into, cannot be specified with
119 // sub_dir.
120 Relative_install_path *string `android:"arch_variant"`
121}
122
Jooyung Han39edb6c2019-11-06 16:53:07 +0900123type PrebuiltEtcModule interface {
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700124 android.Module
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800125
126 // Returns the base install directory, such as "etc", "usr/share".
Jooyung Han0703fd82020-08-26 22:11:53 +0900127 BaseDir() string
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800128
129 // Returns the sub install directory relative to BaseDir().
Jooyung Han39edb6c2019-11-06 16:53:07 +0900130 SubDir() string
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800131
132 // Returns an android.OutputPath to the intermeidate file, which is the renamed prebuilt source
133 // file.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700134 OutputFile() android.OutputPath
Jooyung Han39edb6c2019-11-06 16:53:07 +0900135}
136
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900137type PrebuiltEtc struct {
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700138 android.ModuleBase
Inseob Kim1e27a142021-05-06 11:46:11 +0000139 android.DefaultableModuleBase
Rupert Shuttleworth378fc1b2021-07-28 08:03:16 -0400140 android.BazelModuleBase
Jiyong Parkc678ad32018-04-10 13:07:10 +0900141
Kiyoung Kimae11c232021-07-19 11:38:04 +0900142 snapshot.VendorSnapshotModuleInterface
143 snapshot.RecoverySnapshotModuleInterface
144
Inseob Kim27408bf2021-04-06 21:00:17 +0900145 properties prebuiltEtcProperties
146 subdirProperties prebuiltSubdirProperties
Jiyong Parkc678ad32018-04-10 13:07:10 +0900147
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700148 sourceFilePath android.Path
149 outputFilePath android.OutputPath
Jaewoong Jungc3fcdb42019-02-13 05:50:33 -0800150 // The base install location, e.g. "etc" for prebuilt_etc, "usr/share" for prebuilt_usr_share.
Patrice Arruda057a8b12019-06-03 15:29:27 -0700151 installDirBase string
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800152 // The base install location when soc_specific property is set to true, e.g. "firmware" for
153 // prebuilt_firmware.
Patrice Arruda057a8b12019-06-03 15:29:27 -0700154 socInstallDirBase string
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700155 installDirPath android.InstallPath
156 additionalDependencies *android.Paths
Jiyong Parkc678ad32018-04-10 13:07:10 +0900157}
158
Inseob Kim1e27a142021-05-06 11:46:11 +0000159type Defaults struct {
160 android.ModuleBase
161 android.DefaultsModuleBase
162}
163
Yifan Hong1b3348d2020-01-21 15:53:22 -0800164func (p *PrebuiltEtc) inRamdisk() bool {
165 return p.ModuleBase.InRamdisk() || p.ModuleBase.InstallInRamdisk()
166}
167
168func (p *PrebuiltEtc) onlyInRamdisk() bool {
169 return p.ModuleBase.InstallInRamdisk()
170}
171
172func (p *PrebuiltEtc) InstallInRamdisk() bool {
173 return p.inRamdisk()
174}
175
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700176func (p *PrebuiltEtc) inVendorRamdisk() bool {
177 return p.ModuleBase.InVendorRamdisk() || p.ModuleBase.InstallInVendorRamdisk()
178}
179
180func (p *PrebuiltEtc) onlyInVendorRamdisk() bool {
181 return p.ModuleBase.InstallInVendorRamdisk()
182}
183
184func (p *PrebuiltEtc) InstallInVendorRamdisk() bool {
185 return p.inVendorRamdisk()
186}
187
Inseob Kim08758f02021-04-08 21:13:22 +0900188func (p *PrebuiltEtc) inDebugRamdisk() bool {
189 return p.ModuleBase.InDebugRamdisk() || p.ModuleBase.InstallInDebugRamdisk()
190}
191
192func (p *PrebuiltEtc) onlyInDebugRamdisk() bool {
193 return p.ModuleBase.InstallInDebugRamdisk()
194}
195
196func (p *PrebuiltEtc) InstallInDebugRamdisk() bool {
197 return p.inDebugRamdisk()
198}
199
Kiyoung Kimae11c232021-07-19 11:38:04 +0900200func (p *PrebuiltEtc) InRecovery() bool {
Colin Cross7228ecd2019-11-18 16:00:16 -0800201 return p.ModuleBase.InRecovery() || p.ModuleBase.InstallInRecovery()
Tao Bao0ba5c942018-08-14 22:20:22 -0700202}
203
204func (p *PrebuiltEtc) onlyInRecovery() bool {
205 return p.ModuleBase.InstallInRecovery()
206}
207
208func (p *PrebuiltEtc) InstallInRecovery() bool {
Kiyoung Kimae11c232021-07-19 11:38:04 +0900209 return p.InRecovery()
Tao Bao0ba5c942018-08-14 22:20:22 -0700210}
211
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700212var _ android.ImageInterface = (*PrebuiltEtc)(nil)
Colin Cross7228ecd2019-11-18 16:00:16 -0800213
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700214func (p *PrebuiltEtc) ImageMutatorBegin(ctx android.BaseModuleContext) {}
Colin Cross7228ecd2019-11-18 16:00:16 -0800215
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700216func (p *PrebuiltEtc) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700217 return !p.ModuleBase.InstallInRecovery() && !p.ModuleBase.InstallInRamdisk() &&
Inseob Kim08758f02021-04-08 21:13:22 +0900218 !p.ModuleBase.InstallInVendorRamdisk() && !p.ModuleBase.InstallInDebugRamdisk()
Yifan Hong1b3348d2020-01-21 15:53:22 -0800219}
220
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700221func (p *PrebuiltEtc) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
222 return proptools.Bool(p.properties.Ramdisk_available) || p.ModuleBase.InstallInRamdisk()
Colin Cross7228ecd2019-11-18 16:00:16 -0800223}
224
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700225func (p *PrebuiltEtc) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
226 return proptools.Bool(p.properties.Vendor_ramdisk_available) || p.ModuleBase.InstallInVendorRamdisk()
227}
228
Inseob Kim08758f02021-04-08 21:13:22 +0900229func (p *PrebuiltEtc) DebugRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
230 return proptools.Bool(p.properties.Debug_ramdisk_available) || p.ModuleBase.InstallInDebugRamdisk()
231}
232
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700233func (p *PrebuiltEtc) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
234 return proptools.Bool(p.properties.Recovery_available) || p.ModuleBase.InstallInRecovery()
Colin Cross7228ecd2019-11-18 16:00:16 -0800235}
236
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700237func (p *PrebuiltEtc) ExtraImageVariations(ctx android.BaseModuleContext) []string {
Colin Cross7228ecd2019-11-18 16:00:16 -0800238 return nil
239}
240
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700241func (p *PrebuiltEtc) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) {
Colin Cross7228ecd2019-11-18 16:00:16 -0800242}
243
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700244func (p *PrebuiltEtc) SourceFilePath(ctx android.ModuleContext) android.Path {
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800245 return android.PathForModuleSrc(ctx, proptools.String(p.properties.Src))
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900246}
247
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700248func (p *PrebuiltEtc) InstallDirPath() android.InstallPath {
Jooyung Hana0171822019-07-22 15:48:36 +0900249 return p.installDirPath
250}
251
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900252// This allows other derivative modules (e.g. prebuilt_etc_xml) to perform
253// additional steps (like validating the src) before the file is installed.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700254func (p *PrebuiltEtc) SetAdditionalDependencies(paths android.Paths) {
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900255 p.additionalDependencies = &paths
256}
257
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700258func (p *PrebuiltEtc) OutputFile() android.OutputPath {
Jiyong Parkc43e0ac2018-10-04 20:27:15 +0900259 return p.outputFilePath
260}
261
Jiyong Park76a42f52021-02-16 06:50:37 +0900262var _ android.OutputFileProducer = (*PrebuiltEtc)(nil)
263
264func (p *PrebuiltEtc) OutputFiles(tag string) (android.Paths, error) {
265 switch tag {
266 case "":
267 return android.Paths{p.outputFilePath}, nil
268 default:
269 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
270 }
271}
272
Jiyong Parkc43e0ac2018-10-04 20:27:15 +0900273func (p *PrebuiltEtc) SubDir() string {
Inseob Kim27408bf2021-04-06 21:00:17 +0900274 if subDir := proptools.String(p.subdirProperties.Sub_dir); subDir != "" {
Liz Kammer0449a632020-06-26 10:12:36 -0700275 return subDir
276 }
Inseob Kim27408bf2021-04-06 21:00:17 +0900277 return proptools.String(p.subdirProperties.Relative_install_path)
Jiyong Parkc43e0ac2018-10-04 20:27:15 +0900278}
279
Jooyung Han0703fd82020-08-26 22:11:53 +0900280func (p *PrebuiltEtc) BaseDir() string {
Jooyung Han8e5685d2020-09-21 11:02:57 +0900281 return p.installDirBase
Jooyung Han0703fd82020-08-26 22:11:53 +0900282}
283
Jiyong Parkad9ce042018-10-31 22:49:57 +0900284func (p *PrebuiltEtc) Installable() bool {
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800285 return p.properties.Installable == nil || proptools.Bool(p.properties.Installable)
Jiyong Parkad9ce042018-10-31 22:49:57 +0900286}
287
Kiyoung Kimae11c232021-07-19 11:38:04 +0900288func (p *PrebuiltEtc) InVendor() bool {
289 return p.ModuleBase.InstallInVendor()
290}
291
292func (p *PrebuiltEtc) ExcludeFromVendorSnapshot() bool {
293 return false
294}
295
296func (p *PrebuiltEtc) ExcludeFromRecoverySnapshot() bool {
297 return false
298}
299
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700300func (p *PrebuiltEtc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800301 filename := proptools.String(p.properties.Filename)
302 filenameFromSrc := proptools.Bool(p.properties.Filename_from_src)
Colin Cross725eac62022-10-03 15:31:29 -0700303 if p.properties.Src != nil {
304 p.sourceFilePath = android.PathForModuleSrc(ctx, proptools.String(p.properties.Src))
305
306 // Determine the output file basename.
307 // If Filename is set, use the name specified by the property.
308 // If Filename_from_src is set, use the source file name.
309 // Otherwise use the module name.
310 if filename != "" {
311 if filenameFromSrc {
312 ctx.PropertyErrorf("filename_from_src", "filename is set. filename_from_src can't be true")
313 return
314 }
315 } else if filenameFromSrc {
316 filename = p.sourceFilePath.Base()
317 } else {
318 filename = ctx.ModuleName()
Jiyong Park1a7cf082018-11-13 11:59:12 +0900319 }
Colin Cross725eac62022-10-03 15:31:29 -0700320 } else if ctx.Config().AllowMissingDependencies() {
321 // If no srcs was set and AllowMissingDependencies is enabled then
322 // mark the module as missing dependencies and set a fake source path
323 // and file name.
324 ctx.AddMissingDependencies([]string{"MISSING_PREBUILT_SRC_FILE"})
325 p.sourceFilePath = android.PathForModuleSrc(ctx)
326 if filename == "" {
327 filename = ctx.ModuleName()
328 }
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800329 } else {
Colin Cross725eac62022-10-03 15:31:29 -0700330 ctx.PropertyErrorf("src", "missing prebuilt source file")
331 return
Jiyong Park139a2e62018-10-26 21:49:39 +0900332 }
Patrice Arruda057a8b12019-06-03 15:29:27 -0700333
Inseob Kim27408bf2021-04-06 21:00:17 +0900334 if strings.Contains(filename, "/") {
335 ctx.PropertyErrorf("filename", "filename cannot contain separator '/'")
336 return
337 }
338
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800339 // Check that `sub_dir` and `relative_install_path` are not set at the same time.
Inseob Kim27408bf2021-04-06 21:00:17 +0900340 if p.subdirProperties.Sub_dir != nil && p.subdirProperties.Relative_install_path != nil {
Liz Kammer0449a632020-06-26 10:12:36 -0700341 ctx.PropertyErrorf("sub_dir", "relative_install_path is set. Cannot set sub_dir")
342 }
343
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800344 // If soc install dir was specified and SOC specific is set, set the installDirPath to the
345 // specified socInstallDirBase.
Jooyung Han8e5685d2020-09-21 11:02:57 +0900346 installBaseDir := p.installDirBase
347 if p.SocSpecific() && p.socInstallDirBase != "" {
348 installBaseDir = p.socInstallDirBase
349 }
350 p.installDirPath = android.PathForModuleInstall(ctx, installBaseDir, p.SubDir())
Jiyong Parkc43e0ac2018-10-04 20:27:15 +0900351
Spandan Das756d3402023-06-05 22:49:50 +0000352 // Call InstallFile even when uninstallable to make the module included in the package
353 ip := installProperties{
354 installable: p.Installable(),
355 filename: filename,
356 sourceFilePath: p.sourceFilePath,
357 symlinks: p.properties.Symlinks,
358 }
359 p.addInstallRules(ctx, ip)
360}
Jiyong Parkf9f68052020-09-29 20:15:08 +0900361
Spandan Das756d3402023-06-05 22:49:50 +0000362type installProperties struct {
363 installable bool
364 filename string
365 sourceFilePath android.Path
366 symlinks []string
367}
368
369// utility function to add install rules to the build graph.
370// Reduces code duplication between Soong and Mixed build analysis
371func (p *PrebuiltEtc) addInstallRules(ctx android.ModuleContext, ip installProperties) {
372 if !ip.installable {
Inseob Kim916901e2021-02-17 15:48:53 +0900373 p.SkipInstall()
374 }
375
Spandan Das756d3402023-06-05 22:49:50 +0000376 // Copy the file from src to a location in out/ with the correct `filename`
377 // This ensures that outputFilePath has the correct name for others to
378 // use, as the source file may have a different name.
379 p.outputFilePath = android.PathForModuleOut(ctx, ip.filename).OutputPath
380 ctx.Build(pctx, android.BuildParams{
381 Rule: android.Cp,
382 Output: p.outputFilePath,
383 Input: ip.sourceFilePath,
384 })
385
386 installPath := ctx.InstallFile(p.installDirPath, ip.filename, p.outputFilePath)
387 for _, sl := range ip.symlinks {
Inseob Kim916901e2021-02-17 15:48:53 +0900388 ctx.InstallSymlink(p.installDirPath, sl, installPath)
Jiyong Parkf9f68052020-09-29 20:15:08 +0900389 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900390}
391
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700392func (p *PrebuiltEtc) AndroidMkEntries() []android.AndroidMkEntries {
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700393 nameSuffix := ""
Yifan Hong1b3348d2020-01-21 15:53:22 -0800394 if p.inRamdisk() && !p.onlyInRamdisk() {
395 nameSuffix = ".ramdisk"
396 }
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700397 if p.inVendorRamdisk() && !p.onlyInVendorRamdisk() {
398 nameSuffix = ".vendor_ramdisk"
399 }
Inseob Kim08758f02021-04-08 21:13:22 +0900400 if p.inDebugRamdisk() && !p.onlyInDebugRamdisk() {
401 nameSuffix = ".debug_ramdisk"
402 }
Kiyoung Kimae11c232021-07-19 11:38:04 +0900403 if p.InRecovery() && !p.onlyInRecovery() {
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700404 nameSuffix = ".recovery"
405 }
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700406 return []android.AndroidMkEntries{android.AndroidMkEntries{
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700407 Class: "ETC",
408 SubName: nameSuffix,
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700409 OutputFile: android.OptionalPathForPath(p.outputFilePath),
410 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -0700411 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700412 entries.SetString("LOCAL_MODULE_TAGS", "optional")
Colin Crossc68db4b2021-11-11 18:59:15 -0800413 entries.SetString("LOCAL_MODULE_PATH", p.installDirPath.String())
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700414 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePath.Base())
Yo Chiang3d64d492020-05-27 17:56:39 +0800415 if len(p.properties.Symlinks) > 0 {
416 entries.AddStrings("LOCAL_MODULE_SYMLINKS", p.properties.Symlinks...)
417 }
Yo Chiang803c40d2020-11-16 20:32:51 +0800418 entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.Installable())
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700419 if p.additionalDependencies != nil {
Yo Chiang803c40d2020-11-16 20:32:51 +0800420 entries.AddStrings("LOCAL_ADDITIONAL_DEPENDENCIES", p.additionalDependencies.Strings()...)
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900421 }
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700422 },
Jiyong Parkc678ad32018-04-10 13:07:10 +0900423 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900424 }}
Jiyong Parkc678ad32018-04-10 13:07:10 +0900425}
426
Jooyung Hana0171822019-07-22 15:48:36 +0900427func InitPrebuiltEtcModule(p *PrebuiltEtc, dirBase string) {
428 p.installDirBase = dirBase
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900429 p.AddProperties(&p.properties)
Inseob Kim27408bf2021-04-06 21:00:17 +0900430 p.AddProperties(&p.subdirProperties)
431}
432
433func InitPrebuiltRootModule(p *PrebuiltEtc) {
434 p.installDirBase = "."
435 p.AddProperties(&p.properties)
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900436}
Jiyong Parkc678ad32018-04-10 13:07:10 +0900437
Patrice Arruda9e14b962019-03-11 15:58:50 -0700438// prebuilt_etc is for a prebuilt artifact that is installed in
439// <partition>/etc/<sub_dir> directory.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700440func PrebuiltEtcFactory() android.Module {
Jooyung Hana0171822019-07-22 15:48:36 +0900441 module := &PrebuiltEtc{}
442 InitPrebuiltEtcModule(module, "etc")
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900443 // This module is device-only
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700444 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Inseob Kim1e27a142021-05-06 11:46:11 +0000445 android.InitDefaultableModule(module)
Rupert Shuttleworth378fc1b2021-07-28 08:03:16 -0400446 android.InitBazelModule(module)
Inseob Kim1e27a142021-05-06 11:46:11 +0000447 return module
448}
449
450func defaultsFactory() android.Module {
451 return DefaultsFactory()
452}
453
454func DefaultsFactory(props ...interface{}) android.Module {
455 module := &Defaults{}
456
457 module.AddProperties(props...)
458 module.AddProperties(
459 &prebuiltEtcProperties{},
460 &prebuiltSubdirProperties{},
461 )
462
463 android.InitDefaultsModule(module)
464
Jiyong Parkc678ad32018-04-10 13:07:10 +0900465 return module
466}
Tao Bao0ba5c942018-08-14 22:20:22 -0700467
Patrice Arruda9e14b962019-03-11 15:58:50 -0700468// prebuilt_etc_host is for a host prebuilt artifact that is installed in
469// $(HOST_OUT)/etc/<sub_dir> directory.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700470func PrebuiltEtcHostFactory() android.Module {
Jooyung Hana0171822019-07-22 15:48:36 +0900471 module := &PrebuiltEtc{}
472 InitPrebuiltEtcModule(module, "etc")
Jaewoong Jung24788182019-02-04 14:34:10 -0800473 // This module is host-only
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700474 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100475 android.InitDefaultableModule(module)
Liz Kammera9234422021-12-22 15:32:18 -0500476 android.InitBazelModule(module)
Jaewoong Jung24788182019-02-04 14:34:10 -0800477 return module
478}
479
Miguel32b02802022-12-01 18:38:26 +0000480// prebuilt_etc_host is for a host prebuilt artifact that is installed in
481// <partition>/etc/<sub_dir> directory.
482func PrebuiltEtcCaCertsFactory() android.Module {
483 module := &PrebuiltEtc{}
484 InitPrebuiltEtcModule(module, "cacerts")
485 // This module is device-only
486 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
487 android.InitBazelModule(module)
488 return module
489}
490
Inseob Kim27408bf2021-04-06 21:00:17 +0900491// prebuilt_root is for a prebuilt artifact that is installed in
492// <partition>/ directory. Can't have any sub directories.
493func PrebuiltRootFactory() android.Module {
494 module := &PrebuiltEtc{}
495 InitPrebuiltRootModule(module)
496 // This module is device-only
497 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100498 android.InitDefaultableModule(module)
Inseob Kim27408bf2021-04-06 21:00:17 +0900499 return module
500}
501
Liz Kammere9ecddc2022-01-04 17:27:52 -0500502// prebuilt_root_host is for a host prebuilt artifact that is installed in $(HOST_OUT)/<sub_dir>
503// directory.
504func PrebuiltRootHostFactory() android.Module {
505 module := &PrebuiltEtc{}
506 InitPrebuiltEtcModule(module, ".")
507 // This module is host-only
508 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
509 android.InitDefaultableModule(module)
510 return module
511}
512
Patrice Arruda9e14b962019-03-11 15:58:50 -0700513// prebuilt_usr_share is for a prebuilt artifact that is installed in
514// <partition>/usr/share/<sub_dir> directory.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700515func PrebuiltUserShareFactory() android.Module {
Jooyung Hana0171822019-07-22 15:48:36 +0900516 module := &PrebuiltEtc{}
517 InitPrebuiltEtcModule(module, "usr/share")
Jaewoong Jungc3fcdb42019-02-13 05:50:33 -0800518 // This module is device-only
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700519 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100520 android.InitDefaultableModule(module)
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxc78604e2022-02-28 18:22:59 -0500521 android.InitBazelModule(module)
Jaewoong Jungc3fcdb42019-02-13 05:50:33 -0800522 return module
523}
524
Patrice Arruda9e14b962019-03-11 15:58:50 -0700525// prebuild_usr_share_host is for a host prebuilt artifact that is installed in
526// $(HOST_OUT)/usr/share/<sub_dir> directory.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700527func PrebuiltUserShareHostFactory() android.Module {
Jooyung Hana0171822019-07-22 15:48:36 +0900528 module := &PrebuiltEtc{}
529 InitPrebuiltEtcModule(module, "usr/share")
Patrice Arruda300cef92019-02-22 15:47:57 -0800530 // This module is host-only
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700531 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100532 android.InitDefaultableModule(module)
Patrice Arruda300cef92019-02-22 15:47:57 -0800533 return module
534}
535
Patrice Arruda61583eb2019-05-14 08:20:45 -0700536// prebuilt_font installs a font in <partition>/fonts directory.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700537func PrebuiltFontFactory() android.Module {
Jooyung Hana0171822019-07-22 15:48:36 +0900538 module := &PrebuiltEtc{}
539 InitPrebuiltEtcModule(module, "fonts")
Patrice Arruda61583eb2019-05-14 08:20:45 -0700540 // This module is device-only
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700541 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100542 android.InitDefaultableModule(module)
Patrice Arruda61583eb2019-05-14 08:20:45 -0700543 return module
544}
Patrice Arruda057a8b12019-06-03 15:29:27 -0700545
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800546// prebuilt_firmware installs a firmware file to <partition>/etc/firmware directory for system
547// image.
548// If soc_specific property is set to true, the firmware file is installed to the
549// vendor <partition>/firmware directory for vendor image.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700550func PrebuiltFirmwareFactory() android.Module {
Jooyung Hana0171822019-07-22 15:48:36 +0900551 module := &PrebuiltEtc{}
552 module.socInstallDirBase = "firmware"
553 InitPrebuiltEtcModule(module, "etc/firmware")
Patrice Arruda057a8b12019-06-03 15:29:27 -0700554 // This module is device-only
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700555 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100556 android.InitDefaultableModule(module)
Patrice Arruda057a8b12019-06-03 15:29:27 -0700557 return module
558}
Patrice Arruda0f688002020-06-08 21:40:25 +0000559
560// prebuilt_dsp installs a DSP related file to <partition>/etc/dsp directory for system image.
Yo Chiangf0e19fe2020-11-18 15:28:42 +0800561// If soc_specific property is set to true, the DSP related file is installed to the
562// vendor <partition>/dsp directory for vendor image.
Patrice Arruda0f688002020-06-08 21:40:25 +0000563func PrebuiltDSPFactory() android.Module {
564 module := &PrebuiltEtc{}
565 module.socInstallDirBase = "dsp"
566 InitPrebuiltEtcModule(module, "etc/dsp")
567 // This module is device-only
568 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100569 android.InitDefaultableModule(module)
Patrice Arruda0f688002020-06-08 21:40:25 +0000570 return module
571}
Colin Cross83ebf232021-04-09 09:41:23 -0700572
573// prebuilt_rfsa installs a firmware file that will be available through Qualcomm's RFSA
574// to the <partition>/lib/rfsa directory.
575func PrebuiltRFSAFactory() android.Module {
576 module := &PrebuiltEtc{}
577 // Ideally these would go in /vendor/dsp, but the /vendor/lib/rfsa paths are hardcoded in too
578 // many places outside of the application processor. They could be moved to /vendor/dsp once
579 // that is cleaned up.
580 InitPrebuiltEtcModule(module, "lib/rfsa")
581 // This module is device-only
582 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Martin Stjernholmdc6525e2021-10-14 00:42:59 +0100583 android.InitDefaultableModule(module)
Colin Cross83ebf232021-04-09 09:41:23 -0700584 return module
585}
Kiyoung Kimae11c232021-07-19 11:38:04 +0900586
Kiyoung Kimae11c232021-07-19 11:38:04 +0900587// Copy file into the snapshot
588func copyFile(ctx android.SingletonContext, path android.Path, out string, fake bool) android.OutputPath {
589 if fake {
590 // Create empty file instead for the fake snapshot
591 return snapshot.WriteStringToFileRule(ctx, "", out)
592 } else {
593 return snapshot.CopyFileRule(pctx, ctx, path, out)
594 }
595}
596
597// Check if the module is target of the snapshot
598func isSnapshotAware(ctx android.SingletonContext, m *PrebuiltEtc, image snapshot.SnapshotImage) bool {
599 if !m.Enabled() {
600 return false
601 }
602
603 // Skip if the module is not included in the image
604 if !image.InImage(m)() {
605 return false
606 }
607
608 // When android/prebuilt.go selects between source and prebuilt, it sets
609 // HideFromMake on the other one to avoid duplicate install rules in make.
610 if m.IsHideFromMake() {
611 return false
612 }
613
614 // There are some prebuilt_etc module with multiple definition of same name.
615 // Check if the target would be included from the build
616 if !m.ExportedToMake() {
617 return false
618 }
619
620 // Skip if the module is in the predefined path list to skip
621 if image.IsProprietaryPath(ctx.ModuleDir(m), ctx.DeviceConfig()) {
622 return false
623 }
624
625 // Skip if the module should be excluded
626 if image.ExcludeFromSnapshot(m) || image.ExcludeFromDirectedSnapshot(ctx.DeviceConfig(), m.BaseModuleName()) {
627 return false
628 }
629
630 // Skip from other exceptional cases
631 if m.Target().Os.Class != android.Device {
632 return false
633 }
634 if m.Target().NativeBridge == android.NativeBridgeEnabled {
635 return false
636 }
637
638 return true
639}
640
Justin Yun1db97482023-04-11 18:20:07 +0900641func generatePrebuiltSnapshot(s snapshot.SnapshotSingleton, ctx android.SingletonContext, snapshotArchDir string) snapshot.SnapshotPaths {
Kiyoung Kimae11c232021-07-19 11:38:04 +0900642 /*
643 Snapshot zipped artifacts directory structure for etc modules:
644 {SNAPSHOT_ARCH}/
645 arch-{TARGET_ARCH}-{TARGET_ARCH_VARIANT}/
646 etc/
647 (prebuilt etc files)
648 arch-{TARGET_2ND_ARCH}-{TARGET_2ND_ARCH_VARIANT}/
649 etc/
650 (prebuilt etc files)
651 NOTICE_FILES/
652 (notice files)
653 */
654 var snapshotOutputs android.Paths
Justin Yun1db97482023-04-11 18:20:07 +0900655 var snapshotNotices android.Paths
Kiyoung Kimae11c232021-07-19 11:38:04 +0900656 installedNotices := make(map[string]bool)
657
658 ctx.VisitAllModules(func(module android.Module) {
659 m, ok := module.(*PrebuiltEtc)
660 if !ok {
661 return
662 }
663
664 if !isSnapshotAware(ctx, m, s.Image) {
665 return
666 }
667
668 targetArch := "arch-" + m.Target().Arch.ArchType.String()
669
670 snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, "etc", m.BaseModuleName())
671 snapshotOutputs = append(snapshotOutputs, copyFile(ctx, m.OutputFile(), snapshotLibOut, s.Fake))
672
Rob Seymour925aa092021-08-10 20:42:03 +0000673 prop := snapshot.SnapshotJsonFlags{}
Kiyoung Kimae11c232021-07-19 11:38:04 +0900674 propOut := snapshotLibOut + ".json"
Justin Yun1db97482023-04-11 18:20:07 +0900675 prop.InitBaseSnapshotProps(m)
Justin Yun8bd3afe2023-05-12 15:53:06 +0900676 prop.RelativeInstallPath = m.SubDir()
Kiyoung Kimae11c232021-07-19 11:38:04 +0900677
678 if m.properties.Filename != nil {
679 prop.Filename = *m.properties.Filename
680 }
681
682 j, err := json.Marshal(prop)
683 if err != nil {
684 ctx.Errorf("json marshal to %q failed: %#v", propOut, err)
685 return
686 }
687 snapshotOutputs = append(snapshotOutputs, snapshot.WriteStringToFileRule(ctx, string(j), propOut))
688
Justin Yun1db97482023-04-11 18:20:07 +0900689 for _, notice := range m.EffectiveLicenseFiles() {
690 if _, ok := installedNotices[notice.String()]; !ok {
691 installedNotices[notice.String()] = true
692 snapshotNotices = append(snapshotNotices, notice)
Kiyoung Kimae11c232021-07-19 11:38:04 +0900693 }
694 }
695
696 })
697
Justin Yun1db97482023-04-11 18:20:07 +0900698 return snapshot.SnapshotPaths{OutputFiles: snapshotOutputs, NoticeFiles: snapshotNotices}
Kiyoung Kimae11c232021-07-19 11:38:04 +0900699}
Rupert Shuttleworth378fc1b2021-07-28 08:03:16 -0400700
701// For Bazel / bp2build
702
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxc78604e2022-02-28 18:22:59 -0500703type bazelPrebuiltFileAttributes struct {
Alix993872a2022-06-15 17:42:14 +0000704 Src bazel.LabelAttribute
705 Filename bazel.LabelAttribute
706 Dir string
707 Installable bazel.BoolAttribute
708 Filename_from_src bazel.BoolAttribute
Rupert Shuttleworth378fc1b2021-07-28 08:03:16 -0400709}
710
Alix5918d642022-06-27 20:57:44 +0000711// Bp2buildHelper returns a bazelPrebuiltFileAttributes used for the conversion
712// of prebuilt_* modules. bazelPrebuiltFileAttributes has the common attributes
713// used by both prebuilt_etc_xml and other prebuilt_* moodules
714func (module *PrebuiltEtc) Bp2buildHelper(ctx android.TopDownMutatorContext) *bazelPrebuiltFileAttributes {
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxc78604e2022-02-28 18:22:59 -0500715 var src bazel.LabelAttribute
Liz Kammerdff00ea2021-10-04 13:44:34 -0400716 for axis, configToProps := range module.GetArchVariantProperties(ctx, &prebuiltEtcProperties{}) {
717 for config, p := range configToProps {
718 props, ok := p.(*prebuiltEtcProperties)
719 if !ok {
720 continue
721 }
722 if props.Src != nil {
Chris Parsons58852a02021-12-09 18:10:18 -0500723 label := android.BazelLabelForModuleSrcSingle(ctx, *props.Src)
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxc78604e2022-02-28 18:22:59 -0500724 src.SetSelectValue(axis, config, label)
Liz Kammerdff00ea2021-10-04 13:44:34 -0400725 }
726 }
Alixbbfd5382022-06-09 18:52:05 +0000727
Cole Faust912bc882023-03-08 12:29:50 -0800728 for propName, productConfigProps := range android.ProductVariableProperties(ctx, ctx.Module()) {
Alixbbfd5382022-06-09 18:52:05 +0000729 for configProp, propVal := range productConfigProps {
730 if propName == "Src" {
731 props, ok := propVal.(*string)
732 if !ok {
733 ctx.PropertyErrorf(" Expected Property to have type string, but was %s\n", reflect.TypeOf(propVal).String())
734 continue
735 }
736 if props != nil {
737 label := android.BazelLabelForModuleSrcSingle(ctx, *props)
738 src.SetSelectValue(configProp.ConfigurationAxis(), configProp.SelectKey(), label)
739 }
740 }
741 }
742 }
Rupert Shuttleworth378fc1b2021-07-28 08:03:16 -0400743 }
744
745 var filename string
Alix993872a2022-06-15 17:42:14 +0000746 var filenameFromSrc bool
747 moduleProps := module.properties
748
749 if moduleProps.Filename != nil && *moduleProps.Filename != "" {
750 filename = *moduleProps.Filename
751 } else if moduleProps.Filename_from_src != nil && *moduleProps.Filename_from_src {
752 if moduleProps.Src != nil {
753 filename = *moduleProps.Src
754 }
755 filenameFromSrc = true
756 } else {
757 filename = ctx.ModuleName()
Rupert Shuttleworth378fc1b2021-07-28 08:03:16 -0400758 }
759
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxc78604e2022-02-28 18:22:59 -0500760 var dir = module.installDirBase
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxc78604e2022-02-28 18:22:59 -0500761 if subDir := module.subdirProperties.Sub_dir; subDir != nil {
762 dir = dir + "/" + *subDir
Rupert Shuttleworth378fc1b2021-07-28 08:03:16 -0400763 }
764
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxc78604e2022-02-28 18:22:59 -0500765 var installable bazel.BoolAttribute
766 if install := module.properties.Installable; install != nil {
767 installable.Value = install
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 attrs := &bazelPrebuiltFileAttributes{
771 Src: src,
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxc78604e2022-02-28 18:22:59 -0500772 Dir: dir,
773 Installable: installable,
Rupert Shuttleworth378fc1b2021-07-28 08:03:16 -0400774 }
775
Alix993872a2022-06-15 17:42:14 +0000776 if filename != "" {
777 attrs.Filename = bazel.LabelAttribute{Value: &bazel.Label{Label: filename}}
778 } else if filenameFromSrc {
779 attrs.Filename_from_src = bazel.BoolAttribute{Value: moduleProps.Filename_from_src}
780 }
781
Alix5918d642022-06-27 20:57:44 +0000782 return attrs
783
784}
785
786// ConvertWithBp2build performs bp2build conversion of PrebuiltEtc
787// prebuilt_* modules (except prebuilt_etc_xml) are PrebuiltEtc,
788// which we treat as *PrebuiltFile*
789func (module *PrebuiltEtc) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
790 var dir = module.installDirBase
791 // prebuilt_file supports only `etc` or `usr/share`
792 if !(dir == "etc" || dir == "usr/share") {
793 return
794 }
795
796 attrs := module.Bp2buildHelper(ctx)
797
Rupert Shuttleworth378fc1b2021-07-28 08:03:16 -0400798 props := bazel.BazelTargetModuleProperties{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxb81f77e2022-02-28 17:38:34 -0500799 Rule_class: "prebuilt_file",
800 Bzl_load_location: "//build/bazel/rules:prebuilt_file.bzl",
Rupert Shuttleworth378fc1b2021-07-28 08:03:16 -0400801 }
802
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux447f6c92021-08-31 20:30:36 +0000803 ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: module.Name()}, attrs)
Rupert Shuttleworth378fc1b2021-07-28 08:03:16 -0400804}
Spandan Das756d3402023-06-05 22:49:50 +0000805
806var _ android.MixedBuildBuildable = (*PrebuiltEtc)(nil)
807
808func (pe *PrebuiltEtc) IsMixedBuildSupported(ctx android.BaseModuleContext) bool {
809 return true
810}
811
812func (pe *PrebuiltEtc) QueueBazelCall(ctx android.BaseModuleContext) {
813 ctx.Config().BazelContext.QueueBazelRequest(
814 pe.GetBazelLabel(ctx, pe),
815 cquery.GetPrebuiltFileInfo,
816 android.GetConfigKey(ctx),
817 )
818}
819
820func (pe *PrebuiltEtc) ProcessBazelQueryResponse(ctx android.ModuleContext) {
821 bazelCtx := ctx.Config().BazelContext
822 pfi, err := bazelCtx.GetPrebuiltFileInfo(pe.GetBazelLabel(ctx, pe), android.GetConfigKey(ctx))
823 if err != nil {
824 ctx.ModuleErrorf(err.Error())
825 return
826 }
827
828 // Set properties for androidmk
829 pe.installDirPath = android.PathForModuleInstall(ctx, pfi.Dir)
830
831 // Installation rules
832 ip := installProperties{
833 installable: pfi.Installable,
834 filename: pfi.Filename,
835 sourceFilePath: android.PathForSource(ctx, pfi.Src),
836 // symlinks: pe.properties.Symlinks, // TODO: b/207489266 - Fully support all properties in prebuilt_file
837 }
838 pe.addInstallRules(ctx, ip)
839}