blob: b4454564765d12f0b266c0f24ecfd2bc095d6d69 [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 Trafimovich249386a2020-07-01 14:31:13 +010052 // A list of (location, jar) pairs for the Java modules in this image.
53 modules android.ConfiguredJarList
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +000054
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 Trafimovich249386a2020-07-01 14:31:13 +0100116 m := image.modules.Jar(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 Trafimovich249386a2020-07-01 14:31:13 +0100119 name += "-" + android.ModuleStem(m)
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +0000120 }
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 Trafimovich249386a2020-07-01 14:31:13 +0100125 if image.modules.Len() > 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 {
Ulya Trafimovich249386a2020-07-01 14:31:13 +0100133 ret := make(android.OutputPaths, 0, image.modules.Len()*len(exts))
134 for i := 0; i < image.modules.Len(); i++ {
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 Stjernholm95d6ea32020-06-04 13:03:41 +0100182 return dexpreopt.GetGlobalConfig(ctx).DisablePreopt
Colin Cross800fe132019-02-11 14:21:24 -0800183}
184
Colin Cross44df5812019-02-15 23:06:46 -0800185type dexpreoptBootJars struct {
David Srbeckyc177ebe2020-02-18 20:43:06 +0000186 defaultBootImage *bootImageConfig
187 otherImages []*bootImageConfig
Colin Cross2d00f0d2019-05-09 21:50:00 -0700188
189 dexpreoptConfigForMake android.WritablePath
Colin Cross44df5812019-02-15 23:06:46 -0800190}
Colin Cross800fe132019-02-11 14:21:24 -0800191
Ulyana Trafimovichde534412019-11-08 10:51:01 +0000192// Accessor function for the apex package. Returns nil if dexpreopt is disabled.
Tim Joinesc1ef1bb2020-03-18 18:00:41 +0000193func DexpreoptedArtApexJars(ctx android.BuilderContext) map[android.ArchType]android.OutputPaths {
Ulya Trafimovich44561882020-01-03 13:25:54 +0000194 if skipDexpreoptBootJars(ctx) {
Tim Joinesc1ef1bb2020-03-18 18:00:41 +0000195 return nil
Ulyana Trafimovichde534412019-11-08 10:51:01 +0000196 }
Tim Joinesc1ef1bb2020-03-18 18:00:41 +0000197 // Include dexpreopt files for the primary boot image.
198 files := map[android.ArchType]android.OutputPaths{}
199 for _, variant := range artBootImageConfig(ctx).variants {
David Srbecky7f8dac12020-02-13 16:00:45 +0000200 // 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 +0000201 if variant.target.Os == android.Android {
202 files[variant.target.Arch.ArchType] = variant.imagesDeps
David Srbecky7f8dac12020-02-13 16:00:45 +0000203 }
David Srbeckyc177ebe2020-02-18 20:43:06 +0000204 }
Tim Joinesc1ef1bb2020-03-18 18:00:41 +0000205 return files
Ulyana Trafimovichde534412019-11-08 10:51:01 +0000206}
207
Colin Cross800fe132019-02-11 14:21:24 -0800208// dexpreoptBoot singleton rules
Colin Cross44df5812019-02-15 23:06:46 -0800209func (d *dexpreoptBootJars) GenerateBuildActions(ctx android.SingletonContext) {
Colin Cross800fe132019-02-11 14:21:24 -0800210 if skipDexpreoptBootJars(ctx) {
211 return
212 }
Martin Stjernholm6d415272020-01-31 17:10:36 +0000213 if dexpreopt.GetCachedGlobalSoongConfig(ctx) == nil {
214 // No module has enabled dexpreopting, so we assume there will be no boot image to make.
215 return
216 }
Colin Cross800fe132019-02-11 14:21:24 -0800217
Colin Cross2d00f0d2019-05-09 21:50:00 -0700218 d.dexpreoptConfigForMake = android.PathForOutput(ctx, ctx.Config().DeviceName(), "dexpreopt.config")
219 writeGlobalConfigForMake(ctx, d.dexpreoptConfigForMake)
220
Martin Stjernholm40f9f3c2020-01-20 18:12:23 +0000221 global := dexpreopt.GetGlobalConfig(ctx)
Colin Cross800fe132019-02-11 14:21:24 -0800222
223 // Skip recompiling the boot image for the second sanitization phase. We'll get separate paths
224 // and invalidate first-stage artifacts which are crucial to SANITIZE_LITE builds.
225 // Note: this is technically incorrect. Compiled code contains stack checks which may depend
226 // on ASAN settings.
227 if len(ctx.Config().SanitizeDevice()) == 1 &&
228 ctx.Config().SanitizeDevice()[0] == "address" &&
Colin Cross44df5812019-02-15 23:06:46 -0800229 global.SanitizeLite {
Colin Cross800fe132019-02-11 14:21:24 -0800230 return
231 }
232
Lingfeng Yang54191fa2019-12-19 16:40:09 +0000233 // Always create the default boot image first, to get a unique profile rule for all images.
234 d.defaultBootImage = buildBootImage(ctx, defaultBootImageConfig(ctx))
Ulya Trafimovich44561882020-01-03 13:25:54 +0000235 // Create boot image for the ART apex (build artifacts are accessed via the global boot image config).
236 d.otherImages = append(d.otherImages, buildBootImage(ctx, artBootImageConfig(ctx)))
Colin Crossc9a4c362019-02-26 21:13:48 -0800237
238 dumpOatRules(ctx, d.defaultBootImage)
Colin Cross44df5812019-02-15 23:06:46 -0800239}
240
Ulya Trafimovichb28cc372020-01-13 15:18:16 +0000241// Inspect this module to see if it contains a bootclasspath dex jar.
242// Note that the same jar may occur in multiple modules.
243// This logic is tested in the apex package to avoid import cycle apex <-> java.
244func getBootImageJar(ctx android.SingletonContext, image *bootImageConfig, module android.Module) (int, android.Path) {
245 // All apex Java libraries have non-installable platform variants, skip them.
246 if module.IsSkipInstall() {
247 return -1, nil
248 }
249
Ulyana Trafimovich5539e7b2020-06-04 14:08:17 +0000250 jar, hasJar := module.(interface{ DexJarBuildPath() android.Path })
Ulya Trafimovichb28cc372020-01-13 15:18:16 +0000251 if !hasJar {
252 return -1, nil
253 }
254
255 name := ctx.ModuleName(module)
Ulya Trafimovich249386a2020-07-01 14:31:13 +0100256 index := image.modules.IndexOfJar(name)
Ulya Trafimovichb28cc372020-01-13 15:18:16 +0000257 if index == -1 {
258 return -1, nil
259 }
260
261 // Check that this module satisfies constraints for a particular boot image.
262 apex, isApexModule := module.(android.ApexModule)
Ulya Trafimovich7c140d82020-04-22 18:05:58 +0100263 fromUpdatableApex := isApexModule && apex.Updatable()
Ulya Trafimovichb28cc372020-01-13 15:18:16 +0000264 if image.name == artBootImageName {
265 if isApexModule && strings.HasPrefix(apex.ApexName(), "com.android.art.") {
Ulya Trafimovich7c140d82020-04-22 18:05:58 +0100266 // ok: found the jar in the ART apex
Ulya Trafimovichb28cc372020-01-13 15:18:16 +0000267 } else if isApexModule && apex.IsForPlatform() && Bool(module.(*Library).deviceProperties.Hostdex) {
Ulya Trafimovich7c140d82020-04-22 18:05:58 +0100268 // exception (skip and continue): special "hostdex" platform variant
Ulya Trafimovichb28cc372020-01-13 15:18:16 +0000269 return -1, nil
Ulya Trafimoviche0ce4ba2020-04-08 15:00:49 +0100270 } else if name == "jacocoagent" && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
Ulya Trafimovich7c140d82020-04-22 18:05:58 +0100271 // exception (skip and continue): Jacoco platform variant for a coverage build
Ulya Trafimoviche0ce4ba2020-04-08 15:00:49 +0100272 return -1, nil
Ulya Trafimovich7c140d82020-04-22 18:05:58 +0100273 } else if fromUpdatableApex {
274 // error: this jar is part of an updatable apex other than ART
275 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 +0000276 } else {
Ulya Trafimovich7c140d82020-04-22 18:05:58 +0100277 // error: this jar is part of the platform or a non-updatable apex
278 ctx.Errorf("module '%s' is not allowed in the ART boot image", name)
Ulya Trafimovichb28cc372020-01-13 15:18:16 +0000279 }
280 } else if image.name == frameworkBootImageName {
Ulya Trafimovich7c140d82020-04-22 18:05:58 +0100281 if !fromUpdatableApex {
282 // ok: this jar is part of the platform or a non-updatable apex
Ulya Trafimovichb28cc372020-01-13 15:18:16 +0000283 } else {
Ulya Trafimovich7c140d82020-04-22 18:05:58 +0100284 // error: this jar is part of an updatable apex
Ulya Trafimovichb28cc372020-01-13 15:18:16 +0000285 ctx.Errorf("module '%s' from updatable apex '%s' is not allowed in the framework boot image", name, apex.ApexName())
286 }
287 } else {
288 panic("unknown boot image: " + image.name)
289 }
290
Ulyana Trafimovich5539e7b2020-06-04 14:08:17 +0000291 return index, jar.DexJarBuildPath()
Ulya Trafimovichb28cc372020-01-13 15:18:16 +0000292}
293
David Srbeckyc177ebe2020-02-18 20:43:06 +0000294// buildBootImage takes a bootImageConfig, creates rules to build it, and returns the image.
295func buildBootImage(ctx android.SingletonContext, image *bootImageConfig) *bootImageConfig {
Ulya Trafimovichb28cc372020-01-13 15:18:16 +0000296 // Collect dex jar paths for the boot image modules.
297 // This logic is tested in the apex package to avoid import cycle apex <-> java.
Ulya Trafimovich249386a2020-07-01 14:31:13 +0100298 bootDexJars := make(android.Paths, image.modules.Len())
Colin Cross800fe132019-02-11 14:21:24 -0800299 ctx.VisitAllModules(func(module android.Module) {
Ulya Trafimovichb28cc372020-01-13 15:18:16 +0000300 if i, j := getBootImageJar(ctx, image, module); i != -1 {
301 bootDexJars[i] = j
Colin Cross800fe132019-02-11 14:21:24 -0800302 }
303 })
304
305 var missingDeps []string
306 // Ensure all modules were converted to paths
307 for i := range bootDexJars {
308 if bootDexJars[i] == nil {
Ulya Trafimovich249386a2020-07-01 14:31:13 +0100309 m := image.modules.Jar(i)
Colin Cross800fe132019-02-11 14:21:24 -0800310 if ctx.Config().AllowMissingDependencies() {
Ulya Trafimovich50c4a4b2020-04-21 15:36:33 +0100311 missingDeps = append(missingDeps, m)
Colin Cross800fe132019-02-11 14:21:24 -0800312 bootDexJars[i] = android.PathForOutput(ctx, "missing")
313 } else {
Ulya Trafimovichb28cc372020-01-13 15:18:16 +0000314 ctx.Errorf("failed to find a dex jar path for module '%s'"+
Ulya Trafimovich50c4a4b2020-04-21 15:36:33 +0100315 ", note that some jars may be filtered out by module constraints", m)
Colin Cross800fe132019-02-11 14:21:24 -0800316 }
317 }
318 }
319
320 // The path to bootclasspath dex files needs to be known at module GenerateAndroidBuildAction time, before
321 // the bootclasspath modules have been compiled. Copy the dex jars there so the module rules that have
322 // already been set up can find them.
323 for i := range bootDexJars {
324 ctx.Build(pctx, android.BuildParams{
325 Rule: android.Cp,
326 Input: bootDexJars[i],
Colin Cross44df5812019-02-15 23:06:46 -0800327 Output: image.dexPaths[i],
Colin Cross800fe132019-02-11 14:21:24 -0800328 })
329 }
330
Colin Cross44df5812019-02-15 23:06:46 -0800331 profile := bootImageProfileRule(ctx, image, missingDeps)
Nicolas Geoffraye7102422019-07-24 13:19:29 +0100332 bootFrameworkProfileRule(ctx, image, missingDeps)
Vladimir Marko205e6c22020-04-01 13:52:27 +0100333 updatableBcpPackagesRule(ctx, image, missingDeps)
Colin Cross800fe132019-02-11 14:21:24 -0800334
Ulya Trafimovich9ab49332020-06-10 15:44:25 +0100335 var zipFiles android.Paths
David Srbeckyc177ebe2020-02-18 20:43:06 +0000336 for _, variant := range image.variants {
337 files := buildBootImageVariant(ctx, variant, profile, missingDeps)
Ulya Trafimovich9ab49332020-06-10 15:44:25 +0100338 if variant.target.Os == android.Android {
339 zipFiles = append(zipFiles, files.Paths()...)
340 }
Colin Cross800fe132019-02-11 14:21:24 -0800341 }
Colin Cross44df5812019-02-15 23:06:46 -0800342
Colin Crossdf8eebe2019-04-09 15:29:41 -0700343 if image.zip != nil {
344 rule := android.NewRuleBuilder()
345 rule.Command().
Colin Crossee94d6a2019-07-08 17:08:34 -0700346 BuiltTool(ctx, "soong_zip").
Colin Crossdf8eebe2019-04-09 15:29:41 -0700347 FlagWithOutput("-o ", image.zip).
Ulya Trafimovich9ab49332020-06-10 15:44:25 +0100348 FlagWithArg("-C ", image.dir.Join(ctx, android.Android.String()).String()).
349 FlagWithInputList("-f ", zipFiles, " -f ")
Colin Crossdf8eebe2019-04-09 15:29:41 -0700350
351 rule.Build(pctx, ctx, "zip_"+image.name, "zip "+image.name+" image")
352 }
353
Colin Cross44df5812019-02-15 23:06:46 -0800354 return image
Colin Cross800fe132019-02-11 14:21:24 -0800355}
356
David Srbeckyc177ebe2020-02-18 20:43:06 +0000357func buildBootImageVariant(ctx android.SingletonContext, image *bootImageVariant,
358 profile android.Path, missingDeps []string) android.WritablePaths {
Colin Cross800fe132019-02-11 14:21:24 -0800359
Martin Stjernholm75a48d82020-01-10 20:32:59 +0000360 globalSoong := dexpreopt.GetCachedGlobalSoongConfig(ctx)
Martin Stjernholm40f9f3c2020-01-20 18:12:23 +0000361 global := dexpreopt.GetGlobalConfig(ctx)
Colin Cross44df5812019-02-15 23:06:46 -0800362
David Srbeckyc177ebe2020-02-18 20:43:06 +0000363 arch := image.target.Arch.ArchType
David Srbecky7f8dac12020-02-13 16:00:45 +0000364 os := image.target.Os.String() // We need to distinguish host-x86 and device-x86.
365 symbolsDir := image.symbolsDir.Join(ctx, os, image.installSubdir, arch.String())
Ulyana Trafimovichde534412019-11-08 10:51:01 +0000366 symbolsFile := symbolsDir.Join(ctx, image.stem+".oat")
David Srbecky7f8dac12020-02-13 16:00:45 +0000367 outputDir := image.dir.Join(ctx, os, image.installSubdir, arch.String())
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +0000368 outputPath := outputDir.Join(ctx, image.stem+".oat")
369 oatLocation := dexpreopt.PathToLocation(outputPath, arch)
370 imagePath := outputPath.ReplaceExtension(ctx, "art")
Colin Cross800fe132019-02-11 14:21:24 -0800371
372 rule := android.NewRuleBuilder()
373 rule.MissingDeps(missingDeps)
374
375 rule.Command().Text("mkdir").Flag("-p").Flag(symbolsDir.String())
376 rule.Command().Text("rm").Flag("-f").
377 Flag(symbolsDir.Join(ctx, "*.art").String()).
378 Flag(symbolsDir.Join(ctx, "*.oat").String()).
379 Flag(symbolsDir.Join(ctx, "*.invocation").String())
380 rule.Command().Text("rm").Flag("-f").
381 Flag(outputDir.Join(ctx, "*.art").String()).
382 Flag(outputDir.Join(ctx, "*.oat").String()).
383 Flag(outputDir.Join(ctx, "*.invocation").String())
384
385 cmd := rule.Command()
386
387 extraFlags := ctx.Config().Getenv("ART_BOOT_IMAGE_EXTRA_ARGS")
388 if extraFlags == "" {
389 // Use ANDROID_LOG_TAGS to suppress most logging by default...
390 cmd.Text(`ANDROID_LOG_TAGS="*:e"`)
391 } else {
392 // ...unless the boot image is generated specifically for testing, then allow all logging.
393 cmd.Text(`ANDROID_LOG_TAGS="*:v"`)
394 }
395
396 invocationPath := outputPath.ReplaceExtension(ctx, "invocation")
397
Martin Stjernholm75a48d82020-01-10 20:32:59 +0000398 cmd.Tool(globalSoong.Dex2oat).
Colin Cross800fe132019-02-11 14:21:24 -0800399 Flag("--avoid-storing-invocation").
Colin Cross69f59a32019-02-15 10:39:37 -0800400 FlagWithOutput("--write-invocation-to=", invocationPath).ImplicitOutput(invocationPath).
Colin Cross44df5812019-02-15 23:06:46 -0800401 Flag("--runtime-arg").FlagWithArg("-Xms", global.Dex2oatImageXms).
402 Flag("--runtime-arg").FlagWithArg("-Xmx", global.Dex2oatImageXmx)
Colin Cross800fe132019-02-11 14:21:24 -0800403
Colin Cross69f59a32019-02-15 10:39:37 -0800404 if profile != nil {
Colin Cross800fe132019-02-11 14:21:24 -0800405 cmd.FlagWithArg("--compiler-filter=", "speed-profile")
Colin Cross69f59a32019-02-15 10:39:37 -0800406 cmd.FlagWithInput("--profile-file=", profile)
Colin Cross800fe132019-02-11 14:21:24 -0800407 }
408
Colin Cross44df5812019-02-15 23:06:46 -0800409 if global.DirtyImageObjects.Valid() {
410 cmd.FlagWithInput("--dirty-image-objects=", global.DirtyImageObjects.Path())
Colin Cross800fe132019-02-11 14:21:24 -0800411 }
412
David Srbecky1aacc6c2020-03-26 11:10:45 +0000413 if image.extends != nil {
David Srbeckyc177ebe2020-02-18 20:43:06 +0000414 artImage := image.primaryImages
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +0000415 cmd.
416 Flag("--runtime-arg").FlagWithInputList("-Xbootclasspath:", image.dexPathsDeps.Paths(), ":").
417 Flag("--runtime-arg").FlagWithList("-Xbootclasspath-locations:", image.dexLocationsDeps, ":").
418 FlagWithArg("--boot-image=", dexpreopt.PathToLocation(artImage, arch)).Implicit(artImage)
419 } else {
420 cmd.FlagWithArg("--base=", ctx.Config().LibartImgDeviceBaseAddress())
421 }
422
Colin Cross800fe132019-02-11 14:21:24 -0800423 cmd.
Colin Cross44df5812019-02-15 23:06:46 -0800424 FlagForEachInput("--dex-file=", image.dexPaths.Paths()).
425 FlagForEachArg("--dex-location=", image.dexLocations).
Colin Cross800fe132019-02-11 14:21:24 -0800426 Flag("--generate-debug-info").
427 Flag("--generate-build-id").
Mathieu Chartier54fd8072019-07-26 13:50:04 -0700428 Flag("--image-format=lz4hc").
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +0000429 FlagWithArg("--oat-symbols=", symbolsFile.String()).
Colin Cross800fe132019-02-11 14:21:24 -0800430 Flag("--strip").
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +0000431 FlagWithArg("--oat-file=", outputPath.String()).
Colin Cross800fe132019-02-11 14:21:24 -0800432 FlagWithArg("--oat-location=", oatLocation).
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +0000433 FlagWithArg("--image=", imagePath.String()).
Colin Cross800fe132019-02-11 14:21:24 -0800434 FlagWithArg("--instruction-set=", arch.String()).
Colin Cross44df5812019-02-15 23:06:46 -0800435 FlagWithArg("--android-root=", global.EmptyDirectory).
Colin Cross800fe132019-02-11 14:21:24 -0800436 FlagWithArg("--no-inline-from=", "core-oj.jar").
Ulya Trafimovichc0c98d52020-03-09 12:46:06 +0000437 Flag("--force-determinism").
Colin Cross800fe132019-02-11 14:21:24 -0800438 Flag("--abort-on-hard-verifier-error")
439
David Srbecky7f8dac12020-02-13 16:00:45 +0000440 // Use the default variant/features for host builds.
441 // The map below contains only device CPU info (which might be x86 on some devices).
442 if image.target.Os == android.Android {
443 cmd.FlagWithArg("--instruction-set-variant=", global.CpuVariant[arch])
444 cmd.FlagWithArg("--instruction-set-features=", global.InstructionSetFeatures[arch])
445 }
446
Colin Cross44df5812019-02-15 23:06:46 -0800447 if global.BootFlags != "" {
448 cmd.Flag(global.BootFlags)
Colin Cross800fe132019-02-11 14:21:24 -0800449 }
450
451 if extraFlags != "" {
452 cmd.Flag(extraFlags)
453 }
454
Colin Cross0b9f31f2019-02-28 11:00:01 -0800455 cmd.Textf(`|| ( echo %s ; false )`, proptools.ShellEscape(failureMessage))
Colin Cross800fe132019-02-11 14:21:24 -0800456
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +0000457 installDir := filepath.Join("/", image.installSubdir, arch.String())
Colin Cross800fe132019-02-11 14:21:24 -0800458
Colin Cross800fe132019-02-11 14:21:24 -0800459 var vdexInstalls android.RuleBuilderInstalls
460 var unstrippedInstalls android.RuleBuilderInstalls
461
Colin Crossdf8eebe2019-04-09 15:29:41 -0700462 var zipFiles android.WritablePaths
463
Dan Willemsen0f416782019-06-13 21:44:53 +0000464 for _, artOrOat := range image.moduleFiles(ctx, outputDir, ".art", ".oat") {
465 cmd.ImplicitOutput(artOrOat)
466 zipFiles = append(zipFiles, artOrOat)
Colin Cross800fe132019-02-11 14:21:24 -0800467
Dan Willemsen0f416782019-06-13 21:44:53 +0000468 // Install the .oat and .art files
469 rule.Install(artOrOat, filepath.Join(installDir, artOrOat.Base()))
470 }
Colin Cross800fe132019-02-11 14:21:24 -0800471
Dan Willemsen0f416782019-06-13 21:44:53 +0000472 for _, vdex := range image.moduleFiles(ctx, outputDir, ".vdex") {
473 cmd.ImplicitOutput(vdex)
474 zipFiles = append(zipFiles, vdex)
Colin Cross800fe132019-02-11 14:21:24 -0800475
David Srbecky7f8dac12020-02-13 16:00:45 +0000476 // Note that the vdex files are identical between architectures.
477 // Make rules will create symlinks to share them between architectures.
Colin Cross800fe132019-02-11 14:21:24 -0800478 vdexInstalls = append(vdexInstalls,
David Srbecky7f8dac12020-02-13 16:00:45 +0000479 android.RuleBuilderInstall{vdex, filepath.Join(installDir, vdex.Base())})
Dan Willemsen0f416782019-06-13 21:44:53 +0000480 }
481
482 for _, unstrippedOat := range image.moduleFiles(ctx, symbolsDir, ".oat") {
483 cmd.ImplicitOutput(unstrippedOat)
Colin Cross800fe132019-02-11 14:21:24 -0800484
485 // Install the unstripped oat files. The Make rules will put these in $(TARGET_OUT_UNSTRIPPED)
486 unstrippedInstalls = append(unstrippedInstalls,
Colin Cross69f59a32019-02-15 10:39:37 -0800487 android.RuleBuilderInstall{unstrippedOat, filepath.Join(installDir, unstrippedOat.Base())})
Colin Cross800fe132019-02-11 14:21:24 -0800488 }
489
David Srbecky7f8dac12020-02-13 16:00:45 +0000490 rule.Build(pctx, ctx, image.name+"JarsDexpreopt_"+image.target.String(), "dexpreopt "+image.name+" jars "+arch.String())
Colin Cross800fe132019-02-11 14:21:24 -0800491
492 // save output and installed files for makevars
David Srbeckyc177ebe2020-02-18 20:43:06 +0000493 image.installs = rule.Installs()
494 image.vdexInstalls = vdexInstalls
495 image.unstrippedInstalls = unstrippedInstalls
Colin Crossdf8eebe2019-04-09 15:29:41 -0700496
497 return zipFiles
Colin Cross800fe132019-02-11 14:21:24 -0800498}
499
500const failureMessage = `ERROR: Dex2oat failed to compile a boot image.
501It is likely that the boot classpath is inconsistent.
502Rebuild with ART_BOOT_IMAGE_EXTRA_ARGS="--runtime-arg -verbose:verifier" to see verification errors.`
503
David Srbeckyc177ebe2020-02-18 20:43:06 +0000504func bootImageProfileRule(ctx android.SingletonContext, image *bootImageConfig, missingDeps []string) android.WritablePath {
Martin Stjernholm75a48d82020-01-10 20:32:59 +0000505 globalSoong := dexpreopt.GetCachedGlobalSoongConfig(ctx)
Martin Stjernholm40f9f3c2020-01-20 18:12:23 +0000506 global := dexpreopt.GetGlobalConfig(ctx)
Nicolas Geoffray27c7cc62019-02-24 16:04:52 +0000507
Dan Willemsen9f435972020-05-28 15:28:00 -0700508 if global.DisableGenerateProfile || ctx.Config().UnbundledBuild() {
Nicolas Geoffray27c7cc62019-02-24 16:04:52 +0000509 return nil
510 }
Ulyana Trafimovichde534412019-11-08 10:51:01 +0000511 profile := ctx.Config().Once(bootImageProfileRuleKey, func() interface{} {
Ulyana Trafimovichde534412019-11-08 10:51:01 +0000512 defaultProfile := "frameworks/base/config/boot-image-profile.txt"
Colin Cross800fe132019-02-11 14:21:24 -0800513
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000514 rule := android.NewRuleBuilder()
515 rule.MissingDeps(missingDeps)
Colin Cross800fe132019-02-11 14:21:24 -0800516
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000517 var bootImageProfile android.Path
518 if len(global.BootImageProfiles) > 1 {
519 combinedBootImageProfile := image.dir.Join(ctx, "boot-image-profile.txt")
520 rule.Command().Text("cat").Inputs(global.BootImageProfiles).Text(">").Output(combinedBootImageProfile)
521 bootImageProfile = combinedBootImageProfile
522 } else if len(global.BootImageProfiles) == 1 {
523 bootImageProfile = global.BootImageProfiles[0]
Ulyana Trafimovichde534412019-11-08 10:51:01 +0000524 } else if path := android.ExistentPathForSource(ctx, defaultProfile); path.Valid() {
525 bootImageProfile = path.Path()
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000526 } else {
Ulyana Trafimovichde534412019-11-08 10:51:01 +0000527 // No profile (not even a default one, which is the case on some branches
528 // like master-art-host that don't have frameworks/base).
529 // Return nil and continue without profile.
530 return nil
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000531 }
Colin Cross800fe132019-02-11 14:21:24 -0800532
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000533 profile := image.dir.Join(ctx, "boot.prof")
Colin Cross800fe132019-02-11 14:21:24 -0800534
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000535 rule.Command().
536 Text(`ANDROID_LOG_TAGS="*:e"`).
Martin Stjernholm75a48d82020-01-10 20:32:59 +0000537 Tool(globalSoong.Profman).
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000538 FlagWithInput("--create-profile-from=", bootImageProfile).
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +0000539 FlagForEachInput("--apk=", image.dexPathsDeps.Paths()).
David Srbeckyab994982020-03-30 17:24:13 +0100540 FlagForEachArg("--dex-location=", image.getAnyAndroidVariant().dexLocationsDeps).
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000541 FlagWithOutput("--reference-profile-file=", profile)
Colin Cross800fe132019-02-11 14:21:24 -0800542
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000543 rule.Install(profile, "/system/etc/boot-image.prof")
544
545 rule.Build(pctx, ctx, "bootJarsProfile", "profile boot jars")
546
547 image.profileInstalls = rule.Installs()
548
549 return profile
Ulyana Trafimovichde534412019-11-08 10:51:01 +0000550 })
551 if profile == nil {
552 return nil // wrap nil into a typed pointer with value nil
553 }
554 return profile.(android.WritablePath)
Colin Cross800fe132019-02-11 14:21:24 -0800555}
556
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000557var bootImageProfileRuleKey = android.NewOnceKey("bootImageProfileRule")
558
David Srbeckyc177ebe2020-02-18 20:43:06 +0000559func bootFrameworkProfileRule(ctx android.SingletonContext, image *bootImageConfig, missingDeps []string) android.WritablePath {
Martin Stjernholm75a48d82020-01-10 20:32:59 +0000560 globalSoong := dexpreopt.GetCachedGlobalSoongConfig(ctx)
Martin Stjernholm40f9f3c2020-01-20 18:12:23 +0000561 global := dexpreopt.GetGlobalConfig(ctx)
Nicolas Geoffraye7102422019-07-24 13:19:29 +0100562
Dan Willemsen9f435972020-05-28 15:28:00 -0700563 if global.DisableGenerateProfile || ctx.Config().UnbundledBuild() {
Nicolas Geoffraye7102422019-07-24 13:19:29 +0100564 return nil
565 }
566 return ctx.Config().Once(bootFrameworkProfileRuleKey, func() interface{} {
Nicolas Geoffraye7102422019-07-24 13:19:29 +0100567 rule := android.NewRuleBuilder()
568 rule.MissingDeps(missingDeps)
569
570 // Some branches like master-art-host don't have frameworks/base, so manually
571 // handle the case that the default is missing. Those branches won't attempt to build the profile rule,
572 // and if they do they'll get a missing deps error.
573 defaultProfile := "frameworks/base/config/boot-profile.txt"
574 path := android.ExistentPathForSource(ctx, defaultProfile)
575 var bootFrameworkProfile android.Path
576 if path.Valid() {
577 bootFrameworkProfile = path.Path()
578 } else {
579 missingDeps = append(missingDeps, defaultProfile)
580 bootFrameworkProfile = android.PathForOutput(ctx, "missing")
581 }
582
583 profile := image.dir.Join(ctx, "boot.bprof")
584
585 rule.Command().
586 Text(`ANDROID_LOG_TAGS="*:e"`).
Martin Stjernholm75a48d82020-01-10 20:32:59 +0000587 Tool(globalSoong.Profman).
Nicolas Geoffraye7102422019-07-24 13:19:29 +0100588 Flag("--generate-boot-profile").
589 FlagWithInput("--create-profile-from=", bootFrameworkProfile).
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +0000590 FlagForEachInput("--apk=", image.dexPathsDeps.Paths()).
David Srbeckyab994982020-03-30 17:24:13 +0100591 FlagForEachArg("--dex-location=", image.getAnyAndroidVariant().dexLocationsDeps).
Nicolas Geoffraye7102422019-07-24 13:19:29 +0100592 FlagWithOutput("--reference-profile-file=", profile)
593
594 rule.Install(profile, "/system/etc/boot-image.bprof")
595 rule.Build(pctx, ctx, "bootFrameworkProfile", "profile boot framework jars")
596 image.profileInstalls = append(image.profileInstalls, rule.Installs()...)
597
598 return profile
599 }).(android.WritablePath)
600}
601
602var bootFrameworkProfileRuleKey = android.NewOnceKey("bootFrameworkProfileRule")
603
Vladimir Marko205e6c22020-04-01 13:52:27 +0100604func updatableBcpPackagesRule(ctx android.SingletonContext, image *bootImageConfig, missingDeps []string) android.WritablePath {
Dan Willemsen9f435972020-05-28 15:28:00 -0700605 if ctx.Config().UnbundledBuild() {
Vladimir Marko205e6c22020-04-01 13:52:27 +0100606 return nil
607 }
608
609 return ctx.Config().Once(updatableBcpPackagesRuleKey, func() interface{} {
610 global := dexpreopt.GetGlobalConfig(ctx)
Ulya Trafimovich249386a2020-07-01 14:31:13 +0100611 updatableModules := global.UpdatableBootJars.CopyOfJars()
Vladimir Marko205e6c22020-04-01 13:52:27 +0100612
613 // Collect `permitted_packages` for updatable boot jars.
614 var updatablePackages []string
615 ctx.VisitAllModules(func(module android.Module) {
Paul Duffine739f1e2020-05-29 11:24:51 +0100616 if j, ok := module.(PermittedPackagesForUpdatableBootJars); ok {
Vladimir Marko205e6c22020-04-01 13:52:27 +0100617 name := ctx.ModuleName(module)
618 if i := android.IndexList(name, updatableModules); i != -1 {
Paul Duffine739f1e2020-05-29 11:24:51 +0100619 pp := j.PermittedPackagesForUpdatableBootJars()
Vladimir Marko205e6c22020-04-01 13:52:27 +0100620 if len(pp) > 0 {
621 updatablePackages = append(updatablePackages, pp...)
622 } else {
623 ctx.Errorf("Missing permitted_packages for %s", name)
624 }
625 // Do not match the same library repeatedly.
626 updatableModules = append(updatableModules[:i], updatableModules[i+1:]...)
627 }
628 }
629 })
630
631 // Sort updatable packages to ensure deterministic ordering.
632 sort.Strings(updatablePackages)
633
634 updatableBcpPackagesName := "updatable-bcp-packages.txt"
635 updatableBcpPackages := image.dir.Join(ctx, updatableBcpPackagesName)
636
637 ctx.Build(pctx, android.BuildParams{
638 Rule: android.WriteFile,
639 Output: updatableBcpPackages,
640 Args: map[string]string{
641 // WriteFile automatically adds the last end-of-line.
642 "content": strings.Join(updatablePackages, "\\n"),
643 },
644 })
645
646 rule := android.NewRuleBuilder()
647 rule.MissingDeps(missingDeps)
648 rule.Install(updatableBcpPackages, "/system/etc/"+updatableBcpPackagesName)
649 // TODO: Rename `profileInstalls` to `extraInstalls`?
650 // Maybe even move the field out of the bootImageConfig into some higher level type?
651 image.profileInstalls = append(image.profileInstalls, rule.Installs()...)
652
653 return updatableBcpPackages
654 }).(android.WritablePath)
655}
656
657var updatableBcpPackagesRuleKey = android.NewOnceKey("updatableBcpPackagesRule")
658
David Srbeckyc177ebe2020-02-18 20:43:06 +0000659func dumpOatRules(ctx android.SingletonContext, image *bootImageConfig) {
Colin Crossc9a4c362019-02-26 21:13:48 -0800660 var allPhonies android.Paths
David Srbeckyc177ebe2020-02-18 20:43:06 +0000661 for _, image := range image.variants {
662 arch := image.target.Arch.ArchType
David Srbecky46672322020-03-16 13:27:55 +0000663 suffix := arch.String()
664 // Host and target might both use x86 arch. We need to ensure the names are unique.
665 if image.target.Os.Class == android.Host {
666 suffix = "host-" + suffix
667 }
Colin Crossc9a4c362019-02-26 21:13:48 -0800668 // Create a rule to call oatdump.
David Srbecky7f8dac12020-02-13 16:00:45 +0000669 output := android.PathForOutput(ctx, "boot."+suffix+".oatdump.txt")
Colin Crossc9a4c362019-02-26 21:13:48 -0800670 rule := android.NewRuleBuilder()
671 rule.Command().
672 // TODO: for now, use the debug version for better error reporting
Colin Crossee94d6a2019-07-08 17:08:34 -0700673 BuiltTool(ctx, "oatdumpd").
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +0000674 FlagWithInputList("--runtime-arg -Xbootclasspath:", image.dexPathsDeps.Paths(), ":").
675 FlagWithList("--runtime-arg -Xbootclasspath-locations:", image.dexLocationsDeps, ":").
David Srbecky1aacc6c2020-03-26 11:10:45 +0000676 FlagWithArg("--image=", strings.Join(image.imageLocations(), ":")).Implicits(image.imagesDeps.Paths()).
Colin Crossc9a4c362019-02-26 21:13:48 -0800677 FlagWithOutput("--output=", output).
678 FlagWithArg("--instruction-set=", arch.String())
David Srbecky7f8dac12020-02-13 16:00:45 +0000679 rule.Build(pctx, ctx, "dump-oat-boot-"+suffix, "dump oat boot "+arch.String())
Colin Crossc9a4c362019-02-26 21:13:48 -0800680
681 // Create a phony rule that depends on the output file and prints the path.
David Srbecky7f8dac12020-02-13 16:00:45 +0000682 phony := android.PathForPhony(ctx, "dump-oat-boot-"+suffix)
Colin Crossc9a4c362019-02-26 21:13:48 -0800683 rule = android.NewRuleBuilder()
684 rule.Command().
685 Implicit(output).
686 ImplicitOutput(phony).
687 Text("echo").FlagWithArg("Output in ", output.String())
David Srbecky7f8dac12020-02-13 16:00:45 +0000688 rule.Build(pctx, ctx, "phony-dump-oat-boot-"+suffix, "dump oat boot "+arch.String())
Colin Crossc9a4c362019-02-26 21:13:48 -0800689
David Srbecky1aacc6c2020-03-26 11:10:45 +0000690 allPhonies = append(allPhonies, phony)
Colin Crossc9a4c362019-02-26 21:13:48 -0800691 }
692
693 phony := android.PathForPhony(ctx, "dump-oat-boot")
694 ctx.Build(pctx, android.BuildParams{
695 Rule: android.Phony,
696 Output: phony,
697 Inputs: allPhonies,
698 Description: "dump-oat-boot",
699 })
700
701}
702
Colin Cross2d00f0d2019-05-09 21:50:00 -0700703func writeGlobalConfigForMake(ctx android.SingletonContext, path android.WritablePath) {
Martin Stjernholm40f9f3c2020-01-20 18:12:23 +0000704 data := dexpreopt.GetGlobalConfigRawData(ctx)
Colin Cross2d00f0d2019-05-09 21:50:00 -0700705
706 ctx.Build(pctx, android.BuildParams{
707 Rule: android.WriteFile,
708 Output: path,
709 Args: map[string]string{
710 "content": string(data),
711 },
712 })
713}
714
Colin Cross44df5812019-02-15 23:06:46 -0800715// Export paths for default boot image to Make
716func (d *dexpreoptBootJars) MakeVars(ctx android.MakeVarsContext) {
Colin Cross2d00f0d2019-05-09 21:50:00 -0700717 if d.dexpreoptConfigForMake != nil {
718 ctx.Strict("DEX_PREOPT_CONFIG_FOR_MAKE", d.dexpreoptConfigForMake.String())
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000719 ctx.Strict("DEX_PREOPT_SOONG_CONFIG_FOR_MAKE", android.PathForOutput(ctx, "dexpreopt_soong.config").String())
Colin Cross2d00f0d2019-05-09 21:50:00 -0700720 }
721
Colin Cross44df5812019-02-15 23:06:46 -0800722 image := d.defaultBootImage
723 if image != nil {
Colin Cross44df5812019-02-15 23:06:46 -0800724 ctx.Strict("DEXPREOPT_IMAGE_PROFILE_BUILT_INSTALLED", image.profileInstalls.String())
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +0000725 ctx.Strict("DEXPREOPT_BOOTCLASSPATH_DEX_FILES", strings.Join(image.dexPathsDeps.Strings(), " "))
David Srbeckyab994982020-03-30 17:24:13 +0100726 ctx.Strict("DEXPREOPT_BOOTCLASSPATH_DEX_LOCATIONS", strings.Join(image.getAnyAndroidVariant().dexLocationsDeps, " "))
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000727
728 var imageNames []string
729 for _, current := range append(d.otherImages, image) {
730 imageNames = append(imageNames, current.name)
David Srbecky1aacc6c2020-03-26 11:10:45 +0000731 for _, variant := range current.variants {
David Srbecky7f8dac12020-02-13 16:00:45 +0000732 suffix := ""
David Srbecky1aacc6c2020-03-26 11:10:45 +0000733 if variant.target.Os.Class == android.Host {
David Srbecky7f8dac12020-02-13 16:00:45 +0000734 suffix = "_host"
735 }
David Srbecky1aacc6c2020-03-26 11:10:45 +0000736 sfx := variant.name + suffix + "_" + variant.target.Arch.ArchType.String()
737 ctx.Strict("DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_"+sfx, variant.vdexInstalls.String())
738 ctx.Strict("DEXPREOPT_IMAGE_"+sfx, variant.images.String())
739 ctx.Strict("DEXPREOPT_IMAGE_DEPS_"+sfx, strings.Join(variant.imagesDeps.Strings(), " "))
740 ctx.Strict("DEXPREOPT_IMAGE_BUILT_INSTALLED_"+sfx, variant.installs.String())
741 ctx.Strict("DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_"+sfx, variant.unstrippedInstalls.String())
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000742 }
David Srbeckyab994982020-03-30 17:24:13 +0100743 imageLocations := current.getAnyAndroidVariant().imageLocations()
David Srbecky1aacc6c2020-03-26 11:10:45 +0000744 ctx.Strict("DEXPREOPT_IMAGE_LOCATIONS_"+current.name, strings.Join(imageLocations, ":"))
Colin Cross31bf00d2019-12-04 13:16:01 -0800745 ctx.Strict("DEXPREOPT_IMAGE_ZIP_"+current.name, current.zip.String())
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000746 }
747 ctx.Strict("DEXPREOPT_IMAGE_NAMES", strings.Join(imageNames, " "))
Colin Cross800fe132019-02-11 14:21:24 -0800748 }
Colin Cross800fe132019-02-11 14:21:24 -0800749}