Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1 | // 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 | |
| 15 | package android |
| 16 | |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 17 | import "strconv" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 18 | |
Jaewoong Jung | c3fcdb4 | 2019-02-13 05:50:33 -0800 | [diff] [blame] | 19 | // TODO(jungw): Now that it handles more than the ones in etc/, consider renaming this file. |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 20 | |
| 21 | func init() { |
| 22 | RegisterModuleType("prebuilt_etc", PrebuiltEtcFactory) |
Jaewoong Jung | 4b44fcd | 2019-02-07 08:28:03 -0800 | [diff] [blame] | 23 | RegisterModuleType("prebuilt_etc_host", PrebuiltEtcHostFactory) |
Jaewoong Jung | c3fcdb4 | 2019-02-13 05:50:33 -0800 | [diff] [blame] | 24 | RegisterModuleType("prebuilt_usr_share", PrebuiltUserShareFactory) |
Patrice Arruda | 300cef9 | 2019-02-22 15:47:57 -0800 | [diff] [blame] | 25 | RegisterModuleType("prebuilt_usr_share_host", PrebuiltUserShareHostFactory) |
Patrice Arruda | 61583eb | 2019-05-14 08:20:45 -0700 | [diff] [blame] | 26 | RegisterModuleType("prebuilt_font", PrebuiltFontFactory) |
Patrice Arruda | 057a8b1 | 2019-06-03 15:29:27 -0700 | [diff] [blame] | 27 | RegisterModuleType("prebuilt_firmware", PrebuiltFirmwareFactory) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | type prebuiltEtcProperties struct { |
| 31 | // Source file of this prebuilt. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 32 | Src *string `android:"path,arch_variant"` |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 33 | |
| 34 | // optional subdirectory under which this file is installed into |
| 35 | Sub_dir *string `android:"arch_variant"` |
Tao Bao | 0ba5c94 | 2018-08-14 22:20:22 -0700 | [diff] [blame] | 36 | |
Jiyong Park | 139a2e6 | 2018-10-26 21:49:39 +0900 | [diff] [blame] | 37 | // optional name for the installed file. If unspecified, name of the module is used as the file name |
| 38 | Filename *string `android:"arch_variant"` |
| 39 | |
Jiyong Park | 1a7cf08 | 2018-11-13 11:59:12 +0900 | [diff] [blame] | 40 | // when set to true, and filename property is not set, the name for the installed file |
| 41 | // is the same as the file name of the source file. |
| 42 | Filename_from_src *bool `android:"arch_variant"` |
| 43 | |
Tao Bao | 0ba5c94 | 2018-08-14 22:20:22 -0700 | [diff] [blame] | 44 | // Make this module available when building for recovery. |
| 45 | Recovery_available *bool |
| 46 | |
Jiyong Park | ad9ce04 | 2018-10-31 22:49:57 +0900 | [diff] [blame] | 47 | // Whether this module is directly installable to one of the partitions. Default: true. |
| 48 | Installable *bool |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 49 | } |
| 50 | |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 51 | type PrebuiltEtcModule interface { |
| 52 | Module |
| 53 | SubDir() string |
| 54 | OutputFile() OutputPath |
| 55 | } |
| 56 | |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 57 | type PrebuiltEtc struct { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 58 | ModuleBase |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 59 | |
| 60 | properties prebuiltEtcProperties |
| 61 | |
Jaewoong Jung | c3fcdb4 | 2019-02-13 05:50:33 -0800 | [diff] [blame] | 62 | sourceFilePath Path |
| 63 | outputFilePath OutputPath |
| 64 | // The base install location, e.g. "etc" for prebuilt_etc, "usr/share" for prebuilt_usr_share. |
Patrice Arruda | 057a8b1 | 2019-06-03 15:29:27 -0700 | [diff] [blame] | 65 | installDirBase string |
| 66 | // The base install location when soc_specific property is set to true, e.g. "firmware" for prebuilt_firmware. |
| 67 | socInstallDirBase string |
Colin Cross | 70dda7e | 2019-10-01 22:05:35 -0700 | [diff] [blame] | 68 | installDirPath InstallPath |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 69 | additionalDependencies *Paths |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 70 | } |
| 71 | |
Tao Bao | 0ba5c94 | 2018-08-14 22:20:22 -0700 | [diff] [blame] | 72 | func (p *PrebuiltEtc) inRecovery() bool { |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame^] | 73 | return p.ModuleBase.InRecovery() || p.ModuleBase.InstallInRecovery() |
Tao Bao | 0ba5c94 | 2018-08-14 22:20:22 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | func (p *PrebuiltEtc) onlyInRecovery() bool { |
| 77 | return p.ModuleBase.InstallInRecovery() |
| 78 | } |
| 79 | |
| 80 | func (p *PrebuiltEtc) InstallInRecovery() bool { |
| 81 | return p.inRecovery() |
| 82 | } |
| 83 | |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame^] | 84 | var _ ImageInterface = (*PrebuiltEtc)(nil) |
| 85 | |
| 86 | func (p *PrebuiltEtc) ImageMutatorBegin(ctx BaseModuleContext) {} |
| 87 | |
| 88 | func (p *PrebuiltEtc) CoreVariantNeeded(ctx BaseModuleContext) bool { |
| 89 | return !p.ModuleBase.InstallInRecovery() |
| 90 | } |
| 91 | |
| 92 | func (p *PrebuiltEtc) RecoveryVariantNeeded(ctx BaseModuleContext) bool { |
| 93 | return Bool(p.properties.Recovery_available) || p.ModuleBase.InstallInRecovery() |
| 94 | } |
| 95 | |
| 96 | func (p *PrebuiltEtc) ExtraImageVariations(ctx BaseModuleContext) []string { |
| 97 | return nil |
| 98 | } |
| 99 | |
| 100 | func (p *PrebuiltEtc) SetImageVariation(ctx BaseModuleContext, variation string, module Module) { |
| 101 | } |
| 102 | |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 103 | func (p *PrebuiltEtc) DepsMutator(ctx BottomUpMutatorContext) { |
| 104 | if p.properties.Src == nil { |
| 105 | ctx.PropertyErrorf("src", "missing prebuilt source file") |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 106 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 107 | } |
| 108 | |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 109 | func (p *PrebuiltEtc) SourceFilePath(ctx ModuleContext) Path { |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 110 | return PathForModuleSrc(ctx, String(p.properties.Src)) |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 111 | } |
| 112 | |
Colin Cross | 70dda7e | 2019-10-01 22:05:35 -0700 | [diff] [blame] | 113 | func (p *PrebuiltEtc) InstallDirPath() InstallPath { |
Jooyung Han | a017182 | 2019-07-22 15:48:36 +0900 | [diff] [blame] | 114 | return p.installDirPath |
| 115 | } |
| 116 | |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 117 | // This allows other derivative modules (e.g. prebuilt_etc_xml) to perform |
| 118 | // additional steps (like validating the src) before the file is installed. |
| 119 | func (p *PrebuiltEtc) SetAdditionalDependencies(paths Paths) { |
| 120 | p.additionalDependencies = &paths |
| 121 | } |
| 122 | |
Jiyong Park | c43e0ac | 2018-10-04 20:27:15 +0900 | [diff] [blame] | 123 | func (p *PrebuiltEtc) OutputFile() OutputPath { |
| 124 | return p.outputFilePath |
| 125 | } |
| 126 | |
| 127 | func (p *PrebuiltEtc) SubDir() string { |
| 128 | return String(p.properties.Sub_dir) |
| 129 | } |
| 130 | |
Jiyong Park | ad9ce04 | 2018-10-31 22:49:57 +0900 | [diff] [blame] | 131 | func (p *PrebuiltEtc) Installable() bool { |
| 132 | return p.properties.Installable == nil || Bool(p.properties.Installable) |
| 133 | } |
| 134 | |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 135 | func (p *PrebuiltEtc) GenerateAndroidBuildActions(ctx ModuleContext) { |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 136 | p.sourceFilePath = PathForModuleSrc(ctx, String(p.properties.Src)) |
Jiyong Park | 139a2e6 | 2018-10-26 21:49:39 +0900 | [diff] [blame] | 137 | filename := String(p.properties.Filename) |
Jiyong Park | 1a7cf08 | 2018-11-13 11:59:12 +0900 | [diff] [blame] | 138 | filename_from_src := Bool(p.properties.Filename_from_src) |
Jiyong Park | 139a2e6 | 2018-10-26 21:49:39 +0900 | [diff] [blame] | 139 | if filename == "" { |
Jiyong Park | 1a7cf08 | 2018-11-13 11:59:12 +0900 | [diff] [blame] | 140 | if filename_from_src { |
| 141 | filename = p.sourceFilePath.Base() |
| 142 | } else { |
| 143 | filename = ctx.ModuleName() |
| 144 | } |
| 145 | } else if filename_from_src { |
| 146 | ctx.PropertyErrorf("filename_from_src", "filename is set. filename_from_src can't be true") |
| 147 | return |
Jiyong Park | 139a2e6 | 2018-10-26 21:49:39 +0900 | [diff] [blame] | 148 | } |
| 149 | p.outputFilePath = PathForModuleOut(ctx, filename).OutputPath |
Patrice Arruda | 057a8b1 | 2019-06-03 15:29:27 -0700 | [diff] [blame] | 150 | |
| 151 | // If soc install dir was specified and SOC specific is set, set the installDirPath to the specified |
| 152 | // socInstallDirBase. |
| 153 | installBaseDir := p.installDirBase |
| 154 | if ctx.SocSpecific() && p.socInstallDirBase != "" { |
| 155 | installBaseDir = p.socInstallDirBase |
| 156 | } |
| 157 | p.installDirPath = PathForModuleInstall(ctx, installBaseDir, String(p.properties.Sub_dir)) |
Jiyong Park | c43e0ac | 2018-10-04 20:27:15 +0900 | [diff] [blame] | 158 | |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 159 | // This ensures that outputFilePath has the correct name for others to |
| 160 | // use, as the source file may have a different name. |
Jiyong Park | c43e0ac | 2018-10-04 20:27:15 +0900 | [diff] [blame] | 161 | ctx.Build(pctx, BuildParams{ |
| 162 | Rule: Cp, |
| 163 | Output: p.outputFilePath, |
| 164 | Input: p.sourceFilePath, |
| 165 | }) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 166 | } |
| 167 | |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 168 | func (p *PrebuiltEtc) AndroidMkEntries() AndroidMkEntries { |
| 169 | nameSuffix := "" |
| 170 | if p.inRecovery() && !p.onlyInRecovery() { |
| 171 | nameSuffix = ".recovery" |
| 172 | } |
| 173 | return AndroidMkEntries{ |
| 174 | Class: "ETC", |
| 175 | SubName: nameSuffix, |
| 176 | OutputFile: OptionalPathForPath(p.outputFilePath), |
Jaewoong Jung | e0dc8df | 2019-08-27 17:33:16 -0700 | [diff] [blame] | 177 | ExtraEntries: []AndroidMkExtraEntriesFunc{ |
| 178 | func(entries *AndroidMkEntries) { |
| 179 | entries.SetString("LOCAL_MODULE_TAGS", "optional") |
Colin Cross | ff6c33d | 2019-10-02 16:01:35 -0700 | [diff] [blame] | 180 | entries.SetString("LOCAL_MODULE_PATH", p.installDirPath.ToMakePath().String()) |
Jaewoong Jung | e0dc8df | 2019-08-27 17:33:16 -0700 | [diff] [blame] | 181 | entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePath.Base()) |
| 182 | entries.SetString("LOCAL_UNINSTALLABLE_MODULE", strconv.FormatBool(!p.Installable())) |
| 183 | if p.additionalDependencies != nil { |
| 184 | for _, path := range *p.additionalDependencies { |
| 185 | entries.SetString("LOCAL_ADDITIONAL_DEPENDENCIES", path.String()) |
| 186 | } |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 187 | } |
Jaewoong Jung | e0dc8df | 2019-08-27 17:33:16 -0700 | [diff] [blame] | 188 | }, |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 189 | }, |
| 190 | } |
| 191 | } |
| 192 | |
Jooyung Han | a017182 | 2019-07-22 15:48:36 +0900 | [diff] [blame] | 193 | func InitPrebuiltEtcModule(p *PrebuiltEtc, dirBase string) { |
| 194 | p.installDirBase = dirBase |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 195 | p.AddProperties(&p.properties) |
| 196 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 197 | |
Patrice Arruda | 9e14b96 | 2019-03-11 15:58:50 -0700 | [diff] [blame] | 198 | // prebuilt_etc is for a prebuilt artifact that is installed in |
| 199 | // <partition>/etc/<sub_dir> directory. |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 200 | func PrebuiltEtcFactory() Module { |
Jooyung Han | a017182 | 2019-07-22 15:48:36 +0900 | [diff] [blame] | 201 | module := &PrebuiltEtc{} |
| 202 | InitPrebuiltEtcModule(module, "etc") |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 203 | // This module is device-only |
Jaewoong Jung | b9a1151 | 2019-01-15 10:47:05 -0800 | [diff] [blame] | 204 | InitAndroidArchModule(module, DeviceSupported, MultilibFirst) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 205 | return module |
| 206 | } |
Tao Bao | 0ba5c94 | 2018-08-14 22:20:22 -0700 | [diff] [blame] | 207 | |
Patrice Arruda | 9e14b96 | 2019-03-11 15:58:50 -0700 | [diff] [blame] | 208 | // prebuilt_etc_host is for a host prebuilt artifact that is installed in |
| 209 | // $(HOST_OUT)/etc/<sub_dir> directory. |
Jaewoong Jung | 4b44fcd | 2019-02-07 08:28:03 -0800 | [diff] [blame] | 210 | func PrebuiltEtcHostFactory() Module { |
Jooyung Han | a017182 | 2019-07-22 15:48:36 +0900 | [diff] [blame] | 211 | module := &PrebuiltEtc{} |
| 212 | InitPrebuiltEtcModule(module, "etc") |
Jaewoong Jung | 2478818 | 2019-02-04 14:34:10 -0800 | [diff] [blame] | 213 | // This module is host-only |
| 214 | InitAndroidArchModule(module, HostSupported, MultilibCommon) |
| 215 | return module |
| 216 | } |
| 217 | |
Patrice Arruda | 9e14b96 | 2019-03-11 15:58:50 -0700 | [diff] [blame] | 218 | // prebuilt_usr_share is for a prebuilt artifact that is installed in |
| 219 | // <partition>/usr/share/<sub_dir> directory. |
Jaewoong Jung | c3fcdb4 | 2019-02-13 05:50:33 -0800 | [diff] [blame] | 220 | func PrebuiltUserShareFactory() Module { |
Jooyung Han | a017182 | 2019-07-22 15:48:36 +0900 | [diff] [blame] | 221 | module := &PrebuiltEtc{} |
| 222 | InitPrebuiltEtcModule(module, "usr/share") |
Jaewoong Jung | c3fcdb4 | 2019-02-13 05:50:33 -0800 | [diff] [blame] | 223 | // This module is device-only |
| 224 | InitAndroidArchModule(module, DeviceSupported, MultilibFirst) |
| 225 | return module |
| 226 | } |
| 227 | |
Patrice Arruda | 9e14b96 | 2019-03-11 15:58:50 -0700 | [diff] [blame] | 228 | // prebuild_usr_share_host is for a host prebuilt artifact that is installed in |
| 229 | // $(HOST_OUT)/usr/share/<sub_dir> directory. |
Patrice Arruda | 300cef9 | 2019-02-22 15:47:57 -0800 | [diff] [blame] | 230 | func PrebuiltUserShareHostFactory() Module { |
Jooyung Han | a017182 | 2019-07-22 15:48:36 +0900 | [diff] [blame] | 231 | module := &PrebuiltEtc{} |
| 232 | InitPrebuiltEtcModule(module, "usr/share") |
Patrice Arruda | 300cef9 | 2019-02-22 15:47:57 -0800 | [diff] [blame] | 233 | // This module is host-only |
| 234 | InitAndroidArchModule(module, HostSupported, MultilibCommon) |
| 235 | return module |
| 236 | } |
| 237 | |
Patrice Arruda | 61583eb | 2019-05-14 08:20:45 -0700 | [diff] [blame] | 238 | // prebuilt_font installs a font in <partition>/fonts directory. |
| 239 | func PrebuiltFontFactory() Module { |
Jooyung Han | a017182 | 2019-07-22 15:48:36 +0900 | [diff] [blame] | 240 | module := &PrebuiltEtc{} |
| 241 | InitPrebuiltEtcModule(module, "fonts") |
Patrice Arruda | 61583eb | 2019-05-14 08:20:45 -0700 | [diff] [blame] | 242 | // This module is device-only |
| 243 | InitAndroidArchModule(module, DeviceSupported, MultilibFirst) |
| 244 | return module |
| 245 | } |
Patrice Arruda | 057a8b1 | 2019-06-03 15:29:27 -0700 | [diff] [blame] | 246 | |
| 247 | // prebuilt_firmware installs a firmware file to <partition>/etc/firmware directory for system image. |
| 248 | // If soc_specific property is set to true, the firmware file is installed to the vendor <partition>/firmware |
| 249 | // directory for vendor image. |
| 250 | func PrebuiltFirmwareFactory() Module { |
Jooyung Han | a017182 | 2019-07-22 15:48:36 +0900 | [diff] [blame] | 251 | module := &PrebuiltEtc{} |
| 252 | module.socInstallDirBase = "firmware" |
| 253 | InitPrebuiltEtcModule(module, "etc/firmware") |
Patrice Arruda | 057a8b1 | 2019-06-03 15:29:27 -0700 | [diff] [blame] | 254 | // This module is device-only |
| 255 | InitAndroidArchModule(module, DeviceSupported, MultilibFirst) |
| 256 | return module |
| 257 | } |