blob: e6a431343281d160a87cce13b1ae544e3b5e5514 [file] [log] [blame]
Colin Cross800fe132019-02-11 14:21:24 -08001// Copyright 2019 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 (
18 "path/filepath"
Vladimir Marko205e6c22020-04-01 13:52:27 +010019 "sort"
Colin Cross800fe132019-02-11 14:21:24 -080020 "strings"
21
22 "android/soong/android"
23 "android/soong/dexpreopt"
24
Colin Cross800fe132019-02-11 14:21:24 -080025 "github.com/google/blueprint/proptools"
26)
27
28func init() {
Ulya Trafimovichb28cc372020-01-13 15:18:16 +000029 RegisterDexpreoptBootJarsComponents(android.InitRegistrationContext)
Colin Cross800fe132019-02-11 14:21:24 -080030}
31
David Srbeckyc177ebe2020-02-18 20:43:06 +000032// Target-independent description of pre-compiled boot image.
Colin Cross44df5812019-02-15 23:06:46 -080033type bootImageConfig struct {
David Srbecky1aacc6c2020-03-26 11:10:45 +000034 // If this image is an extension, the image that it extends.
35 extends *bootImageConfig
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +000036
37 // Image name (used in directory names and ninja rule names).
38 name string
39
40 // Basename of the image: the resulting filenames are <stem>[-<jar>].{art,oat,vdex}.
41 stem string
42
43 // Output directory for the image files.
44 dir android.OutputPath
45
46 // Output directory for the image files with debug symbols.
47 symbolsDir android.OutputPath
48
49 // Subdirectory where the image files are installed.
50 installSubdir string
51
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +000052 // The names of jars that constitute this image.
53 modules []string
54
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +000055 // File paths to jars.
56 dexPaths android.WritablePaths // for this image
57 dexPathsDeps android.WritablePaths // for the dependency images and in this image
58
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +000059 // File path to a zip archive with all image files (or nil, if not needed).
60 zip android.WritablePath
David Srbeckyc177ebe2020-02-18 20:43:06 +000061
62 // Rules which should be used in make to install the outputs.
63 profileInstalls android.RuleBuilderInstalls
64
65 // Target-dependent fields.
66 variants []*bootImageVariant
67}
68
69// Target-dependent description of pre-compiled boot image.
70type bootImageVariant struct {
71 *bootImageConfig
72
73 // Target for which the image is generated.
74 target android.Target
75
David Srbeckyab994982020-03-30 17:24:13 +010076 // The "locations" of jars.
77 dexLocations []string // for this image
78 dexLocationsDeps []string // for the dependency images and in this image
79
David Srbeckyc177ebe2020-02-18 20:43:06 +000080 // Paths to image files.
81 images android.OutputPath // first image file
82 imagesDeps android.OutputPaths // all files
83
84 // Only for extensions, paths to the primary boot images.
85 primaryImages android.OutputPath
86
87 // Rules which should be used in make to install the outputs.
88 installs android.RuleBuilderInstalls
89 vdexInstalls android.RuleBuilderInstalls
90 unstrippedInstalls android.RuleBuilderInstalls
91}
92
93func (image bootImageConfig) getVariant(target android.Target) *bootImageVariant {
94 for _, variant := range image.variants {
95 if variant.target.Os == target.Os && variant.target.Arch.ArchType == target.Arch.ArchType {
96 return variant
97 }
98 }
99 return nil
Colin Cross800fe132019-02-11 14:21:24 -0800100}
101
David Srbeckyab994982020-03-30 17:24:13 +0100102// Return any (the first) variant which is for the device (as opposed to for the host)
103func (image bootImageConfig) getAnyAndroidVariant() *bootImageVariant {
104 for _, variant := range image.variants {
105 if variant.target.Os == android.Android {
106 return variant
107 }
108 }
109 return nil
110}
111
Ulya Trafimovich8640ab92020-05-11 18:06:15 +0100112func (image bootImageConfig) moduleName(ctx android.PathContext, idx int) string {
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +0000113 // Dexpreopt on the boot class path produces multiple files. The first dex file
114 // is converted into 'name'.art (to match the legacy assumption that 'name'.art
Dan Willemsen0f416782019-06-13 21:44:53 +0000115 // exists), and the rest are converted to 'name'-<jar>.art.
Ulya Trafimovich8640ab92020-05-11 18:06:15 +0100116 _, m := android.SplitApexJarPair(ctx, image.modules[idx])
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +0000117 name := image.stem
David Srbecky1aacc6c2020-03-26 11:10:45 +0000118 if idx != 0 || image.extends != nil {
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +0000119 name += "-" + stemOf(m)
120 }
121 return name
122}
Dan Willemsen0f416782019-06-13 21:44:53 +0000123
Ulya Trafimovich8640ab92020-05-11 18:06:15 +0100124func (image bootImageConfig) firstModuleNameOrStem(ctx android.PathContext) string {
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +0000125 if len(image.modules) > 0 {
Ulya Trafimovich8640ab92020-05-11 18:06:15 +0100126 return image.moduleName(ctx, 0)
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +0000127 } else {
128 return image.stem
129 }
130}
131
132func (image bootImageConfig) moduleFiles(ctx android.PathContext, dir android.OutputPath, exts ...string) android.OutputPaths {
133 ret := make(android.OutputPaths, 0, len(image.modules)*len(exts))
134 for i := range image.modules {
Ulya Trafimovich8640ab92020-05-11 18:06:15 +0100135 name := image.moduleName(ctx, i)
Dan Willemsen0f416782019-06-13 21:44:53 +0000136 for _, ext := range exts {
137 ret = append(ret, dir.Join(ctx, name+ext))
138 }
139 }
Dan Willemsen0f416782019-06-13 21:44:53 +0000140 return ret
141}
142
David Srbecky1aacc6c2020-03-26 11:10:45 +0000143// The image "location" is a symbolic path that, with multiarchitecture support, doesn't really
144// exist on the device. Typically it is /apex/com.android.art/javalib/boot.art and should be the
145// same for all supported architectures on the device. The concrete architecture specific files
146// actually end up in architecture-specific sub-directory such as arm, arm64, x86, or x86_64.
147//
148// For example a physical file
149// "/apex/com.android.art/javalib/x86/boot.art" has "image location"
150// "/apex/com.android.art/javalib/boot.art" (which is not an actual file).
151//
152// The location is passed as an argument to the ART tools like dex2oat instead of the real path.
153// ART tools will then reconstruct the architecture-specific real path.
154func (image *bootImageVariant) imageLocations() (imageLocations []string) {
155 if image.extends != nil {
156 imageLocations = image.extends.getVariant(image.target).imageLocations()
157 }
158 return append(imageLocations, dexpreopt.PathToLocation(image.images, image.target.Arch.ArchType))
159}
160
Colin Cross800fe132019-02-11 14:21:24 -0800161func concat(lists ...[]string) []string {
162 var size int
163 for _, l := range lists {
164 size += len(l)
165 }
166 ret := make([]string, 0, size)
167 for _, l := range lists {
168 ret = append(ret, l...)
169 }
170 return ret
171}
172
Colin Cross800fe132019-02-11 14:21:24 -0800173func dexpreoptBootJarsFactory() android.Singleton {
Colin Cross44df5812019-02-15 23:06:46 -0800174 return &dexpreoptBootJars{}
Colin Cross800fe132019-02-11 14:21:24 -0800175}
176
Ulya Trafimovichb28cc372020-01-13 15:18:16 +0000177func RegisterDexpreoptBootJarsComponents(ctx android.RegistrationContext) {
178 ctx.RegisterSingletonType("dex_bootjars", dexpreoptBootJarsFactory)
179}
180
Colin Cross800fe132019-02-11 14:21:24 -0800181func skipDexpreoptBootJars(ctx android.PathContext) bool {
Martin Stjernholm40f9f3c2020-01-20 18:12:23 +0000182 if dexpreopt.GetGlobalConfig(ctx).DisablePreopt {
Ulya Trafimovichacb33e02019-11-01 17:57:29 +0000183 return true
184 }
185
Colin Cross800fe132019-02-11 14:21:24 -0800186 if ctx.Config().UnbundledBuild() {
187 return true
188 }
189
Colin Cross800fe132019-02-11 14:21:24 -0800190 return false
191}
192
Colin Cross44df5812019-02-15 23:06:46 -0800193type dexpreoptBootJars struct {
David Srbeckyc177ebe2020-02-18 20:43:06 +0000194 defaultBootImage *bootImageConfig
195 otherImages []*bootImageConfig
Colin Cross2d00f0d2019-05-09 21:50:00 -0700196
197 dexpreoptConfigForMake android.WritablePath
Colin Cross44df5812019-02-15 23:06:46 -0800198}
Colin Cross800fe132019-02-11 14:21:24 -0800199
Ulyana Trafimovichde534412019-11-08 10:51:01 +0000200// Accessor function for the apex package. Returns nil if dexpreopt is disabled.
Tim Joinesc1ef1bb2020-03-18 18:00:41 +0000201func DexpreoptedArtApexJars(ctx android.BuilderContext) map[android.ArchType]android.OutputPaths {
Ulya Trafimovich44561882020-01-03 13:25:54 +0000202 if skipDexpreoptBootJars(ctx) {
Tim Joinesc1ef1bb2020-03-18 18:00:41 +0000203 return nil
Ulyana Trafimovichde534412019-11-08 10:51:01 +0000204 }
Tim Joinesc1ef1bb2020-03-18 18:00:41 +0000205 // Include dexpreopt files for the primary boot image.
206 files := map[android.ArchType]android.OutputPaths{}
207 for _, variant := range artBootImageConfig(ctx).variants {
David Srbecky7f8dac12020-02-13 16:00:45 +0000208 // We also generate boot images for host (for testing), but we don't need those in the apex.
Tim Joinesc1ef1bb2020-03-18 18:00:41 +0000209 if variant.target.Os == android.Android {
210 files[variant.target.Arch.ArchType] = variant.imagesDeps
David Srbecky7f8dac12020-02-13 16:00:45 +0000211 }
David Srbeckyc177ebe2020-02-18 20:43:06 +0000212 }
Tim Joinesc1ef1bb2020-03-18 18:00:41 +0000213 return files
Ulyana Trafimovichde534412019-11-08 10:51:01 +0000214}
215
Colin Cross800fe132019-02-11 14:21:24 -0800216// dexpreoptBoot singleton rules
Colin Cross44df5812019-02-15 23:06:46 -0800217func (d *dexpreoptBootJars) GenerateBuildActions(ctx android.SingletonContext) {
Colin Cross800fe132019-02-11 14:21:24 -0800218 if skipDexpreoptBootJars(ctx) {
219 return
220 }
Martin Stjernholm6d415272020-01-31 17:10:36 +0000221 if dexpreopt.GetCachedGlobalSoongConfig(ctx) == nil {
222 // No module has enabled dexpreopting, so we assume there will be no boot image to make.
223 return
224 }
Colin Cross800fe132019-02-11 14:21:24 -0800225
Colin Cross2d00f0d2019-05-09 21:50:00 -0700226 d.dexpreoptConfigForMake = android.PathForOutput(ctx, ctx.Config().DeviceName(), "dexpreopt.config")
227 writeGlobalConfigForMake(ctx, d.dexpreoptConfigForMake)
228
Martin Stjernholm40f9f3c2020-01-20 18:12:23 +0000229 global := dexpreopt.GetGlobalConfig(ctx)
Colin Cross800fe132019-02-11 14:21:24 -0800230
231 // Skip recompiling the boot image for the second sanitization phase. We'll get separate paths
232 // and invalidate first-stage artifacts which are crucial to SANITIZE_LITE builds.
233 // Note: this is technically incorrect. Compiled code contains stack checks which may depend
234 // on ASAN settings.
235 if len(ctx.Config().SanitizeDevice()) == 1 &&
236 ctx.Config().SanitizeDevice()[0] == "address" &&
Colin Cross44df5812019-02-15 23:06:46 -0800237 global.SanitizeLite {
Colin Cross800fe132019-02-11 14:21:24 -0800238 return
239 }
240
Lingfeng Yang54191fa2019-12-19 16:40:09 +0000241 // Always create the default boot image first, to get a unique profile rule for all images.
242 d.defaultBootImage = buildBootImage(ctx, defaultBootImageConfig(ctx))
Ulya Trafimovich44561882020-01-03 13:25:54 +0000243 // Create boot image for the ART apex (build artifacts are accessed via the global boot image config).
244 d.otherImages = append(d.otherImages, buildBootImage(ctx, artBootImageConfig(ctx)))
Colin Crossc9a4c362019-02-26 21:13:48 -0800245
246 dumpOatRules(ctx, d.defaultBootImage)
Colin Cross44df5812019-02-15 23:06:46 -0800247}
248
Ulya Trafimovichb28cc372020-01-13 15:18:16 +0000249// Inspect this module to see if it contains a bootclasspath dex jar.
250// Note that the same jar may occur in multiple modules.
251// This logic is tested in the apex package to avoid import cycle apex <-> java.
252func getBootImageJar(ctx android.SingletonContext, image *bootImageConfig, module android.Module) (int, android.Path) {
253 // All apex Java libraries have non-installable platform variants, skip them.
254 if module.IsSkipInstall() {
255 return -1, nil
256 }
257
Ulyana Trafimovich5539e7b2020-06-04 14:08:17 +0000258 jar, hasJar := module.(interface{ DexJarBuildPath() android.Path })
Ulya Trafimovichb28cc372020-01-13 15:18:16 +0000259 if !hasJar {
260 return -1, nil
261 }
262
263 name := ctx.ModuleName(module)
Ulya Trafimovich8640ab92020-05-11 18:06:15 +0100264 index := android.IndexList(name, android.GetJarsFromApexJarPairs(ctx, image.modules))
Ulya Trafimovichb28cc372020-01-13 15:18:16 +0000265 if index == -1 {
266 return -1, nil
267 }
268
269 // Check that this module satisfies constraints for a particular boot image.
270 apex, isApexModule := module.(android.ApexModule)
Ulya Trafimovich7c140d82020-04-22 18:05:58 +0100271 fromUpdatableApex := isApexModule && apex.Updatable()
Ulya Trafimovichb28cc372020-01-13 15:18:16 +0000272 if image.name == artBootImageName {
273 if isApexModule && strings.HasPrefix(apex.ApexName(), "com.android.art.") {
Ulya Trafimovich7c140d82020-04-22 18:05:58 +0100274 // ok: found the jar in the ART apex
Ulya Trafimovichb28cc372020-01-13 15:18:16 +0000275 } else if isApexModule && apex.IsForPlatform() && Bool(module.(*Library).deviceProperties.Hostdex) {
Ulya Trafimovich7c140d82020-04-22 18:05:58 +0100276 // exception (skip and continue): special "hostdex" platform variant
Ulya Trafimovichb28cc372020-01-13 15:18:16 +0000277 return -1, nil
Ulya Trafimoviche0ce4ba2020-04-08 15:00:49 +0100278 } else if name == "jacocoagent" && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
Ulya Trafimovich7c140d82020-04-22 18:05:58 +0100279 // exception (skip and continue): Jacoco platform variant for a coverage build
Ulya Trafimoviche0ce4ba2020-04-08 15:00:49 +0100280 return -1, nil
Ulya Trafimovich7c140d82020-04-22 18:05:58 +0100281 } else if fromUpdatableApex {
282 // error: this jar is part of an updatable apex other than ART
283 ctx.Errorf("module '%s' from updatable apex '%s' is not allowed in the ART boot image", name, apex.ApexName())
Ulya Trafimovichb28cc372020-01-13 15:18:16 +0000284 } else {
Ulya Trafimovich7c140d82020-04-22 18:05:58 +0100285 // error: this jar is part of the platform or a non-updatable apex
286 ctx.Errorf("module '%s' is not allowed in the ART boot image", name)
Ulya Trafimovichb28cc372020-01-13 15:18:16 +0000287 }
288 } else if image.name == frameworkBootImageName {
Ulya Trafimovich7c140d82020-04-22 18:05:58 +0100289 if !fromUpdatableApex {
290 // ok: this jar is part of the platform or a non-updatable apex
Ulya Trafimovichb28cc372020-01-13 15:18:16 +0000291 } else {
Ulya Trafimovich7c140d82020-04-22 18:05:58 +0100292 // error: this jar is part of an updatable apex
Ulya Trafimovichb28cc372020-01-13 15:18:16 +0000293 ctx.Errorf("module '%s' from updatable apex '%s' is not allowed in the framework boot image", name, apex.ApexName())
294 }
295 } else {
296 panic("unknown boot image: " + image.name)
297 }
298
Ulyana Trafimovich5539e7b2020-06-04 14:08:17 +0000299 return index, jar.DexJarBuildPath()
Ulya Trafimovichb28cc372020-01-13 15:18:16 +0000300}
301
David Srbeckyc177ebe2020-02-18 20:43:06 +0000302// buildBootImage takes a bootImageConfig, creates rules to build it, and returns the image.
303func buildBootImage(ctx android.SingletonContext, image *bootImageConfig) *bootImageConfig {
Ulya Trafimovichb28cc372020-01-13 15:18:16 +0000304 // Collect dex jar paths for the boot image modules.
305 // This logic is tested in the apex package to avoid import cycle apex <-> java.
Colin Cross44df5812019-02-15 23:06:46 -0800306 bootDexJars := make(android.Paths, len(image.modules))
Colin Cross800fe132019-02-11 14:21:24 -0800307 ctx.VisitAllModules(func(module android.Module) {
Ulya Trafimovichb28cc372020-01-13 15:18:16 +0000308 if i, j := getBootImageJar(ctx, image, module); i != -1 {
309 bootDexJars[i] = j
Colin Cross800fe132019-02-11 14:21:24 -0800310 }
311 })
312
313 var missingDeps []string
314 // Ensure all modules were converted to paths
315 for i := range bootDexJars {
316 if bootDexJars[i] == nil {
Ulya Trafimovich8640ab92020-05-11 18:06:15 +0100317 _, m := android.SplitApexJarPair(ctx, image.modules[i])
Colin Cross800fe132019-02-11 14:21:24 -0800318 if ctx.Config().AllowMissingDependencies() {
Ulya Trafimovich50c4a4b2020-04-21 15:36:33 +0100319 missingDeps = append(missingDeps, m)
Colin Cross800fe132019-02-11 14:21:24 -0800320 bootDexJars[i] = android.PathForOutput(ctx, "missing")
321 } else {
Ulya Trafimovichb28cc372020-01-13 15:18:16 +0000322 ctx.Errorf("failed to find a dex jar path for module '%s'"+
Ulya Trafimovich50c4a4b2020-04-21 15:36:33 +0100323 ", note that some jars may be filtered out by module constraints", m)
Colin Cross800fe132019-02-11 14:21:24 -0800324 }
325 }
326 }
327
328 // The path to bootclasspath dex files needs to be known at module GenerateAndroidBuildAction time, before
329 // the bootclasspath modules have been compiled. Copy the dex jars there so the module rules that have
330 // already been set up can find them.
331 for i := range bootDexJars {
332 ctx.Build(pctx, android.BuildParams{
333 Rule: android.Cp,
334 Input: bootDexJars[i],
Colin Cross44df5812019-02-15 23:06:46 -0800335 Output: image.dexPaths[i],
Colin Cross800fe132019-02-11 14:21:24 -0800336 })
337 }
338
Colin Cross44df5812019-02-15 23:06:46 -0800339 profile := bootImageProfileRule(ctx, image, missingDeps)
Nicolas Geoffraye7102422019-07-24 13:19:29 +0100340 bootFrameworkProfileRule(ctx, image, missingDeps)
Vladimir Marko205e6c22020-04-01 13:52:27 +0100341 updatableBcpPackagesRule(ctx, image, missingDeps)
Colin Cross800fe132019-02-11 14:21:24 -0800342
Ulya Trafimovich9ab49332020-06-10 15:44:25 +0100343 var zipFiles android.Paths
David Srbeckyc177ebe2020-02-18 20:43:06 +0000344 for _, variant := range image.variants {
345 files := buildBootImageVariant(ctx, variant, profile, missingDeps)
Ulya Trafimovich9ab49332020-06-10 15:44:25 +0100346 if variant.target.Os == android.Android {
347 zipFiles = append(zipFiles, files.Paths()...)
348 }
Colin Cross800fe132019-02-11 14:21:24 -0800349 }
Colin Cross44df5812019-02-15 23:06:46 -0800350
Colin Crossdf8eebe2019-04-09 15:29:41 -0700351 if image.zip != nil {
352 rule := android.NewRuleBuilder()
353 rule.Command().
Colin Crossee94d6a2019-07-08 17:08:34 -0700354 BuiltTool(ctx, "soong_zip").
Colin Crossdf8eebe2019-04-09 15:29:41 -0700355 FlagWithOutput("-o ", image.zip).
Ulya Trafimovich9ab49332020-06-10 15:44:25 +0100356 FlagWithArg("-C ", image.dir.Join(ctx, android.Android.String()).String()).
357 FlagWithInputList("-f ", zipFiles, " -f ")
Colin Crossdf8eebe2019-04-09 15:29:41 -0700358
359 rule.Build(pctx, ctx, "zip_"+image.name, "zip "+image.name+" image")
360 }
361
Colin Cross44df5812019-02-15 23:06:46 -0800362 return image
Colin Cross800fe132019-02-11 14:21:24 -0800363}
364
David Srbeckyc177ebe2020-02-18 20:43:06 +0000365func buildBootImageVariant(ctx android.SingletonContext, image *bootImageVariant,
366 profile android.Path, missingDeps []string) android.WritablePaths {
Colin Cross800fe132019-02-11 14:21:24 -0800367
Martin Stjernholm75a48d82020-01-10 20:32:59 +0000368 globalSoong := dexpreopt.GetCachedGlobalSoongConfig(ctx)
Martin Stjernholm40f9f3c2020-01-20 18:12:23 +0000369 global := dexpreopt.GetGlobalConfig(ctx)
Colin Cross44df5812019-02-15 23:06:46 -0800370
David Srbeckyc177ebe2020-02-18 20:43:06 +0000371 arch := image.target.Arch.ArchType
David Srbecky7f8dac12020-02-13 16:00:45 +0000372 os := image.target.Os.String() // We need to distinguish host-x86 and device-x86.
373 symbolsDir := image.symbolsDir.Join(ctx, os, image.installSubdir, arch.String())
Ulyana Trafimovichde534412019-11-08 10:51:01 +0000374 symbolsFile := symbolsDir.Join(ctx, image.stem+".oat")
David Srbecky7f8dac12020-02-13 16:00:45 +0000375 outputDir := image.dir.Join(ctx, os, image.installSubdir, arch.String())
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +0000376 outputPath := outputDir.Join(ctx, image.stem+".oat")
377 oatLocation := dexpreopt.PathToLocation(outputPath, arch)
378 imagePath := outputPath.ReplaceExtension(ctx, "art")
Colin Cross800fe132019-02-11 14:21:24 -0800379
380 rule := android.NewRuleBuilder()
381 rule.MissingDeps(missingDeps)
382
383 rule.Command().Text("mkdir").Flag("-p").Flag(symbolsDir.String())
384 rule.Command().Text("rm").Flag("-f").
385 Flag(symbolsDir.Join(ctx, "*.art").String()).
386 Flag(symbolsDir.Join(ctx, "*.oat").String()).
387 Flag(symbolsDir.Join(ctx, "*.invocation").String())
388 rule.Command().Text("rm").Flag("-f").
389 Flag(outputDir.Join(ctx, "*.art").String()).
390 Flag(outputDir.Join(ctx, "*.oat").String()).
391 Flag(outputDir.Join(ctx, "*.invocation").String())
392
393 cmd := rule.Command()
394
395 extraFlags := ctx.Config().Getenv("ART_BOOT_IMAGE_EXTRA_ARGS")
396 if extraFlags == "" {
397 // Use ANDROID_LOG_TAGS to suppress most logging by default...
398 cmd.Text(`ANDROID_LOG_TAGS="*:e"`)
399 } else {
400 // ...unless the boot image is generated specifically for testing, then allow all logging.
401 cmd.Text(`ANDROID_LOG_TAGS="*:v"`)
402 }
403
404 invocationPath := outputPath.ReplaceExtension(ctx, "invocation")
405
Martin Stjernholm75a48d82020-01-10 20:32:59 +0000406 cmd.Tool(globalSoong.Dex2oat).
Colin Cross800fe132019-02-11 14:21:24 -0800407 Flag("--avoid-storing-invocation").
Colin Cross69f59a32019-02-15 10:39:37 -0800408 FlagWithOutput("--write-invocation-to=", invocationPath).ImplicitOutput(invocationPath).
Colin Cross44df5812019-02-15 23:06:46 -0800409 Flag("--runtime-arg").FlagWithArg("-Xms", global.Dex2oatImageXms).
410 Flag("--runtime-arg").FlagWithArg("-Xmx", global.Dex2oatImageXmx)
Colin Cross800fe132019-02-11 14:21:24 -0800411
Colin Cross69f59a32019-02-15 10:39:37 -0800412 if profile != nil {
Colin Cross800fe132019-02-11 14:21:24 -0800413 cmd.FlagWithArg("--compiler-filter=", "speed-profile")
Colin Cross69f59a32019-02-15 10:39:37 -0800414 cmd.FlagWithInput("--profile-file=", profile)
Colin Cross800fe132019-02-11 14:21:24 -0800415 }
416
Colin Cross44df5812019-02-15 23:06:46 -0800417 if global.DirtyImageObjects.Valid() {
418 cmd.FlagWithInput("--dirty-image-objects=", global.DirtyImageObjects.Path())
Colin Cross800fe132019-02-11 14:21:24 -0800419 }
420
David Srbecky1aacc6c2020-03-26 11:10:45 +0000421 if image.extends != nil {
David Srbeckyc177ebe2020-02-18 20:43:06 +0000422 artImage := image.primaryImages
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +0000423 cmd.
424 Flag("--runtime-arg").FlagWithInputList("-Xbootclasspath:", image.dexPathsDeps.Paths(), ":").
425 Flag("--runtime-arg").FlagWithList("-Xbootclasspath-locations:", image.dexLocationsDeps, ":").
426 FlagWithArg("--boot-image=", dexpreopt.PathToLocation(artImage, arch)).Implicit(artImage)
427 } else {
428 cmd.FlagWithArg("--base=", ctx.Config().LibartImgDeviceBaseAddress())
429 }
430
Colin Cross800fe132019-02-11 14:21:24 -0800431 cmd.
Colin Cross44df5812019-02-15 23:06:46 -0800432 FlagForEachInput("--dex-file=", image.dexPaths.Paths()).
433 FlagForEachArg("--dex-location=", image.dexLocations).
Colin Cross800fe132019-02-11 14:21:24 -0800434 Flag("--generate-debug-info").
435 Flag("--generate-build-id").
Mathieu Chartier54fd8072019-07-26 13:50:04 -0700436 Flag("--image-format=lz4hc").
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +0000437 FlagWithArg("--oat-symbols=", symbolsFile.String()).
Colin Cross800fe132019-02-11 14:21:24 -0800438 Flag("--strip").
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +0000439 FlagWithArg("--oat-file=", outputPath.String()).
Colin Cross800fe132019-02-11 14:21:24 -0800440 FlagWithArg("--oat-location=", oatLocation).
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +0000441 FlagWithArg("--image=", imagePath.String()).
Colin Cross800fe132019-02-11 14:21:24 -0800442 FlagWithArg("--instruction-set=", arch.String()).
Colin Cross44df5812019-02-15 23:06:46 -0800443 FlagWithArg("--android-root=", global.EmptyDirectory).
Colin Cross800fe132019-02-11 14:21:24 -0800444 FlagWithArg("--no-inline-from=", "core-oj.jar").
Ulya Trafimovichc0c98d52020-03-09 12:46:06 +0000445 Flag("--force-determinism").
Colin Cross800fe132019-02-11 14:21:24 -0800446 Flag("--abort-on-hard-verifier-error")
447
David Srbecky7f8dac12020-02-13 16:00:45 +0000448 // Use the default variant/features for host builds.
449 // The map below contains only device CPU info (which might be x86 on some devices).
450 if image.target.Os == android.Android {
451 cmd.FlagWithArg("--instruction-set-variant=", global.CpuVariant[arch])
452 cmd.FlagWithArg("--instruction-set-features=", global.InstructionSetFeatures[arch])
453 }
454
Colin Cross44df5812019-02-15 23:06:46 -0800455 if global.BootFlags != "" {
456 cmd.Flag(global.BootFlags)
Colin Cross800fe132019-02-11 14:21:24 -0800457 }
458
459 if extraFlags != "" {
460 cmd.Flag(extraFlags)
461 }
462
Colin Cross0b9f31f2019-02-28 11:00:01 -0800463 cmd.Textf(`|| ( echo %s ; false )`, proptools.ShellEscape(failureMessage))
Colin Cross800fe132019-02-11 14:21:24 -0800464
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +0000465 installDir := filepath.Join("/", image.installSubdir, arch.String())
Colin Cross800fe132019-02-11 14:21:24 -0800466
Colin Cross800fe132019-02-11 14:21:24 -0800467 var vdexInstalls android.RuleBuilderInstalls
468 var unstrippedInstalls android.RuleBuilderInstalls
469
Colin Crossdf8eebe2019-04-09 15:29:41 -0700470 var zipFiles android.WritablePaths
471
Dan Willemsen0f416782019-06-13 21:44:53 +0000472 for _, artOrOat := range image.moduleFiles(ctx, outputDir, ".art", ".oat") {
473 cmd.ImplicitOutput(artOrOat)
474 zipFiles = append(zipFiles, artOrOat)
Colin Cross800fe132019-02-11 14:21:24 -0800475
Dan Willemsen0f416782019-06-13 21:44:53 +0000476 // Install the .oat and .art files
477 rule.Install(artOrOat, filepath.Join(installDir, artOrOat.Base()))
478 }
Colin Cross800fe132019-02-11 14:21:24 -0800479
Dan Willemsen0f416782019-06-13 21:44:53 +0000480 for _, vdex := range image.moduleFiles(ctx, outputDir, ".vdex") {
481 cmd.ImplicitOutput(vdex)
482 zipFiles = append(zipFiles, vdex)
Colin Cross800fe132019-02-11 14:21:24 -0800483
David Srbecky7f8dac12020-02-13 16:00:45 +0000484 // Note that the vdex files are identical between architectures.
485 // Make rules will create symlinks to share them between architectures.
Colin Cross800fe132019-02-11 14:21:24 -0800486 vdexInstalls = append(vdexInstalls,
David Srbecky7f8dac12020-02-13 16:00:45 +0000487 android.RuleBuilderInstall{vdex, filepath.Join(installDir, vdex.Base())})
Dan Willemsen0f416782019-06-13 21:44:53 +0000488 }
489
490 for _, unstrippedOat := range image.moduleFiles(ctx, symbolsDir, ".oat") {
491 cmd.ImplicitOutput(unstrippedOat)
Colin Cross800fe132019-02-11 14:21:24 -0800492
493 // Install the unstripped oat files. The Make rules will put these in $(TARGET_OUT_UNSTRIPPED)
494 unstrippedInstalls = append(unstrippedInstalls,
Colin Cross69f59a32019-02-15 10:39:37 -0800495 android.RuleBuilderInstall{unstrippedOat, filepath.Join(installDir, unstrippedOat.Base())})
Colin Cross800fe132019-02-11 14:21:24 -0800496 }
497
David Srbecky7f8dac12020-02-13 16:00:45 +0000498 rule.Build(pctx, ctx, image.name+"JarsDexpreopt_"+image.target.String(), "dexpreopt "+image.name+" jars "+arch.String())
Colin Cross800fe132019-02-11 14:21:24 -0800499
500 // save output and installed files for makevars
David Srbeckyc177ebe2020-02-18 20:43:06 +0000501 image.installs = rule.Installs()
502 image.vdexInstalls = vdexInstalls
503 image.unstrippedInstalls = unstrippedInstalls
Colin Crossdf8eebe2019-04-09 15:29:41 -0700504
505 return zipFiles
Colin Cross800fe132019-02-11 14:21:24 -0800506}
507
508const failureMessage = `ERROR: Dex2oat failed to compile a boot image.
509It is likely that the boot classpath is inconsistent.
510Rebuild with ART_BOOT_IMAGE_EXTRA_ARGS="--runtime-arg -verbose:verifier" to see verification errors.`
511
David Srbeckyc177ebe2020-02-18 20:43:06 +0000512func bootImageProfileRule(ctx android.SingletonContext, image *bootImageConfig, missingDeps []string) android.WritablePath {
Martin Stjernholm75a48d82020-01-10 20:32:59 +0000513 globalSoong := dexpreopt.GetCachedGlobalSoongConfig(ctx)
Martin Stjernholm40f9f3c2020-01-20 18:12:23 +0000514 global := dexpreopt.GetGlobalConfig(ctx)
Nicolas Geoffray27c7cc62019-02-24 16:04:52 +0000515
Mathieu Chartier6adeee12019-06-26 10:01:36 -0700516 if global.DisableGenerateProfile || ctx.Config().IsPdkBuild() || ctx.Config().UnbundledBuild() {
Nicolas Geoffray27c7cc62019-02-24 16:04:52 +0000517 return nil
518 }
Ulyana Trafimovichde534412019-11-08 10:51:01 +0000519 profile := ctx.Config().Once(bootImageProfileRuleKey, func() interface{} {
Ulyana Trafimovichde534412019-11-08 10:51:01 +0000520 defaultProfile := "frameworks/base/config/boot-image-profile.txt"
Colin Cross800fe132019-02-11 14:21:24 -0800521
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000522 rule := android.NewRuleBuilder()
523 rule.MissingDeps(missingDeps)
Colin Cross800fe132019-02-11 14:21:24 -0800524
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000525 var bootImageProfile android.Path
526 if len(global.BootImageProfiles) > 1 {
527 combinedBootImageProfile := image.dir.Join(ctx, "boot-image-profile.txt")
528 rule.Command().Text("cat").Inputs(global.BootImageProfiles).Text(">").Output(combinedBootImageProfile)
529 bootImageProfile = combinedBootImageProfile
530 } else if len(global.BootImageProfiles) == 1 {
531 bootImageProfile = global.BootImageProfiles[0]
Ulyana Trafimovichde534412019-11-08 10:51:01 +0000532 } else if path := android.ExistentPathForSource(ctx, defaultProfile); path.Valid() {
533 bootImageProfile = path.Path()
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000534 } else {
Ulyana Trafimovichde534412019-11-08 10:51:01 +0000535 // No profile (not even a default one, which is the case on some branches
536 // like master-art-host that don't have frameworks/base).
537 // Return nil and continue without profile.
538 return nil
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000539 }
Colin Cross800fe132019-02-11 14:21:24 -0800540
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000541 profile := image.dir.Join(ctx, "boot.prof")
Colin Cross800fe132019-02-11 14:21:24 -0800542
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000543 rule.Command().
544 Text(`ANDROID_LOG_TAGS="*:e"`).
Martin Stjernholm75a48d82020-01-10 20:32:59 +0000545 Tool(globalSoong.Profman).
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000546 FlagWithInput("--create-profile-from=", bootImageProfile).
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +0000547 FlagForEachInput("--apk=", image.dexPathsDeps.Paths()).
David Srbeckyab994982020-03-30 17:24:13 +0100548 FlagForEachArg("--dex-location=", image.getAnyAndroidVariant().dexLocationsDeps).
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000549 FlagWithOutput("--reference-profile-file=", profile)
Colin Cross800fe132019-02-11 14:21:24 -0800550
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000551 rule.Install(profile, "/system/etc/boot-image.prof")
552
553 rule.Build(pctx, ctx, "bootJarsProfile", "profile boot jars")
554
555 image.profileInstalls = rule.Installs()
556
557 return profile
Ulyana Trafimovichde534412019-11-08 10:51:01 +0000558 })
559 if profile == nil {
560 return nil // wrap nil into a typed pointer with value nil
561 }
562 return profile.(android.WritablePath)
Colin Cross800fe132019-02-11 14:21:24 -0800563}
564
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000565var bootImageProfileRuleKey = android.NewOnceKey("bootImageProfileRule")
566
David Srbeckyc177ebe2020-02-18 20:43:06 +0000567func bootFrameworkProfileRule(ctx android.SingletonContext, image *bootImageConfig, missingDeps []string) android.WritablePath {
Martin Stjernholm75a48d82020-01-10 20:32:59 +0000568 globalSoong := dexpreopt.GetCachedGlobalSoongConfig(ctx)
Martin Stjernholm40f9f3c2020-01-20 18:12:23 +0000569 global := dexpreopt.GetGlobalConfig(ctx)
Nicolas Geoffraye7102422019-07-24 13:19:29 +0100570
571 if global.DisableGenerateProfile || ctx.Config().IsPdkBuild() || ctx.Config().UnbundledBuild() {
572 return nil
573 }
574 return ctx.Config().Once(bootFrameworkProfileRuleKey, func() interface{} {
Nicolas Geoffraye7102422019-07-24 13:19:29 +0100575 rule := android.NewRuleBuilder()
576 rule.MissingDeps(missingDeps)
577
578 // Some branches like master-art-host don't have frameworks/base, so manually
579 // handle the case that the default is missing. Those branches won't attempt to build the profile rule,
580 // and if they do they'll get a missing deps error.
581 defaultProfile := "frameworks/base/config/boot-profile.txt"
582 path := android.ExistentPathForSource(ctx, defaultProfile)
583 var bootFrameworkProfile android.Path
584 if path.Valid() {
585 bootFrameworkProfile = path.Path()
586 } else {
587 missingDeps = append(missingDeps, defaultProfile)
588 bootFrameworkProfile = android.PathForOutput(ctx, "missing")
589 }
590
591 profile := image.dir.Join(ctx, "boot.bprof")
592
593 rule.Command().
594 Text(`ANDROID_LOG_TAGS="*:e"`).
Martin Stjernholm75a48d82020-01-10 20:32:59 +0000595 Tool(globalSoong.Profman).
Nicolas Geoffraye7102422019-07-24 13:19:29 +0100596 Flag("--generate-boot-profile").
597 FlagWithInput("--create-profile-from=", bootFrameworkProfile).
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +0000598 FlagForEachInput("--apk=", image.dexPathsDeps.Paths()).
David Srbeckyab994982020-03-30 17:24:13 +0100599 FlagForEachArg("--dex-location=", image.getAnyAndroidVariant().dexLocationsDeps).
Nicolas Geoffraye7102422019-07-24 13:19:29 +0100600 FlagWithOutput("--reference-profile-file=", profile)
601
602 rule.Install(profile, "/system/etc/boot-image.bprof")
603 rule.Build(pctx, ctx, "bootFrameworkProfile", "profile boot framework jars")
604 image.profileInstalls = append(image.profileInstalls, rule.Installs()...)
605
606 return profile
607 }).(android.WritablePath)
608}
609
610var bootFrameworkProfileRuleKey = android.NewOnceKey("bootFrameworkProfileRule")
611
Vladimir Marko205e6c22020-04-01 13:52:27 +0100612func updatableBcpPackagesRule(ctx android.SingletonContext, image *bootImageConfig, missingDeps []string) android.WritablePath {
613 if ctx.Config().IsPdkBuild() || ctx.Config().UnbundledBuild() {
614 return nil
615 }
616
617 return ctx.Config().Once(updatableBcpPackagesRuleKey, func() interface{} {
618 global := dexpreopt.GetGlobalConfig(ctx)
Ulya Trafimovich8640ab92020-05-11 18:06:15 +0100619 updatableModules := android.GetJarsFromApexJarPairs(ctx, global.UpdatableBootJars)
Vladimir Marko205e6c22020-04-01 13:52:27 +0100620
621 // Collect `permitted_packages` for updatable boot jars.
622 var updatablePackages []string
623 ctx.VisitAllModules(func(module android.Module) {
Paul Duffine739f1e2020-05-29 11:24:51 +0100624 if j, ok := module.(PermittedPackagesForUpdatableBootJars); ok {
Vladimir Marko205e6c22020-04-01 13:52:27 +0100625 name := ctx.ModuleName(module)
626 if i := android.IndexList(name, updatableModules); i != -1 {
Paul Duffine739f1e2020-05-29 11:24:51 +0100627 pp := j.PermittedPackagesForUpdatableBootJars()
Vladimir Marko205e6c22020-04-01 13:52:27 +0100628 if len(pp) > 0 {
629 updatablePackages = append(updatablePackages, pp...)
630 } else {
631 ctx.Errorf("Missing permitted_packages for %s", name)
632 }
633 // Do not match the same library repeatedly.
634 updatableModules = append(updatableModules[:i], updatableModules[i+1:]...)
635 }
636 }
637 })
638
639 // Sort updatable packages to ensure deterministic ordering.
640 sort.Strings(updatablePackages)
641
642 updatableBcpPackagesName := "updatable-bcp-packages.txt"
643 updatableBcpPackages := image.dir.Join(ctx, updatableBcpPackagesName)
644
645 ctx.Build(pctx, android.BuildParams{
646 Rule: android.WriteFile,
647 Output: updatableBcpPackages,
648 Args: map[string]string{
649 // WriteFile automatically adds the last end-of-line.
650 "content": strings.Join(updatablePackages, "\\n"),
651 },
652 })
653
654 rule := android.NewRuleBuilder()
655 rule.MissingDeps(missingDeps)
656 rule.Install(updatableBcpPackages, "/system/etc/"+updatableBcpPackagesName)
657 // TODO: Rename `profileInstalls` to `extraInstalls`?
658 // Maybe even move the field out of the bootImageConfig into some higher level type?
659 image.profileInstalls = append(image.profileInstalls, rule.Installs()...)
660
661 return updatableBcpPackages
662 }).(android.WritablePath)
663}
664
665var updatableBcpPackagesRuleKey = android.NewOnceKey("updatableBcpPackagesRule")
666
David Srbeckyc177ebe2020-02-18 20:43:06 +0000667func dumpOatRules(ctx android.SingletonContext, image *bootImageConfig) {
Colin Crossc9a4c362019-02-26 21:13:48 -0800668 var allPhonies android.Paths
David Srbeckyc177ebe2020-02-18 20:43:06 +0000669 for _, image := range image.variants {
670 arch := image.target.Arch.ArchType
David Srbecky46672322020-03-16 13:27:55 +0000671 suffix := arch.String()
672 // Host and target might both use x86 arch. We need to ensure the names are unique.
673 if image.target.Os.Class == android.Host {
674 suffix = "host-" + suffix
675 }
Colin Crossc9a4c362019-02-26 21:13:48 -0800676 // Create a rule to call oatdump.
David Srbecky7f8dac12020-02-13 16:00:45 +0000677 output := android.PathForOutput(ctx, "boot."+suffix+".oatdump.txt")
Colin Crossc9a4c362019-02-26 21:13:48 -0800678 rule := android.NewRuleBuilder()
679 rule.Command().
680 // TODO: for now, use the debug version for better error reporting
Colin Crossee94d6a2019-07-08 17:08:34 -0700681 BuiltTool(ctx, "oatdumpd").
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +0000682 FlagWithInputList("--runtime-arg -Xbootclasspath:", image.dexPathsDeps.Paths(), ":").
683 FlagWithList("--runtime-arg -Xbootclasspath-locations:", image.dexLocationsDeps, ":").
David Srbecky1aacc6c2020-03-26 11:10:45 +0000684 FlagWithArg("--image=", strings.Join(image.imageLocations(), ":")).Implicits(image.imagesDeps.Paths()).
Colin Crossc9a4c362019-02-26 21:13:48 -0800685 FlagWithOutput("--output=", output).
686 FlagWithArg("--instruction-set=", arch.String())
David Srbecky7f8dac12020-02-13 16:00:45 +0000687 rule.Build(pctx, ctx, "dump-oat-boot-"+suffix, "dump oat boot "+arch.String())
Colin Crossc9a4c362019-02-26 21:13:48 -0800688
689 // Create a phony rule that depends on the output file and prints the path.
David Srbecky7f8dac12020-02-13 16:00:45 +0000690 phony := android.PathForPhony(ctx, "dump-oat-boot-"+suffix)
Colin Crossc9a4c362019-02-26 21:13:48 -0800691 rule = android.NewRuleBuilder()
692 rule.Command().
693 Implicit(output).
694 ImplicitOutput(phony).
695 Text("echo").FlagWithArg("Output in ", output.String())
David Srbecky7f8dac12020-02-13 16:00:45 +0000696 rule.Build(pctx, ctx, "phony-dump-oat-boot-"+suffix, "dump oat boot "+arch.String())
Colin Crossc9a4c362019-02-26 21:13:48 -0800697
David Srbecky1aacc6c2020-03-26 11:10:45 +0000698 allPhonies = append(allPhonies, phony)
Colin Crossc9a4c362019-02-26 21:13:48 -0800699 }
700
701 phony := android.PathForPhony(ctx, "dump-oat-boot")
702 ctx.Build(pctx, android.BuildParams{
703 Rule: android.Phony,
704 Output: phony,
705 Inputs: allPhonies,
706 Description: "dump-oat-boot",
707 })
708
709}
710
Colin Cross2d00f0d2019-05-09 21:50:00 -0700711func writeGlobalConfigForMake(ctx android.SingletonContext, path android.WritablePath) {
Martin Stjernholm40f9f3c2020-01-20 18:12:23 +0000712 data := dexpreopt.GetGlobalConfigRawData(ctx)
Colin Cross2d00f0d2019-05-09 21:50:00 -0700713
714 ctx.Build(pctx, android.BuildParams{
715 Rule: android.WriteFile,
716 Output: path,
717 Args: map[string]string{
718 "content": string(data),
719 },
720 })
721}
722
Colin Cross44df5812019-02-15 23:06:46 -0800723// Export paths for default boot image to Make
724func (d *dexpreoptBootJars) MakeVars(ctx android.MakeVarsContext) {
Colin Cross2d00f0d2019-05-09 21:50:00 -0700725 if d.dexpreoptConfigForMake != nil {
726 ctx.Strict("DEX_PREOPT_CONFIG_FOR_MAKE", d.dexpreoptConfigForMake.String())
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000727 ctx.Strict("DEX_PREOPT_SOONG_CONFIG_FOR_MAKE", android.PathForOutput(ctx, "dexpreopt_soong.config").String())
Colin Cross2d00f0d2019-05-09 21:50:00 -0700728 }
729
Colin Cross44df5812019-02-15 23:06:46 -0800730 image := d.defaultBootImage
731 if image != nil {
Colin Cross44df5812019-02-15 23:06:46 -0800732 ctx.Strict("DEXPREOPT_IMAGE_PROFILE_BUILT_INSTALLED", image.profileInstalls.String())
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +0000733 ctx.Strict("DEXPREOPT_BOOTCLASSPATH_DEX_FILES", strings.Join(image.dexPathsDeps.Strings(), " "))
David Srbeckyab994982020-03-30 17:24:13 +0100734 ctx.Strict("DEXPREOPT_BOOTCLASSPATH_DEX_LOCATIONS", strings.Join(image.getAnyAndroidVariant().dexLocationsDeps, " "))
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000735
736 var imageNames []string
737 for _, current := range append(d.otherImages, image) {
738 imageNames = append(imageNames, current.name)
David Srbecky1aacc6c2020-03-26 11:10:45 +0000739 for _, variant := range current.variants {
David Srbecky7f8dac12020-02-13 16:00:45 +0000740 suffix := ""
David Srbecky1aacc6c2020-03-26 11:10:45 +0000741 if variant.target.Os.Class == android.Host {
David Srbecky7f8dac12020-02-13 16:00:45 +0000742 suffix = "_host"
743 }
David Srbecky1aacc6c2020-03-26 11:10:45 +0000744 sfx := variant.name + suffix + "_" + variant.target.Arch.ArchType.String()
745 ctx.Strict("DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_"+sfx, variant.vdexInstalls.String())
746 ctx.Strict("DEXPREOPT_IMAGE_"+sfx, variant.images.String())
747 ctx.Strict("DEXPREOPT_IMAGE_DEPS_"+sfx, strings.Join(variant.imagesDeps.Strings(), " "))
748 ctx.Strict("DEXPREOPT_IMAGE_BUILT_INSTALLED_"+sfx, variant.installs.String())
749 ctx.Strict("DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_"+sfx, variant.unstrippedInstalls.String())
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000750 }
David Srbeckyab994982020-03-30 17:24:13 +0100751 imageLocations := current.getAnyAndroidVariant().imageLocations()
David Srbecky1aacc6c2020-03-26 11:10:45 +0000752 ctx.Strict("DEXPREOPT_IMAGE_LOCATIONS_"+current.name, strings.Join(imageLocations, ":"))
Colin Cross31bf00d2019-12-04 13:16:01 -0800753 ctx.Strict("DEXPREOPT_IMAGE_ZIP_"+current.name, current.zip.String())
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000754 }
755 ctx.Strict("DEXPREOPT_IMAGE_NAMES", strings.Join(imageNames, " "))
Colin Cross800fe132019-02-11 14:21:24 -0800756 }
Colin Cross800fe132019-02-11 14:21:24 -0800757}