blob: f52ce5d100190092156dd635a34686de2517b512 [file] [log] [blame]
Colin Cross43f08db2018-11-12 10:13:39 -08001// 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
15package java
16
17import (
Jiakai Zhangca9bc982021-09-09 08:09:41 +000018 "path/filepath"
Jiakai Zhang51b2a8b2023-06-26 16:47:38 +010019 "sort"
Jiakai Zhangca9bc982021-09-09 08:09:41 +000020 "strings"
21
Spandan Das3dbda182024-05-20 22:23:10 +000022 "github.com/google/blueprint/proptools"
23
Colin Cross43f08db2018-11-12 10:13:39 -080024 "android/soong/android"
25 "android/soong/dexpreopt"
26)
27
Jiakai Zhangca9bc982021-09-09 08:09:41 +000028type DexpreopterInterface interface {
Jiakai Zhang81e46812023-02-08 21:56:07 +080029 // True if the java module is to be dexed and installed on devices.
30 // Structs that embed dexpreopter must implement this.
31 IsInstallable() bool
32
33 // True if dexpreopt is disabled for the java module.
Spandan Dase21a8d42024-01-23 23:56:29 +000034 dexpreoptDisabled(ctx android.BaseModuleContext, libraryName string) bool
Jiakai Zhang81e46812023-02-08 21:56:07 +080035
36 // If the java module is to be installed into an APEX, this list contains information about the
37 // dexpreopt outputs to be installed on devices. Note that these dexpreopt outputs are installed
38 // outside of the APEX.
Jiakai Zhangca9bc982021-09-09 08:09:41 +000039 DexpreoptBuiltInstalledForApex() []dexpreopterInstall
Jiakai Zhang81e46812023-02-08 21:56:07 +080040
41 // The Make entries to install the dexpreopt outputs. Derived from
42 // `DexpreoptBuiltInstalledForApex`.
Jiakai Zhangca9bc982021-09-09 08:09:41 +000043 AndroidMkEntriesForApex() []android.AndroidMkEntries
Jiakai Zhang81e46812023-02-08 21:56:07 +080044
45 // See `dexpreopter.outputProfilePathOnHost`.
46 OutputProfilePathOnHost() android.Path
Jiakai Zhangca9bc982021-09-09 08:09:41 +000047}
48
49type dexpreopterInstall struct {
50 // A unique name to distinguish an output from others for the same java library module. Usually in
51 // the form of `<arch>-<encoded-path>.odex/vdex/art`.
52 name string
53
54 // The name of the input java module.
55 moduleName string
56
57 // The path to the dexpreopt output on host.
58 outputPathOnHost android.Path
59
60 // The directory on the device for the output to install to.
61 installDirOnDevice android.InstallPath
62
63 // The basename (the last segment of the path) for the output to install as.
64 installFileOnDevice string
65}
66
67// The full module name of the output in the makefile.
68func (install *dexpreopterInstall) FullModuleName() string {
69 return install.moduleName + install.SubModuleName()
70}
71
72// The sub-module name of the output in the makefile (the name excluding the java module name).
73func (install *dexpreopterInstall) SubModuleName() string {
74 return "-dexpreopt-" + install.name
Martin Stjernholm6d415272020-01-31 17:10:36 +000075}
76
Jiakai Zhang6decef92022-01-12 17:56:19 +000077// Returns Make entries for installing the file.
78//
79// This function uses a value receiver rather than a pointer receiver to ensure that the object is
80// safe to use in `android.AndroidMkExtraEntriesFunc`.
81func (install dexpreopterInstall) ToMakeEntries() android.AndroidMkEntries {
82 return android.AndroidMkEntries{
Jihoon Kangd4063812025-01-24 00:25:30 +000083 OverrideName: install.FullModuleName(),
84 Class: "ETC",
85 OutputFile: android.OptionalPathForPath(install.outputPathOnHost),
Jiakai Zhang6decef92022-01-12 17:56:19 +000086 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
87 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
88 entries.SetString("LOCAL_MODULE_PATH", install.installDirOnDevice.String())
89 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", install.installFileOnDevice)
90 entries.SetString("LOCAL_NOT_AVAILABLE_FOR_PLATFORM", "false")
91 },
92 },
93 }
94}
95
Jihoon Kangd4063812025-01-24 00:25:30 +000096func (install dexpreopterInstall) AddModuleInfoJSONForApex(ctx android.ModuleContext) {
97 moduleInfoJSON := ctx.ExtraModuleInfoJSON()
98 moduleInfoJSON.RegisterNameOverride = install.FullModuleName()
99 moduleInfoJSON.ModuleNameOverride = install.FullModuleName()
100 moduleInfoJSON.Class = []string{"ETC"}
101 moduleInfoJSON.SystemSharedLibs = []string{"none"}
102}
103
Spandan Das2069c3f2023-12-06 19:40:24 +0000104type Dexpreopter struct {
105 dexpreopter
106}
107
Colin Cross43f08db2018-11-12 10:13:39 -0800108type dexpreopter struct {
Jiakai Zhang9c4dc192023-02-09 00:09:24 +0800109 dexpreoptProperties DexpreoptProperties
110 importDexpreoptProperties ImportDexpreoptProperties
Colin Cross43f08db2018-11-12 10:13:39 -0800111
Spandan Das0727ba72024-02-13 16:37:43 +0000112 // If true, the dexpreopt rules will not be generated
113 // Unlike Dex_preopt.Enabled which is user-facing,
114 // shouldDisableDexpreopt is a mutated propery.
115 shouldDisableDexpreopt bool
116
Colin Cross70dda7e2019-10-01 22:05:35 -0700117 installPath android.InstallPath
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700118 uncompressedDex bool
119 isSDKLibrary bool
Ulya Trafimovich76b08522021-01-14 17:52:43 +0000120 isApp bool
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700121 isTest bool
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700122 isPresignedPrebuilt bool
Colin Crossfa9bfcd2021-11-10 16:42:38 -0800123 preventInstall bool
Colin Cross43f08db2018-11-12 10:13:39 -0800124
Ulya Trafimovich8cbc5d22020-11-03 15:15:46 +0000125 manifestFile android.Path
Ulya Trafimovich8c35fcf2021-02-17 16:23:28 +0000126 statusFile android.WritablePath
Ulya Trafimovich8cbc5d22020-11-03 15:15:46 +0000127 enforceUsesLibs bool
128 classLoaderContexts dexpreopt.ClassLoaderContextMap
Colin Cross50ddcc42019-05-16 12:28:22 -0700129
Jiakai Zhangca9bc982021-09-09 08:09:41 +0000130 // See the `dexpreopt` function for details.
131 builtInstalled string
132 builtInstalledForApex []dexpreopterInstall
Ulya Trafimovich76b08522021-01-14 17:52:43 +0000133
Jeongik Chac6246672021-04-08 00:00:19 +0900134 // The config is used for two purposes:
135 // - Passing dexpreopt information about libraries from Soong to Make. This is needed when
136 // a <uses-library> is defined in Android.bp, but used in Android.mk (see dex_preopt_config_merger.py).
137 // Note that dexpreopt.config might be needed even if dexpreopt is disabled for the library itself.
138 // - Dexpreopt post-processing (using dexpreopt artifacts from a prebuilt system image to incrementally
139 // dexpreopt another partition).
Ulya Trafimovich76b08522021-01-14 17:52:43 +0000140 configPath android.WritablePath
Jiakai Zhang3317ce72023-02-08 01:19:19 +0800141
Jiakai Zhang81e46812023-02-08 21:56:07 +0800142 // The path to the profile on host that dexpreopter generates. This is used as the input for
143 // dex2oat.
144 outputProfilePathOnHost android.Path
145
146 // The path to the profile that dexpreopter accepts. It must be in the binary format. If this is
147 // set, it overrides the profile settings in `dexpreoptProperties`.
148 inputProfilePathOnHost android.Path
Spandan Das3dbda182024-05-20 22:23:10 +0000149
150 // The path to the profile that matches the dex optimized by r8/d8. It is in text format. If this is
151 // set, it will be converted to a binary profile which will be subsequently used for dexpreopt.
152 rewrittenProfile android.Path
Colin Cross43f08db2018-11-12 10:13:39 -0800153}
154
155type DexpreoptProperties struct {
156 Dex_preopt struct {
Nicolas Geoffrayc1bf7242019-10-18 14:51:38 +0100157 // If false, prevent dexpreopting. Defaults to true.
Cole Fausteb032462024-09-19 11:12:54 -0700158 Enabled proptools.Configurable[bool] `android:"replace_instead_of_append"`
Colin Cross43f08db2018-11-12 10:13:39 -0800159
160 // If true, generate an app image (.art file) for this module.
Cole Fausteb032462024-09-19 11:12:54 -0700161 App_image proptools.Configurable[bool] `android:"replace_instead_of_append"`
Colin Cross43f08db2018-11-12 10:13:39 -0800162
163 // If true, use a checked-in profile to guide optimization. Defaults to false unless
164 // a matching profile is set or a profile is found in PRODUCT_DEX_PREOPT_PROFILE_DIR
165 // that matches the name of this module, in which case it is defaulted to true.
Cole Fausteb032462024-09-19 11:12:54 -0700166 Profile_guided proptools.Configurable[bool] `android:"replace_instead_of_append"`
Colin Cross43f08db2018-11-12 10:13:39 -0800167
168 // If set, provides the path to profile relative to the Android.bp file. If not set,
169 // defaults to searching for a file that matches the name of this module in the default
170 // profile location set by PRODUCT_DEX_PREOPT_PROFILE_DIR, or empty if not found.
Cole Fausteb032462024-09-19 11:12:54 -0700171 Profile proptools.Configurable[string] `android:"path,replace_instead_of_append"`
Spandan Das3dbda182024-05-20 22:23:10 +0000172
173 // If set to true, r8/d8 will use `profile` as input to generate a new profile that matches
174 // the optimized dex.
175 // The new profile will be subsequently used as the profile to dexpreopt the dex file.
Cole Fausteb032462024-09-19 11:12:54 -0700176 Enable_profile_rewriting proptools.Configurable[bool] `android:"replace_instead_of_append"`
Colin Cross43f08db2018-11-12 10:13:39 -0800177 }
Jiakai Zhang9c4dc192023-02-09 00:09:24 +0800178
179 Dex_preopt_result struct {
180 // True if profile-guided optimization is actually enabled.
181 Profile_guided bool
182 } `blueprint:"mutated"`
183}
184
185type ImportDexpreoptProperties struct {
186 Dex_preopt struct {
187 // If true, use the profile in the prebuilt APEX to guide optimization. Defaults to false.
188 Profile_guided *bool
189 }
Colin Cross43f08db2018-11-12 10:13:39 -0800190}
191
Ulya Trafimovich6cf2c0c2020-04-24 12:15:20 +0100192func init() {
193 dexpreopt.DexpreoptRunningInSoong = true
194}
195
Jiakai Zhangca9bc982021-09-09 08:09:41 +0000196func isApexVariant(ctx android.BaseModuleContext) bool {
Colin Crossff694a82023-12-13 15:54:49 -0800197 apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider)
Jiakai Zhangca9bc982021-09-09 08:09:41 +0000198 return !apexInfo.IsForPlatform()
199}
200
Jiakai Zhang28bc9a82021-12-20 15:08:57 +0000201func forPrebuiltApex(ctx android.BaseModuleContext) bool {
Colin Crossff694a82023-12-13 15:54:49 -0800202 apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider)
Jiakai Zhang28bc9a82021-12-20 15:08:57 +0000203 return apexInfo.ForPrebuiltApex
204}
205
Spandan Dasa8afdcb2024-02-29 06:40:16 +0000206// For apex variant of modules, this returns true on the source variant if the prebuilt apex
207// has been selected using apex_contributions.
208// The prebuilt apex will be responsible for generating the dexpreopt rules of the deapexed java lib.
209func disableSourceApexVariant(ctx android.BaseModuleContext) bool {
210 if !isApexVariant(ctx) {
211 return false // platform variant
212 }
213 apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider)
214 psi := android.PrebuiltSelectionInfoMap{}
Yu Liu7eebf8b2025-01-17 00:23:57 +0000215 ctx.VisitDirectDepsProxy(func(am android.ModuleProxy) {
Jihoon Kanga3a05462024-04-05 00:36:44 +0000216 if prebuiltSelectionInfo, ok := android.OtherModuleProvider(ctx, am, android.PrebuiltSelectionInfoProvider); ok {
217 psi = prebuiltSelectionInfo
218 }
Spandan Dasa8afdcb2024-02-29 06:40:16 +0000219 })
Spandan Das003452f2024-09-06 00:56:25 +0000220
Spandan Dasa8afdcb2024-02-29 06:40:16 +0000221 // Find the apex variant for this module
Colin Crossaf4c8562024-11-20 15:07:58 -0800222 apexVariants := []string{}
Spandan Dased7a0302024-08-26 18:06:25 +0000223 if apexInfo.BaseApexName != "" {
224 // This is a transitive dependency of an override_apex
Colin Crossaf4c8562024-11-20 15:07:58 -0800225 apexVariants = append(apexVariants, apexInfo.BaseApexName)
Spandan Dased7a0302024-08-26 18:06:25 +0000226 } else {
Colin Crossaf4c8562024-11-20 15:07:58 -0800227 apexVariants = append(apexVariants, apexInfo.InApexVariants...)
Spandan Das003452f2024-09-06 00:56:25 +0000228 }
229 if apexInfo.ApexAvailableName != "" {
Colin Crossaf4c8562024-11-20 15:07:58 -0800230 apexVariants = append(apexVariants, apexInfo.ApexAvailableName)
Spandan Dased7a0302024-08-26 18:06:25 +0000231 }
Spandan Dasa8afdcb2024-02-29 06:40:16 +0000232 disableSource := false
233 // find the selected apexes
Colin Crossaf4c8562024-11-20 15:07:58 -0800234 for _, apexVariant := range apexVariants {
Spandan Dased7a0302024-08-26 18:06:25 +0000235 if len(psi.GetSelectedModulesForApiDomain(apexVariant)) > 0 {
236 // If the apex_contribution for this api domain is non-empty, disable the source variant
237 disableSource = true
Spandan Dasa8afdcb2024-02-29 06:40:16 +0000238 }
239 }
240 return disableSource
241}
242
Jiakai Zhangcf61e3c2023-05-08 16:28:38 +0000243// Returns whether dexpreopt is applicable to the module.
244// When it returns true, neither profile nor dexpreopt artifacts will be generated.
Spandan Dase21a8d42024-01-23 23:56:29 +0000245func (d *dexpreopter) dexpreoptDisabled(ctx android.BaseModuleContext, libName string) bool {
Colin Cross38310bb2021-12-01 10:34:14 -0800246 if !ctx.Device() {
Colin Cross43f08db2018-11-12 10:13:39 -0800247 return true
248 }
249
Colin Cross43f08db2018-11-12 10:13:39 -0800250 if d.isTest {
251 return true
252 }
253
Cole Fausteb032462024-09-19 11:12:54 -0700254 if !d.dexpreoptProperties.Dex_preopt.Enabled.GetOrDefault(ctx, true) {
Colin Cross43f08db2018-11-12 10:13:39 -0800255 return true
256 }
257
Spandan Das0727ba72024-02-13 16:37:43 +0000258 if d.shouldDisableDexpreopt {
259 return true
260 }
261
Jiakai Zhang28bc9a82021-12-20 15:08:57 +0000262 // If the module is from a prebuilt APEX, it shouldn't be installable, but it can still be
263 // dexpreopted.
264 if !ctx.Module().(DexpreopterInterface).IsInstallable() && !forPrebuiltApex(ctx) {
Martin Stjernholm6d415272020-01-31 17:10:36 +0000265 return true
266 }
267
Colin Cross38310bb2021-12-01 10:34:14 -0800268 if !android.IsModulePreferred(ctx.Module()) {
269 return true
270 }
271
Spandan Dase21a8d42024-01-23 23:56:29 +0000272 if _, isApex := android.ModuleProvider(ctx, android.ApexBundleInfoProvider); isApex {
273 // dexpreopt rules for system server jars can be generated in the ModuleCtx of prebuilt apexes
274 return false
275 }
276
Colin Cross38310bb2021-12-01 10:34:14 -0800277 global := dexpreopt.GetGlobalConfig(ctx)
278
Spandan Dase21a8d42024-01-23 23:56:29 +0000279 // Use the libName argument to determine if the library being dexpreopt'd is a system server jar
280 // ctx.ModuleName() is not safe. In case of prebuilt apexes, the dexpreopt rules of system server jars
281 // are created in the ctx object of the top-level prebuilt apex.
282 isApexSystemServerJar := global.AllApexSystemServerJars(ctx).ContainsJar(libName)
283
284 if _, isApex := android.ModuleProvider(ctx, android.ApexBundleInfoProvider); isApex || isApexVariant(ctx) {
285 // dexpreopt rules for system server jars can be generated in the ModuleCtx of prebuilt apexes
Jiakai Zhang3317ce72023-02-08 01:19:19 +0800286 if !isApexSystemServerJar {
Jiakai Zhangca9bc982021-09-09 08:09:41 +0000287 return true
288 }
Spandan Das50801e22024-05-13 18:29:45 +0000289 ai, _ := android.ModuleProvider(ctx, android.ApexInfoProvider)
290 allApexInfos := []android.ApexInfo{}
291 if allApexInfosProvider, ok := android.ModuleProvider(ctx, android.AllApexInfoProvider); ok {
292 allApexInfos = allApexInfosProvider.ApexInfos
293 }
294 if len(allApexInfos) > 0 && !ai.MinSdkVersion.EqualTo(allApexInfos[0].MinSdkVersion) {
295 // Apex system server jars are dexpreopted and installed on to the system image.
296 // Since we can have BigAndroid and Go variants of system server jar providing apexes,
297 // and these two variants can have different min_sdk_versions, hide one of the apex variants
298 // from make to prevent collisions.
299 //
300 // Unlike cc, min_sdk_version does not have an effect on the build actions of java libraries.
301 ctx.Module().MakeUninstallable()
302 }
Jiakai Zhangca9bc982021-09-09 08:09:41 +0000303 } else {
304 // Don't preopt the platform variant of an APEX system server jar to avoid conflicts.
Jiakai Zhang389a6472021-12-14 18:54:06 +0000305 if isApexSystemServerJar {
Jiakai Zhangca9bc982021-09-09 08:09:41 +0000306 return true
307 }
Yo Chiangdbdf8f92020-01-09 19:00:27 +0800308 }
309
Colin Cross43f08db2018-11-12 10:13:39 -0800310 // TODO: contains no java code
311
312 return false
313}
314
Martin Stjernholm6d415272020-01-31 17:10:36 +0000315func dexpreoptToolDepsMutator(ctx android.BottomUpMutatorContext) {
Spandan Dase21a8d42024-01-23 23:56:29 +0000316 if _, isApex := android.ModuleProvider(ctx, android.ApexBundleInfoProvider); isApex && dexpreopt.IsDex2oatNeeded(ctx) {
317 // prebuilt apexes can genererate rules to dexpreopt deapexed jars
318 // Add a dex2oat dep aggressively on _every_ apex module
319 dexpreopt.RegisterToolDeps(ctx)
320 return
321 }
322 if d, ok := ctx.Module().(DexpreopterInterface); !ok || d.dexpreoptDisabled(ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName())) || !dexpreopt.IsDex2oatNeeded(ctx) {
Martin Stjernholm6d415272020-01-31 17:10:36 +0000323 return
324 }
325 dexpreopt.RegisterToolDeps(ctx)
326}
327
Jiakai Zhangca9bc982021-09-09 08:09:41 +0000328// Returns the install path of the dex jar of a module.
329//
330// Do not rely on `ApexInfo.ApexVariationName` because it can be something like "apex1000", rather
331// than the `name` in the path `/apex/<name>` as suggested in its comment.
332//
333// This function is on a best-effort basis. It cannot handle the case where an APEX jar is not a
334// system server jar, which is fine because we currently only preopt system server jars for APEXes.
335func (d *dexpreopter) getInstallPath(
Spandan Dase21a8d42024-01-23 23:56:29 +0000336 ctx android.ModuleContext, libName string, defaultInstallPath android.InstallPath) android.InstallPath {
Jiakai Zhangca9bc982021-09-09 08:09:41 +0000337 global := dexpreopt.GetGlobalConfig(ctx)
Spandan Dase21a8d42024-01-23 23:56:29 +0000338 if global.AllApexSystemServerJars(ctx).ContainsJar(libName) {
339 dexLocation := dexpreopt.GetSystemServerDexLocation(ctx, global, libName)
Jiakai Zhangca9bc982021-09-09 08:09:41 +0000340 return android.PathForModuleInPartitionInstall(ctx, "", strings.TrimPrefix(dexLocation, "/"))
341 }
Spandan Dase21a8d42024-01-23 23:56:29 +0000342 if !d.dexpreoptDisabled(ctx, libName) && isApexVariant(ctx) &&
Jiakai Zhangca9bc982021-09-09 08:09:41 +0000343 filepath.Base(defaultInstallPath.PartitionDir()) != "apex" {
344 ctx.ModuleErrorf("unable to get the install path of the dex jar for dexpreopt")
345 }
346 return defaultInstallPath
Nicolas Geoffrayfa6e9ec2019-02-12 13:12:16 +0000347}
348
Spandan Das2069c3f2023-12-06 19:40:24 +0000349// DexpreoptPrebuiltApexSystemServerJars generates the dexpreopt artifacts from a jar file that has been deapexed from a prebuilt apex
350func (d *Dexpreopter) DexpreoptPrebuiltApexSystemServerJars(ctx android.ModuleContext, libraryName string, di *android.DeapexerInfo) {
351 // A single prebuilt apex can have multiple apex system jars
352 // initialize the output path for this dex jar
353 dc := dexpreopt.GetGlobalConfig(ctx)
354 d.installPath = android.PathForModuleInPartitionInstall(ctx, "", strings.TrimPrefix(dexpreopt.GetSystemServerDexLocation(ctx, dc, libraryName), "/"))
355 // generate the rules for creating the .odex and .vdex files for this system server jar
Spandan Das5be63332023-12-13 00:06:32 +0000356 dexJarFile := di.PrebuiltExportPath(ApexRootRelativePathToJavaLib(libraryName))
Spandan Das419b3c62025-01-13 21:46:01 +0000357 if dexJarFile == nil {
358 ctx.ModuleErrorf(
359 `Could not find library %s in prebuilt apex %s.
360Please make sure that the value of PRODUCT_APEX_(SYSTEM_SERVER|STANDALONE_SYSTEM_SERVER)_JARS is correct`, libraryName, ctx.ModuleName())
361 }
Spandan Das2ea84dd2024-01-25 22:12:50 +0000362 d.inputProfilePathOnHost = nil // reset: TODO(spandandas): Make dexpreopter stateless
363 if android.InList(libraryName, di.GetDexpreoptProfileGuidedExportedModuleNames()) {
364 // Set the profile path to guide optimization
365 prof := di.PrebuiltExportPath(ApexRootRelativePathToJavaLib(libraryName) + ".prof")
366 if prof == nil {
367 ctx.ModuleErrorf("Could not find a .prof file in this prebuilt apex")
368 }
369 d.inputProfilePathOnHost = prof
370 }
371
Spandan Dase21a8d42024-01-23 23:56:29 +0000372 d.dexpreopt(ctx, libraryName, dexJarFile)
Spandan Das2069c3f2023-12-06 19:40:24 +0000373}
374
Colin Cross7707b242024-07-26 12:02:36 -0700375func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, libName string, dexJarFile android.Path) {
Jiakai Zhangca9bc982021-09-09 08:09:41 +0000376 global := dexpreopt.GetGlobalConfig(ctx)
377
Martin Stjernholm6d415272020-01-31 17:10:36 +0000378 // TODO(b/148690468): The check on d.installPath is to bail out in cases where
379 // the dexpreopter struct hasn't been fully initialized before we're called,
380 // e.g. in aar.go. This keeps the behaviour that dexpreopting is effectively
381 // disabled, even if installable is true.
Ulya Trafimovich76b08522021-01-14 17:52:43 +0000382 if d.installPath.Base() == "." {
383 return
384 }
385
386 dexLocation := android.InstallPathToOnDevicePath(ctx, d.installPath)
387
Spandan Dase21a8d42024-01-23 23:56:29 +0000388 providesUsesLib := libName
Ulya Trafimovich76b08522021-01-14 17:52:43 +0000389 if ulib, ok := ctx.Module().(ProvidesUsesLib); ok {
390 name := ulib.ProvidesUsesLib()
391 if name != nil {
392 providesUsesLib = *name
393 }
394 }
395
Jeongik Cha4b073cd2021-06-08 11:35:00 +0900396 // If it is test, make config files regardless of its dexpreopt setting.
Jeongik Chac6246672021-04-08 00:00:19 +0900397 // The config files are required for apps defined in make which depend on the lib.
Spandan Dase21a8d42024-01-23 23:56:29 +0000398 if d.isTest && d.dexpreoptDisabled(ctx, libName) {
Jaewoong Jung4b97a562020-12-17 09:43:28 -0800399 return
Nicolas Geoffrayfa6e9ec2019-02-12 13:12:16 +0000400 }
401
Spandan Dase21a8d42024-01-23 23:56:29 +0000402 isSystemServerJar := global.AllSystemServerJars(ctx).ContainsJar(libName)
Ulya Trafimovich9023b022021-03-22 16:02:28 +0000403
Colin Cross44df5812019-02-15 23:06:46 -0800404 bootImage := defaultBootImageConfig(ctx)
Jiakai Zhangb8796202023-03-06 19:16:48 +0000405 // When `global.PreoptWithUpdatableBcp` is true, `bcpForDexpreopt` below includes the mainline
406 // boot jars into bootclasspath, so we should include the mainline boot image as well because it's
407 // generated from those jars.
408 if global.PreoptWithUpdatableBcp {
409 bootImage = mainlineBootImageConfig(ctx)
410 }
Jiakai Zhang02669e82021-09-11 03:44:06 +0000411 dexFiles, dexLocations := bcpForDexpreopt(ctx, global.PreoptWithUpdatableBcp)
Ulya Trafimovich9023b022021-03-22 16:02:28 +0000412
David Srbeckyc177ebe2020-02-18 20:43:06 +0000413 targets := ctx.MultiTargets()
414 if len(targets) == 0 {
Colin Cross43f08db2018-11-12 10:13:39 -0800415 // assume this is a java library, dexpreopt for all arches for now
416 for _, target := range ctx.Config().Targets[android.Android] {
dimitry1f33e402019-03-26 12:39:31 +0100417 if target.NativeBridge == android.NativeBridgeDisabled {
David Srbeckyc177ebe2020-02-18 20:43:06 +0000418 targets = append(targets, target)
dimitry1f33e402019-03-26 12:39:31 +0100419 }
Colin Cross43f08db2018-11-12 10:13:39 -0800420 }
Spandan Dase21a8d42024-01-23 23:56:29 +0000421 if isSystemServerJar && libName != "com.android.location.provider" {
Jiakai Zhang2fbc3552022-11-28 15:38:23 +0000422 // If the module is a system server jar, only preopt for the primary arch because the jar can
423 // only be loaded by system server. "com.android.location.provider" is a special case because
424 // it's also used by apps as a shared library.
David Srbeckyc177ebe2020-02-18 20:43:06 +0000425 targets = targets[:1]
Colin Cross43f08db2018-11-12 10:13:39 -0800426 }
427 }
Colin Cross43f08db2018-11-12 10:13:39 -0800428
David Srbeckyc177ebe2020-02-18 20:43:06 +0000429 var archs []android.ArchType
Colin Cross69f59a32019-02-15 10:39:37 -0800430 var images android.Paths
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +0000431 var imagesDeps []android.OutputPaths
David Srbeckyc177ebe2020-02-18 20:43:06 +0000432 for _, target := range targets {
433 archs = append(archs, target.Arch.ArchType)
434 variant := bootImage.getVariant(target)
Jeongik Chaa5969092021-05-07 18:53:21 +0900435 images = append(images, variant.imagePathOnHost)
David Srbeckyc177ebe2020-02-18 20:43:06 +0000436 imagesDeps = append(imagesDeps, variant.imagesDeps)
Colin Crossc7e40aa2019-02-08 21:37:00 -0800437 }
David Srbeckyab994982020-03-30 17:24:13 +0100438 // The image locations for all Android variants are identical.
Jeongik Cha4dda75e2021-04-27 23:56:44 +0900439 hostImageLocations, deviceImageLocations := bootImage.getAnyAndroidVariant().imageLocations()
Colin Crossc7e40aa2019-02-08 21:37:00 -0800440
Colin Cross43f08db2018-11-12 10:13:39 -0800441 var profileClassListing android.OptionalPath
Nicolas Geoffraye7102422019-07-24 13:19:29 +0100442 var profileBootListing android.OptionalPath
Colin Cross43f08db2018-11-12 10:13:39 -0800443 profileIsTextListing := false
Spandan Das2ea84dd2024-01-25 22:12:50 +0000444
Jiakai Zhang81e46812023-02-08 21:56:07 +0800445 if d.inputProfilePathOnHost != nil {
446 profileClassListing = android.OptionalPathForPath(d.inputProfilePathOnHost)
Cole Fausteb032462024-09-19 11:12:54 -0700447 } else if d.dexpreoptProperties.Dex_preopt.Profile_guided.GetOrDefault(ctx, true) && !forPrebuiltApex(ctx) {
Spandan Das3dbda182024-05-20 22:23:10 +0000448 // If enable_profile_rewriting is set, use the rewritten profile instead of the checked-in profile
Cole Fausteb032462024-09-19 11:12:54 -0700449 if d.EnableProfileRewriting(ctx) {
Spandan Das3dbda182024-05-20 22:23:10 +0000450 profileClassListing = android.OptionalPathForPath(d.GetRewrittenProfile())
451 profileIsTextListing = true
Cole Fausteb032462024-09-19 11:12:54 -0700452 } else if profile := d.GetProfile(ctx); profile != "" {
Spandan Das3dbda182024-05-20 22:23:10 +0000453 // If dex_preopt.profile_guided is not set, default it based on the existence of the
454 // dexprepot.profile option or the profile class listing.
Colin Cross43f08db2018-11-12 10:13:39 -0800455 profileClassListing = android.OptionalPathForPath(
Spandan Das3dbda182024-05-20 22:23:10 +0000456 android.PathForModuleSrc(ctx, profile))
Nicolas Geoffraye7102422019-07-24 13:19:29 +0100457 profileBootListing = android.ExistentPathForSource(ctx,
Spandan Das3dbda182024-05-20 22:23:10 +0000458 ctx.ModuleDir(), profile+"-boot")
Colin Cross43f08db2018-11-12 10:13:39 -0800459 profileIsTextListing = true
Dan Willemsen78d51b02020-06-24 16:33:31 -0700460 } else if global.ProfileDir != "" {
Colin Cross43f08db2018-11-12 10:13:39 -0800461 profileClassListing = android.ExistentPathForSource(ctx,
Spandan Dase21a8d42024-01-23 23:56:29 +0000462 global.ProfileDir, libName+".prof")
Colin Cross43f08db2018-11-12 10:13:39 -0800463 }
464 }
465
Jiakai Zhang9c4dc192023-02-09 00:09:24 +0800466 d.dexpreoptProperties.Dex_preopt_result.Profile_guided = profileClassListing.Valid()
467
Spandan Das2069c3f2023-12-06 19:40:24 +0000468 // A single apex can have multiple system server jars
469 // Use the dexJar to create a unique scope for each
470 dexJarStem := strings.TrimSuffix(dexJarFile.Base(), dexJarFile.Ext())
471
Cole Fausteb032462024-09-19 11:12:54 -0700472 appImage := d.dexpreoptProperties.Dex_preopt.App_image.Get(ctx)
473
Ulya Trafimovich76b08522021-01-14 17:52:43 +0000474 // Full dexpreopt config, used to create dexpreopt build rules.
Martin Stjernholm8d80cee2020-01-31 17:44:54 +0000475 dexpreoptConfig := &dexpreopt.ModuleConfig{
Spandan Dase21a8d42024-01-23 23:56:29 +0000476 Name: libName,
Victor Hsiehd181c8b2019-01-29 13:00:33 -0800477 DexLocation: dexLocation,
Spandan Dase21a8d42024-01-23 23:56:29 +0000478 BuildPath: android.PathForModuleOut(ctx, "dexpreopt", dexJarStem, libName+".jar").OutputPath,
Colin Cross69f59a32019-02-15 10:39:37 -0800479 DexPath: dexJarFile,
Jeongik Cha33a3a812021-04-15 09:12:49 +0900480 ManifestPath: android.OptionalPathForPath(d.manifestFile),
Victor Hsiehd181c8b2019-01-29 13:00:33 -0800481 UncompressedDex: d.uncompressedDex,
482 HasApkLibraries: false,
483 PreoptFlags: nil,
Colin Cross43f08db2018-11-12 10:13:39 -0800484
Colin Cross69f59a32019-02-15 10:39:37 -0800485 ProfileClassListing: profileClassListing,
Colin Cross43f08db2018-11-12 10:13:39 -0800486 ProfileIsTextListing: profileIsTextListing,
Nicolas Geoffraye7102422019-07-24 13:19:29 +0100487 ProfileBootListing: profileBootListing,
Colin Cross43f08db2018-11-12 10:13:39 -0800488
Ulya Trafimovich8c35fcf2021-02-17 16:23:28 +0000489 EnforceUsesLibrariesStatusFile: dexpreopt.UsesLibrariesStatusFile(ctx),
490 EnforceUsesLibraries: d.enforceUsesLibs,
491 ProvidesUsesLibrary: providesUsesLib,
492 ClassLoaderContexts: d.classLoaderContexts,
Colin Cross43f08db2018-11-12 10:13:39 -0800493
Jeongik Cha4dda75e2021-04-27 23:56:44 +0900494 Archs: archs,
495 DexPreoptImagesDeps: imagesDeps,
496 DexPreoptImageLocationsOnHost: hostImageLocations,
497 DexPreoptImageLocationsOnDevice: deviceImageLocations,
Colin Cross43f08db2018-11-12 10:13:39 -0800498
Ulya Trafimovich9023b022021-03-22 16:02:28 +0000499 PreoptBootClassPathDexFiles: dexFiles.Paths(),
Vladimir Marko40139d62020-02-06 15:14:29 +0000500 PreoptBootClassPathDexLocations: dexLocations,
Colin Cross800fe132019-02-11 14:21:24 -0800501
Cole Fausteb032462024-09-19 11:12:54 -0700502 NoCreateAppImage: !appImage.GetOrDefault(true),
503 ForceCreateAppImage: appImage.GetOrDefault(false),
Colin Cross43f08db2018-11-12 10:13:39 -0800504
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700505 PresignedPrebuilt: d.isPresignedPrebuilt,
Colin Cross43f08db2018-11-12 10:13:39 -0800506 }
507
Spandan Das950deca2024-10-01 18:35:23 +0000508 if ctx.Config().InstallApexSystemServerDexpreoptSamePartition() {
509 dexpreoptConfig.ApexPartition = android.PathForModuleInstall(ctx).Partition()
510 } else {
511 dexpreoptConfig.ApexPartition = "system"
512 }
513
Spandan Das2069c3f2023-12-06 19:40:24 +0000514 d.configPath = android.PathForModuleOut(ctx, "dexpreopt", dexJarStem, "dexpreopt.config")
Jeongik Chac6246672021-04-08 00:00:19 +0900515 dexpreopt.WriteModuleConfig(ctx, dexpreoptConfig, d.configPath)
Colin Crossa6182ab2024-08-21 10:47:44 -0700516 ctx.CheckbuildFile(d.configPath)
Jeongik Chac6246672021-04-08 00:00:19 +0900517
Spandan Dase21a8d42024-01-23 23:56:29 +0000518 if d.dexpreoptDisabled(ctx, libName) {
Jeongik Chac6246672021-04-08 00:00:19 +0900519 return
520 }
521
522 globalSoong := dexpreopt.GetGlobalSoongConfig(ctx)
523
Jiakai Zhang51b2a8b2023-06-26 16:47:38 +0100524 // The root "product_packages.txt" is generated by `build/make/core/Makefile`. It contains a list
525 // of all packages that are installed on the device. We use `grep` to filter the list by the app's
526 // dependencies to create a per-app list, and use `rsync --checksum` to prevent the file's mtime
527 // from being changed if the contents don't change. This avoids unnecessary dexpreopt reruns.
Jiakai Zhanga4496782023-05-17 16:57:30 +0100528 productPackages := android.PathForModuleInPartitionInstall(ctx, "", "product_packages.txt")
Spandan Das2069c3f2023-12-06 19:40:24 +0000529 appProductPackages := android.PathForModuleOut(ctx, "dexpreopt", dexJarStem, "product_packages.txt")
Jiakai Zhang51b2a8b2023-06-26 16:47:38 +0100530 appProductPackagesStaging := appProductPackages.ReplaceExtension(ctx, "txt.tmp")
531 clcNames, _ := dexpreopt.ComputeClassLoaderContextDependencies(dexpreoptConfig.ClassLoaderContexts)
532 sort.Strings(clcNames) // The order needs to be deterministic.
533 productPackagesRule := android.NewRuleBuilder(pctx, ctx)
534 if len(clcNames) > 0 {
535 productPackagesRule.Command().
536 Text("grep -F -x").
537 FlagForEachArg("-e ", clcNames).
538 Input(productPackages).
539 FlagWithOutput("> ", appProductPackagesStaging).
540 Text("|| true")
541 } else {
542 productPackagesRule.Command().
543 Text("rm -f").Output(appProductPackagesStaging).
544 Text("&&").
545 Text("touch").Output(appProductPackagesStaging)
546 }
547 productPackagesRule.Command().
548 Text("rsync --checksum").
549 Input(appProductPackagesStaging).
550 Output(appProductPackages)
Spandan Das2069c3f2023-12-06 19:40:24 +0000551 productPackagesRule.Restat().Build("product_packages."+dexJarStem, "dexpreopt product_packages")
Jiakai Zhanga4496782023-05-17 16:57:30 +0100552
Spandan Das5ae65ee2024-04-16 22:03:26 +0000553 // Prebuilts are active, do not copy the dexpreopt'd source javalib to out/soong/system_server_dexjars
554 // The javalib from the deapexed prebuilt will be copied to this location.
555 // TODO (b/331665856): Implement a principled solution for this.
Spandan Das50801e22024-05-13 18:29:45 +0000556 copyApexSystemServerJarDex := !disableSourceApexVariant(ctx) && !ctx.Module().IsHideFromMake()
Jiakai Zhanga4496782023-05-17 16:57:30 +0100557 dexpreoptRule, err := dexpreopt.GenerateDexpreoptRule(
Spandan Das5ae65ee2024-04-16 22:03:26 +0000558 ctx, globalSoong, global, dexpreoptConfig, appProductPackages, copyApexSystemServerJarDex)
Colin Cross43f08db2018-11-12 10:13:39 -0800559 if err != nil {
560 ctx.ModuleErrorf("error generating dexpreopt rule: %s", err.Error())
Jaewoong Jung4b97a562020-12-17 09:43:28 -0800561 return
Colin Cross43f08db2018-11-12 10:13:39 -0800562 }
563
Spandan Das2069c3f2023-12-06 19:40:24 +0000564 dexpreoptRule.Build("dexpreopt"+"."+dexJarStem, "dexpreopt")
Colin Cross43f08db2018-11-12 10:13:39 -0800565
Spandan Das2069c3f2023-12-06 19:40:24 +0000566 // The current ctx might be of a deapexer module created by a prebuilt apex
567 // Use the path of the dex file to determine the library name
568 isApexSystemServerJar := global.AllApexSystemServerJars(ctx).ContainsJar(dexJarStem)
Jiakai Zhang389a6472021-12-14 18:54:06 +0000569
Justin Yun613bdc52024-06-12 21:32:10 +0900570 dexpreoptPartition := d.installPath.Partition()
571 // dexpreoptPartition is set to empty for dexpreopts of system APEX and system_other.
572 // In case of system APEX, however, we can set it to "system" manually.
573 // TODO(b/346662300): Let dexpreopter generate the installPath for dexpreopt files instead of
574 // using the dex location to generate the installPath.
575 if isApexSystemServerJar {
Spandan Das906222c2024-10-17 18:29:54 +0000576 dexpreoptPartition = dexpreoptConfig.ApexPartition
Justin Yun613bdc52024-06-12 21:32:10 +0900577 }
Colin Cross1d0eb7a2021-11-03 14:08:20 -0700578 for _, install := range dexpreoptRule.Installs() {
579 // Remove the "/" prefix because the path should be relative to $ANDROID_PRODUCT_OUT.
580 installDir := strings.TrimPrefix(filepath.Dir(install.To), "/")
Justin Yun613bdc52024-06-12 21:32:10 +0900581 partition := dexpreoptPartition
Justin Yun22c8aca2024-06-05 20:25:03 +0900582 if strings.HasPrefix(installDir, partition+"/") {
583 installDir = strings.TrimPrefix(installDir, partition+"/")
584 } else {
585 // If the partition for the installDir is different from the install partition, set the
586 // partition empty to install the dexpreopt files to the desired partition.
587 // TODO(b/346439786): Define and use the dexpreopt module type to avoid this mismatch.
588 partition = ""
589 }
Colin Cross1d0eb7a2021-11-03 14:08:20 -0700590 installBase := filepath.Base(install.To)
591 arch := filepath.Base(installDir)
Justin Yun22c8aca2024-06-05 20:25:03 +0900592 installPath := android.PathForModuleInPartitionInstall(ctx, partition, installDir)
Jiakai Zhang3317ce72023-02-08 01:19:19 +0800593 isProfile := strings.HasSuffix(installBase, ".prof")
594
595 if isProfile {
Jiakai Zhang81e46812023-02-08 21:56:07 +0800596 d.outputProfilePathOnHost = install.From
Jiakai Zhang3317ce72023-02-08 01:19:19 +0800597 }
Colin Cross1d0eb7a2021-11-03 14:08:20 -0700598
Jiakai Zhang389a6472021-12-14 18:54:06 +0000599 if isApexSystemServerJar {
Jiakai Zhang3317ce72023-02-08 01:19:19 +0800600 // Profiles are handled separately because they are installed into the APEX.
601 if !isProfile {
602 // APEX variants of java libraries are hidden from Make, so their dexpreopt
603 // outputs need special handling. Currently, for APEX variants of java
604 // libraries, only those in the system server classpath are handled here.
605 // Preopting of boot classpath jars in the ART APEX are handled in
606 // java/dexpreopt_bootjars.go, and other APEX jars are not preopted.
607 // The installs will be handled by Make as sub-modules of the java library.
Spandan Das746161d2024-08-21 22:47:53 +0000608 di := dexpreopterInstall{
Jiakai Zhang3317ce72023-02-08 01:19:19 +0800609 name: arch + "-" + installBase,
Spandan Dase21a8d42024-01-23 23:56:29 +0000610 moduleName: libName,
Jiakai Zhang3317ce72023-02-08 01:19:19 +0800611 outputPathOnHost: install.From,
612 installDirOnDevice: installPath,
613 installFileOnDevice: installBase,
Spandan Das746161d2024-08-21 22:47:53 +0000614 }
615 ctx.InstallFile(di.installDirOnDevice, di.installFileOnDevice, di.outputPathOnHost)
616 d.builtInstalledForApex = append(d.builtInstalledForApex, di)
617
Jiakai Zhang3317ce72023-02-08 01:19:19 +0800618 }
Colin Crossfa9bfcd2021-11-10 16:42:38 -0800619 } else if !d.preventInstall {
Colin Crossa6182ab2024-08-21 10:47:44 -0700620 // Install without adding to checkbuild to match behavior of previous Make-based checkbuild rules
621 ctx.InstallFileWithoutCheckbuild(installPath, installBase, install.From)
Jiakai Zhangca9bc982021-09-09 08:09:41 +0000622 }
Colin Cross1d0eb7a2021-11-03 14:08:20 -0700623 }
624
Jiakai Zhang389a6472021-12-14 18:54:06 +0000625 if !isApexSystemServerJar {
Jiakai Zhangca9bc982021-09-09 08:09:41 +0000626 d.builtInstalled = dexpreoptRule.Installs().String()
627 }
628}
629
Justin Yun22c8aca2024-06-05 20:25:03 +0900630func getModuleInstallPathInfo(ctx android.ModuleContext, fullInstallPath string) (android.InstallPath, string, string) {
631 installPath := android.PathForModuleInstall(ctx)
632 installDir, installBase := filepath.Split(strings.TrimPrefix(fullInstallPath, "/"))
633
634 if !strings.HasPrefix(installDir, installPath.Partition()+"/") {
635 // Return empty filename if the install partition is not for the target image.
636 return installPath, "", ""
637 }
638 relDir, err := filepath.Rel(installPath.Partition(), installDir)
639 if err != nil {
640 panic(err)
641 }
642 return installPath, relDir, installBase
643}
644
Spandan Das29207b52024-07-30 23:28:17 +0000645// installFile will install the file if `install` path and the target install partition are the same.
646func installFile(ctx android.ModuleContext, install android.RuleBuilderInstall) {
Justin Yun22c8aca2024-06-05 20:25:03 +0900647 installPath, relDir, name := getModuleInstallPathInfo(ctx, install.To)
648 // Empty name means the install partition is not for the target image.
649 // For the system image, files for "apex" and "system_other" are skipped here.
650 // The skipped "apex" files are for testing only, for example,
651 // "/apex/art_boot_images/javalib/x86/boot.vdex".
652 // TODO(b/320196894): Files for "system_other" are skipped because soong creates the system
653 // image only for now.
654 if name != "" {
Spandan Das29207b52024-07-30 23:28:17 +0000655 ctx.InstallFile(installPath.Join(ctx, relDir), name, install.From)
Justin Yun22c8aca2024-06-05 20:25:03 +0900656 }
657}
658
Jiakai Zhangca9bc982021-09-09 08:09:41 +0000659func (d *dexpreopter) DexpreoptBuiltInstalledForApex() []dexpreopterInstall {
660 return d.builtInstalledForApex
661}
662
663func (d *dexpreopter) AndroidMkEntriesForApex() []android.AndroidMkEntries {
664 var entries []android.AndroidMkEntries
665 for _, install := range d.builtInstalledForApex {
Jiakai Zhang6decef92022-01-12 17:56:19 +0000666 entries = append(entries, install.ToMakeEntries())
Jiakai Zhangca9bc982021-09-09 08:09:41 +0000667 }
668 return entries
Colin Cross43f08db2018-11-12 10:13:39 -0800669}
Jiakai Zhang3317ce72023-02-08 01:19:19 +0800670
Jihoon Kangd4063812025-01-24 00:25:30 +0000671func (d *dexpreopter) ModuleInfoJSONForApex(ctx android.ModuleContext) {
672 for _, install := range d.builtInstalledForApex {
673 install.AddModuleInfoJSONForApex(ctx)
674 }
675}
676
Jiakai Zhang81e46812023-02-08 21:56:07 +0800677func (d *dexpreopter) OutputProfilePathOnHost() android.Path {
678 return d.outputProfilePathOnHost
Jiakai Zhang3317ce72023-02-08 01:19:19 +0800679}
Spandan Das0727ba72024-02-13 16:37:43 +0000680
681func (d *dexpreopter) disableDexpreopt() {
682 d.shouldDisableDexpreopt = true
683}
Spandan Das3dbda182024-05-20 22:23:10 +0000684
Cole Fausteb032462024-09-19 11:12:54 -0700685func (d *dexpreopter) EnableProfileRewriting(ctx android.BaseModuleContext) bool {
686 return d.dexpreoptProperties.Dex_preopt.Enable_profile_rewriting.GetOrDefault(ctx, false)
Spandan Das3dbda182024-05-20 22:23:10 +0000687}
688
Cole Fausteb032462024-09-19 11:12:54 -0700689func (d *dexpreopter) GetProfile(ctx android.BaseModuleContext) string {
690 return d.dexpreoptProperties.Dex_preopt.Profile.GetOrDefault(ctx, "")
Spandan Das3dbda182024-05-20 22:23:10 +0000691}
692
Cole Fausteb032462024-09-19 11:12:54 -0700693func (d *dexpreopter) GetProfileGuided(ctx android.BaseModuleContext) bool {
694 return d.dexpreoptProperties.Dex_preopt.Profile_guided.GetOrDefault(ctx, false)
Spandan Das3dbda182024-05-20 22:23:10 +0000695}
696
697func (d *dexpreopter) GetRewrittenProfile() android.Path {
698 return d.rewrittenProfile
699}
700
701func (d *dexpreopter) SetRewrittenProfile(p android.Path) {
702 d.rewrittenProfile = p
703}