Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 1 | // Copyright (C) 2019 The Android Open Source Project |
| 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 apex |
| 16 | |
| 17 | import ( |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 18 | "strconv" |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 19 | "strings" |
| 20 | |
| 21 | "android/soong/android" |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 22 | "android/soong/dexpreopt" |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 23 | "android/soong/java" |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 24 | "android/soong/provenance" |
Anton Hansson | 805e0a5 | 2022-11-25 14:06:46 +0000 | [diff] [blame] | 25 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 26 | "github.com/google/blueprint" |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 27 | "github.com/google/blueprint/proptools" |
| 28 | ) |
| 29 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 30 | var ( |
| 31 | extractMatchingApex = pctx.StaticRule( |
| 32 | "extractMatchingApex", |
| 33 | blueprint.RuleParams{ |
| 34 | Command: `rm -rf "$out" && ` + |
| 35 | `${extract_apks} -o "${out}" -allow-prereleased=${allow-prereleased} ` + |
Pranav Gupta | 51645ff | 2023-03-20 16:19:53 -0700 | [diff] [blame] | 36 | `-sdk-version=${sdk-version} -skip-sdk-check=${skip-sdk-check} -abis=${abis} ` + |
| 37 | `-screen-densities=all -extract-single ` + |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 38 | `${in}`, |
| 39 | CommandDeps: []string{"${extract_apks}"}, |
| 40 | }, |
Pranav Gupta | 51645ff | 2023-03-20 16:19:53 -0700 | [diff] [blame] | 41 | "abis", "allow-prereleased", "sdk-version", "skip-sdk-check") |
Jooyung Han | 26ec848 | 2024-07-31 15:04:05 +0900 | [diff] [blame] | 42 | decompressApex = pctx.StaticRule("decompressApex", blueprint.RuleParams{ |
Jooyung Han | 8fa6116 | 2024-08-08 10:42:47 +0900 | [diff] [blame] | 43 | Command: `rm -rf $out && ${deapexer} decompress --copy-if-uncompressed --input ${in} --output ${out}`, |
Jooyung Han | 26ec848 | 2024-07-31 15:04:05 +0900 | [diff] [blame] | 44 | CommandDeps: []string{"${deapexer}"}, |
Jooyung Han | 8fa6116 | 2024-08-08 10:42:47 +0900 | [diff] [blame] | 45 | Description: "decompress $out", |
Jooyung Han | 26ec848 | 2024-07-31 15:04:05 +0900 | [diff] [blame] | 46 | }) |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 47 | ) |
| 48 | |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 49 | type prebuilt interface { |
| 50 | isForceDisabled() bool |
| 51 | InstallFilename() string |
| 52 | } |
| 53 | |
| 54 | type prebuiltCommon struct { |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 55 | android.ModuleBase |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 56 | java.Dexpreopter |
Paul Duffin | bb0dc13 | 2021-05-05 16:58:08 +0100 | [diff] [blame] | 57 | prebuilt android.Prebuilt |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 58 | |
Paul Duffin | bb0dc13 | 2021-05-05 16:58:08 +0100 | [diff] [blame] | 59 | // Properties common to both prebuilt_apex and apex_set. |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 60 | prebuiltCommonProperties *PrebuiltCommonProperties |
| 61 | |
| 62 | installDir android.InstallPath |
| 63 | installFilename string |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 64 | installedFile android.InstallPath |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 65 | outputApex android.WritablePath |
| 66 | |
Jooyung Han | 286957d | 2023-10-30 16:17:56 +0900 | [diff] [blame] | 67 | // fragment for this apex for apexkeys.txt |
| 68 | apexKeysPath android.WritablePath |
| 69 | |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 70 | // Installed locations of symlinks for backward compatibility. |
| 71 | compatSymlinks android.InstallPaths |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 72 | |
Jiakai Zhang | e6e90db | 2022-01-28 14:58:56 +0000 | [diff] [blame] | 73 | hostRequired []string |
| 74 | requiredModuleNames []string |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 75 | } |
| 76 | |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 77 | type sanitizedPrebuilt interface { |
| 78 | hasSanitizedSource(sanitizer string) bool |
| 79 | } |
| 80 | |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 81 | type PrebuiltCommonProperties struct { |
Paul Duffin | bb0dc13 | 2021-05-05 16:58:08 +0100 | [diff] [blame] | 82 | SelectedApexProperties |
| 83 | |
Martin Stjernholm | d8da28e | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 84 | // Canonical name of this APEX. Used to determine the path to the activated APEX on |
| 85 | // device (/apex/<apex_name>). If unspecified, follows the name property. |
| 86 | Apex_name *string |
| 87 | |
Spandan Das | 3576e76 | 2024-01-03 18:57:03 +0000 | [diff] [blame] | 88 | // Name of the source APEX that gets shadowed by this prebuilt |
| 89 | // e.g. com.mycompany.android.myapex |
| 90 | // If unspecified, follows the naming convention that the source apex of |
| 91 | // the prebuilt is Name() without "prebuilt_" prefix |
| 92 | Source_apex_name *string |
| 93 | |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 94 | ForceDisable bool `blueprint:"mutated"` |
Paul Duffin | 3bae068 | 2021-05-05 18:03:47 +0100 | [diff] [blame] | 95 | |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 96 | // whether the extracted apex file is installable. |
| 97 | Installable *bool |
| 98 | |
| 99 | // optional name for the installed apex. If unspecified, name of the |
| 100 | // module is used as the file name |
| 101 | Filename *string |
| 102 | |
| 103 | // names of modules to be overridden. Listed modules can only be other binaries |
| 104 | // (in Make or Soong). |
| 105 | // This does not completely prevent installation of the overridden binaries, but if both |
| 106 | // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed |
| 107 | // from PRODUCT_PACKAGES. |
| 108 | Overrides []string |
| 109 | |
Paul Duffin | 3bae068 | 2021-05-05 18:03:47 +0100 | [diff] [blame] | 110 | // List of bootclasspath fragments inside this prebuilt APEX bundle and for which this APEX |
| 111 | // bundle will create an APEX variant. |
| 112 | Exported_bootclasspath_fragments []string |
Jiakai Zhang | 774dd30 | 2021-09-26 03:54:25 +0000 | [diff] [blame] | 113 | |
| 114 | // List of systemserverclasspath fragments inside this prebuilt APEX bundle and for which this |
| 115 | // APEX bundle will create an APEX variant. |
| 116 | Exported_systemserverclasspath_fragments []string |
Spandan Das | a747d2e | 2024-03-11 21:37:25 +0000 | [diff] [blame] | 117 | |
| 118 | // Path to the .prebuilt_info file of the prebuilt apex. |
| 119 | // In case of mainline modules, the .prebuilt_info file contains the build_id that was used to |
| 120 | // generate the prebuilt. |
| 121 | Prebuilt_info *string `android:"path"` |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 122 | } |
| 123 | |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 124 | // initPrebuiltCommon initializes the prebuiltCommon structure and performs initialization of the |
| 125 | // module that is common to Prebuilt and ApexSet. |
| 126 | func (p *prebuiltCommon) initPrebuiltCommon(module android.Module, properties *PrebuiltCommonProperties) { |
| 127 | p.prebuiltCommonProperties = properties |
| 128 | android.InitSingleSourcePrebuiltModule(module.(android.PrebuiltInterface), properties, "Selected_apex") |
| 129 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 130 | } |
| 131 | |
Martin Stjernholm | d8da28e | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 132 | func (p *prebuiltCommon) ApexVariationName() string { |
Spandan Das | 3576e76 | 2024-01-03 18:57:03 +0000 | [diff] [blame] | 133 | return proptools.StringDefault(p.prebuiltCommonProperties.Apex_name, p.BaseModuleName()) |
| 134 | } |
| 135 | |
| 136 | func (p *prebuiltCommon) BaseModuleName() string { |
| 137 | return proptools.StringDefault(p.prebuiltCommonProperties.Source_apex_name, p.ModuleBase.BaseModuleName()) |
Martin Stjernholm | d8da28e | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 138 | } |
| 139 | |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 140 | func (p *prebuiltCommon) Prebuilt() *android.Prebuilt { |
| 141 | return &p.prebuilt |
| 142 | } |
| 143 | |
| 144 | func (p *prebuiltCommon) isForceDisabled() bool { |
Paul Duffin | bb0dc13 | 2021-05-05 16:58:08 +0100 | [diff] [blame] | 145 | return p.prebuiltCommonProperties.ForceDisable |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | func (p *prebuiltCommon) checkForceDisable(ctx android.ModuleContext) bool { |
Jooyung Han | eec1b3f | 2023-06-20 16:25:59 +0900 | [diff] [blame] | 149 | forceDisable := false |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 150 | |
| 151 | // Force disable the prebuilts when we are doing unbundled build. We do unbundled build |
| 152 | // to build the prebuilts themselves. |
| 153 | forceDisable = forceDisable || ctx.Config().UnbundledBuild() |
| 154 | |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 155 | // b/137216042 don't use prebuilts when address sanitizer is on, unless the prebuilt has a sanitized source |
| 156 | sanitized := ctx.Module().(sanitizedPrebuilt) |
| 157 | forceDisable = forceDisable || (android.InList("address", ctx.Config().SanitizeDevice()) && !sanitized.hasSanitizedSource("address")) |
| 158 | forceDisable = forceDisable || (android.InList("hwaddress", ctx.Config().SanitizeDevice()) && !sanitized.hasSanitizedSource("hwaddress")) |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 159 | |
| 160 | if forceDisable && p.prebuilt.SourceExists() { |
Paul Duffin | bb0dc13 | 2021-05-05 16:58:08 +0100 | [diff] [blame] | 161 | p.prebuiltCommonProperties.ForceDisable = true |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 162 | return true |
| 163 | } |
| 164 | return false |
| 165 | } |
| 166 | |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 167 | func (p *prebuiltCommon) InstallFilename() string { |
| 168 | return proptools.StringDefault(p.prebuiltCommonProperties.Filename, p.BaseModuleName()+imageApexSuffix) |
| 169 | } |
| 170 | |
| 171 | func (p *prebuiltCommon) Name() string { |
| 172 | return p.prebuilt.Name(p.ModuleBase.Name()) |
| 173 | } |
| 174 | |
| 175 | func (p *prebuiltCommon) Overrides() []string { |
| 176 | return p.prebuiltCommonProperties.Overrides |
| 177 | } |
| 178 | |
| 179 | func (p *prebuiltCommon) installable() bool { |
| 180 | return proptools.BoolDefault(p.prebuiltCommonProperties.Installable, true) |
| 181 | } |
| 182 | |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 183 | // To satisfy java.DexpreopterInterface |
| 184 | func (p *prebuiltCommon) IsInstallable() bool { |
| 185 | return p.installable() |
| 186 | } |
| 187 | |
| 188 | // initApexFilesForAndroidMk initializes the prebuiltCommon.requiredModuleNames field with the install only deps of the prebuilt apex |
Paul Duffin | c30aea2 | 2021-06-15 19:10:11 +0100 | [diff] [blame] | 189 | func (p *prebuiltCommon) initApexFilesForAndroidMk(ctx android.ModuleContext) { |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 190 | // If this apex contains a system server jar, then the dexpreopt artifacts should be added as required |
| 191 | for _, install := range p.Dexpreopter.DexpreoptBuiltInstalledForApex() { |
| 192 | p.requiredModuleNames = append(p.requiredModuleNames, install.FullModuleName()) |
| 193 | } |
| 194 | } |
Paul Duffin | c30aea2 | 2021-06-15 19:10:11 +0100 | [diff] [blame] | 195 | |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 196 | // If this prebuilt has system server jar, create the rules to dexpreopt it and install it alongside the prebuilt apex |
Spandan Das | 52c01a1 | 2024-09-20 01:09:48 +0000 | [diff] [blame] | 197 | func (p *prebuiltCommon) dexpreoptSystemServerJars(ctx android.ModuleContext, di *android.DeapexerInfo) { |
| 198 | if di == nil { |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 199 | return |
| 200 | } |
Spandan Das | e21a8d4 | 2024-01-23 23:56:29 +0000 | [diff] [blame] | 201 | // If this prebuilt apex has not been selected, return |
| 202 | if p.IsHideFromMake() { |
| 203 | return |
| 204 | } |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 205 | // Use apex_name to determine the api domain of this prebuilt apex |
| 206 | apexName := p.ApexVariationName() |
Spandan Das | 52c01a1 | 2024-09-20 01:09:48 +0000 | [diff] [blame] | 207 | // TODO: do not compute twice |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 208 | dc := dexpreopt.GetGlobalConfig(ctx) |
| 209 | systemServerJarList := dc.AllApexSystemServerJars(ctx) |
| 210 | |
| 211 | for i := 0; i < systemServerJarList.Len(); i++ { |
| 212 | sscpApex := systemServerJarList.Apex(i) |
| 213 | sscpJar := systemServerJarList.Jar(i) |
| 214 | if apexName != sscpApex { |
| 215 | continue |
Paul Duffin | c30aea2 | 2021-06-15 19:10:11 +0100 | [diff] [blame] | 216 | } |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 217 | p.Dexpreopter.DexpreoptPrebuiltApexSystemServerJars(ctx, sscpJar, di) |
| 218 | } |
Paul Duffin | c30aea2 | 2021-06-15 19:10:11 +0100 | [diff] [blame] | 219 | } |
| 220 | |
Jiakai Zhang | 204356f | 2021-09-09 08:12:46 +0000 | [diff] [blame] | 221 | func (p *prebuiltCommon) addRequiredModules(entries *android.AndroidMkEntries) { |
Jiakai Zhang | e6e90db | 2022-01-28 14:58:56 +0000 | [diff] [blame] | 222 | entries.AddStrings("LOCAL_REQUIRED_MODULES", p.requiredModuleNames...) |
Jiakai Zhang | 204356f | 2021-09-09 08:12:46 +0000 | [diff] [blame] | 223 | } |
| 224 | |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 225 | func (p *prebuiltCommon) AndroidMkEntries() []android.AndroidMkEntries { |
Paul Duffin | c30aea2 | 2021-06-15 19:10:11 +0100 | [diff] [blame] | 226 | entriesList := []android.AndroidMkEntries{ |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 227 | { |
| 228 | Class: "ETC", |
| 229 | OutputFile: android.OptionalPathForPath(p.outputApex), |
| 230 | Include: "$(BUILD_PREBUILT)", |
| 231 | Host_required: p.hostRequired, |
| 232 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ |
| 233 | func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { |
Colin Cross | c68db4b | 2021-11-11 18:59:15 -0800 | [diff] [blame] | 234 | entries.SetString("LOCAL_MODULE_PATH", p.installDir.String()) |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 235 | entries.SetString("LOCAL_MODULE_STEM", p.installFilename) |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 236 | entries.SetPath("LOCAL_SOONG_INSTALLED_MODULE", p.installedFile) |
| 237 | entries.SetString("LOCAL_SOONG_INSTALL_PAIRS", p.outputApex.String()+":"+p.installedFile.String()) |
Cole Faust | d22afe9 | 2023-08-18 16:05:44 -0700 | [diff] [blame] | 238 | entries.AddStrings("LOCAL_SOONG_INSTALL_SYMLINKS", p.compatSymlinks.Strings()...) |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 239 | entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable()) |
| 240 | entries.AddStrings("LOCAL_OVERRIDES_MODULES", p.prebuiltCommonProperties.Overrides...) |
Jooyung Han | 286957d | 2023-10-30 16:17:56 +0900 | [diff] [blame] | 241 | entries.SetString("LOCAL_APEX_KEY_PATH", p.apexKeysPath.String()) |
Jiakai Zhang | 204356f | 2021-09-09 08:12:46 +0000 | [diff] [blame] | 242 | p.addRequiredModules(entries) |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 243 | }, |
| 244 | }, |
| 245 | }, |
| 246 | } |
Paul Duffin | c30aea2 | 2021-06-15 19:10:11 +0100 | [diff] [blame] | 247 | |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 248 | // Add the dexpreopt artifacts to androidmk |
| 249 | for _, install := range p.Dexpreopter.DexpreoptBuiltInstalledForApex() { |
| 250 | entriesList = append(entriesList, install.ToMakeEntries()) |
| 251 | } |
| 252 | |
Paul Duffin | c30aea2 | 2021-06-15 19:10:11 +0100 | [diff] [blame] | 253 | return entriesList |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 254 | } |
| 255 | |
Paul Duffin | 5dda3e3 | 2021-05-05 14:13:27 +0100 | [diff] [blame] | 256 | // prebuiltApexModuleCreator defines the methods that need to be implemented by prebuilt_apex and |
| 257 | // apex_set in order to create the modules needed to provide access to the prebuilt .apex file. |
| 258 | type prebuiltApexModuleCreator interface { |
Colin Cross | da279cf | 2024-09-17 14:25:45 -0700 | [diff] [blame] | 259 | createPrebuiltApexModules(ctx android.BottomUpMutatorContext) |
Paul Duffin | 5dda3e3 | 2021-05-05 14:13:27 +0100 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | // prebuiltApexModuleCreatorMutator is the mutator responsible for invoking the |
| 263 | // prebuiltApexModuleCreator's createPrebuiltApexModules method. |
| 264 | // |
| 265 | // It is registered as a pre-arch mutator as it must run after the ComponentDepsMutator because it |
| 266 | // will need to access dependencies added by that (exported modules) but must run before the |
| 267 | // DepsMutator so that the deapexer module it creates can add dependencies onto itself from the |
| 268 | // exported modules. |
Colin Cross | da279cf | 2024-09-17 14:25:45 -0700 | [diff] [blame] | 269 | func prebuiltApexModuleCreatorMutator(ctx android.BottomUpMutatorContext) { |
Paul Duffin | 5dda3e3 | 2021-05-05 14:13:27 +0100 | [diff] [blame] | 270 | module := ctx.Module() |
| 271 | if creator, ok := module.(prebuiltApexModuleCreator); ok { |
| 272 | creator.createPrebuiltApexModules(ctx) |
| 273 | } |
| 274 | } |
| 275 | |
Liz Kammer | 2dc7244 | 2023-04-20 10:10:48 -0400 | [diff] [blame] | 276 | func (p *prebuiltCommon) hasExportedDeps() bool { |
Spandan Das | 1896fd6 | 2024-09-18 21:49:14 +0000 | [diff] [blame] | 277 | return len(p.prebuiltCommonProperties.Exported_bootclasspath_fragments) > 0 || |
Liz Kammer | 2dc7244 | 2023-04-20 10:10:48 -0400 | [diff] [blame] | 278 | len(p.prebuiltCommonProperties.Exported_systemserverclasspath_fragments) > 0 |
Jiakai Zhang | 774dd30 | 2021-09-26 03:54:25 +0000 | [diff] [blame] | 279 | } |
| 280 | |
Paul Duffin | 57f8359 | 2021-05-05 15:09:44 +0100 | [diff] [blame] | 281 | // prebuiltApexContentsDeps adds dependencies onto the prebuilt apex module's contents. |
| 282 | func (p *prebuiltCommon) prebuiltApexContentsDeps(ctx android.BottomUpMutatorContext) { |
| 283 | module := ctx.Module() |
Paul Duffin | 023dba0 | 2021-04-22 01:45:29 +0100 | [diff] [blame] | 284 | |
Liz Kammer | 2dc7244 | 2023-04-20 10:10:48 -0400 | [diff] [blame] | 285 | for _, dep := range p.prebuiltCommonProperties.Exported_bootclasspath_fragments { |
| 286 | prebuiltDep := android.PrebuiltNameFromSource(dep) |
| 287 | ctx.AddDependency(module, exportedBootclasspathFragmentTag, prebuiltDep) |
| 288 | } |
| 289 | |
| 290 | for _, dep := range p.prebuiltCommonProperties.Exported_systemserverclasspath_fragments { |
| 291 | prebuiltDep := android.PrebuiltNameFromSource(dep) |
| 292 | ctx.AddDependency(module, exportedSystemserverclasspathFragmentTag, prebuiltDep) |
Paul Duffin | 023dba0 | 2021-04-22 01:45:29 +0100 | [diff] [blame] | 293 | } |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 294 | } |
| 295 | |
Paul Duffin | b17d044 | 2021-05-05 12:07:00 +0100 | [diff] [blame] | 296 | // Implements android.DepInInSameApex |
| 297 | func (p *prebuiltCommon) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool { |
| 298 | tag := ctx.OtherModuleDependencyTag(dep) |
| 299 | _, ok := tag.(exportedDependencyTag) |
| 300 | return ok |
| 301 | } |
| 302 | |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 303 | // apexInfoMutator marks any modules for which this apex exports a file as requiring an apex |
| 304 | // specific variant and checks that they are supported. |
| 305 | // |
| 306 | // The apexMutator will ensure that the ApexInfo objects passed to BuildForApex(ApexInfo) are |
| 307 | // associated with the apex specific variant using the ApexInfoProvider for later retrieval. |
| 308 | // |
| 309 | // Unlike the source apex module type the prebuilt_apex module type cannot share compatible variants |
| 310 | // across prebuilt_apex modules. That is because there is no way to determine whether two |
| 311 | // prebuilt_apex modules that export files for the same module are compatible. e.g. they could have |
| 312 | // been built from different source at different times or they could have been built with different |
| 313 | // build options that affect the libraries. |
| 314 | // |
| 315 | // While it may be possible to provide sufficient information to determine whether two prebuilt_apex |
| 316 | // modules were compatible it would be a lot of work and would not provide much benefit for a couple |
| 317 | // of reasons: |
Colin Cross | d079e0b | 2022-08-16 10:27:33 -0700 | [diff] [blame] | 318 | // - The number of prebuilt_apex modules that will be exporting files for the same module will be |
| 319 | // low as the prebuilt_apex only exports files for the direct dependencies that require it and |
| 320 | // very few modules are direct dependencies of multiple prebuilt_apex modules, e.g. there are a |
| 321 | // few com.android.art* apex files that contain the same contents and could export files for the |
| 322 | // same modules but only one of them needs to do so. Contrast that with source apex modules which |
| 323 | // need apex specific variants for every module that contributes code to the apex, whether direct |
| 324 | // or indirect. |
| 325 | // - The build cost of a prebuilt_apex variant is generally low as at worst it will involve some |
| 326 | // extra copying of files. Contrast that with source apex modules that has to build each variant |
| 327 | // from source. |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 328 | func (p *prebuiltCommon) apexInfoMutator(mctx android.TopDownMutatorContext) { |
| 329 | |
| 330 | // Collect direct dependencies into contents. |
| 331 | contents := make(map[string]android.ApexMembership) |
| 332 | |
| 333 | // Collect the list of dependencies. |
| 334 | var dependencies []android.ApexModule |
Paul Duffin | b17d044 | 2021-05-05 12:07:00 +0100 | [diff] [blame] | 335 | mctx.WalkDeps(func(child, parent android.Module) bool { |
| 336 | // If the child is not in the same apex as the parent then exit immediately and do not visit |
| 337 | // any of the child's dependencies. |
| 338 | if !android.IsDepInSameApex(mctx, parent, child) { |
| 339 | return false |
| 340 | } |
| 341 | |
| 342 | tag := mctx.OtherModuleDependencyTag(child) |
| 343 | depName := mctx.OtherModuleName(child) |
Paul Duffin | 023dba0 | 2021-04-22 01:45:29 +0100 | [diff] [blame] | 344 | if exportedTag, ok := tag.(exportedDependencyTag); ok { |
| 345 | propertyName := exportedTag.name |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 346 | |
| 347 | // It is an error if the other module is not a prebuilt. |
Paul Duffin | b17d044 | 2021-05-05 12:07:00 +0100 | [diff] [blame] | 348 | if !android.IsModulePrebuilt(child) { |
Paul Duffin | 023dba0 | 2021-04-22 01:45:29 +0100 | [diff] [blame] | 349 | mctx.PropertyErrorf(propertyName, "%q is not a prebuilt module", depName) |
Paul Duffin | b17d044 | 2021-05-05 12:07:00 +0100 | [diff] [blame] | 350 | return false |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | // It is an error if the other module is not an ApexModule. |
Paul Duffin | b17d044 | 2021-05-05 12:07:00 +0100 | [diff] [blame] | 354 | if _, ok := child.(android.ApexModule); !ok { |
Paul Duffin | 023dba0 | 2021-04-22 01:45:29 +0100 | [diff] [blame] | 355 | mctx.PropertyErrorf(propertyName, "%q is not usable within an apex", depName) |
Paul Duffin | b17d044 | 2021-05-05 12:07:00 +0100 | [diff] [blame] | 356 | return false |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 357 | } |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 358 | } |
Paul Duffin | b17d044 | 2021-05-05 12:07:00 +0100 | [diff] [blame] | 359 | |
Paul Duffin | fee8cf3 | 2021-06-29 18:38:38 +0100 | [diff] [blame] | 360 | // Ignore any modules that do not implement ApexModule as they cannot have an APEX specific |
| 361 | // variant. |
| 362 | if _, ok := child.(android.ApexModule); !ok { |
| 363 | return false |
| 364 | } |
| 365 | |
Paul Duffin | b17d044 | 2021-05-05 12:07:00 +0100 | [diff] [blame] | 366 | // Strip off the prebuilt_ prefix if present before storing content to ensure consistent |
| 367 | // behavior whether there is a corresponding source module present or not. |
| 368 | depName = android.RemoveOptionalPrebuiltPrefix(depName) |
| 369 | |
| 370 | // Remember if this module was added as a direct dependency. |
| 371 | direct := parent == mctx.Module() |
| 372 | contents[depName] = contents[depName].Add(direct) |
| 373 | |
| 374 | // Add the module to the list of dependencies that need to have an APEX variant. |
| 375 | dependencies = append(dependencies, child.(android.ApexModule)) |
| 376 | |
| 377 | return true |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 378 | }) |
| 379 | |
| 380 | // Create contents for the prebuilt_apex and store it away for later use. |
| 381 | apexContents := android.NewApexContents(contents) |
Spandan Das | f5e03f1 | 2024-01-25 19:25:42 +0000 | [diff] [blame] | 382 | android.SetProvider(mctx, android.ApexBundleInfoProvider, android.ApexBundleInfo{ |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 383 | Contents: apexContents, |
| 384 | }) |
| 385 | |
| 386 | // Create an ApexInfo for the prebuilt_apex. |
Martin Stjernholm | d8da28e | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 387 | apexVariationName := p.ApexVariationName() |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 388 | apexInfo := android.ApexInfo{ |
Martin Stjernholm | c4f4ced | 2021-05-27 11:17:00 +0000 | [diff] [blame] | 389 | ApexVariationName: apexVariationName, |
| 390 | InApexVariants: []string{apexVariationName}, |
Spandan Das | 3576e76 | 2024-01-03 18:57:03 +0000 | [diff] [blame] | 391 | InApexModules: []string{p.BaseModuleName()}, // BaseModuleName() to avoid the prebuilt_ prefix. |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 392 | ApexContents: []*android.ApexContents{apexContents}, |
| 393 | ForPrebuiltApex: true, |
| 394 | } |
| 395 | |
| 396 | // Mark the dependencies of this module as requiring a variant for this module. |
| 397 | for _, am := range dependencies { |
| 398 | am.BuildForApex(apexInfo) |
| 399 | } |
| 400 | } |
| 401 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 402 | type Prebuilt struct { |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 403 | prebuiltCommon |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 404 | |
Paul Duffin | bb0dc13 | 2021-05-05 16:58:08 +0100 | [diff] [blame] | 405 | properties PrebuiltProperties |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 406 | |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 407 | inputApex android.Path |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 408 | |
| 409 | provenanceMetaDataFile android.OutputPath |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 410 | } |
| 411 | |
Paul Duffin | 851f399 | 2021-01-13 17:03:51 +0000 | [diff] [blame] | 412 | type ApexFileProperties struct { |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 413 | // the path to the prebuilt .apex file to import. |
Paul Duffin | c04fb9e | 2021-03-01 12:25:10 +0000 | [diff] [blame] | 414 | // |
| 415 | // This cannot be marked as `android:"arch_variant"` because the `prebuilt_apex` is only mutated |
| 416 | // for android_common. That is so that it will have the same arch variant as, and so be compatible |
| 417 | // with, the source `apex` module type that it replaces. |
Cole Faust | 642e720 | 2024-08-14 17:46:12 -0700 | [diff] [blame] | 418 | Src proptools.Configurable[string] `android:"path,replace_instead_of_append"` |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 419 | Arch struct { |
| 420 | Arm struct { |
Paul Duffin | 11216db | 2021-03-01 14:14:52 +0000 | [diff] [blame] | 421 | Src *string `android:"path"` |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 422 | } |
| 423 | Arm64 struct { |
Paul Duffin | 11216db | 2021-03-01 14:14:52 +0000 | [diff] [blame] | 424 | Src *string `android:"path"` |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 425 | } |
Chen Guoyin | 401f298 | 2022-10-12 19:28:48 +0800 | [diff] [blame] | 426 | Riscv64 struct { |
| 427 | Src *string `android:"path"` |
| 428 | } |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 429 | X86 struct { |
Paul Duffin | 11216db | 2021-03-01 14:14:52 +0000 | [diff] [blame] | 430 | Src *string `android:"path"` |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 431 | } |
| 432 | X86_64 struct { |
Paul Duffin | 11216db | 2021-03-01 14:14:52 +0000 | [diff] [blame] | 433 | Src *string `android:"path"` |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 434 | } |
| 435 | } |
Paul Duffin | 851f399 | 2021-01-13 17:03:51 +0000 | [diff] [blame] | 436 | } |
| 437 | |
Paul Duffin | c04fb9e | 2021-03-01 12:25:10 +0000 | [diff] [blame] | 438 | // prebuiltApexSelector selects the correct prebuilt APEX file for the build target. |
| 439 | // |
| 440 | // The ctx parameter can be for any module not just the prebuilt module so care must be taken not |
| 441 | // to use methods on it that are specific to the current module. |
| 442 | // |
| 443 | // See the ApexFileProperties.Src property. |
Spandan Das | e350e36 | 2024-09-21 01:49:34 +0000 | [diff] [blame^] | 444 | func (p *ApexFileProperties) prebuiltApexSelector(ctx android.BaseModuleContext, prebuilt android.Module) string { |
Paul Duffin | c04fb9e | 2021-03-01 12:25:10 +0000 | [diff] [blame] | 445 | multiTargets := prebuilt.MultiTargets() |
| 446 | if len(multiTargets) != 1 { |
| 447 | ctx.OtherModuleErrorf(prebuilt, "compile_multilib shouldn't be \"both\" for prebuilt_apex") |
Spandan Das | e350e36 | 2024-09-21 01:49:34 +0000 | [diff] [blame^] | 448 | return "" |
Paul Duffin | 851f399 | 2021-01-13 17:03:51 +0000 | [diff] [blame] | 449 | } |
| 450 | var src string |
Paul Duffin | c04fb9e | 2021-03-01 12:25:10 +0000 | [diff] [blame] | 451 | switch multiTargets[0].Arch.ArchType { |
Paul Duffin | 851f399 | 2021-01-13 17:03:51 +0000 | [diff] [blame] | 452 | case android.Arm: |
| 453 | src = String(p.Arch.Arm.Src) |
| 454 | case android.Arm64: |
| 455 | src = String(p.Arch.Arm64.Src) |
Chen Guoyin | 401f298 | 2022-10-12 19:28:48 +0800 | [diff] [blame] | 456 | case android.Riscv64: |
| 457 | src = String(p.Arch.Riscv64.Src) |
Colin Cross | abacbe8 | 2022-11-01 09:26:51 -0700 | [diff] [blame] | 458 | // HACK: fall back to arm64 prebuilts, the riscv64 ones don't exist yet. |
| 459 | if src == "" { |
| 460 | src = String(p.Arch.Arm64.Src) |
| 461 | } |
Paul Duffin | 851f399 | 2021-01-13 17:03:51 +0000 | [diff] [blame] | 462 | case android.X86: |
| 463 | src = String(p.Arch.X86.Src) |
| 464 | case android.X86_64: |
| 465 | src = String(p.Arch.X86_64.Src) |
Paul Duffin | 851f399 | 2021-01-13 17:03:51 +0000 | [diff] [blame] | 466 | } |
| 467 | if src == "" { |
Cole Faust | 642e720 | 2024-08-14 17:46:12 -0700 | [diff] [blame] | 468 | src = p.Src.GetOrDefault(ctx, "") |
Paul Duffin | 851f399 | 2021-01-13 17:03:51 +0000 | [diff] [blame] | 469 | } |
Paul Duffin | 851f399 | 2021-01-13 17:03:51 +0000 | [diff] [blame] | 470 | |
Paul Duffin | c0609c6 | 2021-03-01 17:27:16 +0000 | [diff] [blame] | 471 | if src == "" { |
Colin Cross | 553a31b | 2022-10-03 22:02:09 -0700 | [diff] [blame] | 472 | if ctx.Config().AllowMissingDependencies() { |
| 473 | ctx.AddMissingDependencies([]string{ctx.OtherModuleName(prebuilt)}) |
| 474 | } else { |
| 475 | ctx.OtherModuleErrorf(prebuilt, "prebuilt_apex does not support %q", multiTargets[0].Arch.String()) |
| 476 | } |
Paul Duffin | c0609c6 | 2021-03-01 17:27:16 +0000 | [diff] [blame] | 477 | // Drop through to return an empty string as the src (instead of nil) to avoid the prebuilt |
| 478 | // logic from reporting a more general, less useful message. |
| 479 | } |
| 480 | |
Spandan Das | e350e36 | 2024-09-21 01:49:34 +0000 | [diff] [blame^] | 481 | return src |
Paul Duffin | 851f399 | 2021-01-13 17:03:51 +0000 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | type PrebuiltProperties struct { |
| 485 | ApexFileProperties |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 486 | |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 487 | PrebuiltCommonProperties |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 488 | } |
| 489 | |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 490 | func (a *Prebuilt) hasSanitizedSource(sanitizer string) bool { |
| 491 | return false |
| 492 | } |
| 493 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 494 | // prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex. |
| 495 | func PrebuiltFactory() android.Module { |
| 496 | module := &Prebuilt{} |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 497 | module.AddProperties(&module.properties) |
Spandan Das | e350e36 | 2024-09-21 01:49:34 +0000 | [diff] [blame^] | 498 | module.prebuiltCommon.prebuiltCommonProperties = &module.properties.PrebuiltCommonProperties |
| 499 | |
| 500 | // init the module as a prebuilt |
| 501 | // even though this module type has srcs, use `InitPrebuiltModuleWithoutSrcs`, since the existing |
| 502 | // InitPrebuiltModule* are not friendly with Sources of Configurable type. |
| 503 | // The actual src will be evaluated in GenerateAndroidBuildActions. |
| 504 | android.InitPrebuiltModuleWithoutSrcs(module) |
| 505 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 506 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 507 | return module |
| 508 | } |
| 509 | |
Spandan Das | 52c01a1 | 2024-09-20 01:09:48 +0000 | [diff] [blame] | 510 | func (p *prebuiltCommon) getDeapexerPropertiesIfNeeded(ctx android.ModuleContext) DeapexerProperties { |
Paul Duffin | 57f8359 | 2021-05-05 15:09:44 +0100 | [diff] [blame] | 511 | // Compute the deapexer properties from the transitive dependencies of this module. |
Paul Duffin | b508405 | 2021-06-07 10:25:31 +0100 | [diff] [blame] | 512 | commonModules := []string{} |
Spandan Das | 2ea84dd | 2024-01-25 22:12:50 +0000 | [diff] [blame] | 513 | dexpreoptProfileGuidedModules := []string{} |
Paul Duffin | 034196d | 2021-06-17 15:59:07 +0100 | [diff] [blame] | 514 | exportedFiles := []string{} |
Paul Duffin | 57f8359 | 2021-05-05 15:09:44 +0100 | [diff] [blame] | 515 | ctx.WalkDeps(func(child, parent android.Module) bool { |
| 516 | tag := ctx.OtherModuleDependencyTag(child) |
| 517 | |
Paul Duffin | 7db57e0 | 2021-06-17 14:56:05 +0100 | [diff] [blame] | 518 | // If the child is not in the same apex as the parent then ignore it and all its children. |
| 519 | if !android.IsDepInSameApex(ctx, parent, child) { |
| 520 | return false |
| 521 | } |
| 522 | |
Spandan Das | 161e468 | 2024-01-19 00:22:22 +0000 | [diff] [blame] | 523 | name := java.ModuleStemForDeapexing(child) |
Paul Duffin | 7db57e0 | 2021-06-17 14:56:05 +0100 | [diff] [blame] | 524 | if _, ok := tag.(android.RequiresFilesFromPrebuiltApexTag); ok { |
Paul Duffin | b508405 | 2021-06-07 10:25:31 +0100 | [diff] [blame] | 525 | commonModules = append(commonModules, name) |
| 526 | |
Spandan Das | 2ea84dd | 2024-01-25 22:12:50 +0000 | [diff] [blame] | 527 | extract := child.(android.RequiredFilesFromPrebuiltApex) |
| 528 | requiredFiles := extract.RequiredFilesFromPrebuiltApex(ctx) |
Paul Duffin | 034196d | 2021-06-17 15:59:07 +0100 | [diff] [blame] | 529 | exportedFiles = append(exportedFiles, requiredFiles...) |
Paul Duffin | b508405 | 2021-06-07 10:25:31 +0100 | [diff] [blame] | 530 | |
Spandan Das | 2ea84dd | 2024-01-25 22:12:50 +0000 | [diff] [blame] | 531 | if extract.UseProfileGuidedDexpreopt() { |
| 532 | dexpreoptProfileGuidedModules = append(dexpreoptProfileGuidedModules, name) |
| 533 | } |
| 534 | |
Paul Duffin | 7db57e0 | 2021-06-17 14:56:05 +0100 | [diff] [blame] | 535 | // Visit the dependencies of this module just in case they also require files from the |
| 536 | // prebuilt apex. |
Paul Duffin | 57f8359 | 2021-05-05 15:09:44 +0100 | [diff] [blame] | 537 | return true |
| 538 | } |
| 539 | |
| 540 | return false |
| 541 | }) |
| 542 | |
Paul Duffin | 3bae068 | 2021-05-05 18:03:47 +0100 | [diff] [blame] | 543 | // Create properties for deapexer module. |
Spandan Das | 52c01a1 | 2024-09-20 01:09:48 +0000 | [diff] [blame] | 544 | deapexerProperties := DeapexerProperties{ |
Paul Duffin | b508405 | 2021-06-07 10:25:31 +0100 | [diff] [blame] | 545 | // Remove any duplicates from the common modules lists as a module may be included via a direct |
Paul Duffin | 3bae068 | 2021-05-05 18:03:47 +0100 | [diff] [blame] | 546 | // dependency as well as transitive ones. |
Spandan Das | 2ea84dd | 2024-01-25 22:12:50 +0000 | [diff] [blame] | 547 | CommonModules: android.SortedUniqueStrings(commonModules), |
| 548 | DexpreoptProfileGuidedModules: android.SortedUniqueStrings(dexpreoptProfileGuidedModules), |
Paul Duffin | 3bae068 | 2021-05-05 18:03:47 +0100 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | // Populate the exported files property in a fixed order. |
Paul Duffin | 034196d | 2021-06-17 15:59:07 +0100 | [diff] [blame] | 552 | deapexerProperties.ExportedFiles = android.SortedUniqueStrings(exportedFiles) |
Spandan Das | 52c01a1 | 2024-09-20 01:09:48 +0000 | [diff] [blame] | 553 | return deapexerProperties |
Paul Duffin | 11216db | 2021-03-01 14:14:52 +0000 | [diff] [blame] | 554 | } |
| 555 | |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 556 | func prebuiltApexExportedModuleName(ctx android.BottomUpMutatorContext, name string) string { |
| 557 | // The prebuilt_apex should be depending on prebuilt modules but as this runs after |
| 558 | // prebuilt_rename the prebuilt module may or may not be using the prebuilt_ prefixed named. So, |
| 559 | // check to see if the prefixed name is in use first, if it is then use that, otherwise assume |
| 560 | // the unprefixed name is the one to use. If the unprefixed one turns out to be a source module |
| 561 | // and not a renamed prebuilt module then that will be detected and reported as an error when |
| 562 | // processing the dependency in ApexInfoMutator(). |
Paul Duffin | 864116c | 2021-04-02 10:24:13 +0100 | [diff] [blame] | 563 | prebuiltName := android.PrebuiltNameFromSource(name) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 564 | if ctx.OtherModuleExists(prebuiltName) { |
| 565 | name = prebuiltName |
| 566 | } |
| 567 | return name |
| 568 | } |
| 569 | |
Paul Duffin | a713942 | 2021-02-08 11:01:58 +0000 | [diff] [blame] | 570 | type exportedDependencyTag struct { |
| 571 | blueprint.BaseDependencyTag |
| 572 | name string |
| 573 | } |
| 574 | |
| 575 | // Mark this tag so dependencies that use it are excluded from visibility enforcement. |
| 576 | // |
| 577 | // This does allow any prebuilt_apex to reference any module which does open up a small window for |
| 578 | // restricted visibility modules to be referenced from the wrong prebuilt_apex. However, doing so |
| 579 | // avoids opening up a much bigger window by widening the visibility of modules that need files |
| 580 | // provided by the prebuilt_apex to include all the possible locations they may be defined, which |
| 581 | // could include everything below vendor/. |
| 582 | // |
| 583 | // A prebuilt_apex that references a module via this tag will have to contain the appropriate files |
| 584 | // corresponding to that module, otherwise it will fail when attempting to retrieve the files from |
| 585 | // the .apex file. It will also have to be included in the module's apex_available property too. |
| 586 | // That makes it highly unlikely that a prebuilt_apex would reference a restricted module |
| 587 | // incorrectly. |
| 588 | func (t exportedDependencyTag) ExcludeFromVisibilityEnforcement() {} |
| 589 | |
Paul Duffin | 7db57e0 | 2021-06-17 14:56:05 +0100 | [diff] [blame] | 590 | func (t exportedDependencyTag) RequiresFilesFromPrebuiltApex() {} |
| 591 | |
| 592 | var _ android.RequiresFilesFromPrebuiltApexTag = exportedDependencyTag{} |
| 593 | |
Paul Duffin | a713942 | 2021-02-08 11:01:58 +0000 | [diff] [blame] | 594 | var ( |
Jiakai Zhang | 774dd30 | 2021-09-26 03:54:25 +0000 | [diff] [blame] | 595 | exportedBootclasspathFragmentTag = exportedDependencyTag{name: "exported_bootclasspath_fragments"} |
| 596 | exportedSystemserverclasspathFragmentTag = exportedDependencyTag{name: "exported_systemserverclasspath_fragments"} |
Paul Duffin | a713942 | 2021-02-08 11:01:58 +0000 | [diff] [blame] | 597 | ) |
| 598 | |
Paul Duffin | 57f8359 | 2021-05-05 15:09:44 +0100 | [diff] [blame] | 599 | func (p *Prebuilt) ComponentDepsMutator(ctx android.BottomUpMutatorContext) { |
| 600 | p.prebuiltApexContentsDeps(ctx) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | var _ ApexInfoMutator = (*Prebuilt)(nil) |
| 604 | |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 605 | func (p *Prebuilt) ApexInfoMutator(mctx android.TopDownMutatorContext) { |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 606 | p.apexInfoMutator(mctx) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 607 | } |
| 608 | |
Spandan Das | 52c01a1 | 2024-09-20 01:09:48 +0000 | [diff] [blame] | 609 | // creates the build rules to deapex the prebuilt, and returns a deapexerInfo |
Spandan Das | e350e36 | 2024-09-21 01:49:34 +0000 | [diff] [blame^] | 610 | func (p *prebuiltCommon) getDeapexerInfo(ctx android.ModuleContext, apexFile android.Path) *android.DeapexerInfo { |
Spandan Das | 52c01a1 | 2024-09-20 01:09:48 +0000 | [diff] [blame] | 611 | if !p.hasExportedDeps() { |
| 612 | // nothing to do |
| 613 | return nil |
| 614 | } |
Spandan Das | 52c01a1 | 2024-09-20 01:09:48 +0000 | [diff] [blame] | 615 | deapexerProps := p.getDeapexerPropertiesIfNeeded(ctx) |
| 616 | return deapex(ctx, apexFile, deapexerProps) |
| 617 | } |
| 618 | |
Spandan Das | da739a3 | 2023-12-13 00:06:32 +0000 | [diff] [blame] | 619 | // Set a provider containing information about the jars and .prof provided by the apex |
| 620 | // Apexes built from prebuilts retrieve this information by visiting its internal deapexer module |
| 621 | // Used by dex_bootjars to generate the boot image |
Spandan Das | 52c01a1 | 2024-09-20 01:09:48 +0000 | [diff] [blame] | 622 | func (p *prebuiltCommon) provideApexExportsInfo(ctx android.ModuleContext, di *android.DeapexerInfo) { |
| 623 | if di == nil { |
Spandan Das | da739a3 | 2023-12-13 00:06:32 +0000 | [diff] [blame] | 624 | return |
| 625 | } |
Spandan Das | 52c01a1 | 2024-09-20 01:09:48 +0000 | [diff] [blame] | 626 | javaModuleToDexPath := map[string]android.Path{} |
| 627 | for _, commonModule := range di.GetExportedModuleNames() { |
| 628 | if dex := di.PrebuiltExportPath(java.ApexRootRelativePathToJavaLib(commonModule)); dex != nil { |
| 629 | javaModuleToDexPath[commonModule] = dex |
Spandan Das | 5be6333 | 2023-12-13 00:06:32 +0000 | [diff] [blame] | 630 | } |
Spandan Das | da739a3 | 2023-12-13 00:06:32 +0000 | [diff] [blame] | 631 | } |
Spandan Das | 52c01a1 | 2024-09-20 01:09:48 +0000 | [diff] [blame] | 632 | |
| 633 | exports := android.ApexExportsInfo{ |
| 634 | ApexName: p.ApexVariationName(), |
| 635 | ProfilePathOnHost: di.PrebuiltExportPath(java.ProfileInstallPathInApex), |
| 636 | LibraryNameToDexJarPathOnHost: javaModuleToDexPath, |
| 637 | } |
| 638 | android.SetProvider(ctx, android.ApexExportsInfoProvider, exports) |
Spandan Das | da739a3 | 2023-12-13 00:06:32 +0000 | [diff] [blame] | 639 | } |
| 640 | |
Spandan Das | a747d2e | 2024-03-11 21:37:25 +0000 | [diff] [blame] | 641 | // Set prebuiltInfoProvider. This will be used by `apex_prebuiltinfo_singleton` to print out a metadata file |
| 642 | // with information about whether source or prebuilt of an apex was used during the build. |
| 643 | func (p *prebuiltCommon) providePrebuiltInfo(ctx android.ModuleContext) { |
Spandan Das | 3490dfd | 2024-03-11 21:37:25 +0000 | [diff] [blame] | 644 | info := android.PrebuiltInfo{ |
| 645 | Name: p.BaseModuleName(), |
Spandan Das | a747d2e | 2024-03-11 21:37:25 +0000 | [diff] [blame] | 646 | Is_prebuilt: true, |
| 647 | } |
| 648 | // If Prebuilt_info information is available in the soong module definition, add it to prebuilt_info.json. |
| 649 | if p.prebuiltCommonProperties.Prebuilt_info != nil { |
| 650 | info.Prebuilt_info_file_path = android.PathForModuleSrc(ctx, *p.prebuiltCommonProperties.Prebuilt_info).String() |
| 651 | } |
Spandan Das | 3490dfd | 2024-03-11 21:37:25 +0000 | [diff] [blame] | 652 | android.SetProvider(ctx, android.PrebuiltInfoProvider, info) |
Spandan Das | a747d2e | 2024-03-11 21:37:25 +0000 | [diff] [blame] | 653 | } |
| 654 | |
Spandan Das | 3d0d31a | 2024-05-03 21:36:48 +0000 | [diff] [blame] | 655 | // Uses an object provided by its deps to validate that the contents of bcpf have been added to the global |
| 656 | // PRODUCT_APEX_BOOT_JARS |
| 657 | // This validation will only run on the apex which is active for this product/release_config |
| 658 | func validateApexClasspathFragments(ctx android.ModuleContext) { |
| 659 | ctx.VisitDirectDeps(func(m android.Module) { |
| 660 | if info, exists := android.OtherModuleProvider(ctx, m, java.ClasspathFragmentValidationInfoProvider); exists { |
| 661 | ctx.ModuleErrorf("%s in contents of %s must also be declared in PRODUCT_APEX_BOOT_JARS", info.UnknownJars, info.ClasspathFragmentModuleName) |
| 662 | } |
| 663 | }) |
| 664 | } |
| 665 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 666 | func (p *Prebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Spandan Das | 3d0d31a | 2024-05-03 21:36:48 +0000 | [diff] [blame] | 667 | // Validate contents of classpath fragments |
Spandan Das | 5f1f940 | 2024-05-21 18:59:23 +0000 | [diff] [blame] | 668 | if !p.IsHideFromMake() { |
| 669 | validateApexClasspathFragments(ctx) |
| 670 | } |
Spandan Das | 3d0d31a | 2024-05-03 21:36:48 +0000 | [diff] [blame] | 671 | |
Jooyung Han | 286957d | 2023-10-30 16:17:56 +0900 | [diff] [blame] | 672 | p.apexKeysPath = writeApexKeys(ctx, p) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 673 | // TODO(jungjw): Check the key validity. |
Spandan Das | e350e36 | 2024-09-21 01:49:34 +0000 | [diff] [blame^] | 674 | p.inputApex = android.PathForModuleSrc(ctx, p.properties.prebuiltApexSelector(ctx, ctx.Module())) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 675 | p.installDir = android.PathForModuleInstall(ctx, "apex") |
| 676 | p.installFilename = p.InstallFilename() |
| 677 | if !strings.HasSuffix(p.installFilename, imageApexSuffix) { |
| 678 | ctx.ModuleErrorf("filename should end in %s for prebuilt_apex", imageApexSuffix) |
| 679 | } |
| 680 | p.outputApex = android.PathForModuleOut(ctx, p.installFilename) |
| 681 | ctx.Build(pctx, android.BuildParams{ |
| 682 | Rule: android.Cp, |
| 683 | Input: p.inputApex, |
| 684 | Output: p.outputApex, |
| 685 | }) |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 686 | |
| 687 | if p.prebuiltCommon.checkForceDisable(ctx) { |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 688 | p.HideFromMake() |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 689 | return |
| 690 | } |
| 691 | |
Spandan Das | e350e36 | 2024-09-21 01:49:34 +0000 | [diff] [blame^] | 692 | deapexerInfo := p.getDeapexerInfo(ctx, p.inputApex) |
Spandan Das | 52c01a1 | 2024-09-20 01:09:48 +0000 | [diff] [blame] | 693 | |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 694 | // dexpreopt any system server jars if present |
Spandan Das | 52c01a1 | 2024-09-20 01:09:48 +0000 | [diff] [blame] | 695 | p.dexpreoptSystemServerJars(ctx, deapexerInfo) |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 696 | |
Spandan Das | da739a3 | 2023-12-13 00:06:32 +0000 | [diff] [blame] | 697 | // provide info used for generating the boot image |
Spandan Das | 52c01a1 | 2024-09-20 01:09:48 +0000 | [diff] [blame] | 698 | p.provideApexExportsInfo(ctx, deapexerInfo) |
Spandan Das | da739a3 | 2023-12-13 00:06:32 +0000 | [diff] [blame] | 699 | |
Spandan Das | a747d2e | 2024-03-11 21:37:25 +0000 | [diff] [blame] | 700 | p.providePrebuiltInfo(ctx) |
| 701 | |
Paul Duffin | c30aea2 | 2021-06-15 19:10:11 +0100 | [diff] [blame] | 702 | // Save the files that need to be made available to Make. |
| 703 | p.initApexFilesForAndroidMk(ctx) |
| 704 | |
Colin Cross | ccba23d | 2021-11-12 19:01:29 +0000 | [diff] [blame] | 705 | // in case that prebuilt_apex replaces source apex (using prefer: prop) |
Jooyung Han | 06a8a1c | 2023-08-23 11:11:43 +0900 | [diff] [blame] | 706 | p.compatSymlinks = makeCompatSymlinks(p.BaseModuleName(), ctx) |
Colin Cross | ccba23d | 2021-11-12 19:01:29 +0000 | [diff] [blame] | 707 | // or that prebuilt_apex overrides other apexes (using overrides: prop) |
| 708 | for _, overridden := range p.prebuiltCommonProperties.Overrides { |
Jooyung Han | 06a8a1c | 2023-08-23 11:11:43 +0900 | [diff] [blame] | 709 | p.compatSymlinks = append(p.compatSymlinks, makeCompatSymlinks(overridden, ctx)...) |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | if p.installable() { |
Colin Cross | 09ad3a6 | 2023-11-15 12:29:33 -0800 | [diff] [blame] | 713 | p.installedFile = ctx.InstallFile(p.installDir, p.installFilename, p.inputApex, p.compatSymlinks...) |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 714 | p.provenanceMetaDataFile = provenance.GenerateArtifactProvenanceMetaData(ctx, p.inputApex, p.installedFile) |
Jooyung Han | 002ab68 | 2020-01-08 01:57:58 +0900 | [diff] [blame] | 715 | } |
mrziwang | 1587b9c | 2024-06-13 11:26:04 -0700 | [diff] [blame] | 716 | |
| 717 | ctx.SetOutputFiles(android.Paths{p.outputApex}, "") |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 718 | } |
| 719 | |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 720 | func (p *Prebuilt) ProvenanceMetaDataFile() android.OutputPath { |
| 721 | return p.provenanceMetaDataFile |
| 722 | } |
| 723 | |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 724 | // prebuiltApexExtractorModule is a private module type that is only created by the prebuilt_apex |
| 725 | // module. It extracts the correct apex to use and makes it available for use by apex_set. |
| 726 | type prebuiltApexExtractorModule struct { |
| 727 | android.ModuleBase |
| 728 | |
| 729 | properties ApexExtractorProperties |
| 730 | |
| 731 | extractedApex android.WritablePath |
| 732 | } |
| 733 | |
| 734 | func privateApexExtractorModuleFactory() android.Module { |
| 735 | module := &prebuiltApexExtractorModule{} |
| 736 | module.AddProperties( |
| 737 | &module.properties, |
| 738 | ) |
| 739 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 740 | return module |
| 741 | } |
| 742 | |
| 743 | func (p *prebuiltApexExtractorModule) Srcs() android.Paths { |
| 744 | return android.Paths{p.extractedApex} |
| 745 | } |
| 746 | |
| 747 | func (p *prebuiltApexExtractorModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 748 | srcsSupplier := func(ctx android.BaseModuleContext, prebuilt android.Module) []string { |
| 749 | return p.properties.prebuiltSrcs(ctx) |
| 750 | } |
Paul Duffin | 76fdd67 | 2022-12-12 18:00:47 +0000 | [diff] [blame] | 751 | defaultAllowPrerelease := ctx.Config().IsEnvTrue("SOONG_ALLOW_PRERELEASE_APEXES") |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 752 | apexSet := android.SingleSourcePathFromSupplier(ctx, srcsSupplier, "set") |
| 753 | p.extractedApex = android.PathForModuleOut(ctx, "extracted", apexSet.Base()) |
Anton Hansson | 805e0a5 | 2022-11-25 14:06:46 +0000 | [diff] [blame] | 754 | // Filter out NativeBridge archs (b/260115309) |
| 755 | abis := java.SupportedAbis(ctx, true) |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 756 | ctx.Build(pctx, |
| 757 | android.BuildParams{ |
| 758 | Rule: extractMatchingApex, |
| 759 | Description: "Extract an apex from an apex set", |
| 760 | Inputs: android.Paths{apexSet}, |
| 761 | Output: p.extractedApex, |
| 762 | Args: map[string]string{ |
Anton Hansson | 805e0a5 | 2022-11-25 14:06:46 +0000 | [diff] [blame] | 763 | "abis": strings.Join(abis, ","), |
Paul Duffin | 76fdd67 | 2022-12-12 18:00:47 +0000 | [diff] [blame] | 764 | "allow-prereleased": strconv.FormatBool(proptools.BoolDefault(p.properties.Prerelease, defaultAllowPrerelease)), |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 765 | "sdk-version": ctx.Config().PlatformSdkVersion().String(), |
Pranav Gupta | 51645ff | 2023-03-20 16:19:53 -0700 | [diff] [blame] | 766 | "skip-sdk-check": strconv.FormatBool(ctx.Config().IsEnvTrue("SOONG_SKIP_APPSET_SDK_CHECK")), |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 767 | }, |
| 768 | }) |
| 769 | } |
| 770 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 771 | type ApexSet struct { |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 772 | prebuiltCommon |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 773 | |
| 774 | properties ApexSetProperties |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 775 | } |
| 776 | |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 777 | type ApexExtractorProperties struct { |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 778 | // the .apks file path that contains prebuilt apex files to be extracted. |
Pranav Gupta | eba03b0 | 2022-09-27 00:27:08 +0000 | [diff] [blame] | 779 | Set *string `android:"path"` |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 780 | |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 781 | Sanitized struct { |
| 782 | None struct { |
Pranav Gupta | eba03b0 | 2022-09-27 00:27:08 +0000 | [diff] [blame] | 783 | Set *string `android:"path"` |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 784 | } |
| 785 | Address struct { |
Pranav Gupta | eba03b0 | 2022-09-27 00:27:08 +0000 | [diff] [blame] | 786 | Set *string `android:"path"` |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 787 | } |
| 788 | Hwaddress struct { |
Pranav Gupta | eba03b0 | 2022-09-27 00:27:08 +0000 | [diff] [blame] | 789 | Set *string `android:"path"` |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 790 | } |
| 791 | } |
| 792 | |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 793 | // apexes in this set use prerelease SDK version |
| 794 | Prerelease *bool |
| 795 | } |
| 796 | |
| 797 | func (e *ApexExtractorProperties) prebuiltSrcs(ctx android.BaseModuleContext) []string { |
| 798 | var srcs []string |
| 799 | if e.Set != nil { |
| 800 | srcs = append(srcs, *e.Set) |
| 801 | } |
| 802 | |
Jooyung Han | 8d4a1f0 | 2023-08-23 13:54:08 +0900 | [diff] [blame] | 803 | sanitizers := ctx.Config().SanitizeDevice() |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 804 | |
| 805 | if android.InList("address", sanitizers) && e.Sanitized.Address.Set != nil { |
| 806 | srcs = append(srcs, *e.Sanitized.Address.Set) |
| 807 | } else if android.InList("hwaddress", sanitizers) && e.Sanitized.Hwaddress.Set != nil { |
| 808 | srcs = append(srcs, *e.Sanitized.Hwaddress.Set) |
| 809 | } else if e.Sanitized.None.Set != nil { |
| 810 | srcs = append(srcs, *e.Sanitized.None.Set) |
| 811 | } |
| 812 | |
| 813 | return srcs |
| 814 | } |
| 815 | |
| 816 | type ApexSetProperties struct { |
| 817 | ApexExtractorProperties |
| 818 | |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 819 | PrebuiltCommonProperties |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | func (a *ApexSet) hasSanitizedSource(sanitizer string) bool { |
| 823 | if sanitizer == "address" { |
| 824 | return a.properties.Sanitized.Address.Set != nil |
| 825 | } |
| 826 | if sanitizer == "hwaddress" { |
| 827 | return a.properties.Sanitized.Hwaddress.Set != nil |
| 828 | } |
| 829 | |
| 830 | return false |
| 831 | } |
| 832 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 833 | // prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex. |
| 834 | func apexSetFactory() android.Module { |
| 835 | module := &ApexSet{} |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 836 | module.AddProperties(&module.properties) |
| 837 | module.initPrebuiltCommon(module, &module.properties.PrebuiltCommonProperties) |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 838 | |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 839 | return module |
| 840 | } |
| 841 | |
Colin Cross | da279cf | 2024-09-17 14:25:45 -0700 | [diff] [blame] | 842 | func createApexExtractorModule(ctx android.BottomUpMutatorContext, name string, apexExtractorProperties *ApexExtractorProperties) { |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 843 | props := struct { |
| 844 | Name *string |
| 845 | }{ |
| 846 | Name: proptools.StringPtr(name), |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 847 | } |
| 848 | |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 849 | ctx.CreateModule(privateApexExtractorModuleFactory, |
| 850 | &props, |
| 851 | apexExtractorProperties, |
| 852 | ) |
| 853 | } |
| 854 | |
| 855 | func apexExtractorModuleName(baseModuleName string) string { |
| 856 | return baseModuleName + ".apex.extractor" |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 857 | } |
| 858 | |
Paul Duffin | 5dda3e3 | 2021-05-05 14:13:27 +0100 | [diff] [blame] | 859 | var _ prebuiltApexModuleCreator = (*ApexSet)(nil) |
| 860 | |
| 861 | // createPrebuiltApexModules creates modules necessary to export files from the apex set to other |
| 862 | // modules. |
| 863 | // |
| 864 | // This effectively does for apex_set what Prebuilt.createPrebuiltApexModules does for a |
| 865 | // prebuilt_apex except that instead of creating a selector module which selects one .apex file |
| 866 | // from those provided this creates an extractor module which extracts the appropriate .apex file |
| 867 | // from the zip file containing them. |
Colin Cross | da279cf | 2024-09-17 14:25:45 -0700 | [diff] [blame] | 868 | func (a *ApexSet) createPrebuiltApexModules(ctx android.BottomUpMutatorContext) { |
Spandan Das | 3576e76 | 2024-01-03 18:57:03 +0000 | [diff] [blame] | 869 | apexExtractorModuleName := apexExtractorModuleName(a.Name()) |
Paul Duffin | 5dda3e3 | 2021-05-05 14:13:27 +0100 | [diff] [blame] | 870 | createApexExtractorModule(ctx, apexExtractorModuleName, &a.properties.ApexExtractorProperties) |
| 871 | |
| 872 | apexFileSource := ":" + apexExtractorModuleName |
Paul Duffin | 5dda3e3 | 2021-05-05 14:13:27 +0100 | [diff] [blame] | 873 | |
| 874 | // After passing the arch specific src properties to the creating the apex selector module |
Paul Duffin | bb0dc13 | 2021-05-05 16:58:08 +0100 | [diff] [blame] | 875 | a.prebuiltCommonProperties.Selected_apex = proptools.StringPtr(apexFileSource) |
Paul Duffin | 5dda3e3 | 2021-05-05 14:13:27 +0100 | [diff] [blame] | 876 | } |
| 877 | |
Paul Duffin | 57f8359 | 2021-05-05 15:09:44 +0100 | [diff] [blame] | 878 | func (a *ApexSet) ComponentDepsMutator(ctx android.BottomUpMutatorContext) { |
| 879 | a.prebuiltApexContentsDeps(ctx) |
Paul Duffin | f58fd9a | 2021-04-06 16:00:22 +0100 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | var _ ApexInfoMutator = (*ApexSet)(nil) |
| 883 | |
| 884 | func (a *ApexSet) ApexInfoMutator(mctx android.TopDownMutatorContext) { |
| 885 | a.apexInfoMutator(mctx) |
| 886 | } |
| 887 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 888 | func (a *ApexSet) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Spandan Das | 3d0d31a | 2024-05-03 21:36:48 +0000 | [diff] [blame] | 889 | // Validate contents of classpath fragments |
Spandan Das | 5f1f940 | 2024-05-21 18:59:23 +0000 | [diff] [blame] | 890 | if !a.IsHideFromMake() { |
| 891 | validateApexClasspathFragments(ctx) |
| 892 | } |
Spandan Das | 3d0d31a | 2024-05-03 21:36:48 +0000 | [diff] [blame] | 893 | |
Jooyung Han | 286957d | 2023-10-30 16:17:56 +0900 | [diff] [blame] | 894 | a.apexKeysPath = writeApexKeys(ctx, a) |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 895 | a.installFilename = a.InstallFilename() |
Samiul Islam | 7c02e26 | 2021-09-08 17:48:28 +0100 | [diff] [blame] | 896 | if !strings.HasSuffix(a.installFilename, imageApexSuffix) && !strings.HasSuffix(a.installFilename, imageCapexSuffix) { |
| 897 | ctx.ModuleErrorf("filename should end in %s or %s for apex_set", imageApexSuffix, imageCapexSuffix) |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 898 | } |
| 899 | |
Paul Duffin | bb0dc13 | 2021-05-05 16:58:08 +0100 | [diff] [blame] | 900 | inputApex := android.OptionalPathForModuleSrc(ctx, a.prebuiltCommonProperties.Selected_apex).Path() |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 901 | a.outputApex = android.PathForModuleOut(ctx, a.installFilename) |
Jooyung Han | 26ec848 | 2024-07-31 15:04:05 +0900 | [diff] [blame] | 902 | |
| 903 | // Build the output APEX. If compression is not enabled, make sure the output is not compressed even if the input is compressed |
| 904 | buildRule := android.Cp |
| 905 | if !ctx.Config().ApexCompressionEnabled() { |
| 906 | buildRule = decompressApex |
| 907 | } |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 908 | ctx.Build(pctx, android.BuildParams{ |
Jooyung Han | 26ec848 | 2024-07-31 15:04:05 +0900 | [diff] [blame] | 909 | Rule: buildRule, |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 910 | Input: inputApex, |
| 911 | Output: a.outputApex, |
| 912 | }) |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 913 | |
| 914 | if a.prebuiltCommon.checkForceDisable(ctx) { |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 915 | a.HideFromMake() |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 916 | return |
| 917 | } |
| 918 | |
Spandan Das | e350e36 | 2024-09-21 01:49:34 +0000 | [diff] [blame^] | 919 | deapexerInfo := a.getDeapexerInfo(ctx, inputApex) |
Spandan Das | 52c01a1 | 2024-09-20 01:09:48 +0000 | [diff] [blame] | 920 | |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 921 | // dexpreopt any system server jars if present |
Spandan Das | 52c01a1 | 2024-09-20 01:09:48 +0000 | [diff] [blame] | 922 | a.dexpreoptSystemServerJars(ctx, deapexerInfo) |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 923 | |
Spandan Das | da739a3 | 2023-12-13 00:06:32 +0000 | [diff] [blame] | 924 | // provide info used for generating the boot image |
Spandan Das | 52c01a1 | 2024-09-20 01:09:48 +0000 | [diff] [blame] | 925 | a.provideApexExportsInfo(ctx, deapexerInfo) |
Spandan Das | da739a3 | 2023-12-13 00:06:32 +0000 | [diff] [blame] | 926 | |
Spandan Das | a747d2e | 2024-03-11 21:37:25 +0000 | [diff] [blame] | 927 | a.providePrebuiltInfo(ctx) |
| 928 | |
Paul Duffin | c30aea2 | 2021-06-15 19:10:11 +0100 | [diff] [blame] | 929 | // Save the files that need to be made available to Make. |
| 930 | a.initApexFilesForAndroidMk(ctx) |
| 931 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 932 | a.installDir = android.PathForModuleInstall(ctx, "apex") |
| 933 | if a.installable() { |
Colin Cross | 730e3f6 | 2021-12-08 21:09:04 -0800 | [diff] [blame] | 934 | a.installedFile = ctx.InstallFile(a.installDir, a.installFilename, a.outputApex) |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | // in case that apex_set replaces source apex (using prefer: prop) |
Jooyung Han | 06a8a1c | 2023-08-23 11:11:43 +0900 | [diff] [blame] | 938 | a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx) |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 939 | // or that apex_set overrides other apexes (using overrides: prop) |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 940 | for _, overridden := range a.prebuiltCommonProperties.Overrides { |
Jooyung Han | 06a8a1c | 2023-08-23 11:11:43 +0900 | [diff] [blame] | 941 | a.compatSymlinks = append(a.compatSymlinks, makeCompatSymlinks(overridden, ctx)...) |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 942 | } |
mrziwang | 1587b9c | 2024-06-13 11:26:04 -0700 | [diff] [blame] | 943 | |
| 944 | ctx.SetOutputFiles(android.Paths{a.outputApex}, "") |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 945 | } |
| 946 | |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 947 | type systemExtContext struct { |
| 948 | android.ModuleContext |
| 949 | } |
| 950 | |
| 951 | func (*systemExtContext) SystemExtSpecific() bool { |
| 952 | return true |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 953 | } |