Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 1 | // Copyright 2018 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package java |
| 16 | |
| 17 | import ( |
Jiakai Zhang | ca9bc98 | 2021-09-09 08:09:41 +0000 | [diff] [blame] | 18 | "path/filepath" |
Jiakai Zhang | 51b2a8b | 2023-06-26 16:47:38 +0100 | [diff] [blame] | 19 | "sort" |
Jiakai Zhang | ca9bc98 | 2021-09-09 08:09:41 +0000 | [diff] [blame] | 20 | "strings" |
| 21 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 22 | "android/soong/android" |
| 23 | "android/soong/dexpreopt" |
| 24 | ) |
| 25 | |
Jiakai Zhang | ca9bc98 | 2021-09-09 08:09:41 +0000 | [diff] [blame] | 26 | type DexpreopterInterface interface { |
Jiakai Zhang | 81e4681 | 2023-02-08 21:56:07 +0800 | [diff] [blame] | 27 | // True if the java module is to be dexed and installed on devices. |
| 28 | // Structs that embed dexpreopter must implement this. |
| 29 | IsInstallable() bool |
| 30 | |
| 31 | // True if dexpreopt is disabled for the java module. |
Spandan Das | e21a8d4 | 2024-01-23 23:56:29 +0000 | [diff] [blame] | 32 | dexpreoptDisabled(ctx android.BaseModuleContext, libraryName string) bool |
Jiakai Zhang | 81e4681 | 2023-02-08 21:56:07 +0800 | [diff] [blame] | 33 | |
| 34 | // If the java module is to be installed into an APEX, this list contains information about the |
| 35 | // dexpreopt outputs to be installed on devices. Note that these dexpreopt outputs are installed |
| 36 | // outside of the APEX. |
Jiakai Zhang | ca9bc98 | 2021-09-09 08:09:41 +0000 | [diff] [blame] | 37 | DexpreoptBuiltInstalledForApex() []dexpreopterInstall |
Jiakai Zhang | 81e4681 | 2023-02-08 21:56:07 +0800 | [diff] [blame] | 38 | |
| 39 | // The Make entries to install the dexpreopt outputs. Derived from |
| 40 | // `DexpreoptBuiltInstalledForApex`. |
Jiakai Zhang | ca9bc98 | 2021-09-09 08:09:41 +0000 | [diff] [blame] | 41 | AndroidMkEntriesForApex() []android.AndroidMkEntries |
Jiakai Zhang | 81e4681 | 2023-02-08 21:56:07 +0800 | [diff] [blame] | 42 | |
| 43 | // See `dexpreopter.outputProfilePathOnHost`. |
| 44 | OutputProfilePathOnHost() android.Path |
Jiakai Zhang | ca9bc98 | 2021-09-09 08:09:41 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | type dexpreopterInstall struct { |
| 48 | // A unique name to distinguish an output from others for the same java library module. Usually in |
| 49 | // the form of `<arch>-<encoded-path>.odex/vdex/art`. |
| 50 | name string |
| 51 | |
| 52 | // The name of the input java module. |
| 53 | moduleName string |
| 54 | |
| 55 | // The path to the dexpreopt output on host. |
| 56 | outputPathOnHost android.Path |
| 57 | |
| 58 | // The directory on the device for the output to install to. |
| 59 | installDirOnDevice android.InstallPath |
| 60 | |
| 61 | // The basename (the last segment of the path) for the output to install as. |
| 62 | installFileOnDevice string |
| 63 | } |
| 64 | |
| 65 | // The full module name of the output in the makefile. |
| 66 | func (install *dexpreopterInstall) FullModuleName() string { |
| 67 | return install.moduleName + install.SubModuleName() |
| 68 | } |
| 69 | |
| 70 | // The sub-module name of the output in the makefile (the name excluding the java module name). |
| 71 | func (install *dexpreopterInstall) SubModuleName() string { |
| 72 | return "-dexpreopt-" + install.name |
Martin Stjernholm | 6d41527 | 2020-01-31 17:10:36 +0000 | [diff] [blame] | 73 | } |
| 74 | |
Jiakai Zhang | 6decef9 | 2022-01-12 17:56:19 +0000 | [diff] [blame] | 75 | // Returns Make entries for installing the file. |
| 76 | // |
| 77 | // This function uses a value receiver rather than a pointer receiver to ensure that the object is |
| 78 | // safe to use in `android.AndroidMkExtraEntriesFunc`. |
| 79 | func (install dexpreopterInstall) ToMakeEntries() android.AndroidMkEntries { |
| 80 | return android.AndroidMkEntries{ |
| 81 | Class: "ETC", |
Jiakai Zhang | 6decef9 | 2022-01-12 17:56:19 +0000 | [diff] [blame] | 82 | OutputFile: android.OptionalPathForPath(install.outputPathOnHost), |
| 83 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ |
| 84 | func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 85 | entries.SetString("LOCAL_MODULE", install.FullModuleName()) |
Jiakai Zhang | 6decef9 | 2022-01-12 17:56:19 +0000 | [diff] [blame] | 86 | entries.SetString("LOCAL_MODULE_PATH", install.installDirOnDevice.String()) |
| 87 | entries.SetString("LOCAL_INSTALLED_MODULE_STEM", install.installFileOnDevice) |
| 88 | entries.SetString("LOCAL_NOT_AVAILABLE_FOR_PLATFORM", "false") |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 89 | // Unset LOCAL_SOONG_INSTALLED_MODULE so that this does not default to the primary .apex file |
| 90 | // Without this, installation of the dexpreopt artifacts get skipped |
| 91 | entries.SetString("LOCAL_SOONG_INSTALLED_MODULE", "") |
Jiakai Zhang | 6decef9 | 2022-01-12 17:56:19 +0000 | [diff] [blame] | 92 | }, |
| 93 | }, |
| 94 | } |
| 95 | } |
| 96 | |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 97 | type Dexpreopter struct { |
| 98 | dexpreopter |
| 99 | } |
| 100 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 101 | type dexpreopter struct { |
Jiakai Zhang | 9c4dc19 | 2023-02-09 00:09:24 +0800 | [diff] [blame] | 102 | dexpreoptProperties DexpreoptProperties |
| 103 | importDexpreoptProperties ImportDexpreoptProperties |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 104 | |
Spandan Das | 0727ba7 | 2024-02-13 16:37:43 +0000 | [diff] [blame] | 105 | // If true, the dexpreopt rules will not be generated |
| 106 | // Unlike Dex_preopt.Enabled which is user-facing, |
| 107 | // shouldDisableDexpreopt is a mutated propery. |
| 108 | shouldDisableDexpreopt bool |
| 109 | |
Colin Cross | 70dda7e | 2019-10-01 22:05:35 -0700 | [diff] [blame] | 110 | installPath android.InstallPath |
Jaewoong Jung | ccbb393 | 2019-04-15 09:48:31 -0700 | [diff] [blame] | 111 | uncompressedDex bool |
| 112 | isSDKLibrary bool |
Ulya Trafimovich | 76b0852 | 2021-01-14 17:52:43 +0000 | [diff] [blame] | 113 | isApp bool |
Jaewoong Jung | ccbb393 | 2019-04-15 09:48:31 -0700 | [diff] [blame] | 114 | isTest bool |
Jaewoong Jung | ccbb393 | 2019-04-15 09:48:31 -0700 | [diff] [blame] | 115 | isPresignedPrebuilt bool |
Colin Cross | fa9bfcd | 2021-11-10 16:42:38 -0800 | [diff] [blame] | 116 | preventInstall bool |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 117 | |
Ulya Trafimovich | 8cbc5d2 | 2020-11-03 15:15:46 +0000 | [diff] [blame] | 118 | manifestFile android.Path |
Ulya Trafimovich | 8c35fcf | 2021-02-17 16:23:28 +0000 | [diff] [blame] | 119 | statusFile android.WritablePath |
Ulya Trafimovich | 8cbc5d2 | 2020-11-03 15:15:46 +0000 | [diff] [blame] | 120 | enforceUsesLibs bool |
| 121 | classLoaderContexts dexpreopt.ClassLoaderContextMap |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 122 | |
Jiakai Zhang | ca9bc98 | 2021-09-09 08:09:41 +0000 | [diff] [blame] | 123 | // See the `dexpreopt` function for details. |
| 124 | builtInstalled string |
| 125 | builtInstalledForApex []dexpreopterInstall |
Ulya Trafimovich | 76b0852 | 2021-01-14 17:52:43 +0000 | [diff] [blame] | 126 | |
Jeongik Cha | c624667 | 2021-04-08 00:00:19 +0900 | [diff] [blame] | 127 | // The config is used for two purposes: |
| 128 | // - Passing dexpreopt information about libraries from Soong to Make. This is needed when |
| 129 | // a <uses-library> is defined in Android.bp, but used in Android.mk (see dex_preopt_config_merger.py). |
| 130 | // Note that dexpreopt.config might be needed even if dexpreopt is disabled for the library itself. |
| 131 | // - Dexpreopt post-processing (using dexpreopt artifacts from a prebuilt system image to incrementally |
| 132 | // dexpreopt another partition). |
Ulya Trafimovich | 76b0852 | 2021-01-14 17:52:43 +0000 | [diff] [blame] | 133 | configPath android.WritablePath |
Jiakai Zhang | 3317ce7 | 2023-02-08 01:19:19 +0800 | [diff] [blame] | 134 | |
Jiakai Zhang | 81e4681 | 2023-02-08 21:56:07 +0800 | [diff] [blame] | 135 | // The path to the profile on host that dexpreopter generates. This is used as the input for |
| 136 | // dex2oat. |
| 137 | outputProfilePathOnHost android.Path |
| 138 | |
| 139 | // The path to the profile that dexpreopter accepts. It must be in the binary format. If this is |
| 140 | // set, it overrides the profile settings in `dexpreoptProperties`. |
| 141 | inputProfilePathOnHost android.Path |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | type DexpreoptProperties struct { |
| 145 | Dex_preopt struct { |
Nicolas Geoffray | c1bf724 | 2019-10-18 14:51:38 +0100 | [diff] [blame] | 146 | // If false, prevent dexpreopting. Defaults to true. |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 147 | Enabled *bool |
| 148 | |
| 149 | // If true, generate an app image (.art file) for this module. |
| 150 | App_image *bool |
| 151 | |
| 152 | // If true, use a checked-in profile to guide optimization. Defaults to false unless |
| 153 | // a matching profile is set or a profile is found in PRODUCT_DEX_PREOPT_PROFILE_DIR |
| 154 | // that matches the name of this module, in which case it is defaulted to true. |
| 155 | Profile_guided *bool |
| 156 | |
| 157 | // If set, provides the path to profile relative to the Android.bp file. If not set, |
| 158 | // defaults to searching for a file that matches the name of this module in the default |
| 159 | // profile location set by PRODUCT_DEX_PREOPT_PROFILE_DIR, or empty if not found. |
Colin Cross | de4e4e6 | 2019-04-26 10:52:32 -0700 | [diff] [blame] | 160 | Profile *string `android:"path"` |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 161 | } |
Jiakai Zhang | 9c4dc19 | 2023-02-09 00:09:24 +0800 | [diff] [blame] | 162 | |
| 163 | Dex_preopt_result struct { |
| 164 | // True if profile-guided optimization is actually enabled. |
| 165 | Profile_guided bool |
| 166 | } `blueprint:"mutated"` |
| 167 | } |
| 168 | |
| 169 | type ImportDexpreoptProperties struct { |
| 170 | Dex_preopt struct { |
| 171 | // If true, use the profile in the prebuilt APEX to guide optimization. Defaults to false. |
| 172 | Profile_guided *bool |
| 173 | } |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 174 | } |
| 175 | |
Ulya Trafimovich | 6cf2c0c | 2020-04-24 12:15:20 +0100 | [diff] [blame] | 176 | func init() { |
| 177 | dexpreopt.DexpreoptRunningInSoong = true |
| 178 | } |
| 179 | |
Jiakai Zhang | ca9bc98 | 2021-09-09 08:09:41 +0000 | [diff] [blame] | 180 | func isApexVariant(ctx android.BaseModuleContext) bool { |
Colin Cross | ff694a8 | 2023-12-13 15:54:49 -0800 | [diff] [blame] | 181 | apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider) |
Jiakai Zhang | ca9bc98 | 2021-09-09 08:09:41 +0000 | [diff] [blame] | 182 | return !apexInfo.IsForPlatform() |
| 183 | } |
| 184 | |
Jiakai Zhang | 28bc9a8 | 2021-12-20 15:08:57 +0000 | [diff] [blame] | 185 | func forPrebuiltApex(ctx android.BaseModuleContext) bool { |
Colin Cross | ff694a8 | 2023-12-13 15:54:49 -0800 | [diff] [blame] | 186 | apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider) |
Jiakai Zhang | 28bc9a8 | 2021-12-20 15:08:57 +0000 | [diff] [blame] | 187 | return apexInfo.ForPrebuiltApex |
| 188 | } |
| 189 | |
Spandan Das | a8afdcb | 2024-02-29 06:40:16 +0000 | [diff] [blame^] | 190 | // For apex variant of modules, this returns true on the source variant if the prebuilt apex |
| 191 | // has been selected using apex_contributions. |
| 192 | // The prebuilt apex will be responsible for generating the dexpreopt rules of the deapexed java lib. |
| 193 | func disableSourceApexVariant(ctx android.BaseModuleContext) bool { |
| 194 | if !isApexVariant(ctx) { |
| 195 | return false // platform variant |
| 196 | } |
| 197 | apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider) |
| 198 | psi := android.PrebuiltSelectionInfoMap{} |
| 199 | ctx.VisitDirectDepsWithTag(android.PrebuiltDepTag, func(am android.Module) { |
| 200 | psi, _ = android.OtherModuleProvider(ctx, am, android.PrebuiltSelectionInfoProvider) |
| 201 | }) |
| 202 | // Find the apex variant for this module |
| 203 | _, apexVariantsWithoutTestApexes, _ := android.ListSetDifference(apexInfo.InApexVariants, apexInfo.TestApexes) |
| 204 | disableSource := false |
| 205 | // find the selected apexes |
| 206 | for _, apexVariant := range apexVariantsWithoutTestApexes { |
| 207 | for _, selected := range psi.GetSelectedModulesForApiDomain(apexVariant) { |
| 208 | // If the apex_contribution for this api domain contains a prebuilt apex, disable the source variant |
| 209 | if strings.HasPrefix(selected, "prebuilt_com.google.android") { |
| 210 | disableSource = true |
| 211 | } |
| 212 | } |
| 213 | } |
| 214 | return disableSource |
| 215 | } |
| 216 | |
Jiakai Zhang | cf61e3c | 2023-05-08 16:28:38 +0000 | [diff] [blame] | 217 | // Returns whether dexpreopt is applicable to the module. |
| 218 | // When it returns true, neither profile nor dexpreopt artifacts will be generated. |
Spandan Das | e21a8d4 | 2024-01-23 23:56:29 +0000 | [diff] [blame] | 219 | func (d *dexpreopter) dexpreoptDisabled(ctx android.BaseModuleContext, libName string) bool { |
Colin Cross | 38310bb | 2021-12-01 10:34:14 -0800 | [diff] [blame] | 220 | if !ctx.Device() { |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 221 | return true |
| 222 | } |
| 223 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 224 | if d.isTest { |
| 225 | return true |
| 226 | } |
| 227 | |
| 228 | if !BoolDefault(d.dexpreoptProperties.Dex_preopt.Enabled, true) { |
| 229 | return true |
| 230 | } |
| 231 | |
Spandan Das | 0727ba7 | 2024-02-13 16:37:43 +0000 | [diff] [blame] | 232 | if d.shouldDisableDexpreopt { |
| 233 | return true |
| 234 | } |
| 235 | |
Jiakai Zhang | 28bc9a8 | 2021-12-20 15:08:57 +0000 | [diff] [blame] | 236 | // If the module is from a prebuilt APEX, it shouldn't be installable, but it can still be |
| 237 | // dexpreopted. |
| 238 | if !ctx.Module().(DexpreopterInterface).IsInstallable() && !forPrebuiltApex(ctx) { |
Martin Stjernholm | 6d41527 | 2020-01-31 17:10:36 +0000 | [diff] [blame] | 239 | return true |
| 240 | } |
| 241 | |
Colin Cross | 38310bb | 2021-12-01 10:34:14 -0800 | [diff] [blame] | 242 | if !android.IsModulePreferred(ctx.Module()) { |
| 243 | return true |
| 244 | } |
| 245 | |
Spandan Das | a8afdcb | 2024-02-29 06:40:16 +0000 | [diff] [blame^] | 246 | if disableSourceApexVariant(ctx) { |
| 247 | return true |
| 248 | } |
| 249 | |
Spandan Das | e21a8d4 | 2024-01-23 23:56:29 +0000 | [diff] [blame] | 250 | if _, isApex := android.ModuleProvider(ctx, android.ApexBundleInfoProvider); isApex { |
| 251 | // dexpreopt rules for system server jars can be generated in the ModuleCtx of prebuilt apexes |
| 252 | return false |
| 253 | } |
| 254 | |
Colin Cross | 38310bb | 2021-12-01 10:34:14 -0800 | [diff] [blame] | 255 | global := dexpreopt.GetGlobalConfig(ctx) |
| 256 | |
Spandan Das | e21a8d4 | 2024-01-23 23:56:29 +0000 | [diff] [blame] | 257 | // Use the libName argument to determine if the library being dexpreopt'd is a system server jar |
| 258 | // ctx.ModuleName() is not safe. In case of prebuilt apexes, the dexpreopt rules of system server jars |
| 259 | // are created in the ctx object of the top-level prebuilt apex. |
| 260 | isApexSystemServerJar := global.AllApexSystemServerJars(ctx).ContainsJar(libName) |
| 261 | |
| 262 | if _, isApex := android.ModuleProvider(ctx, android.ApexBundleInfoProvider); isApex || isApexVariant(ctx) { |
| 263 | // dexpreopt rules for system server jars can be generated in the ModuleCtx of prebuilt apexes |
Jiakai Zhang | 3317ce7 | 2023-02-08 01:19:19 +0800 | [diff] [blame] | 264 | if !isApexSystemServerJar { |
Jiakai Zhang | ca9bc98 | 2021-09-09 08:09:41 +0000 | [diff] [blame] | 265 | return true |
| 266 | } |
| 267 | } else { |
| 268 | // Don't preopt the platform variant of an APEX system server jar to avoid conflicts. |
Jiakai Zhang | 389a647 | 2021-12-14 18:54:06 +0000 | [diff] [blame] | 269 | if isApexSystemServerJar { |
Jiakai Zhang | ca9bc98 | 2021-09-09 08:09:41 +0000 | [diff] [blame] | 270 | return true |
| 271 | } |
Yo Chiang | dbdf8f9 | 2020-01-09 19:00:27 +0800 | [diff] [blame] | 272 | } |
| 273 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 274 | // TODO: contains no java code |
| 275 | |
| 276 | return false |
| 277 | } |
| 278 | |
Martin Stjernholm | 6d41527 | 2020-01-31 17:10:36 +0000 | [diff] [blame] | 279 | func dexpreoptToolDepsMutator(ctx android.BottomUpMutatorContext) { |
Spandan Das | e21a8d4 | 2024-01-23 23:56:29 +0000 | [diff] [blame] | 280 | if _, isApex := android.ModuleProvider(ctx, android.ApexBundleInfoProvider); isApex && dexpreopt.IsDex2oatNeeded(ctx) { |
| 281 | // prebuilt apexes can genererate rules to dexpreopt deapexed jars |
| 282 | // Add a dex2oat dep aggressively on _every_ apex module |
| 283 | dexpreopt.RegisterToolDeps(ctx) |
| 284 | return |
| 285 | } |
| 286 | if d, ok := ctx.Module().(DexpreopterInterface); !ok || d.dexpreoptDisabled(ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName())) || !dexpreopt.IsDex2oatNeeded(ctx) { |
Martin Stjernholm | 6d41527 | 2020-01-31 17:10:36 +0000 | [diff] [blame] | 287 | return |
| 288 | } |
| 289 | dexpreopt.RegisterToolDeps(ctx) |
| 290 | } |
| 291 | |
Spandan Das | e21a8d4 | 2024-01-23 23:56:29 +0000 | [diff] [blame] | 292 | func (d *dexpreopter) odexOnSystemOther(ctx android.ModuleContext, libName string, installPath android.InstallPath) bool { |
| 293 | return dexpreopt.OdexOnSystemOtherByName(libName, android.InstallPathToOnDevicePath(ctx, installPath), dexpreopt.GetGlobalConfig(ctx)) |
Jiakai Zhang | ca9bc98 | 2021-09-09 08:09:41 +0000 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | // Returns the install path of the dex jar of a module. |
| 297 | // |
| 298 | // Do not rely on `ApexInfo.ApexVariationName` because it can be something like "apex1000", rather |
| 299 | // than the `name` in the path `/apex/<name>` as suggested in its comment. |
| 300 | // |
| 301 | // This function is on a best-effort basis. It cannot handle the case where an APEX jar is not a |
| 302 | // system server jar, which is fine because we currently only preopt system server jars for APEXes. |
| 303 | func (d *dexpreopter) getInstallPath( |
Spandan Das | e21a8d4 | 2024-01-23 23:56:29 +0000 | [diff] [blame] | 304 | ctx android.ModuleContext, libName string, defaultInstallPath android.InstallPath) android.InstallPath { |
Jiakai Zhang | ca9bc98 | 2021-09-09 08:09:41 +0000 | [diff] [blame] | 305 | global := dexpreopt.GetGlobalConfig(ctx) |
Spandan Das | e21a8d4 | 2024-01-23 23:56:29 +0000 | [diff] [blame] | 306 | if global.AllApexSystemServerJars(ctx).ContainsJar(libName) { |
| 307 | dexLocation := dexpreopt.GetSystemServerDexLocation(ctx, global, libName) |
Jiakai Zhang | ca9bc98 | 2021-09-09 08:09:41 +0000 | [diff] [blame] | 308 | return android.PathForModuleInPartitionInstall(ctx, "", strings.TrimPrefix(dexLocation, "/")) |
| 309 | } |
Spandan Das | e21a8d4 | 2024-01-23 23:56:29 +0000 | [diff] [blame] | 310 | if !d.dexpreoptDisabled(ctx, libName) && isApexVariant(ctx) && |
Jiakai Zhang | ca9bc98 | 2021-09-09 08:09:41 +0000 | [diff] [blame] | 311 | filepath.Base(defaultInstallPath.PartitionDir()) != "apex" { |
| 312 | ctx.ModuleErrorf("unable to get the install path of the dex jar for dexpreopt") |
| 313 | } |
| 314 | return defaultInstallPath |
Nicolas Geoffray | fa6e9ec | 2019-02-12 13:12:16 +0000 | [diff] [blame] | 315 | } |
| 316 | |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 317 | // DexpreoptPrebuiltApexSystemServerJars generates the dexpreopt artifacts from a jar file that has been deapexed from a prebuilt apex |
| 318 | func (d *Dexpreopter) DexpreoptPrebuiltApexSystemServerJars(ctx android.ModuleContext, libraryName string, di *android.DeapexerInfo) { |
| 319 | // A single prebuilt apex can have multiple apex system jars |
| 320 | // initialize the output path for this dex jar |
| 321 | dc := dexpreopt.GetGlobalConfig(ctx) |
| 322 | d.installPath = android.PathForModuleInPartitionInstall(ctx, "", strings.TrimPrefix(dexpreopt.GetSystemServerDexLocation(ctx, dc, libraryName), "/")) |
| 323 | // generate the rules for creating the .odex and .vdex files for this system server jar |
Spandan Das | 5be6333 | 2023-12-13 00:06:32 +0000 | [diff] [blame] | 324 | dexJarFile := di.PrebuiltExportPath(ApexRootRelativePathToJavaLib(libraryName)) |
Spandan Das | 2ea84dd | 2024-01-25 22:12:50 +0000 | [diff] [blame] | 325 | |
| 326 | d.inputProfilePathOnHost = nil // reset: TODO(spandandas): Make dexpreopter stateless |
| 327 | if android.InList(libraryName, di.GetDexpreoptProfileGuidedExportedModuleNames()) { |
| 328 | // Set the profile path to guide optimization |
| 329 | prof := di.PrebuiltExportPath(ApexRootRelativePathToJavaLib(libraryName) + ".prof") |
| 330 | if prof == nil { |
| 331 | ctx.ModuleErrorf("Could not find a .prof file in this prebuilt apex") |
| 332 | } |
| 333 | d.inputProfilePathOnHost = prof |
| 334 | } |
| 335 | |
Spandan Das | e21a8d4 | 2024-01-23 23:56:29 +0000 | [diff] [blame] | 336 | d.dexpreopt(ctx, libraryName, dexJarFile) |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 337 | } |
| 338 | |
Spandan Das | e21a8d4 | 2024-01-23 23:56:29 +0000 | [diff] [blame] | 339 | func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, libName string, dexJarFile android.WritablePath) { |
Jiakai Zhang | ca9bc98 | 2021-09-09 08:09:41 +0000 | [diff] [blame] | 340 | global := dexpreopt.GetGlobalConfig(ctx) |
| 341 | |
Martin Stjernholm | 6d41527 | 2020-01-31 17:10:36 +0000 | [diff] [blame] | 342 | // TODO(b/148690468): The check on d.installPath is to bail out in cases where |
| 343 | // the dexpreopter struct hasn't been fully initialized before we're called, |
| 344 | // e.g. in aar.go. This keeps the behaviour that dexpreopting is effectively |
| 345 | // disabled, even if installable is true. |
Ulya Trafimovich | 76b0852 | 2021-01-14 17:52:43 +0000 | [diff] [blame] | 346 | if d.installPath.Base() == "." { |
| 347 | return |
| 348 | } |
| 349 | |
| 350 | dexLocation := android.InstallPathToOnDevicePath(ctx, d.installPath) |
| 351 | |
Spandan Das | e21a8d4 | 2024-01-23 23:56:29 +0000 | [diff] [blame] | 352 | providesUsesLib := libName |
Ulya Trafimovich | 76b0852 | 2021-01-14 17:52:43 +0000 | [diff] [blame] | 353 | if ulib, ok := ctx.Module().(ProvidesUsesLib); ok { |
| 354 | name := ulib.ProvidesUsesLib() |
| 355 | if name != nil { |
| 356 | providesUsesLib = *name |
| 357 | } |
| 358 | } |
| 359 | |
Jeongik Cha | 4b073cd | 2021-06-08 11:35:00 +0900 | [diff] [blame] | 360 | // If it is test, make config files regardless of its dexpreopt setting. |
Jeongik Cha | c624667 | 2021-04-08 00:00:19 +0900 | [diff] [blame] | 361 | // The config files are required for apps defined in make which depend on the lib. |
Spandan Das | e21a8d4 | 2024-01-23 23:56:29 +0000 | [diff] [blame] | 362 | if d.isTest && d.dexpreoptDisabled(ctx, libName) { |
Jaewoong Jung | 4b97a56 | 2020-12-17 09:43:28 -0800 | [diff] [blame] | 363 | return |
Nicolas Geoffray | fa6e9ec | 2019-02-12 13:12:16 +0000 | [diff] [blame] | 364 | } |
| 365 | |
Spandan Das | e21a8d4 | 2024-01-23 23:56:29 +0000 | [diff] [blame] | 366 | isSystemServerJar := global.AllSystemServerJars(ctx).ContainsJar(libName) |
Ulya Trafimovich | 9023b02 | 2021-03-22 16:02:28 +0000 | [diff] [blame] | 367 | |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame] | 368 | bootImage := defaultBootImageConfig(ctx) |
Jiakai Zhang | b879620 | 2023-03-06 19:16:48 +0000 | [diff] [blame] | 369 | // When `global.PreoptWithUpdatableBcp` is true, `bcpForDexpreopt` below includes the mainline |
| 370 | // boot jars into bootclasspath, so we should include the mainline boot image as well because it's |
| 371 | // generated from those jars. |
| 372 | if global.PreoptWithUpdatableBcp { |
| 373 | bootImage = mainlineBootImageConfig(ctx) |
| 374 | } |
Jiakai Zhang | 02669e8 | 2021-09-11 03:44:06 +0000 | [diff] [blame] | 375 | dexFiles, dexLocations := bcpForDexpreopt(ctx, global.PreoptWithUpdatableBcp) |
Ulya Trafimovich | 9023b02 | 2021-03-22 16:02:28 +0000 | [diff] [blame] | 376 | |
David Srbecky | c177ebe | 2020-02-18 20:43:06 +0000 | [diff] [blame] | 377 | targets := ctx.MultiTargets() |
| 378 | if len(targets) == 0 { |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 379 | // assume this is a java library, dexpreopt for all arches for now |
| 380 | for _, target := range ctx.Config().Targets[android.Android] { |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 381 | if target.NativeBridge == android.NativeBridgeDisabled { |
David Srbecky | c177ebe | 2020-02-18 20:43:06 +0000 | [diff] [blame] | 382 | targets = append(targets, target) |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 383 | } |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 384 | } |
Spandan Das | e21a8d4 | 2024-01-23 23:56:29 +0000 | [diff] [blame] | 385 | if isSystemServerJar && libName != "com.android.location.provider" { |
Jiakai Zhang | 2fbc355 | 2022-11-28 15:38:23 +0000 | [diff] [blame] | 386 | // If the module is a system server jar, only preopt for the primary arch because the jar can |
| 387 | // only be loaded by system server. "com.android.location.provider" is a special case because |
| 388 | // it's also used by apps as a shared library. |
David Srbecky | c177ebe | 2020-02-18 20:43:06 +0000 | [diff] [blame] | 389 | targets = targets[:1] |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 390 | } |
| 391 | } |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 392 | |
David Srbecky | c177ebe | 2020-02-18 20:43:06 +0000 | [diff] [blame] | 393 | var archs []android.ArchType |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 394 | var images android.Paths |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 395 | var imagesDeps []android.OutputPaths |
David Srbecky | c177ebe | 2020-02-18 20:43:06 +0000 | [diff] [blame] | 396 | for _, target := range targets { |
| 397 | archs = append(archs, target.Arch.ArchType) |
| 398 | variant := bootImage.getVariant(target) |
Jeongik Cha | a596909 | 2021-05-07 18:53:21 +0900 | [diff] [blame] | 399 | images = append(images, variant.imagePathOnHost) |
David Srbecky | c177ebe | 2020-02-18 20:43:06 +0000 | [diff] [blame] | 400 | imagesDeps = append(imagesDeps, variant.imagesDeps) |
Colin Cross | c7e40aa | 2019-02-08 21:37:00 -0800 | [diff] [blame] | 401 | } |
David Srbecky | ab99498 | 2020-03-30 17:24:13 +0100 | [diff] [blame] | 402 | // The image locations for all Android variants are identical. |
Jeongik Cha | 4dda75e | 2021-04-27 23:56:44 +0900 | [diff] [blame] | 403 | hostImageLocations, deviceImageLocations := bootImage.getAnyAndroidVariant().imageLocations() |
Colin Cross | c7e40aa | 2019-02-08 21:37:00 -0800 | [diff] [blame] | 404 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 405 | var profileClassListing android.OptionalPath |
Nicolas Geoffray | e710242 | 2019-07-24 13:19:29 +0100 | [diff] [blame] | 406 | var profileBootListing android.OptionalPath |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 407 | profileIsTextListing := false |
Spandan Das | 2ea84dd | 2024-01-25 22:12:50 +0000 | [diff] [blame] | 408 | |
Jiakai Zhang | 81e4681 | 2023-02-08 21:56:07 +0800 | [diff] [blame] | 409 | if d.inputProfilePathOnHost != nil { |
| 410 | profileClassListing = android.OptionalPathForPath(d.inputProfilePathOnHost) |
| 411 | } else if BoolDefault(d.dexpreoptProperties.Dex_preopt.Profile_guided, true) && !forPrebuiltApex(ctx) { |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 412 | // If dex_preopt.profile_guided is not set, default it based on the existence of the |
| 413 | // dexprepot.profile option or the profile class listing. |
| 414 | if String(d.dexpreoptProperties.Dex_preopt.Profile) != "" { |
| 415 | profileClassListing = android.OptionalPathForPath( |
| 416 | android.PathForModuleSrc(ctx, String(d.dexpreoptProperties.Dex_preopt.Profile))) |
Nicolas Geoffray | e710242 | 2019-07-24 13:19:29 +0100 | [diff] [blame] | 417 | profileBootListing = android.ExistentPathForSource(ctx, |
| 418 | ctx.ModuleDir(), String(d.dexpreoptProperties.Dex_preopt.Profile)+"-boot") |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 419 | profileIsTextListing = true |
Dan Willemsen | 78d51b0 | 2020-06-24 16:33:31 -0700 | [diff] [blame] | 420 | } else if global.ProfileDir != "" { |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 421 | profileClassListing = android.ExistentPathForSource(ctx, |
Spandan Das | e21a8d4 | 2024-01-23 23:56:29 +0000 | [diff] [blame] | 422 | global.ProfileDir, libName+".prof") |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 423 | } |
| 424 | } |
| 425 | |
Jiakai Zhang | 9c4dc19 | 2023-02-09 00:09:24 +0800 | [diff] [blame] | 426 | d.dexpreoptProperties.Dex_preopt_result.Profile_guided = profileClassListing.Valid() |
| 427 | |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 428 | // A single apex can have multiple system server jars |
| 429 | // Use the dexJar to create a unique scope for each |
| 430 | dexJarStem := strings.TrimSuffix(dexJarFile.Base(), dexJarFile.Ext()) |
| 431 | |
Ulya Trafimovich | 76b0852 | 2021-01-14 17:52:43 +0000 | [diff] [blame] | 432 | // Full dexpreopt config, used to create dexpreopt build rules. |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 433 | dexpreoptConfig := &dexpreopt.ModuleConfig{ |
Spandan Das | e21a8d4 | 2024-01-23 23:56:29 +0000 | [diff] [blame] | 434 | Name: libName, |
Victor Hsieh | d181c8b | 2019-01-29 13:00:33 -0800 | [diff] [blame] | 435 | DexLocation: dexLocation, |
Spandan Das | e21a8d4 | 2024-01-23 23:56:29 +0000 | [diff] [blame] | 436 | BuildPath: android.PathForModuleOut(ctx, "dexpreopt", dexJarStem, libName+".jar").OutputPath, |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 437 | DexPath: dexJarFile, |
Jeongik Cha | 33a3a81 | 2021-04-15 09:12:49 +0900 | [diff] [blame] | 438 | ManifestPath: android.OptionalPathForPath(d.manifestFile), |
Victor Hsieh | d181c8b | 2019-01-29 13:00:33 -0800 | [diff] [blame] | 439 | UncompressedDex: d.uncompressedDex, |
| 440 | HasApkLibraries: false, |
| 441 | PreoptFlags: nil, |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 442 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 443 | ProfileClassListing: profileClassListing, |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 444 | ProfileIsTextListing: profileIsTextListing, |
Nicolas Geoffray | e710242 | 2019-07-24 13:19:29 +0100 | [diff] [blame] | 445 | ProfileBootListing: profileBootListing, |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 446 | |
Ulya Trafimovich | 8c35fcf | 2021-02-17 16:23:28 +0000 | [diff] [blame] | 447 | EnforceUsesLibrariesStatusFile: dexpreopt.UsesLibrariesStatusFile(ctx), |
| 448 | EnforceUsesLibraries: d.enforceUsesLibs, |
| 449 | ProvidesUsesLibrary: providesUsesLib, |
| 450 | ClassLoaderContexts: d.classLoaderContexts, |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 451 | |
Jeongik Cha | 4dda75e | 2021-04-27 23:56:44 +0900 | [diff] [blame] | 452 | Archs: archs, |
| 453 | DexPreoptImagesDeps: imagesDeps, |
| 454 | DexPreoptImageLocationsOnHost: hostImageLocations, |
| 455 | DexPreoptImageLocationsOnDevice: deviceImageLocations, |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 456 | |
Ulya Trafimovich | 9023b02 | 2021-03-22 16:02:28 +0000 | [diff] [blame] | 457 | PreoptBootClassPathDexFiles: dexFiles.Paths(), |
Vladimir Marko | 40139d6 | 2020-02-06 15:14:29 +0000 | [diff] [blame] | 458 | PreoptBootClassPathDexLocations: dexLocations, |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 459 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 460 | NoCreateAppImage: !BoolDefault(d.dexpreoptProperties.Dex_preopt.App_image, true), |
| 461 | ForceCreateAppImage: BoolDefault(d.dexpreoptProperties.Dex_preopt.App_image, false), |
| 462 | |
Jaewoong Jung | ccbb393 | 2019-04-15 09:48:31 -0700 | [diff] [blame] | 463 | PresignedPrebuilt: d.isPresignedPrebuilt, |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 464 | } |
| 465 | |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 466 | d.configPath = android.PathForModuleOut(ctx, "dexpreopt", dexJarStem, "dexpreopt.config") |
Jeongik Cha | c624667 | 2021-04-08 00:00:19 +0900 | [diff] [blame] | 467 | dexpreopt.WriteModuleConfig(ctx, dexpreoptConfig, d.configPath) |
| 468 | |
Spandan Das | e21a8d4 | 2024-01-23 23:56:29 +0000 | [diff] [blame] | 469 | if d.dexpreoptDisabled(ctx, libName) { |
Jeongik Cha | c624667 | 2021-04-08 00:00:19 +0900 | [diff] [blame] | 470 | return |
| 471 | } |
| 472 | |
| 473 | globalSoong := dexpreopt.GetGlobalSoongConfig(ctx) |
| 474 | |
Jiakai Zhang | 51b2a8b | 2023-06-26 16:47:38 +0100 | [diff] [blame] | 475 | // The root "product_packages.txt" is generated by `build/make/core/Makefile`. It contains a list |
| 476 | // of all packages that are installed on the device. We use `grep` to filter the list by the app's |
| 477 | // dependencies to create a per-app list, and use `rsync --checksum` to prevent the file's mtime |
| 478 | // from being changed if the contents don't change. This avoids unnecessary dexpreopt reruns. |
Jiakai Zhang | a449678 | 2023-05-17 16:57:30 +0100 | [diff] [blame] | 479 | productPackages := android.PathForModuleInPartitionInstall(ctx, "", "product_packages.txt") |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 480 | appProductPackages := android.PathForModuleOut(ctx, "dexpreopt", dexJarStem, "product_packages.txt") |
Jiakai Zhang | 51b2a8b | 2023-06-26 16:47:38 +0100 | [diff] [blame] | 481 | appProductPackagesStaging := appProductPackages.ReplaceExtension(ctx, "txt.tmp") |
| 482 | clcNames, _ := dexpreopt.ComputeClassLoaderContextDependencies(dexpreoptConfig.ClassLoaderContexts) |
| 483 | sort.Strings(clcNames) // The order needs to be deterministic. |
| 484 | productPackagesRule := android.NewRuleBuilder(pctx, ctx) |
| 485 | if len(clcNames) > 0 { |
| 486 | productPackagesRule.Command(). |
| 487 | Text("grep -F -x"). |
| 488 | FlagForEachArg("-e ", clcNames). |
| 489 | Input(productPackages). |
| 490 | FlagWithOutput("> ", appProductPackagesStaging). |
| 491 | Text("|| true") |
| 492 | } else { |
| 493 | productPackagesRule.Command(). |
| 494 | Text("rm -f").Output(appProductPackagesStaging). |
| 495 | Text("&&"). |
| 496 | Text("touch").Output(appProductPackagesStaging) |
| 497 | } |
| 498 | productPackagesRule.Command(). |
| 499 | Text("rsync --checksum"). |
| 500 | Input(appProductPackagesStaging). |
| 501 | Output(appProductPackages) |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 502 | productPackagesRule.Restat().Build("product_packages."+dexJarStem, "dexpreopt product_packages") |
Jiakai Zhang | a449678 | 2023-05-17 16:57:30 +0100 | [diff] [blame] | 503 | |
| 504 | dexpreoptRule, err := dexpreopt.GenerateDexpreoptRule( |
Jiakai Zhang | 51b2a8b | 2023-06-26 16:47:38 +0100 | [diff] [blame] | 505 | ctx, globalSoong, global, dexpreoptConfig, appProductPackages) |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 506 | if err != nil { |
| 507 | ctx.ModuleErrorf("error generating dexpreopt rule: %s", err.Error()) |
Jaewoong Jung | 4b97a56 | 2020-12-17 09:43:28 -0800 | [diff] [blame] | 508 | return |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 509 | } |
| 510 | |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 511 | dexpreoptRule.Build("dexpreopt"+"."+dexJarStem, "dexpreopt") |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 512 | |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 513 | // The current ctx might be of a deapexer module created by a prebuilt apex |
| 514 | // Use the path of the dex file to determine the library name |
| 515 | isApexSystemServerJar := global.AllApexSystemServerJars(ctx).ContainsJar(dexJarStem) |
Jiakai Zhang | 389a647 | 2021-12-14 18:54:06 +0000 | [diff] [blame] | 516 | |
Colin Cross | 1d0eb7a | 2021-11-03 14:08:20 -0700 | [diff] [blame] | 517 | for _, install := range dexpreoptRule.Installs() { |
| 518 | // Remove the "/" prefix because the path should be relative to $ANDROID_PRODUCT_OUT. |
| 519 | installDir := strings.TrimPrefix(filepath.Dir(install.To), "/") |
| 520 | installBase := filepath.Base(install.To) |
| 521 | arch := filepath.Base(installDir) |
| 522 | installPath := android.PathForModuleInPartitionInstall(ctx, "", installDir) |
Jiakai Zhang | 3317ce7 | 2023-02-08 01:19:19 +0800 | [diff] [blame] | 523 | isProfile := strings.HasSuffix(installBase, ".prof") |
| 524 | |
| 525 | if isProfile { |
Jiakai Zhang | 81e4681 | 2023-02-08 21:56:07 +0800 | [diff] [blame] | 526 | d.outputProfilePathOnHost = install.From |
Jiakai Zhang | 3317ce7 | 2023-02-08 01:19:19 +0800 | [diff] [blame] | 527 | } |
Colin Cross | 1d0eb7a | 2021-11-03 14:08:20 -0700 | [diff] [blame] | 528 | |
Jiakai Zhang | 389a647 | 2021-12-14 18:54:06 +0000 | [diff] [blame] | 529 | if isApexSystemServerJar { |
Jiakai Zhang | 3317ce7 | 2023-02-08 01:19:19 +0800 | [diff] [blame] | 530 | // Profiles are handled separately because they are installed into the APEX. |
| 531 | if !isProfile { |
| 532 | // APEX variants of java libraries are hidden from Make, so their dexpreopt |
| 533 | // outputs need special handling. Currently, for APEX variants of java |
| 534 | // libraries, only those in the system server classpath are handled here. |
| 535 | // Preopting of boot classpath jars in the ART APEX are handled in |
| 536 | // java/dexpreopt_bootjars.go, and other APEX jars are not preopted. |
| 537 | // The installs will be handled by Make as sub-modules of the java library. |
| 538 | d.builtInstalledForApex = append(d.builtInstalledForApex, dexpreopterInstall{ |
| 539 | name: arch + "-" + installBase, |
Spandan Das | e21a8d4 | 2024-01-23 23:56:29 +0000 | [diff] [blame] | 540 | moduleName: libName, |
Jiakai Zhang | 3317ce7 | 2023-02-08 01:19:19 +0800 | [diff] [blame] | 541 | outputPathOnHost: install.From, |
| 542 | installDirOnDevice: installPath, |
| 543 | installFileOnDevice: installBase, |
| 544 | }) |
| 545 | } |
Colin Cross | fa9bfcd | 2021-11-10 16:42:38 -0800 | [diff] [blame] | 546 | } else if !d.preventInstall { |
Colin Cross | 1d0eb7a | 2021-11-03 14:08:20 -0700 | [diff] [blame] | 547 | ctx.InstallFile(installPath, installBase, install.From) |
Jiakai Zhang | ca9bc98 | 2021-09-09 08:09:41 +0000 | [diff] [blame] | 548 | } |
Colin Cross | 1d0eb7a | 2021-11-03 14:08:20 -0700 | [diff] [blame] | 549 | } |
| 550 | |
Jiakai Zhang | 389a647 | 2021-12-14 18:54:06 +0000 | [diff] [blame] | 551 | if !isApexSystemServerJar { |
Jiakai Zhang | ca9bc98 | 2021-09-09 08:09:41 +0000 | [diff] [blame] | 552 | d.builtInstalled = dexpreoptRule.Installs().String() |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | func (d *dexpreopter) DexpreoptBuiltInstalledForApex() []dexpreopterInstall { |
| 557 | return d.builtInstalledForApex |
| 558 | } |
| 559 | |
| 560 | func (d *dexpreopter) AndroidMkEntriesForApex() []android.AndroidMkEntries { |
| 561 | var entries []android.AndroidMkEntries |
| 562 | for _, install := range d.builtInstalledForApex { |
Jiakai Zhang | 6decef9 | 2022-01-12 17:56:19 +0000 | [diff] [blame] | 563 | entries = append(entries, install.ToMakeEntries()) |
Jiakai Zhang | ca9bc98 | 2021-09-09 08:09:41 +0000 | [diff] [blame] | 564 | } |
| 565 | return entries |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 566 | } |
Jiakai Zhang | 3317ce7 | 2023-02-08 01:19:19 +0800 | [diff] [blame] | 567 | |
Jiakai Zhang | 81e4681 | 2023-02-08 21:56:07 +0800 | [diff] [blame] | 568 | func (d *dexpreopter) OutputProfilePathOnHost() android.Path { |
| 569 | return d.outputProfilePathOnHost |
Jiakai Zhang | 3317ce7 | 2023-02-08 01:19:19 +0800 | [diff] [blame] | 570 | } |
Spandan Das | 0727ba7 | 2024-02-13 16:37:43 +0000 | [diff] [blame] | 571 | |
| 572 | func (d *dexpreopter) disableDexpreopt() { |
| 573 | d.shouldDisableDexpreopt = true |
| 574 | } |