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 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 15 | package etc |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 16 | |
Yo Chiang | 803c40d | 2020-11-16 20:32:51 +0800 | [diff] [blame] | 17 | // 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 Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 29 | |
Yo Chiang | 803c40d | 2020-11-16 20:32:51 +0800 | [diff] [blame] | 30 | import ( |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 31 | "encoding/json" |
Jiyong Park | 76a42f5 | 2021-02-16 06:50:37 +0900 | [diff] [blame] | 32 | "fmt" |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 33 | "path/filepath" |
Inseob Kim | 27408bf | 2021-04-06 21:00:17 +0900 | [diff] [blame] | 34 | "strings" |
Jiyong Park | 76a42f5 | 2021-02-16 06:50:37 +0900 | [diff] [blame] | 35 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 36 | "github.com/google/blueprint/proptools" |
| 37 | |
| 38 | "android/soong/android" |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 39 | "android/soong/snapshot" |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 40 | ) |
| 41 | |
| 42 | var pctx = android.NewPackageContext("android/soong/etc") |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 43 | |
Jaewoong Jung | c3fcdb4 | 2019-02-13 05:50:33 -0800 | [diff] [blame] | 44 | // 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] | 45 | |
| 46 | func init() { |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 47 | pctx.Import("android/soong/android") |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 48 | RegisterPrebuiltEtcBuildComponents(android.InitRegistrationContext) |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 49 | snapshot.RegisterSnapshotAction(generatePrebuiltSnapshot) |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 50 | } |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 51 | |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 52 | func RegisterPrebuiltEtcBuildComponents(ctx android.RegistrationContext) { |
| 53 | ctx.RegisterModuleType("prebuilt_etc", PrebuiltEtcFactory) |
| 54 | ctx.RegisterModuleType("prebuilt_etc_host", PrebuiltEtcHostFactory) |
Miguel | 32b0280 | 2022-12-01 18:38:26 +0000 | [diff] [blame] | 55 | ctx.RegisterModuleType("prebuilt_etc_cacerts", PrebuiltEtcCaCertsFactory) |
Inseob Kim | 27408bf | 2021-04-06 21:00:17 +0900 | [diff] [blame] | 56 | ctx.RegisterModuleType("prebuilt_root", PrebuiltRootFactory) |
Liz Kammer | e9ecddc | 2022-01-04 17:27:52 -0500 | [diff] [blame] | 57 | ctx.RegisterModuleType("prebuilt_root_host", PrebuiltRootHostFactory) |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 58 | ctx.RegisterModuleType("prebuilt_usr_share", PrebuiltUserShareFactory) |
| 59 | ctx.RegisterModuleType("prebuilt_usr_share_host", PrebuiltUserShareHostFactory) |
yangbill | 63c5e19 | 2024-03-27 09:02:12 +0000 | [diff] [blame^] | 60 | ctx.RegisterModuleType("prebuilt_usr_hyphendata", PrebuiltUserHyphenDataFactory) |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 61 | ctx.RegisterModuleType("prebuilt_font", PrebuiltFontFactory) |
| 62 | ctx.RegisterModuleType("prebuilt_firmware", PrebuiltFirmwareFactory) |
| 63 | ctx.RegisterModuleType("prebuilt_dsp", PrebuiltDSPFactory) |
Colin Cross | 83ebf23 | 2021-04-09 09:41:23 -0700 | [diff] [blame] | 64 | ctx.RegisterModuleType("prebuilt_rfsa", PrebuiltRFSAFactory) |
Colin Cross | f17e2b5 | 2023-10-30 15:17:25 -0700 | [diff] [blame] | 65 | ctx.RegisterModuleType("prebuilt_renderscript_bitcode", PrebuiltRenderScriptBitcodeFactory) |
Inseob Kim | 1e27a14 | 2021-05-06 11:46:11 +0000 | [diff] [blame] | 66 | |
| 67 | ctx.RegisterModuleType("prebuilt_defaults", defaultsFactory) |
Rupert Shuttleworth | 378fc1b | 2021-07-28 08:03:16 -0400 | [diff] [blame] | 68 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 69 | } |
| 70 | |
Paul Duffin | 1172fed | 2021-03-08 11:28:18 +0000 | [diff] [blame] | 71 | var PrepareForTestWithPrebuiltEtc = android.FixtureRegisterWithContext(RegisterPrebuiltEtcBuildComponents) |
| 72 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 73 | type prebuiltEtcProperties struct { |
Yo Chiang | 803c40d | 2020-11-16 20:32:51 +0800 | [diff] [blame] | 74 | // Source file of this prebuilt. Can reference a genrule type module with the ":module" syntax. |
Thiébaud Weksteen | 00e8b31 | 2024-03-18 14:06:00 +1100 | [diff] [blame] | 75 | // Mutually exclusive with srcs. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 76 | Src *string `android:"path,arch_variant"` |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 77 | |
Thiébaud Weksteen | 00e8b31 | 2024-03-18 14:06:00 +1100 | [diff] [blame] | 78 | // Source files of this prebuilt. Can reference a genrule type module with the ":module" syntax. |
| 79 | // Mutually exclusive with src. When used, filename_from_src is set to true. |
| 80 | Srcs []string `android:"path,arch_variant"` |
| 81 | |
Yo Chiang | f0e19fe | 2020-11-18 15:28:42 +0800 | [diff] [blame] | 82 | // Optional name for the installed file. If unspecified, name of the module is used as the file |
Thiébaud Weksteen | 00e8b31 | 2024-03-18 14:06:00 +1100 | [diff] [blame] | 83 | // name. Only available when using a single source (src). |
Jiyong Park | 139a2e6 | 2018-10-26 21:49:39 +0900 | [diff] [blame] | 84 | Filename *string `android:"arch_variant"` |
| 85 | |
Yo Chiang | f0e19fe | 2020-11-18 15:28:42 +0800 | [diff] [blame] | 86 | // When set to true, and filename property is not set, the name for the installed file |
Jiyong Park | 1a7cf08 | 2018-11-13 11:59:12 +0900 | [diff] [blame] | 87 | // is the same as the file name of the source file. |
| 88 | Filename_from_src *bool `android:"arch_variant"` |
| 89 | |
Yifan Hong | 1b3348d | 2020-01-21 15:53:22 -0800 | [diff] [blame] | 90 | // Make this module available when building for ramdisk. |
Yifan Hong | 39143a9 | 2020-10-26 12:43:12 -0700 | [diff] [blame] | 91 | // On device without a dedicated recovery partition, the module is only |
| 92 | // available after switching root into |
| 93 | // /first_stage_ramdisk. To expose the module before switching root, install |
| 94 | // the recovery variant instead. |
Yifan Hong | 1b3348d | 2020-01-21 15:53:22 -0800 | [diff] [blame] | 95 | Ramdisk_available *bool |
| 96 | |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 97 | // Make this module available when building for vendor ramdisk. |
Yifan Hong | 39143a9 | 2020-10-26 12:43:12 -0700 | [diff] [blame] | 98 | // On device without a dedicated recovery partition, the module is only |
| 99 | // available after switching root into |
| 100 | // /first_stage_ramdisk. To expose the module before switching root, install |
| 101 | // the recovery variant instead. |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 102 | Vendor_ramdisk_available *bool |
| 103 | |
Inseob Kim | 08758f0 | 2021-04-08 21:13:22 +0900 | [diff] [blame] | 104 | // Make this module available when building for debug ramdisk. |
| 105 | Debug_ramdisk_available *bool |
| 106 | |
Tao Bao | 0ba5c94 | 2018-08-14 22:20:22 -0700 | [diff] [blame] | 107 | // Make this module available when building for recovery. |
| 108 | Recovery_available *bool |
| 109 | |
Jiyong Park | ad9ce04 | 2018-10-31 22:49:57 +0900 | [diff] [blame] | 110 | // Whether this module is directly installable to one of the partitions. Default: true. |
| 111 | Installable *bool |
Yo Chiang | 3d64d49 | 2020-05-27 17:56:39 +0800 | [diff] [blame] | 112 | |
| 113 | // Install symlinks to the installed file. |
| 114 | Symlinks []string `android:"arch_variant"` |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 115 | } |
| 116 | |
Inseob Kim | 27408bf | 2021-04-06 21:00:17 +0900 | [diff] [blame] | 117 | type prebuiltSubdirProperties struct { |
| 118 | // Optional subdirectory under which this file is installed into, cannot be specified with |
| 119 | // relative_install_path, prefer relative_install_path. |
| 120 | Sub_dir *string `android:"arch_variant"` |
| 121 | |
| 122 | // Optional subdirectory under which this file is installed into, cannot be specified with |
| 123 | // sub_dir. |
| 124 | Relative_install_path *string `android:"arch_variant"` |
| 125 | } |
| 126 | |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 127 | type PrebuiltEtcModule interface { |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 128 | android.Module |
Yo Chiang | f0e19fe | 2020-11-18 15:28:42 +0800 | [diff] [blame] | 129 | |
| 130 | // Returns the base install directory, such as "etc", "usr/share". |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 131 | BaseDir() string |
Yo Chiang | f0e19fe | 2020-11-18 15:28:42 +0800 | [diff] [blame] | 132 | |
| 133 | // Returns the sub install directory relative to BaseDir(). |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 134 | SubDir() string |
Yo Chiang | f0e19fe | 2020-11-18 15:28:42 +0800 | [diff] [blame] | 135 | |
Thiébaud Weksteen | 00e8b31 | 2024-03-18 14:06:00 +1100 | [diff] [blame] | 136 | // Returns an android.OutputPath to the intermediate file, which is the renamed prebuilt source |
Yo Chiang | f0e19fe | 2020-11-18 15:28:42 +0800 | [diff] [blame] | 137 | // file. |
Thiébaud Weksteen | 00e8b31 | 2024-03-18 14:06:00 +1100 | [diff] [blame] | 138 | OutputFiles(tag string) (android.Paths, error) |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 139 | } |
| 140 | |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 141 | type PrebuiltEtc struct { |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 142 | android.ModuleBase |
Inseob Kim | 1e27a14 | 2021-05-06 11:46:11 +0000 | [diff] [blame] | 143 | android.DefaultableModuleBase |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 144 | |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 145 | snapshot.VendorSnapshotModuleInterface |
| 146 | snapshot.RecoverySnapshotModuleInterface |
| 147 | |
Inseob Kim | 27408bf | 2021-04-06 21:00:17 +0900 | [diff] [blame] | 148 | properties prebuiltEtcProperties |
| 149 | subdirProperties prebuiltSubdirProperties |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 150 | |
Thiébaud Weksteen | 00e8b31 | 2024-03-18 14:06:00 +1100 | [diff] [blame] | 151 | sourceFilePaths android.Paths |
| 152 | outputFilePaths android.OutputPaths |
Jaewoong Jung | c3fcdb4 | 2019-02-13 05:50:33 -0800 | [diff] [blame] | 153 | // The base install location, e.g. "etc" for prebuilt_etc, "usr/share" for prebuilt_usr_share. |
Colin Cross | 2f63457 | 2023-11-13 12:12:06 -0800 | [diff] [blame] | 154 | installDirBase string |
| 155 | installDirBase64 string |
| 156 | installAvoidMultilibConflict bool |
Yo Chiang | f0e19fe | 2020-11-18 15:28:42 +0800 | [diff] [blame] | 157 | // The base install location when soc_specific property is set to true, e.g. "firmware" for |
| 158 | // prebuilt_firmware. |
Patrice Arruda | 057a8b1 | 2019-06-03 15:29:27 -0700 | [diff] [blame] | 159 | socInstallDirBase string |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 160 | installDirPath android.InstallPath |
| 161 | additionalDependencies *android.Paths |
Colin Cross | f17e2b5 | 2023-10-30 15:17:25 -0700 | [diff] [blame] | 162 | |
| 163 | makeClass string |
LaMont Jones | afe7baf | 2024-01-09 22:47:39 +0000 | [diff] [blame] | 164 | |
| 165 | // Aconfig files for all transitive deps. Also exposed via TransitiveDeclarationsInfo |
| 166 | mergedAconfigFiles map[string]android.Paths |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 167 | } |
| 168 | |
Inseob Kim | 1e27a14 | 2021-05-06 11:46:11 +0000 | [diff] [blame] | 169 | type Defaults struct { |
| 170 | android.ModuleBase |
| 171 | android.DefaultsModuleBase |
| 172 | } |
| 173 | |
Yifan Hong | 1b3348d | 2020-01-21 15:53:22 -0800 | [diff] [blame] | 174 | func (p *PrebuiltEtc) inRamdisk() bool { |
| 175 | return p.ModuleBase.InRamdisk() || p.ModuleBase.InstallInRamdisk() |
| 176 | } |
| 177 | |
| 178 | func (p *PrebuiltEtc) onlyInRamdisk() bool { |
| 179 | return p.ModuleBase.InstallInRamdisk() |
| 180 | } |
| 181 | |
| 182 | func (p *PrebuiltEtc) InstallInRamdisk() bool { |
| 183 | return p.inRamdisk() |
| 184 | } |
| 185 | |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 186 | func (p *PrebuiltEtc) inVendorRamdisk() bool { |
| 187 | return p.ModuleBase.InVendorRamdisk() || p.ModuleBase.InstallInVendorRamdisk() |
| 188 | } |
| 189 | |
| 190 | func (p *PrebuiltEtc) onlyInVendorRamdisk() bool { |
| 191 | return p.ModuleBase.InstallInVendorRamdisk() |
| 192 | } |
| 193 | |
| 194 | func (p *PrebuiltEtc) InstallInVendorRamdisk() bool { |
| 195 | return p.inVendorRamdisk() |
| 196 | } |
| 197 | |
Inseob Kim | 08758f0 | 2021-04-08 21:13:22 +0900 | [diff] [blame] | 198 | func (p *PrebuiltEtc) inDebugRamdisk() bool { |
| 199 | return p.ModuleBase.InDebugRamdisk() || p.ModuleBase.InstallInDebugRamdisk() |
| 200 | } |
| 201 | |
| 202 | func (p *PrebuiltEtc) onlyInDebugRamdisk() bool { |
| 203 | return p.ModuleBase.InstallInDebugRamdisk() |
| 204 | } |
| 205 | |
| 206 | func (p *PrebuiltEtc) InstallInDebugRamdisk() bool { |
| 207 | return p.inDebugRamdisk() |
| 208 | } |
| 209 | |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 210 | func (p *PrebuiltEtc) InRecovery() bool { |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 211 | return p.ModuleBase.InRecovery() || p.ModuleBase.InstallInRecovery() |
Tao Bao | 0ba5c94 | 2018-08-14 22:20:22 -0700 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | func (p *PrebuiltEtc) onlyInRecovery() bool { |
| 215 | return p.ModuleBase.InstallInRecovery() |
| 216 | } |
| 217 | |
| 218 | func (p *PrebuiltEtc) InstallInRecovery() bool { |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 219 | return p.InRecovery() |
Tao Bao | 0ba5c94 | 2018-08-14 22:20:22 -0700 | [diff] [blame] | 220 | } |
| 221 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 222 | var _ android.ImageInterface = (*PrebuiltEtc)(nil) |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 223 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 224 | func (p *PrebuiltEtc) ImageMutatorBegin(ctx android.BaseModuleContext) {} |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 225 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 226 | func (p *PrebuiltEtc) CoreVariantNeeded(ctx android.BaseModuleContext) bool { |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 227 | return !p.ModuleBase.InstallInRecovery() && !p.ModuleBase.InstallInRamdisk() && |
Inseob Kim | 08758f0 | 2021-04-08 21:13:22 +0900 | [diff] [blame] | 228 | !p.ModuleBase.InstallInVendorRamdisk() && !p.ModuleBase.InstallInDebugRamdisk() |
Yifan Hong | 1b3348d | 2020-01-21 15:53:22 -0800 | [diff] [blame] | 229 | } |
| 230 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 231 | func (p *PrebuiltEtc) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool { |
| 232 | return proptools.Bool(p.properties.Ramdisk_available) || p.ModuleBase.InstallInRamdisk() |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 233 | } |
| 234 | |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 235 | func (p *PrebuiltEtc) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool { |
| 236 | return proptools.Bool(p.properties.Vendor_ramdisk_available) || p.ModuleBase.InstallInVendorRamdisk() |
| 237 | } |
| 238 | |
Inseob Kim | 08758f0 | 2021-04-08 21:13:22 +0900 | [diff] [blame] | 239 | func (p *PrebuiltEtc) DebugRamdiskVariantNeeded(ctx android.BaseModuleContext) bool { |
| 240 | return proptools.Bool(p.properties.Debug_ramdisk_available) || p.ModuleBase.InstallInDebugRamdisk() |
| 241 | } |
| 242 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 243 | func (p *PrebuiltEtc) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool { |
| 244 | return proptools.Bool(p.properties.Recovery_available) || p.ModuleBase.InstallInRecovery() |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 245 | } |
| 246 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 247 | func (p *PrebuiltEtc) ExtraImageVariations(ctx android.BaseModuleContext) []string { |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 248 | return nil |
| 249 | } |
| 250 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 251 | func (p *PrebuiltEtc) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) { |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 252 | } |
| 253 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 254 | func (p *PrebuiltEtc) SourceFilePath(ctx android.ModuleContext) android.Path { |
Thiébaud Weksteen | 00e8b31 | 2024-03-18 14:06:00 +1100 | [diff] [blame] | 255 | if len(p.properties.Srcs) > 0 { |
| 256 | panic(fmt.Errorf("SourceFilePath not available on multi-source prebuilt %q", p.Name())) |
| 257 | } |
Yo Chiang | f0e19fe | 2020-11-18 15:28:42 +0800 | [diff] [blame] | 258 | return android.PathForModuleSrc(ctx, proptools.String(p.properties.Src)) |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 259 | } |
| 260 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 261 | func (p *PrebuiltEtc) InstallDirPath() android.InstallPath { |
Jooyung Han | a017182 | 2019-07-22 15:48:36 +0900 | [diff] [blame] | 262 | return p.installDirPath |
| 263 | } |
| 264 | |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 265 | // This allows other derivative modules (e.g. prebuilt_etc_xml) to perform |
| 266 | // additional steps (like validating the src) before the file is installed. |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 267 | func (p *PrebuiltEtc) SetAdditionalDependencies(paths android.Paths) { |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 268 | p.additionalDependencies = &paths |
| 269 | } |
| 270 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 271 | func (p *PrebuiltEtc) OutputFile() android.OutputPath { |
Thiébaud Weksteen | 00e8b31 | 2024-03-18 14:06:00 +1100 | [diff] [blame] | 272 | if len(p.properties.Srcs) > 0 { |
| 273 | panic(fmt.Errorf("OutputFile not available on multi-source prebuilt %q", p.Name())) |
| 274 | } |
| 275 | return p.outputFilePaths[0] |
Jiyong Park | c43e0ac | 2018-10-04 20:27:15 +0900 | [diff] [blame] | 276 | } |
| 277 | |
Jiyong Park | 76a42f5 | 2021-02-16 06:50:37 +0900 | [diff] [blame] | 278 | var _ android.OutputFileProducer = (*PrebuiltEtc)(nil) |
| 279 | |
| 280 | func (p *PrebuiltEtc) OutputFiles(tag string) (android.Paths, error) { |
| 281 | switch tag { |
| 282 | case "": |
Thiébaud Weksteen | 00e8b31 | 2024-03-18 14:06:00 +1100 | [diff] [blame] | 283 | return p.outputFilePaths.Paths(), nil |
Jiyong Park | 76a42f5 | 2021-02-16 06:50:37 +0900 | [diff] [blame] | 284 | default: |
| 285 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
| 286 | } |
| 287 | } |
| 288 | |
Jiyong Park | c43e0ac | 2018-10-04 20:27:15 +0900 | [diff] [blame] | 289 | func (p *PrebuiltEtc) SubDir() string { |
Inseob Kim | 27408bf | 2021-04-06 21:00:17 +0900 | [diff] [blame] | 290 | if subDir := proptools.String(p.subdirProperties.Sub_dir); subDir != "" { |
Liz Kammer | 0449a63 | 2020-06-26 10:12:36 -0700 | [diff] [blame] | 291 | return subDir |
| 292 | } |
Inseob Kim | 27408bf | 2021-04-06 21:00:17 +0900 | [diff] [blame] | 293 | return proptools.String(p.subdirProperties.Relative_install_path) |
Jiyong Park | c43e0ac | 2018-10-04 20:27:15 +0900 | [diff] [blame] | 294 | } |
| 295 | |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 296 | func (p *PrebuiltEtc) BaseDir() string { |
Jooyung Han | 8e5685d | 2020-09-21 11:02:57 +0900 | [diff] [blame] | 297 | return p.installDirBase |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 298 | } |
| 299 | |
Jiyong Park | ad9ce04 | 2018-10-31 22:49:57 +0900 | [diff] [blame] | 300 | func (p *PrebuiltEtc) Installable() bool { |
Yo Chiang | f0e19fe | 2020-11-18 15:28:42 +0800 | [diff] [blame] | 301 | return p.properties.Installable == nil || proptools.Bool(p.properties.Installable) |
Jiyong Park | ad9ce04 | 2018-10-31 22:49:57 +0900 | [diff] [blame] | 302 | } |
| 303 | |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 304 | func (p *PrebuiltEtc) InVendor() bool { |
| 305 | return p.ModuleBase.InstallInVendor() |
| 306 | } |
| 307 | |
| 308 | func (p *PrebuiltEtc) ExcludeFromVendorSnapshot() bool { |
| 309 | return false |
| 310 | } |
| 311 | |
| 312 | func (p *PrebuiltEtc) ExcludeFromRecoverySnapshot() bool { |
| 313 | return false |
| 314 | } |
| 315 | |
Thiébaud Weksteen | 00e8b31 | 2024-03-18 14:06:00 +1100 | [diff] [blame] | 316 | func (p *PrebuiltEtc) installBaseDir(ctx android.ModuleContext) string { |
Yo Chiang | f0e19fe | 2020-11-18 15:28:42 +0800 | [diff] [blame] | 317 | // If soc install dir was specified and SOC specific is set, set the installDirPath to the |
| 318 | // specified socInstallDirBase. |
Jooyung Han | 8e5685d | 2020-09-21 11:02:57 +0900 | [diff] [blame] | 319 | installBaseDir := p.installDirBase |
Colin Cross | f17e2b5 | 2023-10-30 15:17:25 -0700 | [diff] [blame] | 320 | if p.Target().Arch.ArchType.Multilib == "lib64" && p.installDirBase64 != "" { |
| 321 | installBaseDir = p.installDirBase64 |
| 322 | } |
Jooyung Han | 8e5685d | 2020-09-21 11:02:57 +0900 | [diff] [blame] | 323 | if p.SocSpecific() && p.socInstallDirBase != "" { |
| 324 | installBaseDir = p.socInstallDirBase |
| 325 | } |
Colin Cross | 2f63457 | 2023-11-13 12:12:06 -0800 | [diff] [blame] | 326 | if p.installAvoidMultilibConflict && !ctx.Host() && ctx.Config().HasMultilibConflict(ctx.Arch().ArchType) { |
| 327 | installBaseDir = filepath.Join(installBaseDir, ctx.Arch().ArchType.String()) |
| 328 | } |
Thiébaud Weksteen | 00e8b31 | 2024-03-18 14:06:00 +1100 | [diff] [blame] | 329 | return installBaseDir |
| 330 | } |
Colin Cross | 2f63457 | 2023-11-13 12:12:06 -0800 | [diff] [blame] | 331 | |
Thiébaud Weksteen | 00e8b31 | 2024-03-18 14:06:00 +1100 | [diff] [blame] | 332 | func (p *PrebuiltEtc) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 333 | var installs []installProperties |
Jiyong Park | c43e0ac | 2018-10-04 20:27:15 +0900 | [diff] [blame] | 334 | |
Thiébaud Weksteen | 00e8b31 | 2024-03-18 14:06:00 +1100 | [diff] [blame] | 335 | if p.properties.Src != nil && len(p.properties.Srcs) > 0 { |
| 336 | ctx.PropertyErrorf("src", "src is set. Cannot set srcs") |
Spandan Das | 756d340 | 2023-06-05 22:49:50 +0000 | [diff] [blame] | 337 | } |
Thiébaud Weksteen | 00e8b31 | 2024-03-18 14:06:00 +1100 | [diff] [blame] | 338 | |
| 339 | // Check that `sub_dir` and `relative_install_path` are not set at the same time. |
| 340 | if p.subdirProperties.Sub_dir != nil && p.subdirProperties.Relative_install_path != nil { |
| 341 | ctx.PropertyErrorf("sub_dir", "relative_install_path is set. Cannot set sub_dir") |
| 342 | } |
| 343 | p.installDirPath = android.PathForModuleInstall(ctx, p.installBaseDir(ctx), p.SubDir()) |
| 344 | |
| 345 | filename := proptools.String(p.properties.Filename) |
| 346 | filenameFromSrc := proptools.Bool(p.properties.Filename_from_src) |
| 347 | if p.properties.Src != nil { |
| 348 | p.sourceFilePaths = android.PathsForModuleSrc(ctx, []string{proptools.String(p.properties.Src)}) |
| 349 | // If the source was not found, set a fake source path to |
| 350 | // support AllowMissingDependencies executions. |
| 351 | if len(p.sourceFilePaths) == 0 { |
| 352 | p.sourceFilePaths = android.Paths{android.PathForModuleSrc(ctx)} |
| 353 | } |
| 354 | |
| 355 | // Determine the output file basename. |
| 356 | // If Filename is set, use the name specified by the property. |
| 357 | // If Filename_from_src is set, use the source file name. |
| 358 | // Otherwise use the module name. |
| 359 | if filename != "" { |
| 360 | if filenameFromSrc { |
| 361 | ctx.PropertyErrorf("filename_from_src", "filename is set. filename_from_src can't be true") |
| 362 | return |
| 363 | } |
| 364 | } else if filenameFromSrc { |
| 365 | filename = p.sourceFilePaths[0].Base() |
| 366 | } else { |
| 367 | filename = ctx.ModuleName() |
| 368 | } |
| 369 | if strings.Contains(filename, "/") { |
| 370 | ctx.PropertyErrorf("filename", "filename cannot contain separator '/'") |
| 371 | return |
| 372 | } |
| 373 | p.outputFilePaths = android.OutputPaths{android.PathForModuleOut(ctx, filename).OutputPath} |
| 374 | |
| 375 | ip := installProperties{ |
| 376 | filename: filename, |
| 377 | sourceFilePath: p.sourceFilePaths[0], |
| 378 | outputFilePath: p.outputFilePaths[0], |
| 379 | installDirPath: p.installDirPath, |
| 380 | symlinks: p.properties.Symlinks, |
| 381 | } |
| 382 | installs = append(installs, ip) |
| 383 | } else if len(p.properties.Srcs) > 0 { |
| 384 | if filename != "" { |
| 385 | ctx.PropertyErrorf("filename", "filename cannot be set when using srcs") |
| 386 | } |
| 387 | if len(p.properties.Symlinks) > 0 { |
| 388 | ctx.PropertyErrorf("symlinks", "symlinks cannot be set when using srcs") |
| 389 | } |
| 390 | if p.properties.Filename_from_src != nil { |
| 391 | ctx.PropertyErrorf("filename_from_src", "filename_from_src is implicitly set to true when using srcs") |
| 392 | } |
| 393 | p.sourceFilePaths = android.PathsForModuleSrc(ctx, p.properties.Srcs) |
| 394 | for _, src := range p.sourceFilePaths { |
| 395 | filename := src.Base() |
| 396 | output := android.PathForModuleOut(ctx, filename).OutputPath |
| 397 | ip := installProperties{ |
| 398 | filename: filename, |
| 399 | sourceFilePath: src, |
| 400 | outputFilePath: output, |
| 401 | installDirPath: p.installDirPath, |
| 402 | } |
| 403 | p.outputFilePaths = append(p.outputFilePaths, output) |
| 404 | installs = append(installs, ip) |
| 405 | } |
| 406 | } else if ctx.Config().AllowMissingDependencies() { |
| 407 | // If no srcs was set and AllowMissingDependencies is enabled then |
| 408 | // mark the module as missing dependencies and set a fake source path |
| 409 | // and file name. |
| 410 | ctx.AddMissingDependencies([]string{"MISSING_PREBUILT_SRC_FILE"}) |
| 411 | p.sourceFilePaths = android.Paths{android.PathForModuleSrc(ctx)} |
| 412 | if filename == "" { |
| 413 | filename = ctx.ModuleName() |
| 414 | } |
| 415 | p.outputFilePaths = android.OutputPaths{android.PathForModuleOut(ctx, filename).OutputPath} |
| 416 | ip := installProperties{ |
| 417 | filename: filename, |
| 418 | sourceFilePath: p.sourceFilePaths[0], |
| 419 | outputFilePath: p.outputFilePaths[0], |
| 420 | installDirPath: p.installDirPath, |
| 421 | } |
| 422 | installs = append(installs, ip) |
| 423 | } else { |
| 424 | ctx.PropertyErrorf("src", "missing prebuilt source file") |
| 425 | return |
| 426 | } |
| 427 | |
| 428 | // Call InstallFile even when uninstallable to make the module included in the package. |
| 429 | if !p.Installable() { |
| 430 | p.SkipInstall() |
| 431 | } |
| 432 | for _, ip := range installs { |
| 433 | ip.addInstallRules(ctx) |
| 434 | } |
LaMont Jones | afe7baf | 2024-01-09 22:47:39 +0000 | [diff] [blame] | 435 | android.CollectDependencyAconfigFiles(ctx, &p.mergedAconfigFiles) |
Spandan Das | 756d340 | 2023-06-05 22:49:50 +0000 | [diff] [blame] | 436 | } |
Jiyong Park | f9f6805 | 2020-09-29 20:15:08 +0900 | [diff] [blame] | 437 | |
Spandan Das | 756d340 | 2023-06-05 22:49:50 +0000 | [diff] [blame] | 438 | type installProperties struct { |
Spandan Das | 756d340 | 2023-06-05 22:49:50 +0000 | [diff] [blame] | 439 | filename string |
| 440 | sourceFilePath android.Path |
Thiébaud Weksteen | 00e8b31 | 2024-03-18 14:06:00 +1100 | [diff] [blame] | 441 | outputFilePath android.OutputPath |
| 442 | installDirPath android.InstallPath |
Spandan Das | 756d340 | 2023-06-05 22:49:50 +0000 | [diff] [blame] | 443 | symlinks []string |
| 444 | } |
| 445 | |
| 446 | // utility function to add install rules to the build graph. |
| 447 | // Reduces code duplication between Soong and Mixed build analysis |
Thiébaud Weksteen | 00e8b31 | 2024-03-18 14:06:00 +1100 | [diff] [blame] | 448 | func (ip *installProperties) addInstallRules(ctx android.ModuleContext) { |
Spandan Das | 756d340 | 2023-06-05 22:49:50 +0000 | [diff] [blame] | 449 | // Copy the file from src to a location in out/ with the correct `filename` |
| 450 | // This ensures that outputFilePath has the correct name for others to |
| 451 | // use, as the source file may have a different name. |
Spandan Das | 756d340 | 2023-06-05 22:49:50 +0000 | [diff] [blame] | 452 | ctx.Build(pctx, android.BuildParams{ |
| 453 | Rule: android.Cp, |
Thiébaud Weksteen | 00e8b31 | 2024-03-18 14:06:00 +1100 | [diff] [blame] | 454 | Output: ip.outputFilePath, |
Spandan Das | 756d340 | 2023-06-05 22:49:50 +0000 | [diff] [blame] | 455 | Input: ip.sourceFilePath, |
| 456 | }) |
| 457 | |
Thiébaud Weksteen | 00e8b31 | 2024-03-18 14:06:00 +1100 | [diff] [blame] | 458 | installPath := ctx.InstallFile(ip.installDirPath, ip.filename, ip.outputFilePath) |
Spandan Das | 756d340 | 2023-06-05 22:49:50 +0000 | [diff] [blame] | 459 | for _, sl := range ip.symlinks { |
Thiébaud Weksteen | 00e8b31 | 2024-03-18 14:06:00 +1100 | [diff] [blame] | 460 | ctx.InstallSymlink(ip.installDirPath, sl, installPath) |
Jiyong Park | f9f6805 | 2020-09-29 20:15:08 +0900 | [diff] [blame] | 461 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 462 | } |
| 463 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 464 | func (p *PrebuiltEtc) AndroidMkEntries() []android.AndroidMkEntries { |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 465 | nameSuffix := "" |
Yifan Hong | 1b3348d | 2020-01-21 15:53:22 -0800 | [diff] [blame] | 466 | if p.inRamdisk() && !p.onlyInRamdisk() { |
| 467 | nameSuffix = ".ramdisk" |
| 468 | } |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 469 | if p.inVendorRamdisk() && !p.onlyInVendorRamdisk() { |
| 470 | nameSuffix = ".vendor_ramdisk" |
| 471 | } |
Inseob Kim | 08758f0 | 2021-04-08 21:13:22 +0900 | [diff] [blame] | 472 | if p.inDebugRamdisk() && !p.onlyInDebugRamdisk() { |
| 473 | nameSuffix = ".debug_ramdisk" |
| 474 | } |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 475 | if p.InRecovery() && !p.onlyInRecovery() { |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 476 | nameSuffix = ".recovery" |
| 477 | } |
Colin Cross | f17e2b5 | 2023-10-30 15:17:25 -0700 | [diff] [blame] | 478 | |
| 479 | class := p.makeClass |
| 480 | if class == "" { |
| 481 | class = "ETC" |
| 482 | } |
| 483 | |
Thiébaud Weksteen | 00e8b31 | 2024-03-18 14:06:00 +1100 | [diff] [blame] | 484 | return []android.AndroidMkEntries{{ |
Colin Cross | f17e2b5 | 2023-10-30 15:17:25 -0700 | [diff] [blame] | 485 | Class: class, |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 486 | SubName: nameSuffix, |
Thiébaud Weksteen | 00e8b31 | 2024-03-18 14:06:00 +1100 | [diff] [blame] | 487 | OutputFile: android.OptionalPathForPath(p.outputFilePaths[0]), |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 488 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 489 | func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { |
Jaewoong Jung | e0dc8df | 2019-08-27 17:33:16 -0700 | [diff] [blame] | 490 | entries.SetString("LOCAL_MODULE_TAGS", "optional") |
Colin Cross | c68db4b | 2021-11-11 18:59:15 -0800 | [diff] [blame] | 491 | entries.SetString("LOCAL_MODULE_PATH", p.installDirPath.String()) |
Thiébaud Weksteen | 00e8b31 | 2024-03-18 14:06:00 +1100 | [diff] [blame] | 492 | entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePaths[0].Base()) |
Yo Chiang | 3d64d49 | 2020-05-27 17:56:39 +0800 | [diff] [blame] | 493 | if len(p.properties.Symlinks) > 0 { |
| 494 | entries.AddStrings("LOCAL_MODULE_SYMLINKS", p.properties.Symlinks...) |
| 495 | } |
Yo Chiang | 803c40d | 2020-11-16 20:32:51 +0800 | [diff] [blame] | 496 | entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.Installable()) |
Jaewoong Jung | e0dc8df | 2019-08-27 17:33:16 -0700 | [diff] [blame] | 497 | if p.additionalDependencies != nil { |
Yo Chiang | 803c40d | 2020-11-16 20:32:51 +0800 | [diff] [blame] | 498 | entries.AddStrings("LOCAL_ADDITIONAL_DEPENDENCIES", p.additionalDependencies.Strings()...) |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 499 | } |
LaMont Jones | afe7baf | 2024-01-09 22:47:39 +0000 | [diff] [blame] | 500 | android.SetAconfigFileMkEntries(p.AndroidModuleBase(), entries, p.mergedAconfigFiles) |
Jaewoong Jung | e0dc8df | 2019-08-27 17:33:16 -0700 | [diff] [blame] | 501 | }, |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 502 | }, |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 503 | }} |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 504 | } |
| 505 | |
LaMont Jones | afe7baf | 2024-01-09 22:47:39 +0000 | [diff] [blame] | 506 | func (p *PrebuiltEtc) AndroidModuleBase() *android.ModuleBase { |
| 507 | return &p.ModuleBase |
| 508 | } |
| 509 | |
Jooyung Han | a017182 | 2019-07-22 15:48:36 +0900 | [diff] [blame] | 510 | func InitPrebuiltEtcModule(p *PrebuiltEtc, dirBase string) { |
| 511 | p.installDirBase = dirBase |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 512 | p.AddProperties(&p.properties) |
Inseob Kim | 27408bf | 2021-04-06 21:00:17 +0900 | [diff] [blame] | 513 | p.AddProperties(&p.subdirProperties) |
| 514 | } |
| 515 | |
| 516 | func InitPrebuiltRootModule(p *PrebuiltEtc) { |
| 517 | p.installDirBase = "." |
| 518 | p.AddProperties(&p.properties) |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 519 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 520 | |
Patrice Arruda | 9e14b96 | 2019-03-11 15:58:50 -0700 | [diff] [blame] | 521 | // prebuilt_etc is for a prebuilt artifact that is installed in |
| 522 | // <partition>/etc/<sub_dir> directory. |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 523 | func PrebuiltEtcFactory() android.Module { |
Jooyung Han | a017182 | 2019-07-22 15:48:36 +0900 | [diff] [blame] | 524 | module := &PrebuiltEtc{} |
| 525 | InitPrebuiltEtcModule(module, "etc") |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 526 | // This module is device-only |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 527 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst) |
Inseob Kim | 1e27a14 | 2021-05-06 11:46:11 +0000 | [diff] [blame] | 528 | android.InitDefaultableModule(module) |
| 529 | return module |
| 530 | } |
| 531 | |
| 532 | func defaultsFactory() android.Module { |
| 533 | return DefaultsFactory() |
| 534 | } |
| 535 | |
| 536 | func DefaultsFactory(props ...interface{}) android.Module { |
| 537 | module := &Defaults{} |
| 538 | |
| 539 | module.AddProperties(props...) |
| 540 | module.AddProperties( |
| 541 | &prebuiltEtcProperties{}, |
| 542 | &prebuiltSubdirProperties{}, |
| 543 | ) |
| 544 | |
| 545 | android.InitDefaultsModule(module) |
| 546 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 547 | return module |
| 548 | } |
Tao Bao | 0ba5c94 | 2018-08-14 22:20:22 -0700 | [diff] [blame] | 549 | |
Patrice Arruda | 9e14b96 | 2019-03-11 15:58:50 -0700 | [diff] [blame] | 550 | // prebuilt_etc_host is for a host prebuilt artifact that is installed in |
| 551 | // $(HOST_OUT)/etc/<sub_dir> directory. |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 552 | func PrebuiltEtcHostFactory() android.Module { |
Jooyung Han | a017182 | 2019-07-22 15:48:36 +0900 | [diff] [blame] | 553 | module := &PrebuiltEtc{} |
| 554 | InitPrebuiltEtcModule(module, "etc") |
Jaewoong Jung | 2478818 | 2019-02-04 14:34:10 -0800 | [diff] [blame] | 555 | // This module is host-only |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 556 | android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon) |
Martin Stjernholm | dc6525e | 2021-10-14 00:42:59 +0100 | [diff] [blame] | 557 | android.InitDefaultableModule(module) |
Jaewoong Jung | 2478818 | 2019-02-04 14:34:10 -0800 | [diff] [blame] | 558 | return module |
| 559 | } |
| 560 | |
Miguel | 32b0280 | 2022-12-01 18:38:26 +0000 | [diff] [blame] | 561 | // prebuilt_etc_host is for a host prebuilt artifact that is installed in |
| 562 | // <partition>/etc/<sub_dir> directory. |
| 563 | func PrebuiltEtcCaCertsFactory() android.Module { |
| 564 | module := &PrebuiltEtc{} |
| 565 | InitPrebuiltEtcModule(module, "cacerts") |
| 566 | // This module is device-only |
| 567 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst) |
Miguel | 32b0280 | 2022-12-01 18:38:26 +0000 | [diff] [blame] | 568 | return module |
| 569 | } |
| 570 | |
Inseob Kim | 27408bf | 2021-04-06 21:00:17 +0900 | [diff] [blame] | 571 | // prebuilt_root is for a prebuilt artifact that is installed in |
| 572 | // <partition>/ directory. Can't have any sub directories. |
| 573 | func PrebuiltRootFactory() android.Module { |
| 574 | module := &PrebuiltEtc{} |
| 575 | InitPrebuiltRootModule(module) |
| 576 | // This module is device-only |
| 577 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst) |
Martin Stjernholm | dc6525e | 2021-10-14 00:42:59 +0100 | [diff] [blame] | 578 | android.InitDefaultableModule(module) |
Inseob Kim | 27408bf | 2021-04-06 21:00:17 +0900 | [diff] [blame] | 579 | return module |
| 580 | } |
| 581 | |
Liz Kammer | e9ecddc | 2022-01-04 17:27:52 -0500 | [diff] [blame] | 582 | // prebuilt_root_host is for a host prebuilt artifact that is installed in $(HOST_OUT)/<sub_dir> |
| 583 | // directory. |
| 584 | func PrebuiltRootHostFactory() android.Module { |
| 585 | module := &PrebuiltEtc{} |
| 586 | InitPrebuiltEtcModule(module, ".") |
| 587 | // This module is host-only |
| 588 | android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon) |
| 589 | android.InitDefaultableModule(module) |
| 590 | return module |
| 591 | } |
| 592 | |
Patrice Arruda | 9e14b96 | 2019-03-11 15:58:50 -0700 | [diff] [blame] | 593 | // prebuilt_usr_share is for a prebuilt artifact that is installed in |
| 594 | // <partition>/usr/share/<sub_dir> directory. |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 595 | func PrebuiltUserShareFactory() android.Module { |
Jooyung Han | a017182 | 2019-07-22 15:48:36 +0900 | [diff] [blame] | 596 | module := &PrebuiltEtc{} |
| 597 | InitPrebuiltEtcModule(module, "usr/share") |
Jaewoong Jung | c3fcdb4 | 2019-02-13 05:50:33 -0800 | [diff] [blame] | 598 | // This module is device-only |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 599 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst) |
Martin Stjernholm | dc6525e | 2021-10-14 00:42:59 +0100 | [diff] [blame] | 600 | android.InitDefaultableModule(module) |
Jaewoong Jung | c3fcdb4 | 2019-02-13 05:50:33 -0800 | [diff] [blame] | 601 | return module |
| 602 | } |
| 603 | |
Patrice Arruda | 9e14b96 | 2019-03-11 15:58:50 -0700 | [diff] [blame] | 604 | // prebuild_usr_share_host is for a host prebuilt artifact that is installed in |
| 605 | // $(HOST_OUT)/usr/share/<sub_dir> directory. |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 606 | func PrebuiltUserShareHostFactory() android.Module { |
Jooyung Han | a017182 | 2019-07-22 15:48:36 +0900 | [diff] [blame] | 607 | module := &PrebuiltEtc{} |
| 608 | InitPrebuiltEtcModule(module, "usr/share") |
Patrice Arruda | 300cef9 | 2019-02-22 15:47:57 -0800 | [diff] [blame] | 609 | // This module is host-only |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 610 | android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon) |
Martin Stjernholm | dc6525e | 2021-10-14 00:42:59 +0100 | [diff] [blame] | 611 | android.InitDefaultableModule(module) |
Patrice Arruda | 300cef9 | 2019-02-22 15:47:57 -0800 | [diff] [blame] | 612 | return module |
| 613 | } |
| 614 | |
yangbill | 63c5e19 | 2024-03-27 09:02:12 +0000 | [diff] [blame^] | 615 | // prebuilt_usr_hyphendata is for a prebuilt artifact that is installed in |
| 616 | // <partition>/usr/hyphen-data/<sub_dir> directory. |
| 617 | func PrebuiltUserHyphenDataFactory() android.Module { |
| 618 | module := &PrebuiltEtc{} |
| 619 | InitPrebuiltEtcModule(module, "usr/hyphen-data") |
| 620 | // This module is device-only |
| 621 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst) |
| 622 | android.InitDefaultableModule(module) |
| 623 | return module |
| 624 | } |
| 625 | |
Patrice Arruda | 61583eb | 2019-05-14 08:20:45 -0700 | [diff] [blame] | 626 | // prebuilt_font installs a font in <partition>/fonts directory. |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 627 | func PrebuiltFontFactory() android.Module { |
Jooyung Han | a017182 | 2019-07-22 15:48:36 +0900 | [diff] [blame] | 628 | module := &PrebuiltEtc{} |
| 629 | InitPrebuiltEtcModule(module, "fonts") |
Patrice Arruda | 61583eb | 2019-05-14 08:20:45 -0700 | [diff] [blame] | 630 | // This module is device-only |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 631 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst) |
Martin Stjernholm | dc6525e | 2021-10-14 00:42:59 +0100 | [diff] [blame] | 632 | android.InitDefaultableModule(module) |
Patrice Arruda | 61583eb | 2019-05-14 08:20:45 -0700 | [diff] [blame] | 633 | return module |
| 634 | } |
Patrice Arruda | 057a8b1 | 2019-06-03 15:29:27 -0700 | [diff] [blame] | 635 | |
Yo Chiang | f0e19fe | 2020-11-18 15:28:42 +0800 | [diff] [blame] | 636 | // prebuilt_firmware installs a firmware file to <partition>/etc/firmware directory for system |
| 637 | // image. |
| 638 | // If soc_specific property is set to true, the firmware file is installed to the |
| 639 | // vendor <partition>/firmware directory for vendor image. |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 640 | func PrebuiltFirmwareFactory() android.Module { |
Jooyung Han | a017182 | 2019-07-22 15:48:36 +0900 | [diff] [blame] | 641 | module := &PrebuiltEtc{} |
| 642 | module.socInstallDirBase = "firmware" |
| 643 | InitPrebuiltEtcModule(module, "etc/firmware") |
Patrice Arruda | 057a8b1 | 2019-06-03 15:29:27 -0700 | [diff] [blame] | 644 | // This module is device-only |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 645 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst) |
Martin Stjernholm | dc6525e | 2021-10-14 00:42:59 +0100 | [diff] [blame] | 646 | android.InitDefaultableModule(module) |
Patrice Arruda | 057a8b1 | 2019-06-03 15:29:27 -0700 | [diff] [blame] | 647 | return module |
| 648 | } |
Patrice Arruda | 0f68800 | 2020-06-08 21:40:25 +0000 | [diff] [blame] | 649 | |
| 650 | // prebuilt_dsp installs a DSP related file to <partition>/etc/dsp directory for system image. |
Yo Chiang | f0e19fe | 2020-11-18 15:28:42 +0800 | [diff] [blame] | 651 | // If soc_specific property is set to true, the DSP related file is installed to the |
| 652 | // vendor <partition>/dsp directory for vendor image. |
Patrice Arruda | 0f68800 | 2020-06-08 21:40:25 +0000 | [diff] [blame] | 653 | func PrebuiltDSPFactory() android.Module { |
| 654 | module := &PrebuiltEtc{} |
| 655 | module.socInstallDirBase = "dsp" |
| 656 | InitPrebuiltEtcModule(module, "etc/dsp") |
| 657 | // This module is device-only |
| 658 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst) |
Martin Stjernholm | dc6525e | 2021-10-14 00:42:59 +0100 | [diff] [blame] | 659 | android.InitDefaultableModule(module) |
Patrice Arruda | 0f68800 | 2020-06-08 21:40:25 +0000 | [diff] [blame] | 660 | return module |
| 661 | } |
Colin Cross | 83ebf23 | 2021-04-09 09:41:23 -0700 | [diff] [blame] | 662 | |
Colin Cross | f17e2b5 | 2023-10-30 15:17:25 -0700 | [diff] [blame] | 663 | // prebuilt_renderscript_bitcode installs a *.bc file into /system/lib or /system/lib64. |
| 664 | func PrebuiltRenderScriptBitcodeFactory() android.Module { |
| 665 | module := &PrebuiltEtc{} |
| 666 | module.makeClass = "RENDERSCRIPT_BITCODE" |
| 667 | module.installDirBase64 = "lib64" |
Colin Cross | 2f63457 | 2023-11-13 12:12:06 -0800 | [diff] [blame] | 668 | module.installAvoidMultilibConflict = true |
Colin Cross | f17e2b5 | 2023-10-30 15:17:25 -0700 | [diff] [blame] | 669 | InitPrebuiltEtcModule(module, "lib") |
| 670 | // This module is device-only |
| 671 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibBoth) |
| 672 | android.InitDefaultableModule(module) |
| 673 | return module |
| 674 | } |
| 675 | |
Colin Cross | 83ebf23 | 2021-04-09 09:41:23 -0700 | [diff] [blame] | 676 | // prebuilt_rfsa installs a firmware file that will be available through Qualcomm's RFSA |
| 677 | // to the <partition>/lib/rfsa directory. |
| 678 | func PrebuiltRFSAFactory() android.Module { |
| 679 | module := &PrebuiltEtc{} |
| 680 | // Ideally these would go in /vendor/dsp, but the /vendor/lib/rfsa paths are hardcoded in too |
| 681 | // many places outside of the application processor. They could be moved to /vendor/dsp once |
| 682 | // that is cleaned up. |
| 683 | InitPrebuiltEtcModule(module, "lib/rfsa") |
| 684 | // This module is device-only |
| 685 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst) |
Martin Stjernholm | dc6525e | 2021-10-14 00:42:59 +0100 | [diff] [blame] | 686 | android.InitDefaultableModule(module) |
Colin Cross | 83ebf23 | 2021-04-09 09:41:23 -0700 | [diff] [blame] | 687 | return module |
| 688 | } |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 689 | |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 690 | // Copy file into the snapshot |
| 691 | func copyFile(ctx android.SingletonContext, path android.Path, out string, fake bool) android.OutputPath { |
| 692 | if fake { |
| 693 | // Create empty file instead for the fake snapshot |
| 694 | return snapshot.WriteStringToFileRule(ctx, "", out) |
| 695 | } else { |
| 696 | return snapshot.CopyFileRule(pctx, ctx, path, out) |
| 697 | } |
| 698 | } |
| 699 | |
| 700 | // Check if the module is target of the snapshot |
| 701 | func isSnapshotAware(ctx android.SingletonContext, m *PrebuiltEtc, image snapshot.SnapshotImage) bool { |
| 702 | if !m.Enabled() { |
| 703 | return false |
| 704 | } |
| 705 | |
| 706 | // Skip if the module is not included in the image |
| 707 | if !image.InImage(m)() { |
| 708 | return false |
| 709 | } |
| 710 | |
| 711 | // When android/prebuilt.go selects between source and prebuilt, it sets |
| 712 | // HideFromMake on the other one to avoid duplicate install rules in make. |
| 713 | if m.IsHideFromMake() { |
| 714 | return false |
| 715 | } |
| 716 | |
| 717 | // There are some prebuilt_etc module with multiple definition of same name. |
| 718 | // Check if the target would be included from the build |
| 719 | if !m.ExportedToMake() { |
| 720 | return false |
| 721 | } |
| 722 | |
| 723 | // Skip if the module is in the predefined path list to skip |
| 724 | if image.IsProprietaryPath(ctx.ModuleDir(m), ctx.DeviceConfig()) { |
| 725 | return false |
| 726 | } |
| 727 | |
| 728 | // Skip if the module should be excluded |
| 729 | if image.ExcludeFromSnapshot(m) || image.ExcludeFromDirectedSnapshot(ctx.DeviceConfig(), m.BaseModuleName()) { |
| 730 | return false |
| 731 | } |
| 732 | |
| 733 | // Skip from other exceptional cases |
| 734 | if m.Target().Os.Class != android.Device { |
| 735 | return false |
| 736 | } |
| 737 | if m.Target().NativeBridge == android.NativeBridgeEnabled { |
| 738 | return false |
| 739 | } |
| 740 | |
| 741 | return true |
| 742 | } |
| 743 | |
Justin Yun | 1db9748 | 2023-04-11 18:20:07 +0900 | [diff] [blame] | 744 | func generatePrebuiltSnapshot(s snapshot.SnapshotSingleton, ctx android.SingletonContext, snapshotArchDir string) snapshot.SnapshotPaths { |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 745 | /* |
| 746 | Snapshot zipped artifacts directory structure for etc modules: |
| 747 | {SNAPSHOT_ARCH}/ |
| 748 | arch-{TARGET_ARCH}-{TARGET_ARCH_VARIANT}/ |
| 749 | etc/ |
| 750 | (prebuilt etc files) |
| 751 | arch-{TARGET_2ND_ARCH}-{TARGET_2ND_ARCH_VARIANT}/ |
| 752 | etc/ |
| 753 | (prebuilt etc files) |
| 754 | NOTICE_FILES/ |
| 755 | (notice files) |
| 756 | */ |
| 757 | var snapshotOutputs android.Paths |
Justin Yun | 1db9748 | 2023-04-11 18:20:07 +0900 | [diff] [blame] | 758 | var snapshotNotices android.Paths |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 759 | installedNotices := make(map[string]bool) |
| 760 | |
| 761 | ctx.VisitAllModules(func(module android.Module) { |
| 762 | m, ok := module.(*PrebuiltEtc) |
| 763 | if !ok { |
| 764 | return |
| 765 | } |
| 766 | |
| 767 | if !isSnapshotAware(ctx, m, s.Image) { |
| 768 | return |
| 769 | } |
| 770 | |
| 771 | targetArch := "arch-" + m.Target().Arch.ArchType.String() |
| 772 | |
| 773 | snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, "etc", m.BaseModuleName()) |
Thiébaud Weksteen | 00e8b31 | 2024-03-18 14:06:00 +1100 | [diff] [blame] | 774 | outputs, _ := m.OutputFiles("") |
| 775 | for _, output := range outputs { |
| 776 | cp := copyFile(ctx, output, snapshotLibOut, s.Fake) |
| 777 | snapshotOutputs = append(snapshotOutputs, cp) |
| 778 | } |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 779 | |
Rob Seymour | 925aa09 | 2021-08-10 20:42:03 +0000 | [diff] [blame] | 780 | prop := snapshot.SnapshotJsonFlags{} |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 781 | propOut := snapshotLibOut + ".json" |
Justin Yun | 1db9748 | 2023-04-11 18:20:07 +0900 | [diff] [blame] | 782 | prop.InitBaseSnapshotProps(m) |
Justin Yun | 8bd3afe | 2023-05-12 15:53:06 +0900 | [diff] [blame] | 783 | prop.RelativeInstallPath = m.SubDir() |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 784 | |
| 785 | if m.properties.Filename != nil { |
| 786 | prop.Filename = *m.properties.Filename |
| 787 | } |
| 788 | |
| 789 | j, err := json.Marshal(prop) |
| 790 | if err != nil { |
| 791 | ctx.Errorf("json marshal to %q failed: %#v", propOut, err) |
| 792 | return |
| 793 | } |
| 794 | snapshotOutputs = append(snapshotOutputs, snapshot.WriteStringToFileRule(ctx, string(j), propOut)) |
| 795 | |
Justin Yun | 1db9748 | 2023-04-11 18:20:07 +0900 | [diff] [blame] | 796 | for _, notice := range m.EffectiveLicenseFiles() { |
| 797 | if _, ok := installedNotices[notice.String()]; !ok { |
| 798 | installedNotices[notice.String()] = true |
| 799 | snapshotNotices = append(snapshotNotices, notice) |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 800 | } |
| 801 | } |
| 802 | |
| 803 | }) |
| 804 | |
Justin Yun | 1db9748 | 2023-04-11 18:20:07 +0900 | [diff] [blame] | 805 | return snapshot.SnapshotPaths{OutputFiles: snapshotOutputs, NoticeFiles: snapshotNotices} |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 806 | } |