blob: df6d79d76e36b810a110161bf748af706b6f1ba8 [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
Jaewoong Jung4b79e982020-06-01 10:45:49 -070017import (
18 "strconv"
19
20 "github.com/google/blueprint/proptools"
21
22 "android/soong/android"
23)
24
25var pctx = android.NewPackageContext("android/soong/etc")
Jiyong Parkc678ad32018-04-10 13:07:10 +090026
Jaewoong Jungc3fcdb42019-02-13 05:50:33 -080027// TODO(jungw): Now that it handles more than the ones in etc/, consider renaming this file.
Jiyong Parkc678ad32018-04-10 13:07:10 +090028
29func init() {
Jaewoong Jung4b79e982020-06-01 10:45:49 -070030 pctx.Import("android/soong/android")
31
32 android.RegisterModuleType("prebuilt_etc", PrebuiltEtcFactory)
33 android.RegisterModuleType("prebuilt_etc_host", PrebuiltEtcHostFactory)
34 android.RegisterModuleType("prebuilt_usr_share", PrebuiltUserShareFactory)
35 android.RegisterModuleType("prebuilt_usr_share_host", PrebuiltUserShareHostFactory)
36 android.RegisterModuleType("prebuilt_font", PrebuiltFontFactory)
37 android.RegisterModuleType("prebuilt_firmware", PrebuiltFirmwareFactory)
Patrice Arruda0f688002020-06-08 21:40:25 +000038 android.RegisterModuleType("prebuilt_dsp", PrebuiltDSPFactory)
Jiyong Parkc678ad32018-04-10 13:07:10 +090039}
40
41type prebuiltEtcProperties struct {
42 // Source file of this prebuilt.
Colin Cross27b922f2019-03-04 22:35:41 -080043 Src *string `android:"path,arch_variant"`
Jiyong Parkc678ad32018-04-10 13:07:10 +090044
45 // optional subdirectory under which this file is installed into
46 Sub_dir *string `android:"arch_variant"`
Tao Bao0ba5c942018-08-14 22:20:22 -070047
Jiyong Park139a2e62018-10-26 21:49:39 +090048 // optional name for the installed file. If unspecified, name of the module is used as the file name
49 Filename *string `android:"arch_variant"`
50
Jiyong Park1a7cf082018-11-13 11:59:12 +090051 // when set to true, and filename property is not set, the name for the installed file
52 // is the same as the file name of the source file.
53 Filename_from_src *bool `android:"arch_variant"`
54
Yifan Hong1b3348d2020-01-21 15:53:22 -080055 // Make this module available when building for ramdisk.
56 Ramdisk_available *bool
57
Tao Bao0ba5c942018-08-14 22:20:22 -070058 // Make this module available when building for recovery.
59 Recovery_available *bool
60
Jiyong Parkad9ce042018-10-31 22:49:57 +090061 // Whether this module is directly installable to one of the partitions. Default: true.
62 Installable *bool
Yo Chiang3d64d492020-05-27 17:56:39 +080063
64 // Install symlinks to the installed file.
65 Symlinks []string `android:"arch_variant"`
Jiyong Parkc678ad32018-04-10 13:07:10 +090066}
67
Jooyung Han39edb6c2019-11-06 16:53:07 +090068type PrebuiltEtcModule interface {
Jaewoong Jung4b79e982020-06-01 10:45:49 -070069 android.Module
Jooyung Han39edb6c2019-11-06 16:53:07 +090070 SubDir() string
Jaewoong Jung4b79e982020-06-01 10:45:49 -070071 OutputFile() android.OutputPath
Jooyung Han39edb6c2019-11-06 16:53:07 +090072}
73
Jiyong Park5a8d1be2018-04-25 22:57:34 +090074type PrebuiltEtc struct {
Jaewoong Jung4b79e982020-06-01 10:45:49 -070075 android.ModuleBase
Jiyong Parkc678ad32018-04-10 13:07:10 +090076
77 properties prebuiltEtcProperties
78
Jaewoong Jung4b79e982020-06-01 10:45:49 -070079 sourceFilePath android.Path
80 outputFilePath android.OutputPath
Jaewoong Jungc3fcdb42019-02-13 05:50:33 -080081 // The base install location, e.g. "etc" for prebuilt_etc, "usr/share" for prebuilt_usr_share.
Patrice Arruda057a8b12019-06-03 15:29:27 -070082 installDirBase string
83 // The base install location when soc_specific property is set to true, e.g. "firmware" for prebuilt_firmware.
84 socInstallDirBase string
Jaewoong Jung4b79e982020-06-01 10:45:49 -070085 installDirPath android.InstallPath
86 additionalDependencies *android.Paths
Jiyong Parkc678ad32018-04-10 13:07:10 +090087}
88
Yifan Hong1b3348d2020-01-21 15:53:22 -080089func (p *PrebuiltEtc) inRamdisk() bool {
90 return p.ModuleBase.InRamdisk() || p.ModuleBase.InstallInRamdisk()
91}
92
93func (p *PrebuiltEtc) onlyInRamdisk() bool {
94 return p.ModuleBase.InstallInRamdisk()
95}
96
97func (p *PrebuiltEtc) InstallInRamdisk() bool {
98 return p.inRamdisk()
99}
100
Tao Bao0ba5c942018-08-14 22:20:22 -0700101func (p *PrebuiltEtc) inRecovery() bool {
Colin Cross7228ecd2019-11-18 16:00:16 -0800102 return p.ModuleBase.InRecovery() || p.ModuleBase.InstallInRecovery()
Tao Bao0ba5c942018-08-14 22:20:22 -0700103}
104
105func (p *PrebuiltEtc) onlyInRecovery() bool {
106 return p.ModuleBase.InstallInRecovery()
107}
108
109func (p *PrebuiltEtc) InstallInRecovery() bool {
110 return p.inRecovery()
111}
112
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700113var _ android.ImageInterface = (*PrebuiltEtc)(nil)
Colin Cross7228ecd2019-11-18 16:00:16 -0800114
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700115func (p *PrebuiltEtc) ImageMutatorBegin(ctx android.BaseModuleContext) {}
Colin Cross7228ecd2019-11-18 16:00:16 -0800116
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700117func (p *PrebuiltEtc) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
Yifan Hong1b3348d2020-01-21 15:53:22 -0800118 return !p.ModuleBase.InstallInRecovery() && !p.ModuleBase.InstallInRamdisk()
119}
120
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700121func (p *PrebuiltEtc) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
122 return proptools.Bool(p.properties.Ramdisk_available) || p.ModuleBase.InstallInRamdisk()
Colin Cross7228ecd2019-11-18 16:00:16 -0800123}
124
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700125func (p *PrebuiltEtc) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
126 return proptools.Bool(p.properties.Recovery_available) || p.ModuleBase.InstallInRecovery()
Colin Cross7228ecd2019-11-18 16:00:16 -0800127}
128
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700129func (p *PrebuiltEtc) ExtraImageVariations(ctx android.BaseModuleContext) []string {
Colin Cross7228ecd2019-11-18 16:00:16 -0800130 return nil
131}
132
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700133func (p *PrebuiltEtc) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) {
Colin Cross7228ecd2019-11-18 16:00:16 -0800134}
135
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700136func (p *PrebuiltEtc) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900137 if p.properties.Src == nil {
138 ctx.PropertyErrorf("src", "missing prebuilt source file")
Jiyong Parkc678ad32018-04-10 13:07:10 +0900139 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900140}
141
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700142func (p *PrebuiltEtc) SourceFilePath(ctx android.ModuleContext) android.Path {
143 return android.PathForModuleSrc(ctx, android.String(p.properties.Src))
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900144}
145
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700146func (p *PrebuiltEtc) InstallDirPath() android.InstallPath {
Jooyung Hana0171822019-07-22 15:48:36 +0900147 return p.installDirPath
148}
149
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900150// This allows other derivative modules (e.g. prebuilt_etc_xml) to perform
151// additional steps (like validating the src) before the file is installed.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700152func (p *PrebuiltEtc) SetAdditionalDependencies(paths android.Paths) {
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900153 p.additionalDependencies = &paths
154}
155
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700156func (p *PrebuiltEtc) OutputFile() android.OutputPath {
Jiyong Parkc43e0ac2018-10-04 20:27:15 +0900157 return p.outputFilePath
158}
159
160func (p *PrebuiltEtc) SubDir() string {
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700161 return android.String(p.properties.Sub_dir)
Jiyong Parkc43e0ac2018-10-04 20:27:15 +0900162}
163
Jiyong Parkad9ce042018-10-31 22:49:57 +0900164func (p *PrebuiltEtc) Installable() bool {
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700165 return p.properties.Installable == nil || android.Bool(p.properties.Installable)
Jiyong Parkad9ce042018-10-31 22:49:57 +0900166}
167
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700168func (p *PrebuiltEtc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
169 p.sourceFilePath = android.PathForModuleSrc(ctx, android.String(p.properties.Src))
170 filename := android.String(p.properties.Filename)
171 filename_from_src := android.Bool(p.properties.Filename_from_src)
Jiyong Park139a2e62018-10-26 21:49:39 +0900172 if filename == "" {
Jiyong Park1a7cf082018-11-13 11:59:12 +0900173 if filename_from_src {
174 filename = p.sourceFilePath.Base()
175 } else {
176 filename = ctx.ModuleName()
177 }
178 } else if filename_from_src {
179 ctx.PropertyErrorf("filename_from_src", "filename is set. filename_from_src can't be true")
180 return
Jiyong Park139a2e62018-10-26 21:49:39 +0900181 }
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700182 p.outputFilePath = android.PathForModuleOut(ctx, filename).OutputPath
Patrice Arruda057a8b12019-06-03 15:29:27 -0700183
184 // If soc install dir was specified and SOC specific is set, set the installDirPath to the specified
185 // socInstallDirBase.
186 installBaseDir := p.installDirBase
187 if ctx.SocSpecific() && p.socInstallDirBase != "" {
188 installBaseDir = p.socInstallDirBase
189 }
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700190 p.installDirPath = android.PathForModuleInstall(ctx, installBaseDir, proptools.String(p.properties.Sub_dir))
Jiyong Parkc43e0ac2018-10-04 20:27:15 +0900191
Dan Willemsenb0552672019-01-25 16:04:11 -0800192 // This ensures that outputFilePath has the correct name for others to
193 // use, as the source file may have a different name.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700194 ctx.Build(pctx, android.BuildParams{
195 Rule: android.Cp,
Jiyong Parkc43e0ac2018-10-04 20:27:15 +0900196 Output: p.outputFilePath,
197 Input: p.sourceFilePath,
198 })
Jiyong Parkc678ad32018-04-10 13:07:10 +0900199}
200
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700201func (p *PrebuiltEtc) AndroidMkEntries() []android.AndroidMkEntries {
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700202 nameSuffix := ""
Yifan Hong1b3348d2020-01-21 15:53:22 -0800203 if p.inRamdisk() && !p.onlyInRamdisk() {
204 nameSuffix = ".ramdisk"
205 }
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700206 if p.inRecovery() && !p.onlyInRecovery() {
207 nameSuffix = ".recovery"
208 }
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700209 return []android.AndroidMkEntries{android.AndroidMkEntries{
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700210 Class: "ETC",
211 SubName: nameSuffix,
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700212 OutputFile: android.OptionalPathForPath(p.outputFilePath),
213 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
214 func(entries *android.AndroidMkEntries) {
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700215 entries.SetString("LOCAL_MODULE_TAGS", "optional")
Colin Crossff6c33d2019-10-02 16:01:35 -0700216 entries.SetString("LOCAL_MODULE_PATH", p.installDirPath.ToMakePath().String())
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700217 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePath.Base())
Yo Chiang3d64d492020-05-27 17:56:39 +0800218 if len(p.properties.Symlinks) > 0 {
219 entries.AddStrings("LOCAL_MODULE_SYMLINKS", p.properties.Symlinks...)
220 }
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700221 entries.SetString("LOCAL_UNINSTALLABLE_MODULE", strconv.FormatBool(!p.Installable()))
222 if p.additionalDependencies != nil {
223 for _, path := range *p.additionalDependencies {
Yo Chiang3d64d492020-05-27 17:56:39 +0800224 entries.AddStrings("LOCAL_ADDITIONAL_DEPENDENCIES", path.String())
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700225 }
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900226 }
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700227 },
Jiyong Parkc678ad32018-04-10 13:07:10 +0900228 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900229 }}
Jiyong Parkc678ad32018-04-10 13:07:10 +0900230}
231
Jooyung Hana0171822019-07-22 15:48:36 +0900232func InitPrebuiltEtcModule(p *PrebuiltEtc, dirBase string) {
233 p.installDirBase = dirBase
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900234 p.AddProperties(&p.properties)
235}
Jiyong Parkc678ad32018-04-10 13:07:10 +0900236
Patrice Arruda9e14b962019-03-11 15:58:50 -0700237// prebuilt_etc is for a prebuilt artifact that is installed in
238// <partition>/etc/<sub_dir> directory.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700239func PrebuiltEtcFactory() android.Module {
Jooyung Hana0171822019-07-22 15:48:36 +0900240 module := &PrebuiltEtc{}
241 InitPrebuiltEtcModule(module, "etc")
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900242 // This module is device-only
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700243 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900244 return module
245}
Tao Bao0ba5c942018-08-14 22:20:22 -0700246
Patrice Arruda9e14b962019-03-11 15:58:50 -0700247// prebuilt_etc_host is for a host prebuilt artifact that is installed in
248// $(HOST_OUT)/etc/<sub_dir> directory.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700249func PrebuiltEtcHostFactory() android.Module {
Jooyung Hana0171822019-07-22 15:48:36 +0900250 module := &PrebuiltEtc{}
251 InitPrebuiltEtcModule(module, "etc")
Jaewoong Jung24788182019-02-04 14:34:10 -0800252 // This module is host-only
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700253 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
Jaewoong Jung24788182019-02-04 14:34:10 -0800254 return module
255}
256
Patrice Arruda9e14b962019-03-11 15:58:50 -0700257// prebuilt_usr_share is for a prebuilt artifact that is installed in
258// <partition>/usr/share/<sub_dir> directory.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700259func PrebuiltUserShareFactory() android.Module {
Jooyung Hana0171822019-07-22 15:48:36 +0900260 module := &PrebuiltEtc{}
261 InitPrebuiltEtcModule(module, "usr/share")
Jaewoong Jungc3fcdb42019-02-13 05:50:33 -0800262 // This module is device-only
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700263 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Jaewoong Jungc3fcdb42019-02-13 05:50:33 -0800264 return module
265}
266
Patrice Arruda9e14b962019-03-11 15:58:50 -0700267// prebuild_usr_share_host is for a host prebuilt artifact that is installed in
268// $(HOST_OUT)/usr/share/<sub_dir> directory.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700269func PrebuiltUserShareHostFactory() android.Module {
Jooyung Hana0171822019-07-22 15:48:36 +0900270 module := &PrebuiltEtc{}
271 InitPrebuiltEtcModule(module, "usr/share")
Patrice Arruda300cef92019-02-22 15:47:57 -0800272 // This module is host-only
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700273 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
Patrice Arruda300cef92019-02-22 15:47:57 -0800274 return module
275}
276
Patrice Arruda61583eb2019-05-14 08:20:45 -0700277// prebuilt_font installs a font in <partition>/fonts directory.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700278func PrebuiltFontFactory() android.Module {
Jooyung Hana0171822019-07-22 15:48:36 +0900279 module := &PrebuiltEtc{}
280 InitPrebuiltEtcModule(module, "fonts")
Patrice Arruda61583eb2019-05-14 08:20:45 -0700281 // This module is device-only
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700282 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Patrice Arruda61583eb2019-05-14 08:20:45 -0700283 return module
284}
Patrice Arruda057a8b12019-06-03 15:29:27 -0700285
286// prebuilt_firmware installs a firmware file to <partition>/etc/firmware directory for system image.
287// If soc_specific property is set to true, the firmware file is installed to the vendor <partition>/firmware
288// directory for vendor image.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700289func PrebuiltFirmwareFactory() android.Module {
Jooyung Hana0171822019-07-22 15:48:36 +0900290 module := &PrebuiltEtc{}
291 module.socInstallDirBase = "firmware"
292 InitPrebuiltEtcModule(module, "etc/firmware")
Patrice Arruda057a8b12019-06-03 15:29:27 -0700293 // This module is device-only
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700294 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
Patrice Arruda057a8b12019-06-03 15:29:27 -0700295 return module
296}
Patrice Arruda0f688002020-06-08 21:40:25 +0000297
298// prebuilt_dsp installs a DSP related file to <partition>/etc/dsp directory for system image.
299// If soc_specific property is set to true, the DSP related file is installed to the vendor <partition>/dsp
300// directory for vendor image.
301func PrebuiltDSPFactory() android.Module {
302 module := &PrebuiltEtc{}
303 module.socInstallDirBase = "dsp"
304 InitPrebuiltEtcModule(module, "etc/dsp")
305 // This module is device-only
306 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
307 return module
308}