blob: e857fe81a62eb22a65909bede6858aac561e5c5e [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"
Colin Crossc9a4c362019-02-26 21:13:48 -080019 "sort"
Colin Cross800fe132019-02-11 14:21:24 -080020 "strings"
21
22 "android/soong/android"
23 "android/soong/dexpreopt"
24
25 "github.com/google/blueprint/pathtools"
26 "github.com/google/blueprint/proptools"
27)
28
29func init() {
30 android.RegisterSingletonType("dex_bootjars", dexpreoptBootJarsFactory)
31}
32
33// The image "location" is a symbolic path that with multiarchitecture
34// support doesn't really exist on the device. Typically it is
35// /system/framework/boot.art and should be the same for all supported
36// architectures on the device. The concrete architecture specific
37// content actually ends up in a "filename" that contains an
38// architecture specific directory name such as arm, arm64, mips,
39// mips64, x86, x86_64.
40//
41// Here are some example values for an x86_64 / x86 configuration:
42//
43// bootImages["x86_64"] = "out/soong/generic_x86_64/dex_bootjars/system/framework/x86_64/boot.art"
44// dexpreopt.PathToLocation(bootImages["x86_64"], "x86_64") = "out/soong/generic_x86_64/dex_bootjars/system/framework/boot.art"
45//
46// bootImages["x86"] = "out/soong/generic_x86_64/dex_bootjars/system/framework/x86/boot.art"
47// dexpreopt.PathToLocation(bootImages["x86"])= "out/soong/generic_x86_64/dex_bootjars/system/framework/boot.art"
48//
49// The location is passed as an argument to the ART tools like dex2oat instead of the real path. The ART tools
50// will then reconstruct the real path, so the rules must have a dependency on the real path.
51
Colin Cross44df5812019-02-15 23:06:46 -080052type bootImageConfig struct {
53 name string
54 modules []string
55 dexLocations []string
56 dexPaths android.WritablePaths
57 dir android.OutputPath
58 symbolsDir android.OutputPath
59 images map[android.ArchType]android.OutputPath
Colin Crossdf8eebe2019-04-09 15:29:41 -070060 zip android.WritablePath
Colin Cross800fe132019-02-11 14:21:24 -080061}
62
Colin Cross44df5812019-02-15 23:06:46 -080063type bootImage struct {
64 bootImageConfig
Colin Cross800fe132019-02-11 14:21:24 -080065
Colin Cross44df5812019-02-15 23:06:46 -080066 installs map[android.ArchType]android.RuleBuilderInstalls
67 vdexInstalls map[android.ArchType]android.RuleBuilderInstalls
68 unstrippedInstalls map[android.ArchType]android.RuleBuilderInstalls
Colin Cross800fe132019-02-11 14:21:24 -080069
Colin Cross44df5812019-02-15 23:06:46 -080070 profileInstalls android.RuleBuilderInstalls
71}
Colin Cross800fe132019-02-11 14:21:24 -080072
Colin Cross44df5812019-02-15 23:06:46 -080073func newBootImage(ctx android.PathContext, config bootImageConfig) *bootImage {
74 image := &bootImage{
Nicolas Geoffray72892f12019-02-22 15:34:40 +000075 bootImageConfig: config,
Colin Cross800fe132019-02-11 14:21:24 -080076
Colin Cross44df5812019-02-15 23:06:46 -080077 installs: make(map[android.ArchType]android.RuleBuilderInstalls),
78 vdexInstalls: make(map[android.ArchType]android.RuleBuilderInstalls),
79 unstrippedInstalls: make(map[android.ArchType]android.RuleBuilderInstalls),
80 }
Colin Cross800fe132019-02-11 14:21:24 -080081
Colin Cross44df5812019-02-15 23:06:46 -080082 return image
Colin Cross800fe132019-02-11 14:21:24 -080083}
84
85func concat(lists ...[]string) []string {
86 var size int
87 for _, l := range lists {
88 size += len(l)
89 }
90 ret := make([]string, 0, size)
91 for _, l := range lists {
92 ret = append(ret, l...)
93 }
94 return ret
95}
96
Colin Cross800fe132019-02-11 14:21:24 -080097func dexpreoptBootJarsFactory() android.Singleton {
Colin Cross44df5812019-02-15 23:06:46 -080098 return &dexpreoptBootJars{}
Colin Cross800fe132019-02-11 14:21:24 -080099}
100
101func skipDexpreoptBootJars(ctx android.PathContext) bool {
102 if ctx.Config().UnbundledBuild() {
103 return true
104 }
105
106 if len(ctx.Config().Targets[android.Android]) == 0 {
107 // Host-only build
108 return true
109 }
110
111 return false
112}
113
Colin Cross44df5812019-02-15 23:06:46 -0800114type dexpreoptBootJars struct {
115 defaultBootImage *bootImage
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000116 otherImages []*bootImage
Colin Cross44df5812019-02-15 23:06:46 -0800117}
Colin Cross800fe132019-02-11 14:21:24 -0800118
119// dexpreoptBoot singleton rules
Colin Cross44df5812019-02-15 23:06:46 -0800120func (d *dexpreoptBootJars) GenerateBuildActions(ctx android.SingletonContext) {
Colin Cross800fe132019-02-11 14:21:24 -0800121 if skipDexpreoptBootJars(ctx) {
122 return
123 }
124
Colin Cross44df5812019-02-15 23:06:46 -0800125 global := dexpreoptGlobalConfig(ctx)
Colin Cross800fe132019-02-11 14:21:24 -0800126
127 // Skip recompiling the boot image for the second sanitization phase. We'll get separate paths
128 // and invalidate first-stage artifacts which are crucial to SANITIZE_LITE builds.
129 // Note: this is technically incorrect. Compiled code contains stack checks which may depend
130 // on ASAN settings.
131 if len(ctx.Config().SanitizeDevice()) == 1 &&
132 ctx.Config().SanitizeDevice()[0] == "address" &&
Colin Cross44df5812019-02-15 23:06:46 -0800133 global.SanitizeLite {
Colin Cross800fe132019-02-11 14:21:24 -0800134 return
135 }
136
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000137 // Always create the default boot image first, to get a unique profile rule for all images.
Colin Cross44df5812019-02-15 23:06:46 -0800138 d.defaultBootImage = buildBootImage(ctx, defaultBootImageConfig(ctx))
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000139 if global.GenerateApexImage {
140 d.otherImages = append(d.otherImages, buildBootImage(ctx, apexBootImageConfig(ctx)))
141 }
Colin Crossc9a4c362019-02-26 21:13:48 -0800142
143 dumpOatRules(ctx, d.defaultBootImage)
Colin Cross44df5812019-02-15 23:06:46 -0800144}
145
146// buildBootImage takes a bootImageConfig, creates rules to build it, and returns a *bootImage.
147func buildBootImage(ctx android.SingletonContext, config bootImageConfig) *bootImage {
148 global := dexpreoptGlobalConfig(ctx)
149
150 image := newBootImage(ctx, config)
151
152 bootDexJars := make(android.Paths, len(image.modules))
Colin Cross800fe132019-02-11 14:21:24 -0800153
154 ctx.VisitAllModules(func(module android.Module) {
155 // Collect dex jar paths for the modules listed above.
Colin Cross42be7612019-02-21 18:12:14 -0800156 if j, ok := module.(interface{ DexJar() android.Path }); ok {
Colin Cross800fe132019-02-11 14:21:24 -0800157 name := ctx.ModuleName(module)
Colin Cross44df5812019-02-15 23:06:46 -0800158 if i := android.IndexList(name, image.modules); i != -1 {
Colin Cross800fe132019-02-11 14:21:24 -0800159 bootDexJars[i] = j.DexJar()
160 }
161 }
162 })
163
164 var missingDeps []string
165 // Ensure all modules were converted to paths
166 for i := range bootDexJars {
167 if bootDexJars[i] == nil {
168 if ctx.Config().AllowMissingDependencies() {
Colin Cross44df5812019-02-15 23:06:46 -0800169 missingDeps = append(missingDeps, image.modules[i])
Colin Cross800fe132019-02-11 14:21:24 -0800170 bootDexJars[i] = android.PathForOutput(ctx, "missing")
171 } else {
172 ctx.Errorf("failed to find dex jar path for module %q",
Colin Cross44df5812019-02-15 23:06:46 -0800173 image.modules[i])
Colin Cross800fe132019-02-11 14:21:24 -0800174 }
175 }
176 }
177
178 // The path to bootclasspath dex files needs to be known at module GenerateAndroidBuildAction time, before
179 // the bootclasspath modules have been compiled. Copy the dex jars there so the module rules that have
180 // already been set up can find them.
181 for i := range bootDexJars {
182 ctx.Build(pctx, android.BuildParams{
183 Rule: android.Cp,
184 Input: bootDexJars[i],
Colin Cross44df5812019-02-15 23:06:46 -0800185 Output: image.dexPaths[i],
Colin Cross800fe132019-02-11 14:21:24 -0800186 })
187 }
188
Colin Cross44df5812019-02-15 23:06:46 -0800189 profile := bootImageProfileRule(ctx, image, missingDeps)
Colin Cross800fe132019-02-11 14:21:24 -0800190
Colin Crossdf8eebe2019-04-09 15:29:41 -0700191 var allFiles android.Paths
192
Colin Cross44df5812019-02-15 23:06:46 -0800193 if !global.DisablePreopt {
Colin Cross800fe132019-02-11 14:21:24 -0800194 targets := ctx.Config().Targets[android.Android]
195 if ctx.Config().SecondArchIsTranslated() {
196 targets = targets[:1]
197 }
198
199 for _, target := range targets {
Colin Crossdf8eebe2019-04-09 15:29:41 -0700200 files := buildBootImageRuleForArch(ctx, image, target.Arch.ArchType, profile, missingDeps)
201 allFiles = append(allFiles, files.Paths()...)
Colin Cross800fe132019-02-11 14:21:24 -0800202 }
203 }
Colin Cross44df5812019-02-15 23:06:46 -0800204
Colin Crossdf8eebe2019-04-09 15:29:41 -0700205 if image.zip != nil {
206 rule := android.NewRuleBuilder()
207 rule.Command().
208 Tool(ctx.Config().HostToolPath(ctx, "soong_zip")).
209 FlagWithOutput("-o ", image.zip).
210 FlagWithArg("-C ", image.dir.String()).
211 FlagWithInputList("-f ", allFiles, " -f ")
212
213 rule.Build(pctx, ctx, "zip_"+image.name, "zip "+image.name+" image")
214 }
215
Colin Cross44df5812019-02-15 23:06:46 -0800216 return image
Colin Cross800fe132019-02-11 14:21:24 -0800217}
218
Colin Cross44df5812019-02-15 23:06:46 -0800219func buildBootImageRuleForArch(ctx android.SingletonContext, image *bootImage,
Colin Crossdf8eebe2019-04-09 15:29:41 -0700220 arch android.ArchType, profile android.Path, missingDeps []string) android.WritablePaths {
Colin Cross800fe132019-02-11 14:21:24 -0800221
Colin Cross44df5812019-02-15 23:06:46 -0800222 global := dexpreoptGlobalConfig(ctx)
223
224 symbolsDir := image.symbolsDir.Join(ctx, "system/framework", arch.String())
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000225 symbolsFile := symbolsDir.Join(ctx, image.name+".oat")
Colin Cross44df5812019-02-15 23:06:46 -0800226 outputDir := image.dir.Join(ctx, "system/framework", arch.String())
227 outputPath := image.images[arch]
Colin Cross69f59a32019-02-15 10:39:37 -0800228 oatLocation := pathtools.ReplaceExtension(dexpreopt.PathToLocation(outputPath, arch), "oat")
Colin Cross800fe132019-02-11 14:21:24 -0800229
230 rule := android.NewRuleBuilder()
231 rule.MissingDeps(missingDeps)
232
233 rule.Command().Text("mkdir").Flag("-p").Flag(symbolsDir.String())
234 rule.Command().Text("rm").Flag("-f").
235 Flag(symbolsDir.Join(ctx, "*.art").String()).
236 Flag(symbolsDir.Join(ctx, "*.oat").String()).
237 Flag(symbolsDir.Join(ctx, "*.invocation").String())
238 rule.Command().Text("rm").Flag("-f").
239 Flag(outputDir.Join(ctx, "*.art").String()).
240 Flag(outputDir.Join(ctx, "*.oat").String()).
241 Flag(outputDir.Join(ctx, "*.invocation").String())
242
243 cmd := rule.Command()
244
245 extraFlags := ctx.Config().Getenv("ART_BOOT_IMAGE_EXTRA_ARGS")
246 if extraFlags == "" {
247 // Use ANDROID_LOG_TAGS to suppress most logging by default...
248 cmd.Text(`ANDROID_LOG_TAGS="*:e"`)
249 } else {
250 // ...unless the boot image is generated specifically for testing, then allow all logging.
251 cmd.Text(`ANDROID_LOG_TAGS="*:v"`)
252 }
253
254 invocationPath := outputPath.ReplaceExtension(ctx, "invocation")
255
Colin Cross44df5812019-02-15 23:06:46 -0800256 cmd.Tool(global.Tools.Dex2oat).
Colin Cross800fe132019-02-11 14:21:24 -0800257 Flag("--avoid-storing-invocation").
Colin Cross69f59a32019-02-15 10:39:37 -0800258 FlagWithOutput("--write-invocation-to=", invocationPath).ImplicitOutput(invocationPath).
Colin Cross44df5812019-02-15 23:06:46 -0800259 Flag("--runtime-arg").FlagWithArg("-Xms", global.Dex2oatImageXms).
260 Flag("--runtime-arg").FlagWithArg("-Xmx", global.Dex2oatImageXmx)
Colin Cross800fe132019-02-11 14:21:24 -0800261
Colin Cross69f59a32019-02-15 10:39:37 -0800262 if profile != nil {
Colin Cross800fe132019-02-11 14:21:24 -0800263 cmd.FlagWithArg("--compiler-filter=", "speed-profile")
Colin Cross69f59a32019-02-15 10:39:37 -0800264 cmd.FlagWithInput("--profile-file=", profile)
Colin Cross44df5812019-02-15 23:06:46 -0800265 } else if global.PreloadedClasses.Valid() {
266 cmd.FlagWithInput("--image-classes=", global.PreloadedClasses.Path())
Colin Cross800fe132019-02-11 14:21:24 -0800267 }
268
Colin Cross44df5812019-02-15 23:06:46 -0800269 if global.DirtyImageObjects.Valid() {
270 cmd.FlagWithInput("--dirty-image-objects=", global.DirtyImageObjects.Path())
Colin Cross800fe132019-02-11 14:21:24 -0800271 }
272
273 cmd.
Colin Cross44df5812019-02-15 23:06:46 -0800274 FlagForEachInput("--dex-file=", image.dexPaths.Paths()).
275 FlagForEachArg("--dex-location=", image.dexLocations).
Colin Cross800fe132019-02-11 14:21:24 -0800276 Flag("--generate-debug-info").
277 Flag("--generate-build-id").
Colin Cross69f59a32019-02-15 10:39:37 -0800278 FlagWithOutput("--oat-symbols=", symbolsFile).
Colin Cross800fe132019-02-11 14:21:24 -0800279 Flag("--strip").
Colin Cross69f59a32019-02-15 10:39:37 -0800280 FlagWithOutput("--oat-file=", outputPath.ReplaceExtension(ctx, "oat")).
Colin Cross800fe132019-02-11 14:21:24 -0800281 FlagWithArg("--oat-location=", oatLocation).
Colin Cross69f59a32019-02-15 10:39:37 -0800282 FlagWithOutput("--image=", outputPath).
Colin Cross800fe132019-02-11 14:21:24 -0800283 FlagWithArg("--base=", ctx.Config().LibartImgDeviceBaseAddress()).
284 FlagWithArg("--instruction-set=", arch.String()).
Colin Cross44df5812019-02-15 23:06:46 -0800285 FlagWithArg("--instruction-set-variant=", global.CpuVariant[arch]).
286 FlagWithArg("--instruction-set-features=", global.InstructionSetFeatures[arch]).
287 FlagWithArg("--android-root=", global.EmptyDirectory).
Colin Cross800fe132019-02-11 14:21:24 -0800288 FlagWithArg("--no-inline-from=", "core-oj.jar").
289 Flag("--abort-on-hard-verifier-error")
290
Colin Cross44df5812019-02-15 23:06:46 -0800291 if global.BootFlags != "" {
292 cmd.Flag(global.BootFlags)
Colin Cross800fe132019-02-11 14:21:24 -0800293 }
294
295 if extraFlags != "" {
296 cmd.Flag(extraFlags)
297 }
298
Colin Cross0b9f31f2019-02-28 11:00:01 -0800299 cmd.Textf(`|| ( echo %s ; false )`, proptools.ShellEscape(failureMessage))
Colin Cross800fe132019-02-11 14:21:24 -0800300
301 installDir := filepath.Join("/system/framework", arch.String())
302 vdexInstallDir := filepath.Join("/system/framework")
303
304 var extraFiles android.WritablePaths
305 var vdexInstalls android.RuleBuilderInstalls
306 var unstrippedInstalls android.RuleBuilderInstalls
307
Colin Crossdf8eebe2019-04-09 15:29:41 -0700308 var zipFiles android.WritablePaths
309
Colin Cross800fe132019-02-11 14:21:24 -0800310 // dex preopt on the bootclasspath produces multiple files. The first dex file
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000311 // is converted into to 'name'.art (to match the legacy assumption that 'name'.art
312 // exists), and the rest are converted to 'name'-<jar>.art.
Colin Cross800fe132019-02-11 14:21:24 -0800313 // In addition, each .art file has an associated .oat and .vdex file, and an
314 // unstripped .oat file
Colin Cross44df5812019-02-15 23:06:46 -0800315 for i, m := range image.modules {
316 name := image.name
Colin Cross800fe132019-02-11 14:21:24 -0800317 if i != 0 {
318 name += "-" + m
319 }
320
321 art := outputDir.Join(ctx, name+".art")
322 oat := outputDir.Join(ctx, name+".oat")
323 vdex := outputDir.Join(ctx, name+".vdex")
324 unstrippedOat := symbolsDir.Join(ctx, name+".oat")
325
326 extraFiles = append(extraFiles, art, oat, vdex, unstrippedOat)
327
Colin Crossdf8eebe2019-04-09 15:29:41 -0700328 zipFiles = append(zipFiles, art, oat, vdex)
329
Colin Cross800fe132019-02-11 14:21:24 -0800330 // Install the .oat and .art files.
Colin Cross69f59a32019-02-15 10:39:37 -0800331 rule.Install(art, filepath.Join(installDir, art.Base()))
332 rule.Install(oat, filepath.Join(installDir, oat.Base()))
Colin Cross800fe132019-02-11 14:21:24 -0800333
334 // The vdex files are identical between architectures, install them to a shared location. The Make rules will
335 // only use the install rules for one architecture, and will create symlinks into the architecture-specific
336 // directories.
337 vdexInstalls = append(vdexInstalls,
Colin Cross69f59a32019-02-15 10:39:37 -0800338 android.RuleBuilderInstall{vdex, filepath.Join(vdexInstallDir, vdex.Base())})
Colin Cross800fe132019-02-11 14:21:24 -0800339
340 // Install the unstripped oat files. The Make rules will put these in $(TARGET_OUT_UNSTRIPPED)
341 unstrippedInstalls = append(unstrippedInstalls,
Colin Cross69f59a32019-02-15 10:39:37 -0800342 android.RuleBuilderInstall{unstrippedOat, filepath.Join(installDir, unstrippedOat.Base())})
Colin Cross800fe132019-02-11 14:21:24 -0800343 }
344
Colin Cross69f59a32019-02-15 10:39:37 -0800345 cmd.ImplicitOutputs(extraFiles)
Colin Cross800fe132019-02-11 14:21:24 -0800346
Colin Cross44df5812019-02-15 23:06:46 -0800347 rule.Build(pctx, ctx, image.name+"JarsDexpreopt_"+arch.String(), "dexpreopt "+image.name+" jars "+arch.String())
Colin Cross800fe132019-02-11 14:21:24 -0800348
349 // save output and installed files for makevars
Colin Cross44df5812019-02-15 23:06:46 -0800350 image.installs[arch] = rule.Installs()
351 image.vdexInstalls[arch] = vdexInstalls
352 image.unstrippedInstalls[arch] = unstrippedInstalls
Colin Crossdf8eebe2019-04-09 15:29:41 -0700353
354 return zipFiles
Colin Cross800fe132019-02-11 14:21:24 -0800355}
356
357const failureMessage = `ERROR: Dex2oat failed to compile a boot image.
358It is likely that the boot classpath is inconsistent.
359Rebuild with ART_BOOT_IMAGE_EXTRA_ARGS="--runtime-arg -verbose:verifier" to see verification errors.`
360
Colin Cross44df5812019-02-15 23:06:46 -0800361func bootImageProfileRule(ctx android.SingletonContext, image *bootImage, missingDeps []string) android.WritablePath {
Nicolas Geoffray27c7cc62019-02-24 16:04:52 +0000362 global := dexpreoptGlobalConfig(ctx)
363
364 if !global.UseProfileForBootImage || ctx.Config().IsPdkBuild() || ctx.Config().UnbundledBuild() {
365 return nil
366 }
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000367 return ctx.Config().Once(bootImageProfileRuleKey, func() interface{} {
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000368 tools := global.Tools
Colin Cross800fe132019-02-11 14:21:24 -0800369
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000370 rule := android.NewRuleBuilder()
371 rule.MissingDeps(missingDeps)
Colin Cross800fe132019-02-11 14:21:24 -0800372
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000373 var bootImageProfile android.Path
374 if len(global.BootImageProfiles) > 1 {
375 combinedBootImageProfile := image.dir.Join(ctx, "boot-image-profile.txt")
376 rule.Command().Text("cat").Inputs(global.BootImageProfiles).Text(">").Output(combinedBootImageProfile)
377 bootImageProfile = combinedBootImageProfile
378 } else if len(global.BootImageProfiles) == 1 {
379 bootImageProfile = global.BootImageProfiles[0]
380 } else {
381 // If not set, use the default. Some branches like master-art-host don't have frameworks/base, so manually
382 // handle the case that the default is missing. Those branches won't attempt to build the profile rule,
383 // and if they do they'll get a missing deps error.
384 defaultProfile := "frameworks/base/config/boot-image-profile.txt"
385 path := android.ExistentPathForSource(ctx, defaultProfile)
386 if path.Valid() {
387 bootImageProfile = path.Path()
388 } else {
389 missingDeps = append(missingDeps, defaultProfile)
390 bootImageProfile = android.PathForOutput(ctx, "missing")
391 }
392 }
Colin Cross800fe132019-02-11 14:21:24 -0800393
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000394 profile := image.dir.Join(ctx, "boot.prof")
Colin Cross800fe132019-02-11 14:21:24 -0800395
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000396 rule.Command().
397 Text(`ANDROID_LOG_TAGS="*:e"`).
398 Tool(tools.Profman).
399 FlagWithInput("--create-profile-from=", bootImageProfile).
400 FlagForEachInput("--apk=", image.dexPaths.Paths()).
401 FlagForEachArg("--dex-location=", image.dexLocations).
402 FlagWithOutput("--reference-profile-file=", profile)
Colin Cross800fe132019-02-11 14:21:24 -0800403
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000404 rule.Install(profile, "/system/etc/boot-image.prof")
405
406 rule.Build(pctx, ctx, "bootJarsProfile", "profile boot jars")
407
408 image.profileInstalls = rule.Installs()
409
410 return profile
411 }).(android.WritablePath)
Colin Cross800fe132019-02-11 14:21:24 -0800412}
413
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000414var bootImageProfileRuleKey = android.NewOnceKey("bootImageProfileRule")
415
Colin Crossc9a4c362019-02-26 21:13:48 -0800416func dumpOatRules(ctx android.SingletonContext, image *bootImage) {
417 var archs []android.ArchType
418 for arch := range image.images {
419 archs = append(archs, arch)
420 }
421 sort.Slice(archs, func(i, j int) bool { return archs[i].String() < archs[j].String() })
422
423 var allPhonies android.Paths
424 for _, arch := range archs {
425 // Create a rule to call oatdump.
426 output := android.PathForOutput(ctx, "boot."+arch.String()+".oatdump.txt")
427 rule := android.NewRuleBuilder()
428 rule.Command().
429 // TODO: for now, use the debug version for better error reporting
430 Tool(ctx.Config().HostToolPath(ctx, "oatdumpd")).
431 FlagWithInputList("--runtime-arg -Xbootclasspath:", image.dexPaths.Paths(), ":").
432 FlagWithList("--runtime-arg -Xbootclasspath-locations:", image.dexLocations, ":").
433 FlagWithArg("--image=", dexpreopt.PathToLocation(image.images[arch], arch)).Implicit(image.images[arch]).
434 FlagWithOutput("--output=", output).
435 FlagWithArg("--instruction-set=", arch.String())
436 rule.Build(pctx, ctx, "dump-oat-boot-"+arch.String(), "dump oat boot "+arch.String())
437
438 // Create a phony rule that depends on the output file and prints the path.
439 phony := android.PathForPhony(ctx, "dump-oat-boot-"+arch.String())
440 rule = android.NewRuleBuilder()
441 rule.Command().
442 Implicit(output).
443 ImplicitOutput(phony).
444 Text("echo").FlagWithArg("Output in ", output.String())
445 rule.Build(pctx, ctx, "phony-dump-oat-boot-"+arch.String(), "dump oat boot "+arch.String())
446
447 allPhonies = append(allPhonies, phony)
448 }
449
450 phony := android.PathForPhony(ctx, "dump-oat-boot")
451 ctx.Build(pctx, android.BuildParams{
452 Rule: android.Phony,
453 Output: phony,
454 Inputs: allPhonies,
455 Description: "dump-oat-boot",
456 })
457
458}
459
Colin Cross44df5812019-02-15 23:06:46 -0800460// Export paths for default boot image to Make
461func (d *dexpreoptBootJars) MakeVars(ctx android.MakeVarsContext) {
462 image := d.defaultBootImage
463 if image != nil {
Colin Cross44df5812019-02-15 23:06:46 -0800464 ctx.Strict("DEXPREOPT_IMAGE_PROFILE_BUILT_INSTALLED", image.profileInstalls.String())
Colin Cross44df5812019-02-15 23:06:46 -0800465 ctx.Strict("DEXPREOPT_BOOTCLASSPATH_DEX_FILES", strings.Join(image.dexPaths.Strings(), " "))
466 ctx.Strict("DEXPREOPT_BOOTCLASSPATH_DEX_LOCATIONS", strings.Join(image.dexLocations, " "))
Colin Crossdf8eebe2019-04-09 15:29:41 -0700467 ctx.Strict("DEXPREOPT_IMAGE_ZIP_"+image.name, image.zip.String())
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000468
469 var imageNames []string
470 for _, current := range append(d.otherImages, image) {
471 imageNames = append(imageNames, current.name)
472 for arch, _ := range current.images {
473 ctx.Strict("DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_"+current.name+"_"+arch.String(), current.vdexInstalls[arch].String())
474 ctx.Strict("DEXPREOPT_IMAGE_"+current.name+"_"+arch.String(), current.images[arch].String())
475 ctx.Strict("DEXPREOPT_IMAGE_BUILT_INSTALLED_"+current.name+"_"+arch.String(), current.installs[arch].String())
476 ctx.Strict("DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_"+current.name+"_"+arch.String(), current.unstrippedInstalls[arch].String())
Colin Crossdf8eebe2019-04-09 15:29:41 -0700477 if current.zip != nil {
478 }
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000479 }
480 }
481 ctx.Strict("DEXPREOPT_IMAGE_NAMES", strings.Join(imageNames, " "))
Colin Cross800fe132019-02-11 14:21:24 -0800482 }
Colin Cross800fe132019-02-11 14:21:24 -0800483}