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