blob: 092a1332ee44912f2286dc234e4d6a9ad11253fa [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 {
dimitry1f33e402019-03-26 12:39:31 +0100200 if target.NativeBridge == android.NativeBridgeDisabled {
201 files := buildBootImageRuleForArch(ctx, image, target.Arch.ArchType, profile, missingDeps)
202 allFiles = append(allFiles, files.Paths()...)
203 }
Colin Cross800fe132019-02-11 14:21:24 -0800204 }
205 }
Colin Cross44df5812019-02-15 23:06:46 -0800206
Colin Crossdf8eebe2019-04-09 15:29:41 -0700207 if image.zip != nil {
208 rule := android.NewRuleBuilder()
209 rule.Command().
210 Tool(ctx.Config().HostToolPath(ctx, "soong_zip")).
211 FlagWithOutput("-o ", image.zip).
212 FlagWithArg("-C ", image.dir.String()).
213 FlagWithInputList("-f ", allFiles, " -f ")
214
215 rule.Build(pctx, ctx, "zip_"+image.name, "zip "+image.name+" image")
216 }
217
Colin Cross44df5812019-02-15 23:06:46 -0800218 return image
Colin Cross800fe132019-02-11 14:21:24 -0800219}
220
Colin Cross44df5812019-02-15 23:06:46 -0800221func buildBootImageRuleForArch(ctx android.SingletonContext, image *bootImage,
Colin Crossdf8eebe2019-04-09 15:29:41 -0700222 arch android.ArchType, profile android.Path, missingDeps []string) android.WritablePaths {
Colin Cross800fe132019-02-11 14:21:24 -0800223
Colin Cross44df5812019-02-15 23:06:46 -0800224 global := dexpreoptGlobalConfig(ctx)
225
226 symbolsDir := image.symbolsDir.Join(ctx, "system/framework", arch.String())
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000227 symbolsFile := symbolsDir.Join(ctx, image.name+".oat")
Colin Cross44df5812019-02-15 23:06:46 -0800228 outputDir := image.dir.Join(ctx, "system/framework", arch.String())
229 outputPath := image.images[arch]
Colin Cross69f59a32019-02-15 10:39:37 -0800230 oatLocation := pathtools.ReplaceExtension(dexpreopt.PathToLocation(outputPath, arch), "oat")
Colin Cross800fe132019-02-11 14:21:24 -0800231
232 rule := android.NewRuleBuilder()
233 rule.MissingDeps(missingDeps)
234
235 rule.Command().Text("mkdir").Flag("-p").Flag(symbolsDir.String())
236 rule.Command().Text("rm").Flag("-f").
237 Flag(symbolsDir.Join(ctx, "*.art").String()).
238 Flag(symbolsDir.Join(ctx, "*.oat").String()).
239 Flag(symbolsDir.Join(ctx, "*.invocation").String())
240 rule.Command().Text("rm").Flag("-f").
241 Flag(outputDir.Join(ctx, "*.art").String()).
242 Flag(outputDir.Join(ctx, "*.oat").String()).
243 Flag(outputDir.Join(ctx, "*.invocation").String())
244
245 cmd := rule.Command()
246
247 extraFlags := ctx.Config().Getenv("ART_BOOT_IMAGE_EXTRA_ARGS")
248 if extraFlags == "" {
249 // Use ANDROID_LOG_TAGS to suppress most logging by default...
250 cmd.Text(`ANDROID_LOG_TAGS="*:e"`)
251 } else {
252 // ...unless the boot image is generated specifically for testing, then allow all logging.
253 cmd.Text(`ANDROID_LOG_TAGS="*:v"`)
254 }
255
256 invocationPath := outputPath.ReplaceExtension(ctx, "invocation")
257
Colin Cross44df5812019-02-15 23:06:46 -0800258 cmd.Tool(global.Tools.Dex2oat).
Colin Cross800fe132019-02-11 14:21:24 -0800259 Flag("--avoid-storing-invocation").
Colin Cross69f59a32019-02-15 10:39:37 -0800260 FlagWithOutput("--write-invocation-to=", invocationPath).ImplicitOutput(invocationPath).
Colin Cross44df5812019-02-15 23:06:46 -0800261 Flag("--runtime-arg").FlagWithArg("-Xms", global.Dex2oatImageXms).
262 Flag("--runtime-arg").FlagWithArg("-Xmx", global.Dex2oatImageXmx)
Colin Cross800fe132019-02-11 14:21:24 -0800263
Colin Cross69f59a32019-02-15 10:39:37 -0800264 if profile != nil {
Colin Cross800fe132019-02-11 14:21:24 -0800265 cmd.FlagWithArg("--compiler-filter=", "speed-profile")
Colin Cross69f59a32019-02-15 10:39:37 -0800266 cmd.FlagWithInput("--profile-file=", profile)
Colin Cross44df5812019-02-15 23:06:46 -0800267 } else if global.PreloadedClasses.Valid() {
268 cmd.FlagWithInput("--image-classes=", global.PreloadedClasses.Path())
Colin Cross800fe132019-02-11 14:21:24 -0800269 }
270
Colin Cross44df5812019-02-15 23:06:46 -0800271 if global.DirtyImageObjects.Valid() {
272 cmd.FlagWithInput("--dirty-image-objects=", global.DirtyImageObjects.Path())
Colin Cross800fe132019-02-11 14:21:24 -0800273 }
274
275 cmd.
Colin Cross44df5812019-02-15 23:06:46 -0800276 FlagForEachInput("--dex-file=", image.dexPaths.Paths()).
277 FlagForEachArg("--dex-location=", image.dexLocations).
Colin Cross800fe132019-02-11 14:21:24 -0800278 Flag("--generate-debug-info").
279 Flag("--generate-build-id").
Colin Cross69f59a32019-02-15 10:39:37 -0800280 FlagWithOutput("--oat-symbols=", symbolsFile).
Colin Cross800fe132019-02-11 14:21:24 -0800281 Flag("--strip").
Colin Cross69f59a32019-02-15 10:39:37 -0800282 FlagWithOutput("--oat-file=", outputPath.ReplaceExtension(ctx, "oat")).
Colin Cross800fe132019-02-11 14:21:24 -0800283 FlagWithArg("--oat-location=", oatLocation).
Colin Cross69f59a32019-02-15 10:39:37 -0800284 FlagWithOutput("--image=", outputPath).
Colin Cross800fe132019-02-11 14:21:24 -0800285 FlagWithArg("--base=", ctx.Config().LibartImgDeviceBaseAddress()).
286 FlagWithArg("--instruction-set=", arch.String()).
Colin Cross44df5812019-02-15 23:06:46 -0800287 FlagWithArg("--instruction-set-variant=", global.CpuVariant[arch]).
288 FlagWithArg("--instruction-set-features=", global.InstructionSetFeatures[arch]).
289 FlagWithArg("--android-root=", global.EmptyDirectory).
Colin Cross800fe132019-02-11 14:21:24 -0800290 FlagWithArg("--no-inline-from=", "core-oj.jar").
291 Flag("--abort-on-hard-verifier-error")
292
Colin Cross44df5812019-02-15 23:06:46 -0800293 if global.BootFlags != "" {
294 cmd.Flag(global.BootFlags)
Colin Cross800fe132019-02-11 14:21:24 -0800295 }
296
297 if extraFlags != "" {
298 cmd.Flag(extraFlags)
299 }
300
Colin Cross0b9f31f2019-02-28 11:00:01 -0800301 cmd.Textf(`|| ( echo %s ; false )`, proptools.ShellEscape(failureMessage))
Colin Cross800fe132019-02-11 14:21:24 -0800302
303 installDir := filepath.Join("/system/framework", arch.String())
304 vdexInstallDir := filepath.Join("/system/framework")
305
306 var extraFiles android.WritablePaths
307 var vdexInstalls android.RuleBuilderInstalls
308 var unstrippedInstalls android.RuleBuilderInstalls
309
Colin Crossdf8eebe2019-04-09 15:29:41 -0700310 var zipFiles android.WritablePaths
311
Colin Cross800fe132019-02-11 14:21:24 -0800312 // dex preopt on the bootclasspath produces multiple files. The first dex file
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000313 // is converted into to 'name'.art (to match the legacy assumption that 'name'.art
314 // exists), and the rest are converted to 'name'-<jar>.art.
Colin Cross800fe132019-02-11 14:21:24 -0800315 // In addition, each .art file has an associated .oat and .vdex file, and an
316 // unstripped .oat file
Colin Cross44df5812019-02-15 23:06:46 -0800317 for i, m := range image.modules {
318 name := image.name
Colin Cross800fe132019-02-11 14:21:24 -0800319 if i != 0 {
320 name += "-" + m
321 }
322
323 art := outputDir.Join(ctx, name+".art")
324 oat := outputDir.Join(ctx, name+".oat")
325 vdex := outputDir.Join(ctx, name+".vdex")
326 unstrippedOat := symbolsDir.Join(ctx, name+".oat")
327
328 extraFiles = append(extraFiles, art, oat, vdex, unstrippedOat)
329
Colin Crossdf8eebe2019-04-09 15:29:41 -0700330 zipFiles = append(zipFiles, art, oat, vdex)
331
Colin Cross800fe132019-02-11 14:21:24 -0800332 // Install the .oat and .art files.
Colin Cross69f59a32019-02-15 10:39:37 -0800333 rule.Install(art, filepath.Join(installDir, art.Base()))
334 rule.Install(oat, filepath.Join(installDir, oat.Base()))
Colin Cross800fe132019-02-11 14:21:24 -0800335
336 // The vdex files are identical between architectures, install them to a shared location. The Make rules will
337 // only use the install rules for one architecture, and will create symlinks into the architecture-specific
338 // directories.
339 vdexInstalls = append(vdexInstalls,
Colin Cross69f59a32019-02-15 10:39:37 -0800340 android.RuleBuilderInstall{vdex, filepath.Join(vdexInstallDir, vdex.Base())})
Colin Cross800fe132019-02-11 14:21:24 -0800341
342 // Install the unstripped oat files. The Make rules will put these in $(TARGET_OUT_UNSTRIPPED)
343 unstrippedInstalls = append(unstrippedInstalls,
Colin Cross69f59a32019-02-15 10:39:37 -0800344 android.RuleBuilderInstall{unstrippedOat, filepath.Join(installDir, unstrippedOat.Base())})
Colin Cross800fe132019-02-11 14:21:24 -0800345 }
346
Colin Cross69f59a32019-02-15 10:39:37 -0800347 cmd.ImplicitOutputs(extraFiles)
Colin Cross800fe132019-02-11 14:21:24 -0800348
Colin Cross44df5812019-02-15 23:06:46 -0800349 rule.Build(pctx, ctx, image.name+"JarsDexpreopt_"+arch.String(), "dexpreopt "+image.name+" jars "+arch.String())
Colin Cross800fe132019-02-11 14:21:24 -0800350
351 // save output and installed files for makevars
Colin Cross44df5812019-02-15 23:06:46 -0800352 image.installs[arch] = rule.Installs()
353 image.vdexInstalls[arch] = vdexInstalls
354 image.unstrippedInstalls[arch] = unstrippedInstalls
Colin Crossdf8eebe2019-04-09 15:29:41 -0700355
356 return zipFiles
Colin Cross800fe132019-02-11 14:21:24 -0800357}
358
359const failureMessage = `ERROR: Dex2oat failed to compile a boot image.
360It is likely that the boot classpath is inconsistent.
361Rebuild with ART_BOOT_IMAGE_EXTRA_ARGS="--runtime-arg -verbose:verifier" to see verification errors.`
362
Colin Cross44df5812019-02-15 23:06:46 -0800363func bootImageProfileRule(ctx android.SingletonContext, image *bootImage, missingDeps []string) android.WritablePath {
Nicolas Geoffray27c7cc62019-02-24 16:04:52 +0000364 global := dexpreoptGlobalConfig(ctx)
365
366 if !global.UseProfileForBootImage || ctx.Config().IsPdkBuild() || ctx.Config().UnbundledBuild() {
367 return nil
368 }
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000369 return ctx.Config().Once(bootImageProfileRuleKey, func() interface{} {
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000370 tools := global.Tools
Colin Cross800fe132019-02-11 14:21:24 -0800371
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000372 rule := android.NewRuleBuilder()
373 rule.MissingDeps(missingDeps)
Colin Cross800fe132019-02-11 14:21:24 -0800374
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000375 var bootImageProfile android.Path
376 if len(global.BootImageProfiles) > 1 {
377 combinedBootImageProfile := image.dir.Join(ctx, "boot-image-profile.txt")
378 rule.Command().Text("cat").Inputs(global.BootImageProfiles).Text(">").Output(combinedBootImageProfile)
379 bootImageProfile = combinedBootImageProfile
380 } else if len(global.BootImageProfiles) == 1 {
381 bootImageProfile = global.BootImageProfiles[0]
382 } else {
383 // If not set, use the default. Some branches like master-art-host don't have frameworks/base, so manually
384 // handle the case that the default is missing. Those branches won't attempt to build the profile rule,
385 // and if they do they'll get a missing deps error.
386 defaultProfile := "frameworks/base/config/boot-image-profile.txt"
387 path := android.ExistentPathForSource(ctx, defaultProfile)
388 if path.Valid() {
389 bootImageProfile = path.Path()
390 } else {
391 missingDeps = append(missingDeps, defaultProfile)
392 bootImageProfile = android.PathForOutput(ctx, "missing")
393 }
394 }
Colin Cross800fe132019-02-11 14:21:24 -0800395
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000396 profile := image.dir.Join(ctx, "boot.prof")
Colin Cross800fe132019-02-11 14:21:24 -0800397
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000398 rule.Command().
399 Text(`ANDROID_LOG_TAGS="*:e"`).
400 Tool(tools.Profman).
401 FlagWithInput("--create-profile-from=", bootImageProfile).
402 FlagForEachInput("--apk=", image.dexPaths.Paths()).
403 FlagForEachArg("--dex-location=", image.dexLocations).
404 FlagWithOutput("--reference-profile-file=", profile)
Colin Cross800fe132019-02-11 14:21:24 -0800405
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000406 rule.Install(profile, "/system/etc/boot-image.prof")
407
408 rule.Build(pctx, ctx, "bootJarsProfile", "profile boot jars")
409
410 image.profileInstalls = rule.Installs()
411
412 return profile
413 }).(android.WritablePath)
Colin Cross800fe132019-02-11 14:21:24 -0800414}
415
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000416var bootImageProfileRuleKey = android.NewOnceKey("bootImageProfileRule")
417
Colin Crossc9a4c362019-02-26 21:13:48 -0800418func dumpOatRules(ctx android.SingletonContext, image *bootImage) {
419 var archs []android.ArchType
420 for arch := range image.images {
421 archs = append(archs, arch)
422 }
423 sort.Slice(archs, func(i, j int) bool { return archs[i].String() < archs[j].String() })
424
425 var allPhonies android.Paths
426 for _, arch := range archs {
427 // Create a rule to call oatdump.
428 output := android.PathForOutput(ctx, "boot."+arch.String()+".oatdump.txt")
429 rule := android.NewRuleBuilder()
430 rule.Command().
431 // TODO: for now, use the debug version for better error reporting
432 Tool(ctx.Config().HostToolPath(ctx, "oatdumpd")).
433 FlagWithInputList("--runtime-arg -Xbootclasspath:", image.dexPaths.Paths(), ":").
434 FlagWithList("--runtime-arg -Xbootclasspath-locations:", image.dexLocations, ":").
435 FlagWithArg("--image=", dexpreopt.PathToLocation(image.images[arch], arch)).Implicit(image.images[arch]).
436 FlagWithOutput("--output=", output).
437 FlagWithArg("--instruction-set=", arch.String())
438 rule.Build(pctx, ctx, "dump-oat-boot-"+arch.String(), "dump oat boot "+arch.String())
439
440 // Create a phony rule that depends on the output file and prints the path.
441 phony := android.PathForPhony(ctx, "dump-oat-boot-"+arch.String())
442 rule = android.NewRuleBuilder()
443 rule.Command().
444 Implicit(output).
445 ImplicitOutput(phony).
446 Text("echo").FlagWithArg("Output in ", output.String())
447 rule.Build(pctx, ctx, "phony-dump-oat-boot-"+arch.String(), "dump oat boot "+arch.String())
448
449 allPhonies = append(allPhonies, phony)
450 }
451
452 phony := android.PathForPhony(ctx, "dump-oat-boot")
453 ctx.Build(pctx, android.BuildParams{
454 Rule: android.Phony,
455 Output: phony,
456 Inputs: allPhonies,
457 Description: "dump-oat-boot",
458 })
459
460}
461
Colin Cross44df5812019-02-15 23:06:46 -0800462// Export paths for default boot image to Make
463func (d *dexpreoptBootJars) MakeVars(ctx android.MakeVarsContext) {
464 image := d.defaultBootImage
465 if image != nil {
Colin Cross44df5812019-02-15 23:06:46 -0800466 ctx.Strict("DEXPREOPT_IMAGE_PROFILE_BUILT_INSTALLED", image.profileInstalls.String())
Colin Cross44df5812019-02-15 23:06:46 -0800467 ctx.Strict("DEXPREOPT_BOOTCLASSPATH_DEX_FILES", strings.Join(image.dexPaths.Strings(), " "))
468 ctx.Strict("DEXPREOPT_BOOTCLASSPATH_DEX_LOCATIONS", strings.Join(image.dexLocations, " "))
Colin Crossdf8eebe2019-04-09 15:29:41 -0700469 ctx.Strict("DEXPREOPT_IMAGE_ZIP_"+image.name, image.zip.String())
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000470
471 var imageNames []string
472 for _, current := range append(d.otherImages, image) {
473 imageNames = append(imageNames, current.name)
Colin Cross91268c62019-04-11 14:07:04 -0700474 var arches []android.ArchType
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000475 for arch, _ := range current.images {
Colin Cross91268c62019-04-11 14:07:04 -0700476 arches = append(arches, arch)
477 }
478
479 sort.Slice(arches, func(i, j int) bool { return arches[i].String() < arches[j].String() })
480
481 for _, arch := range arches {
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000482 ctx.Strict("DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_"+current.name+"_"+arch.String(), current.vdexInstalls[arch].String())
483 ctx.Strict("DEXPREOPT_IMAGE_"+current.name+"_"+arch.String(), current.images[arch].String())
484 ctx.Strict("DEXPREOPT_IMAGE_BUILT_INSTALLED_"+current.name+"_"+arch.String(), current.installs[arch].String())
485 ctx.Strict("DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_"+current.name+"_"+arch.String(), current.unstrippedInstalls[arch].String())
Colin Crossdf8eebe2019-04-09 15:29:41 -0700486 if current.zip != nil {
487 }
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000488 }
489 }
490 ctx.Strict("DEXPREOPT_IMAGE_NAMES", strings.Join(imageNames, " "))
Colin Cross800fe132019-02-11 14:21:24 -0800491 }
Colin Cross800fe132019-02-11 14:21:24 -0800492}