blob: c4b0af441717f1f43f2920c88b8ba138d2aff53c [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"
19 "strings"
20
Colin Cross43f08db2018-11-12 10:13:39 -080021 "android/soong/android"
22 "android/soong/dexpreopt"
23)
24
Jiakai Zhangca9bc982021-09-09 08:09:41 +000025type DexpreopterInterface interface {
Martin Stjernholm6d415272020-01-31 17:10:36 +000026 IsInstallable() bool // Structs that embed dexpreopter must implement this.
27 dexpreoptDisabled(ctx android.BaseModuleContext) bool
Jiakai Zhangca9bc982021-09-09 08:09:41 +000028 DexpreoptBuiltInstalledForApex() []dexpreopterInstall
29 AndroidMkEntriesForApex() []android.AndroidMkEntries
Jiakai Zhang3317ce72023-02-08 01:19:19 +080030 ProfilePathOnHost() android.Path
Jiakai Zhangca9bc982021-09-09 08:09:41 +000031}
32
33type dexpreopterInstall struct {
34 // A unique name to distinguish an output from others for the same java library module. Usually in
35 // the form of `<arch>-<encoded-path>.odex/vdex/art`.
36 name string
37
38 // The name of the input java module.
39 moduleName string
40
41 // The path to the dexpreopt output on host.
42 outputPathOnHost android.Path
43
44 // The directory on the device for the output to install to.
45 installDirOnDevice android.InstallPath
46
47 // The basename (the last segment of the path) for the output to install as.
48 installFileOnDevice string
49}
50
51// The full module name of the output in the makefile.
52func (install *dexpreopterInstall) FullModuleName() string {
53 return install.moduleName + install.SubModuleName()
54}
55
56// The sub-module name of the output in the makefile (the name excluding the java module name).
57func (install *dexpreopterInstall) SubModuleName() string {
58 return "-dexpreopt-" + install.name
Martin Stjernholm6d415272020-01-31 17:10:36 +000059}
60
Jiakai Zhang6decef92022-01-12 17:56:19 +000061// Returns Make entries for installing the file.
62//
63// This function uses a value receiver rather than a pointer receiver to ensure that the object is
64// safe to use in `android.AndroidMkExtraEntriesFunc`.
65func (install dexpreopterInstall) ToMakeEntries() android.AndroidMkEntries {
66 return android.AndroidMkEntries{
67 Class: "ETC",
68 SubName: install.SubModuleName(),
69 OutputFile: android.OptionalPathForPath(install.outputPathOnHost),
70 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
71 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
72 entries.SetString("LOCAL_MODULE_PATH", install.installDirOnDevice.String())
73 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", install.installFileOnDevice)
74 entries.SetString("LOCAL_NOT_AVAILABLE_FOR_PLATFORM", "false")
75 },
76 },
77 }
78}
79
Colin Cross43f08db2018-11-12 10:13:39 -080080type dexpreopter struct {
81 dexpreoptProperties DexpreoptProperties
82
Colin Cross70dda7e2019-10-01 22:05:35 -070083 installPath android.InstallPath
Jaewoong Jungccbb3932019-04-15 09:48:31 -070084 uncompressedDex bool
85 isSDKLibrary bool
Ulya Trafimovich76b08522021-01-14 17:52:43 +000086 isApp bool
Jaewoong Jungccbb3932019-04-15 09:48:31 -070087 isTest bool
Jaewoong Jungccbb3932019-04-15 09:48:31 -070088 isPresignedPrebuilt bool
Colin Crossfa9bfcd2021-11-10 16:42:38 -080089 preventInstall bool
Colin Cross43f08db2018-11-12 10:13:39 -080090
Ulya Trafimovich8cbc5d22020-11-03 15:15:46 +000091 manifestFile android.Path
Ulya Trafimovich8c35fcf2021-02-17 16:23:28 +000092 statusFile android.WritablePath
Ulya Trafimovich8cbc5d22020-11-03 15:15:46 +000093 enforceUsesLibs bool
94 classLoaderContexts dexpreopt.ClassLoaderContextMap
Colin Cross50ddcc42019-05-16 12:28:22 -070095
Jiakai Zhangca9bc982021-09-09 08:09:41 +000096 // See the `dexpreopt` function for details.
97 builtInstalled string
98 builtInstalledForApex []dexpreopterInstall
Ulya Trafimovich76b08522021-01-14 17:52:43 +000099
Jeongik Chac6246672021-04-08 00:00:19 +0900100 // The config is used for two purposes:
101 // - Passing dexpreopt information about libraries from Soong to Make. This is needed when
102 // a <uses-library> is defined in Android.bp, but used in Android.mk (see dex_preopt_config_merger.py).
103 // Note that dexpreopt.config might be needed even if dexpreopt is disabled for the library itself.
104 // - Dexpreopt post-processing (using dexpreopt artifacts from a prebuilt system image to incrementally
105 // dexpreopt another partition).
Ulya Trafimovich76b08522021-01-14 17:52:43 +0000106 configPath android.WritablePath
Jiakai Zhang3317ce72023-02-08 01:19:19 +0800107
108 // The path to the profile on host.
109 profilePathOnHost android.Path
Colin Cross43f08db2018-11-12 10:13:39 -0800110}
111
112type DexpreoptProperties struct {
113 Dex_preopt struct {
Nicolas Geoffrayc1bf7242019-10-18 14:51:38 +0100114 // If false, prevent dexpreopting. Defaults to true.
Colin Cross43f08db2018-11-12 10:13:39 -0800115 Enabled *bool
116
117 // If true, generate an app image (.art file) for this module.
118 App_image *bool
119
120 // If true, use a checked-in profile to guide optimization. Defaults to false unless
121 // a matching profile is set or a profile is found in PRODUCT_DEX_PREOPT_PROFILE_DIR
122 // that matches the name of this module, in which case it is defaulted to true.
123 Profile_guided *bool
124
125 // If set, provides the path to profile relative to the Android.bp file. If not set,
126 // defaults to searching for a file that matches the name of this module in the default
127 // profile location set by PRODUCT_DEX_PREOPT_PROFILE_DIR, or empty if not found.
Colin Crossde4e4e62019-04-26 10:52:32 -0700128 Profile *string `android:"path"`
Colin Cross43f08db2018-11-12 10:13:39 -0800129 }
130}
131
Ulya Trafimovich6cf2c0c2020-04-24 12:15:20 +0100132func init() {
133 dexpreopt.DexpreoptRunningInSoong = true
134}
135
Jiakai Zhangca9bc982021-09-09 08:09:41 +0000136func isApexVariant(ctx android.BaseModuleContext) bool {
137 apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
138 return !apexInfo.IsForPlatform()
139}
140
Jiakai Zhang28bc9a82021-12-20 15:08:57 +0000141func forPrebuiltApex(ctx android.BaseModuleContext) bool {
142 apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
143 return apexInfo.ForPrebuiltApex
144}
145
Jiakai Zhangca9bc982021-09-09 08:09:41 +0000146func moduleName(ctx android.BaseModuleContext) string {
147 // Remove the "prebuilt_" prefix if the module is from a prebuilt because the prefix is not
148 // expected by dexpreopter.
149 return android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName())
150}
151
Martin Stjernholm6d415272020-01-31 17:10:36 +0000152func (d *dexpreopter) dexpreoptDisabled(ctx android.BaseModuleContext) bool {
Colin Cross38310bb2021-12-01 10:34:14 -0800153 if !ctx.Device() {
Colin Cross43f08db2018-11-12 10:13:39 -0800154 return true
155 }
156
Colin Cross43f08db2018-11-12 10:13:39 -0800157 if d.isTest {
158 return true
159 }
160
161 if !BoolDefault(d.dexpreoptProperties.Dex_preopt.Enabled, true) {
162 return true
163 }
164
Jiakai Zhang28bc9a82021-12-20 15:08:57 +0000165 // If the module is from a prebuilt APEX, it shouldn't be installable, but it can still be
166 // dexpreopted.
167 if !ctx.Module().(DexpreopterInterface).IsInstallable() && !forPrebuiltApex(ctx) {
Martin Stjernholm6d415272020-01-31 17:10:36 +0000168 return true
169 }
170
Colin Cross38310bb2021-12-01 10:34:14 -0800171 if !android.IsModulePreferred(ctx.Module()) {
172 return true
173 }
174
175 global := dexpreopt.GetGlobalConfig(ctx)
176
177 if global.DisablePreopt {
178 return true
179 }
180
181 if inList(moduleName(ctx), global.DisablePreoptModules) {
Colin Crossdc2da912019-01-05 22:13:05 -0800182 return true
183 }
184
Jiakai Zhang389a6472021-12-14 18:54:06 +0000185 isApexSystemServerJar := global.AllApexSystemServerJars(ctx).ContainsJar(moduleName(ctx))
Jiakai Zhangca9bc982021-09-09 08:09:41 +0000186 if isApexVariant(ctx) {
Jiakai Zhang3317ce72023-02-08 01:19:19 +0800187 // Don't preopt APEX variant module unless the module is an APEX system server jar.
188 if !isApexSystemServerJar {
Jiakai Zhangca9bc982021-09-09 08:09:41 +0000189 return true
190 }
191 } else {
192 // Don't preopt the platform variant of an APEX system server jar to avoid conflicts.
Jiakai Zhang389a6472021-12-14 18:54:06 +0000193 if isApexSystemServerJar {
Jiakai Zhangca9bc982021-09-09 08:09:41 +0000194 return true
195 }
Yo Chiangdbdf8f92020-01-09 19:00:27 +0800196 }
197
Colin Cross43f08db2018-11-12 10:13:39 -0800198 // TODO: contains no java code
199
200 return false
201}
202
Martin Stjernholm6d415272020-01-31 17:10:36 +0000203func dexpreoptToolDepsMutator(ctx android.BottomUpMutatorContext) {
Jiakai Zhangca9bc982021-09-09 08:09:41 +0000204 if d, ok := ctx.Module().(DexpreopterInterface); !ok || d.dexpreoptDisabled(ctx) {
Martin Stjernholm6d415272020-01-31 17:10:36 +0000205 return
206 }
207 dexpreopt.RegisterToolDeps(ctx)
208}
209
Jiakai Zhangca9bc982021-09-09 08:09:41 +0000210func (d *dexpreopter) odexOnSystemOther(ctx android.ModuleContext, installPath android.InstallPath) bool {
211 return dexpreopt.OdexOnSystemOtherByName(moduleName(ctx), android.InstallPathToOnDevicePath(ctx, installPath), dexpreopt.GetGlobalConfig(ctx))
212}
213
214// Returns the install path of the dex jar of a module.
215//
216// Do not rely on `ApexInfo.ApexVariationName` because it can be something like "apex1000", rather
217// than the `name` in the path `/apex/<name>` as suggested in its comment.
218//
219// This function is on a best-effort basis. It cannot handle the case where an APEX jar is not a
220// system server jar, which is fine because we currently only preopt system server jars for APEXes.
221func (d *dexpreopter) getInstallPath(
222 ctx android.ModuleContext, defaultInstallPath android.InstallPath) android.InstallPath {
223 global := dexpreopt.GetGlobalConfig(ctx)
Jiakai Zhang389a6472021-12-14 18:54:06 +0000224 if global.AllApexSystemServerJars(ctx).ContainsJar(moduleName(ctx)) {
225 dexLocation := dexpreopt.GetSystemServerDexLocation(ctx, global, moduleName(ctx))
Jiakai Zhangca9bc982021-09-09 08:09:41 +0000226 return android.PathForModuleInPartitionInstall(ctx, "", strings.TrimPrefix(dexLocation, "/"))
227 }
228 if !d.dexpreoptDisabled(ctx) && isApexVariant(ctx) &&
229 filepath.Base(defaultInstallPath.PartitionDir()) != "apex" {
230 ctx.ModuleErrorf("unable to get the install path of the dex jar for dexpreopt")
231 }
232 return defaultInstallPath
Nicolas Geoffrayfa6e9ec2019-02-12 13:12:16 +0000233}
234
Paul Duffin612e6102021-02-02 13:38:13 +0000235func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.WritablePath) {
Jiakai Zhangca9bc982021-09-09 08:09:41 +0000236 global := dexpreopt.GetGlobalConfig(ctx)
237
Martin Stjernholm6d415272020-01-31 17:10:36 +0000238 // TODO(b/148690468): The check on d.installPath is to bail out in cases where
239 // the dexpreopter struct hasn't been fully initialized before we're called,
240 // e.g. in aar.go. This keeps the behaviour that dexpreopting is effectively
241 // disabled, even if installable is true.
Ulya Trafimovich76b08522021-01-14 17:52:43 +0000242 if d.installPath.Base() == "." {
243 return
244 }
245
246 dexLocation := android.InstallPathToOnDevicePath(ctx, d.installPath)
247
Jiakai Zhangca9bc982021-09-09 08:09:41 +0000248 providesUsesLib := moduleName(ctx)
Ulya Trafimovich76b08522021-01-14 17:52:43 +0000249 if ulib, ok := ctx.Module().(ProvidesUsesLib); ok {
250 name := ulib.ProvidesUsesLib()
251 if name != nil {
252 providesUsesLib = *name
253 }
254 }
255
Jeongik Cha4b073cd2021-06-08 11:35:00 +0900256 // If it is test, make config files regardless of its dexpreopt setting.
Jeongik Chac6246672021-04-08 00:00:19 +0900257 // The config files are required for apps defined in make which depend on the lib.
Jeongik Cha4b073cd2021-06-08 11:35:00 +0900258 if d.isTest && d.dexpreoptDisabled(ctx) {
Jaewoong Jung4b97a562020-12-17 09:43:28 -0800259 return
Nicolas Geoffrayfa6e9ec2019-02-12 13:12:16 +0000260 }
261
Jiakai Zhang389a6472021-12-14 18:54:06 +0000262 isSystemServerJar := global.AllSystemServerJars(ctx).ContainsJar(moduleName(ctx))
Ulya Trafimovich9023b022021-03-22 16:02:28 +0000263
Colin Cross44df5812019-02-15 23:06:46 -0800264 bootImage := defaultBootImageConfig(ctx)
Jiakai Zhang02669e82021-09-11 03:44:06 +0000265 dexFiles, dexLocations := bcpForDexpreopt(ctx, global.PreoptWithUpdatableBcp)
Ulya Trafimovich9023b022021-03-22 16:02:28 +0000266
David Srbeckyc177ebe2020-02-18 20:43:06 +0000267 targets := ctx.MultiTargets()
268 if len(targets) == 0 {
Colin Cross43f08db2018-11-12 10:13:39 -0800269 // assume this is a java library, dexpreopt for all arches for now
270 for _, target := range ctx.Config().Targets[android.Android] {
dimitry1f33e402019-03-26 12:39:31 +0100271 if target.NativeBridge == android.NativeBridgeDisabled {
David Srbeckyc177ebe2020-02-18 20:43:06 +0000272 targets = append(targets, target)
dimitry1f33e402019-03-26 12:39:31 +0100273 }
Colin Cross43f08db2018-11-12 10:13:39 -0800274 }
Jiakai Zhang2fbc3552022-11-28 15:38:23 +0000275 if isSystemServerJar && moduleName(ctx) != "com.android.location.provider" {
276 // If the module is a system server jar, only preopt for the primary arch because the jar can
277 // only be loaded by system server. "com.android.location.provider" is a special case because
278 // it's also used by apps as a shared library.
David Srbeckyc177ebe2020-02-18 20:43:06 +0000279 targets = targets[:1]
Colin Cross43f08db2018-11-12 10:13:39 -0800280 }
281 }
Colin Cross43f08db2018-11-12 10:13:39 -0800282
David Srbeckyc177ebe2020-02-18 20:43:06 +0000283 var archs []android.ArchType
Colin Cross69f59a32019-02-15 10:39:37 -0800284 var images android.Paths
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +0000285 var imagesDeps []android.OutputPaths
David Srbeckyc177ebe2020-02-18 20:43:06 +0000286 for _, target := range targets {
287 archs = append(archs, target.Arch.ArchType)
288 variant := bootImage.getVariant(target)
Jeongik Chaa5969092021-05-07 18:53:21 +0900289 images = append(images, variant.imagePathOnHost)
David Srbeckyc177ebe2020-02-18 20:43:06 +0000290 imagesDeps = append(imagesDeps, variant.imagesDeps)
Colin Crossc7e40aa2019-02-08 21:37:00 -0800291 }
David Srbeckyab994982020-03-30 17:24:13 +0100292 // The image locations for all Android variants are identical.
Jeongik Cha4dda75e2021-04-27 23:56:44 +0900293 hostImageLocations, deviceImageLocations := bootImage.getAnyAndroidVariant().imageLocations()
Colin Crossc7e40aa2019-02-08 21:37:00 -0800294
Colin Cross43f08db2018-11-12 10:13:39 -0800295 var profileClassListing android.OptionalPath
Nicolas Geoffraye7102422019-07-24 13:19:29 +0100296 var profileBootListing android.OptionalPath
Colin Cross43f08db2018-11-12 10:13:39 -0800297 profileIsTextListing := false
298 if BoolDefault(d.dexpreoptProperties.Dex_preopt.Profile_guided, true) {
299 // If dex_preopt.profile_guided is not set, default it based on the existence of the
300 // dexprepot.profile option or the profile class listing.
301 if String(d.dexpreoptProperties.Dex_preopt.Profile) != "" {
302 profileClassListing = android.OptionalPathForPath(
303 android.PathForModuleSrc(ctx, String(d.dexpreoptProperties.Dex_preopt.Profile)))
Nicolas Geoffraye7102422019-07-24 13:19:29 +0100304 profileBootListing = android.ExistentPathForSource(ctx,
305 ctx.ModuleDir(), String(d.dexpreoptProperties.Dex_preopt.Profile)+"-boot")
Colin Cross43f08db2018-11-12 10:13:39 -0800306 profileIsTextListing = true
Dan Willemsen78d51b02020-06-24 16:33:31 -0700307 } else if global.ProfileDir != "" {
Colin Cross43f08db2018-11-12 10:13:39 -0800308 profileClassListing = android.ExistentPathForSource(ctx,
Jiakai Zhangca9bc982021-09-09 08:09:41 +0000309 global.ProfileDir, moduleName(ctx)+".prof")
Colin Cross43f08db2018-11-12 10:13:39 -0800310 }
311 }
312
Ulya Trafimovich76b08522021-01-14 17:52:43 +0000313 // Full dexpreopt config, used to create dexpreopt build rules.
Martin Stjernholm8d80cee2020-01-31 17:44:54 +0000314 dexpreoptConfig := &dexpreopt.ModuleConfig{
Jiakai Zhangca9bc982021-09-09 08:09:41 +0000315 Name: moduleName(ctx),
Victor Hsiehd181c8b2019-01-29 13:00:33 -0800316 DexLocation: dexLocation,
Jiakai Zhangca9bc982021-09-09 08:09:41 +0000317 BuildPath: android.PathForModuleOut(ctx, "dexpreopt", moduleName(ctx)+".jar").OutputPath,
Colin Cross69f59a32019-02-15 10:39:37 -0800318 DexPath: dexJarFile,
Jeongik Cha33a3a812021-04-15 09:12:49 +0900319 ManifestPath: android.OptionalPathForPath(d.manifestFile),
Victor Hsiehd181c8b2019-01-29 13:00:33 -0800320 UncompressedDex: d.uncompressedDex,
321 HasApkLibraries: false,
322 PreoptFlags: nil,
Colin Cross43f08db2018-11-12 10:13:39 -0800323
Colin Cross69f59a32019-02-15 10:39:37 -0800324 ProfileClassListing: profileClassListing,
Colin Cross43f08db2018-11-12 10:13:39 -0800325 ProfileIsTextListing: profileIsTextListing,
Nicolas Geoffraye7102422019-07-24 13:19:29 +0100326 ProfileBootListing: profileBootListing,
Colin Cross43f08db2018-11-12 10:13:39 -0800327
Ulya Trafimovich8c35fcf2021-02-17 16:23:28 +0000328 EnforceUsesLibrariesStatusFile: dexpreopt.UsesLibrariesStatusFile(ctx),
329 EnforceUsesLibraries: d.enforceUsesLibs,
330 ProvidesUsesLibrary: providesUsesLib,
331 ClassLoaderContexts: d.classLoaderContexts,
Colin Cross43f08db2018-11-12 10:13:39 -0800332
Jeongik Cha4dda75e2021-04-27 23:56:44 +0900333 Archs: archs,
334 DexPreoptImagesDeps: imagesDeps,
335 DexPreoptImageLocationsOnHost: hostImageLocations,
336 DexPreoptImageLocationsOnDevice: deviceImageLocations,
Colin Cross43f08db2018-11-12 10:13:39 -0800337
Ulya Trafimovich9023b022021-03-22 16:02:28 +0000338 PreoptBootClassPathDexFiles: dexFiles.Paths(),
Vladimir Marko40139d62020-02-06 15:14:29 +0000339 PreoptBootClassPathDexLocations: dexLocations,
Colin Cross800fe132019-02-11 14:21:24 -0800340
Colin Cross43f08db2018-11-12 10:13:39 -0800341 PreoptExtractedApk: false,
342
343 NoCreateAppImage: !BoolDefault(d.dexpreoptProperties.Dex_preopt.App_image, true),
344 ForceCreateAppImage: BoolDefault(d.dexpreoptProperties.Dex_preopt.App_image, false),
345
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700346 PresignedPrebuilt: d.isPresignedPrebuilt,
Colin Cross43f08db2018-11-12 10:13:39 -0800347 }
348
Jeongik Chac6246672021-04-08 00:00:19 +0900349 d.configPath = android.PathForModuleOut(ctx, "dexpreopt", "dexpreopt.config")
350 dexpreopt.WriteModuleConfig(ctx, dexpreoptConfig, d.configPath)
351
352 if d.dexpreoptDisabled(ctx) {
353 return
354 }
355
356 globalSoong := dexpreopt.GetGlobalSoongConfig(ctx)
357
Martin Stjernholm75a48d82020-01-10 20:32:59 +0000358 dexpreoptRule, err := dexpreopt.GenerateDexpreoptRule(ctx, globalSoong, global, dexpreoptConfig)
Colin Cross43f08db2018-11-12 10:13:39 -0800359 if err != nil {
360 ctx.ModuleErrorf("error generating dexpreopt rule: %s", err.Error())
Jaewoong Jung4b97a562020-12-17 09:43:28 -0800361 return
Colin Cross43f08db2018-11-12 10:13:39 -0800362 }
363
Colin Crossf1a035e2020-11-16 17:32:30 -0800364 dexpreoptRule.Build("dexpreopt", "dexpreopt")
Colin Cross43f08db2018-11-12 10:13:39 -0800365
Jiakai Zhang389a6472021-12-14 18:54:06 +0000366 isApexSystemServerJar := global.AllApexSystemServerJars(ctx).ContainsJar(moduleName(ctx))
367
Colin Cross1d0eb7a2021-11-03 14:08:20 -0700368 for _, install := range dexpreoptRule.Installs() {
369 // Remove the "/" prefix because the path should be relative to $ANDROID_PRODUCT_OUT.
370 installDir := strings.TrimPrefix(filepath.Dir(install.To), "/")
371 installBase := filepath.Base(install.To)
372 arch := filepath.Base(installDir)
373 installPath := android.PathForModuleInPartitionInstall(ctx, "", installDir)
Jiakai Zhang3317ce72023-02-08 01:19:19 +0800374 isProfile := strings.HasSuffix(installBase, ".prof")
375
376 if isProfile {
377 d.profilePathOnHost = install.From
378 }
Colin Cross1d0eb7a2021-11-03 14:08:20 -0700379
Jiakai Zhang389a6472021-12-14 18:54:06 +0000380 if isApexSystemServerJar {
Jiakai Zhang3317ce72023-02-08 01:19:19 +0800381 // Profiles are handled separately because they are installed into the APEX.
382 if !isProfile {
383 // APEX variants of java libraries are hidden from Make, so their dexpreopt
384 // outputs need special handling. Currently, for APEX variants of java
385 // libraries, only those in the system server classpath are handled here.
386 // Preopting of boot classpath jars in the ART APEX are handled in
387 // java/dexpreopt_bootjars.go, and other APEX jars are not preopted.
388 // The installs will be handled by Make as sub-modules of the java library.
389 d.builtInstalledForApex = append(d.builtInstalledForApex, dexpreopterInstall{
390 name: arch + "-" + installBase,
391 moduleName: moduleName(ctx),
392 outputPathOnHost: install.From,
393 installDirOnDevice: installPath,
394 installFileOnDevice: installBase,
395 })
396 }
Colin Crossfa9bfcd2021-11-10 16:42:38 -0800397 } else if !d.preventInstall {
Colin Cross1d0eb7a2021-11-03 14:08:20 -0700398 ctx.InstallFile(installPath, installBase, install.From)
Jiakai Zhangca9bc982021-09-09 08:09:41 +0000399 }
Colin Cross1d0eb7a2021-11-03 14:08:20 -0700400 }
401
Jiakai Zhang389a6472021-12-14 18:54:06 +0000402 if !isApexSystemServerJar {
Jiakai Zhangca9bc982021-09-09 08:09:41 +0000403 d.builtInstalled = dexpreoptRule.Installs().String()
404 }
405}
406
407func (d *dexpreopter) DexpreoptBuiltInstalledForApex() []dexpreopterInstall {
408 return d.builtInstalledForApex
409}
410
411func (d *dexpreopter) AndroidMkEntriesForApex() []android.AndroidMkEntries {
412 var entries []android.AndroidMkEntries
413 for _, install := range d.builtInstalledForApex {
Jiakai Zhang6decef92022-01-12 17:56:19 +0000414 entries = append(entries, install.ToMakeEntries())
Jiakai Zhangca9bc982021-09-09 08:09:41 +0000415 }
416 return entries
Colin Cross43f08db2018-11-12 10:13:39 -0800417}
Jiakai Zhang3317ce72023-02-08 01:19:19 +0800418
419func (d *dexpreopter) ProfilePathOnHost() android.Path {
420 return d.profilePathOnHost
421}