blob: f48428f46e4a594a84522c5a671f3ca2c6b5a1ce [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
Colin Crossc11e0c52019-05-08 15:18:22 -070059 targets []android.Target
Colin Cross44df5812019-02-15 23:06:46 -080060 images map[android.ArchType]android.OutputPath
Colin Crossdf8eebe2019-04-09 15:29:41 -070061 zip android.WritablePath
Colin Cross800fe132019-02-11 14:21:24 -080062}
63
Colin Cross44df5812019-02-15 23:06:46 -080064type bootImage struct {
65 bootImageConfig
Colin Cross800fe132019-02-11 14:21:24 -080066
Colin Cross44df5812019-02-15 23:06:46 -080067 installs map[android.ArchType]android.RuleBuilderInstalls
68 vdexInstalls map[android.ArchType]android.RuleBuilderInstalls
69 unstrippedInstalls map[android.ArchType]android.RuleBuilderInstalls
Colin Cross800fe132019-02-11 14:21:24 -080070
Colin Cross44df5812019-02-15 23:06:46 -080071 profileInstalls android.RuleBuilderInstalls
72}
Colin Cross800fe132019-02-11 14:21:24 -080073
Colin Cross44df5812019-02-15 23:06:46 -080074func newBootImage(ctx android.PathContext, config bootImageConfig) *bootImage {
75 image := &bootImage{
Nicolas Geoffray72892f12019-02-22 15:34:40 +000076 bootImageConfig: config,
Colin Cross800fe132019-02-11 14:21:24 -080077
Colin Cross44df5812019-02-15 23:06:46 -080078 installs: make(map[android.ArchType]android.RuleBuilderInstalls),
79 vdexInstalls: make(map[android.ArchType]android.RuleBuilderInstalls),
80 unstrippedInstalls: make(map[android.ArchType]android.RuleBuilderInstalls),
81 }
Colin Cross800fe132019-02-11 14:21:24 -080082
Colin Cross44df5812019-02-15 23:06:46 -080083 return image
Colin Cross800fe132019-02-11 14:21:24 -080084}
85
86func concat(lists ...[]string) []string {
87 var size int
88 for _, l := range lists {
89 size += len(l)
90 }
91 ret := make([]string, 0, size)
92 for _, l := range lists {
93 ret = append(ret, l...)
94 }
95 return ret
96}
97
Colin Cross800fe132019-02-11 14:21:24 -080098func dexpreoptBootJarsFactory() android.Singleton {
Colin Cross44df5812019-02-15 23:06:46 -080099 return &dexpreoptBootJars{}
Colin Cross800fe132019-02-11 14:21:24 -0800100}
101
102func skipDexpreoptBootJars(ctx android.PathContext) bool {
103 if ctx.Config().UnbundledBuild() {
104 return true
105 }
106
107 if len(ctx.Config().Targets[android.Android]) == 0 {
108 // Host-only build
109 return true
110 }
111
112 return false
113}
114
Colin Cross44df5812019-02-15 23:06:46 -0800115type dexpreoptBootJars struct {
116 defaultBootImage *bootImage
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000117 otherImages []*bootImage
Colin Cross44df5812019-02-15 23:06:46 -0800118}
Colin Cross800fe132019-02-11 14:21:24 -0800119
120// dexpreoptBoot singleton rules
Colin Cross44df5812019-02-15 23:06:46 -0800121func (d *dexpreoptBootJars) GenerateBuildActions(ctx android.SingletonContext) {
Colin Cross800fe132019-02-11 14:21:24 -0800122 if skipDexpreoptBootJars(ctx) {
123 return
124 }
125
Colin Cross44df5812019-02-15 23:06:46 -0800126 global := dexpreoptGlobalConfig(ctx)
Colin Cross800fe132019-02-11 14:21:24 -0800127
128 // Skip recompiling the boot image for the second sanitization phase. We'll get separate paths
129 // and invalidate first-stage artifacts which are crucial to SANITIZE_LITE builds.
130 // Note: this is technically incorrect. Compiled code contains stack checks which may depend
131 // on ASAN settings.
132 if len(ctx.Config().SanitizeDevice()) == 1 &&
133 ctx.Config().SanitizeDevice()[0] == "address" &&
Colin Cross44df5812019-02-15 23:06:46 -0800134 global.SanitizeLite {
Colin Cross800fe132019-02-11 14:21:24 -0800135 return
136 }
137
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000138 // Always create the default boot image first, to get a unique profile rule for all images.
Colin Cross44df5812019-02-15 23:06:46 -0800139 d.defaultBootImage = buildBootImage(ctx, defaultBootImageConfig(ctx))
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000140 if global.GenerateApexImage {
141 d.otherImages = append(d.otherImages, buildBootImage(ctx, apexBootImageConfig(ctx)))
142 }
Colin Crossc9a4c362019-02-26 21:13:48 -0800143
144 dumpOatRules(ctx, d.defaultBootImage)
Colin Cross44df5812019-02-15 23:06:46 -0800145}
146
147// buildBootImage takes a bootImageConfig, creates rules to build it, and returns a *bootImage.
148func buildBootImage(ctx android.SingletonContext, config bootImageConfig) *bootImage {
149 global := dexpreoptGlobalConfig(ctx)
150
151 image := newBootImage(ctx, config)
152
153 bootDexJars := make(android.Paths, len(image.modules))
Colin Cross800fe132019-02-11 14:21:24 -0800154
155 ctx.VisitAllModules(func(module android.Module) {
156 // Collect dex jar paths for the modules listed above.
Colin Cross42be7612019-02-21 18:12:14 -0800157 if j, ok := module.(interface{ DexJar() android.Path }); ok {
Colin Cross800fe132019-02-11 14:21:24 -0800158 name := ctx.ModuleName(module)
Colin Cross44df5812019-02-15 23:06:46 -0800159 if i := android.IndexList(name, image.modules); i != -1 {
Colin Cross800fe132019-02-11 14:21:24 -0800160 bootDexJars[i] = j.DexJar()
161 }
162 }
163 })
164
165 var missingDeps []string
166 // Ensure all modules were converted to paths
167 for i := range bootDexJars {
168 if bootDexJars[i] == nil {
169 if ctx.Config().AllowMissingDependencies() {
Colin Cross44df5812019-02-15 23:06:46 -0800170 missingDeps = append(missingDeps, image.modules[i])
Colin Cross800fe132019-02-11 14:21:24 -0800171 bootDexJars[i] = android.PathForOutput(ctx, "missing")
172 } else {
173 ctx.Errorf("failed to find dex jar path for module %q",
Colin Cross44df5812019-02-15 23:06:46 -0800174 image.modules[i])
Colin Cross800fe132019-02-11 14:21:24 -0800175 }
176 }
177 }
178
179 // The path to bootclasspath dex files needs to be known at module GenerateAndroidBuildAction time, before
180 // the bootclasspath modules have been compiled. Copy the dex jars there so the module rules that have
181 // already been set up can find them.
182 for i := range bootDexJars {
183 ctx.Build(pctx, android.BuildParams{
184 Rule: android.Cp,
185 Input: bootDexJars[i],
Colin Cross44df5812019-02-15 23:06:46 -0800186 Output: image.dexPaths[i],
Colin Cross800fe132019-02-11 14:21:24 -0800187 })
188 }
189
Colin Cross44df5812019-02-15 23:06:46 -0800190 profile := bootImageProfileRule(ctx, image, missingDeps)
Colin Cross800fe132019-02-11 14:21:24 -0800191
Colin Crossdf8eebe2019-04-09 15:29:41 -0700192 var allFiles android.Paths
193
Colin Cross44df5812019-02-15 23:06:46 -0800194 if !global.DisablePreopt {
Colin Crossc11e0c52019-05-08 15:18:22 -0700195 for _, target := range image.targets {
196 files := buildBootImageRuleForArch(ctx, image, target.Arch.ArchType, profile, missingDeps)
197 allFiles = append(allFiles, files.Paths()...)
Colin Cross800fe132019-02-11 14:21:24 -0800198 }
199 }
Colin Cross44df5812019-02-15 23:06:46 -0800200
Colin Crossdf8eebe2019-04-09 15:29:41 -0700201 if image.zip != nil {
202 rule := android.NewRuleBuilder()
203 rule.Command().
204 Tool(ctx.Config().HostToolPath(ctx, "soong_zip")).
205 FlagWithOutput("-o ", image.zip).
206 FlagWithArg("-C ", image.dir.String()).
207 FlagWithInputList("-f ", allFiles, " -f ")
208
209 rule.Build(pctx, ctx, "zip_"+image.name, "zip "+image.name+" image")
210 }
211
Colin Cross44df5812019-02-15 23:06:46 -0800212 return image
Colin Cross800fe132019-02-11 14:21:24 -0800213}
214
Colin Cross44df5812019-02-15 23:06:46 -0800215func buildBootImageRuleForArch(ctx android.SingletonContext, image *bootImage,
Colin Crossdf8eebe2019-04-09 15:29:41 -0700216 arch android.ArchType, profile android.Path, missingDeps []string) android.WritablePaths {
Colin Cross800fe132019-02-11 14:21:24 -0800217
Colin Cross44df5812019-02-15 23:06:46 -0800218 global := dexpreoptGlobalConfig(ctx)
219
220 symbolsDir := image.symbolsDir.Join(ctx, "system/framework", arch.String())
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000221 symbolsFile := symbolsDir.Join(ctx, image.name+".oat")
Colin Cross44df5812019-02-15 23:06:46 -0800222 outputDir := image.dir.Join(ctx, "system/framework", arch.String())
223 outputPath := image.images[arch]
Colin Cross69f59a32019-02-15 10:39:37 -0800224 oatLocation := pathtools.ReplaceExtension(dexpreopt.PathToLocation(outputPath, arch), "oat")
Colin Cross800fe132019-02-11 14:21:24 -0800225
226 rule := android.NewRuleBuilder()
227 rule.MissingDeps(missingDeps)
228
229 rule.Command().Text("mkdir").Flag("-p").Flag(symbolsDir.String())
230 rule.Command().Text("rm").Flag("-f").
231 Flag(symbolsDir.Join(ctx, "*.art").String()).
232 Flag(symbolsDir.Join(ctx, "*.oat").String()).
233 Flag(symbolsDir.Join(ctx, "*.invocation").String())
234 rule.Command().Text("rm").Flag("-f").
235 Flag(outputDir.Join(ctx, "*.art").String()).
236 Flag(outputDir.Join(ctx, "*.oat").String()).
237 Flag(outputDir.Join(ctx, "*.invocation").String())
238
239 cmd := rule.Command()
240
241 extraFlags := ctx.Config().Getenv("ART_BOOT_IMAGE_EXTRA_ARGS")
242 if extraFlags == "" {
243 // Use ANDROID_LOG_TAGS to suppress most logging by default...
244 cmd.Text(`ANDROID_LOG_TAGS="*:e"`)
245 } else {
246 // ...unless the boot image is generated specifically for testing, then allow all logging.
247 cmd.Text(`ANDROID_LOG_TAGS="*:v"`)
248 }
249
250 invocationPath := outputPath.ReplaceExtension(ctx, "invocation")
251
Colin Cross44df5812019-02-15 23:06:46 -0800252 cmd.Tool(global.Tools.Dex2oat).
Colin Cross800fe132019-02-11 14:21:24 -0800253 Flag("--avoid-storing-invocation").
Colin Cross69f59a32019-02-15 10:39:37 -0800254 FlagWithOutput("--write-invocation-to=", invocationPath).ImplicitOutput(invocationPath).
Colin Cross44df5812019-02-15 23:06:46 -0800255 Flag("--runtime-arg").FlagWithArg("-Xms", global.Dex2oatImageXms).
256 Flag("--runtime-arg").FlagWithArg("-Xmx", global.Dex2oatImageXmx)
Colin Cross800fe132019-02-11 14:21:24 -0800257
Colin Cross69f59a32019-02-15 10:39:37 -0800258 if profile != nil {
Colin Cross800fe132019-02-11 14:21:24 -0800259 cmd.FlagWithArg("--compiler-filter=", "speed-profile")
Colin Cross69f59a32019-02-15 10:39:37 -0800260 cmd.FlagWithInput("--profile-file=", profile)
Colin Cross44df5812019-02-15 23:06:46 -0800261 } else if global.PreloadedClasses.Valid() {
262 cmd.FlagWithInput("--image-classes=", global.PreloadedClasses.Path())
Colin Cross800fe132019-02-11 14:21:24 -0800263 }
264
Colin Cross44df5812019-02-15 23:06:46 -0800265 if global.DirtyImageObjects.Valid() {
266 cmd.FlagWithInput("--dirty-image-objects=", global.DirtyImageObjects.Path())
Colin Cross800fe132019-02-11 14:21:24 -0800267 }
268
269 cmd.
Colin Cross44df5812019-02-15 23:06:46 -0800270 FlagForEachInput("--dex-file=", image.dexPaths.Paths()).
271 FlagForEachArg("--dex-location=", image.dexLocations).
Colin Cross800fe132019-02-11 14:21:24 -0800272 Flag("--generate-debug-info").
273 Flag("--generate-build-id").
Colin Cross69f59a32019-02-15 10:39:37 -0800274 FlagWithOutput("--oat-symbols=", symbolsFile).
Colin Cross800fe132019-02-11 14:21:24 -0800275 Flag("--strip").
Colin Cross69f59a32019-02-15 10:39:37 -0800276 FlagWithOutput("--oat-file=", outputPath.ReplaceExtension(ctx, "oat")).
Colin Cross800fe132019-02-11 14:21:24 -0800277 FlagWithArg("--oat-location=", oatLocation).
Colin Cross69f59a32019-02-15 10:39:37 -0800278 FlagWithOutput("--image=", outputPath).
Colin Cross800fe132019-02-11 14:21:24 -0800279 FlagWithArg("--base=", ctx.Config().LibartImgDeviceBaseAddress()).
280 FlagWithArg("--instruction-set=", arch.String()).
Colin Cross44df5812019-02-15 23:06:46 -0800281 FlagWithArg("--instruction-set-variant=", global.CpuVariant[arch]).
282 FlagWithArg("--instruction-set-features=", global.InstructionSetFeatures[arch]).
283 FlagWithArg("--android-root=", global.EmptyDirectory).
Colin Cross800fe132019-02-11 14:21:24 -0800284 FlagWithArg("--no-inline-from=", "core-oj.jar").
285 Flag("--abort-on-hard-verifier-error")
286
Colin Cross44df5812019-02-15 23:06:46 -0800287 if global.BootFlags != "" {
288 cmd.Flag(global.BootFlags)
Colin Cross800fe132019-02-11 14:21:24 -0800289 }
290
291 if extraFlags != "" {
292 cmd.Flag(extraFlags)
293 }
294
Colin Cross0b9f31f2019-02-28 11:00:01 -0800295 cmd.Textf(`|| ( echo %s ; false )`, proptools.ShellEscape(failureMessage))
Colin Cross800fe132019-02-11 14:21:24 -0800296
297 installDir := filepath.Join("/system/framework", arch.String())
298 vdexInstallDir := filepath.Join("/system/framework")
299
300 var extraFiles android.WritablePaths
301 var vdexInstalls android.RuleBuilderInstalls
302 var unstrippedInstalls android.RuleBuilderInstalls
303
Colin Crossdf8eebe2019-04-09 15:29:41 -0700304 var zipFiles android.WritablePaths
305
Colin Cross800fe132019-02-11 14:21:24 -0800306 // dex preopt on the bootclasspath produces multiple files. The first dex file
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000307 // is converted into to 'name'.art (to match the legacy assumption that 'name'.art
308 // exists), and the rest are converted to 'name'-<jar>.art.
Colin Cross800fe132019-02-11 14:21:24 -0800309 // In addition, each .art file has an associated .oat and .vdex file, and an
310 // unstripped .oat file
Colin Cross44df5812019-02-15 23:06:46 -0800311 for i, m := range image.modules {
312 name := image.name
Colin Cross800fe132019-02-11 14:21:24 -0800313 if i != 0 {
314 name += "-" + m
315 }
316
317 art := outputDir.Join(ctx, name+".art")
318 oat := outputDir.Join(ctx, name+".oat")
319 vdex := outputDir.Join(ctx, name+".vdex")
320 unstrippedOat := symbolsDir.Join(ctx, name+".oat")
321
322 extraFiles = append(extraFiles, art, oat, vdex, unstrippedOat)
323
Colin Crossdf8eebe2019-04-09 15:29:41 -0700324 zipFiles = append(zipFiles, art, oat, vdex)
325
Colin Cross800fe132019-02-11 14:21:24 -0800326 // Install the .oat and .art files.
Colin Cross69f59a32019-02-15 10:39:37 -0800327 rule.Install(art, filepath.Join(installDir, art.Base()))
328 rule.Install(oat, filepath.Join(installDir, oat.Base()))
Colin Cross800fe132019-02-11 14:21:24 -0800329
330 // The vdex files are identical between architectures, install them to a shared location. The Make rules will
331 // only use the install rules for one architecture, and will create symlinks into the architecture-specific
332 // directories.
333 vdexInstalls = append(vdexInstalls,
Colin Cross69f59a32019-02-15 10:39:37 -0800334 android.RuleBuilderInstall{vdex, filepath.Join(vdexInstallDir, vdex.Base())})
Colin Cross800fe132019-02-11 14:21:24 -0800335
336 // Install the unstripped oat files. The Make rules will put these in $(TARGET_OUT_UNSTRIPPED)
337 unstrippedInstalls = append(unstrippedInstalls,
Colin Cross69f59a32019-02-15 10:39:37 -0800338 android.RuleBuilderInstall{unstrippedOat, filepath.Join(installDir, unstrippedOat.Base())})
Colin Cross800fe132019-02-11 14:21:24 -0800339 }
340
Colin Cross69f59a32019-02-15 10:39:37 -0800341 cmd.ImplicitOutputs(extraFiles)
Colin Cross800fe132019-02-11 14:21:24 -0800342
Colin Cross44df5812019-02-15 23:06:46 -0800343 rule.Build(pctx, ctx, image.name+"JarsDexpreopt_"+arch.String(), "dexpreopt "+image.name+" jars "+arch.String())
Colin Cross800fe132019-02-11 14:21:24 -0800344
345 // save output and installed files for makevars
Colin Cross44df5812019-02-15 23:06:46 -0800346 image.installs[arch] = rule.Installs()
347 image.vdexInstalls[arch] = vdexInstalls
348 image.unstrippedInstalls[arch] = unstrippedInstalls
Colin Crossdf8eebe2019-04-09 15:29:41 -0700349
350 return zipFiles
Colin Cross800fe132019-02-11 14:21:24 -0800351}
352
353const failureMessage = `ERROR: Dex2oat failed to compile a boot image.
354It is likely that the boot classpath is inconsistent.
355Rebuild with ART_BOOT_IMAGE_EXTRA_ARGS="--runtime-arg -verbose:verifier" to see verification errors.`
356
Colin Cross44df5812019-02-15 23:06:46 -0800357func bootImageProfileRule(ctx android.SingletonContext, image *bootImage, missingDeps []string) android.WritablePath {
Nicolas Geoffray27c7cc62019-02-24 16:04:52 +0000358 global := dexpreoptGlobalConfig(ctx)
359
360 if !global.UseProfileForBootImage || ctx.Config().IsPdkBuild() || ctx.Config().UnbundledBuild() {
361 return nil
362 }
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000363 return ctx.Config().Once(bootImageProfileRuleKey, func() interface{} {
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000364 tools := global.Tools
Colin Cross800fe132019-02-11 14:21:24 -0800365
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000366 rule := android.NewRuleBuilder()
367 rule.MissingDeps(missingDeps)
Colin Cross800fe132019-02-11 14:21:24 -0800368
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000369 var bootImageProfile android.Path
370 if len(global.BootImageProfiles) > 1 {
371 combinedBootImageProfile := image.dir.Join(ctx, "boot-image-profile.txt")
372 rule.Command().Text("cat").Inputs(global.BootImageProfiles).Text(">").Output(combinedBootImageProfile)
373 bootImageProfile = combinedBootImageProfile
374 } else if len(global.BootImageProfiles) == 1 {
375 bootImageProfile = global.BootImageProfiles[0]
376 } else {
377 // If not set, use the default. Some branches like master-art-host don't have frameworks/base, so manually
378 // handle the case that the default is missing. Those branches won't attempt to build the profile rule,
379 // and if they do they'll get a missing deps error.
380 defaultProfile := "frameworks/base/config/boot-image-profile.txt"
381 path := android.ExistentPathForSource(ctx, defaultProfile)
382 if path.Valid() {
383 bootImageProfile = path.Path()
384 } else {
385 missingDeps = append(missingDeps, defaultProfile)
386 bootImageProfile = android.PathForOutput(ctx, "missing")
387 }
388 }
Colin Cross800fe132019-02-11 14:21:24 -0800389
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000390 profile := image.dir.Join(ctx, "boot.prof")
Colin Cross800fe132019-02-11 14:21:24 -0800391
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000392 rule.Command().
393 Text(`ANDROID_LOG_TAGS="*:e"`).
394 Tool(tools.Profman).
395 FlagWithInput("--create-profile-from=", bootImageProfile).
396 FlagForEachInput("--apk=", image.dexPaths.Paths()).
397 FlagForEachArg("--dex-location=", image.dexLocations).
398 FlagWithOutput("--reference-profile-file=", profile)
Colin Cross800fe132019-02-11 14:21:24 -0800399
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000400 rule.Install(profile, "/system/etc/boot-image.prof")
401
402 rule.Build(pctx, ctx, "bootJarsProfile", "profile boot jars")
403
404 image.profileInstalls = rule.Installs()
405
406 return profile
407 }).(android.WritablePath)
Colin Cross800fe132019-02-11 14:21:24 -0800408}
409
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000410var bootImageProfileRuleKey = android.NewOnceKey("bootImageProfileRule")
411
Colin Crossc9a4c362019-02-26 21:13:48 -0800412func dumpOatRules(ctx android.SingletonContext, image *bootImage) {
413 var archs []android.ArchType
414 for arch := range image.images {
415 archs = append(archs, arch)
416 }
417 sort.Slice(archs, func(i, j int) bool { return archs[i].String() < archs[j].String() })
418
419 var allPhonies android.Paths
420 for _, arch := range archs {
421 // Create a rule to call oatdump.
422 output := android.PathForOutput(ctx, "boot."+arch.String()+".oatdump.txt")
423 rule := android.NewRuleBuilder()
424 rule.Command().
425 // TODO: for now, use the debug version for better error reporting
426 Tool(ctx.Config().HostToolPath(ctx, "oatdumpd")).
427 FlagWithInputList("--runtime-arg -Xbootclasspath:", image.dexPaths.Paths(), ":").
428 FlagWithList("--runtime-arg -Xbootclasspath-locations:", image.dexLocations, ":").
429 FlagWithArg("--image=", dexpreopt.PathToLocation(image.images[arch], arch)).Implicit(image.images[arch]).
430 FlagWithOutput("--output=", output).
431 FlagWithArg("--instruction-set=", arch.String())
432 rule.Build(pctx, ctx, "dump-oat-boot-"+arch.String(), "dump oat boot "+arch.String())
433
434 // Create a phony rule that depends on the output file and prints the path.
435 phony := android.PathForPhony(ctx, "dump-oat-boot-"+arch.String())
436 rule = android.NewRuleBuilder()
437 rule.Command().
438 Implicit(output).
439 ImplicitOutput(phony).
440 Text("echo").FlagWithArg("Output in ", output.String())
441 rule.Build(pctx, ctx, "phony-dump-oat-boot-"+arch.String(), "dump oat boot "+arch.String())
442
443 allPhonies = append(allPhonies, phony)
444 }
445
446 phony := android.PathForPhony(ctx, "dump-oat-boot")
447 ctx.Build(pctx, android.BuildParams{
448 Rule: android.Phony,
449 Output: phony,
450 Inputs: allPhonies,
451 Description: "dump-oat-boot",
452 })
453
454}
455
Colin Cross44df5812019-02-15 23:06:46 -0800456// Export paths for default boot image to Make
457func (d *dexpreoptBootJars) MakeVars(ctx android.MakeVarsContext) {
458 image := d.defaultBootImage
459 if image != nil {
Colin Cross44df5812019-02-15 23:06:46 -0800460 ctx.Strict("DEXPREOPT_IMAGE_PROFILE_BUILT_INSTALLED", image.profileInstalls.String())
Colin Cross44df5812019-02-15 23:06:46 -0800461 ctx.Strict("DEXPREOPT_BOOTCLASSPATH_DEX_FILES", strings.Join(image.dexPaths.Strings(), " "))
462 ctx.Strict("DEXPREOPT_BOOTCLASSPATH_DEX_LOCATIONS", strings.Join(image.dexLocations, " "))
Colin Crossdf8eebe2019-04-09 15:29:41 -0700463 ctx.Strict("DEXPREOPT_IMAGE_ZIP_"+image.name, image.zip.String())
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000464
465 var imageNames []string
466 for _, current := range append(d.otherImages, image) {
467 imageNames = append(imageNames, current.name)
Colin Cross91268c62019-04-11 14:07:04 -0700468 var arches []android.ArchType
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000469 for arch, _ := range current.images {
Colin Cross91268c62019-04-11 14:07:04 -0700470 arches = append(arches, arch)
471 }
472
473 sort.Slice(arches, func(i, j int) bool { return arches[i].String() < arches[j].String() })
474
475 for _, arch := range arches {
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000476 ctx.Strict("DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_"+current.name+"_"+arch.String(), current.vdexInstalls[arch].String())
477 ctx.Strict("DEXPREOPT_IMAGE_"+current.name+"_"+arch.String(), current.images[arch].String())
478 ctx.Strict("DEXPREOPT_IMAGE_BUILT_INSTALLED_"+current.name+"_"+arch.String(), current.installs[arch].String())
479 ctx.Strict("DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_"+current.name+"_"+arch.String(), current.unstrippedInstalls[arch].String())
Colin Crossdf8eebe2019-04-09 15:29:41 -0700480 if current.zip != nil {
481 }
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000482 }
483 }
484 ctx.Strict("DEXPREOPT_IMAGE_NAMES", strings.Join(imageNames, " "))
Colin Cross800fe132019-02-11 14:21:24 -0800485 }
Colin Cross800fe132019-02-11 14:21:24 -0800486}