blob: 2a1a901b706e7b4206638e02b8427518908dbe2c [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 Cross2d00f0d2019-05-09 21:50:00 -0700118
119 dexpreoptConfigForMake android.WritablePath
Colin Cross44df5812019-02-15 23:06:46 -0800120}
Colin Cross800fe132019-02-11 14:21:24 -0800121
122// dexpreoptBoot singleton rules
Colin Cross44df5812019-02-15 23:06:46 -0800123func (d *dexpreoptBootJars) GenerateBuildActions(ctx android.SingletonContext) {
Colin Cross800fe132019-02-11 14:21:24 -0800124 if skipDexpreoptBootJars(ctx) {
125 return
126 }
127
Colin Cross2d00f0d2019-05-09 21:50:00 -0700128 d.dexpreoptConfigForMake = android.PathForOutput(ctx, ctx.Config().DeviceName(), "dexpreopt.config")
129 writeGlobalConfigForMake(ctx, d.dexpreoptConfigForMake)
130
Colin Cross44df5812019-02-15 23:06:46 -0800131 global := dexpreoptGlobalConfig(ctx)
Colin Cross800fe132019-02-11 14:21:24 -0800132
133 // Skip recompiling the boot image for the second sanitization phase. We'll get separate paths
134 // and invalidate first-stage artifacts which are crucial to SANITIZE_LITE builds.
135 // Note: this is technically incorrect. Compiled code contains stack checks which may depend
136 // on ASAN settings.
137 if len(ctx.Config().SanitizeDevice()) == 1 &&
138 ctx.Config().SanitizeDevice()[0] == "address" &&
Colin Cross44df5812019-02-15 23:06:46 -0800139 global.SanitizeLite {
Colin Cross800fe132019-02-11 14:21:24 -0800140 return
141 }
142
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000143 // Always create the default boot image first, to get a unique profile rule for all images.
Colin Cross44df5812019-02-15 23:06:46 -0800144 d.defaultBootImage = buildBootImage(ctx, defaultBootImageConfig(ctx))
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000145 if global.GenerateApexImage {
146 d.otherImages = append(d.otherImages, buildBootImage(ctx, apexBootImageConfig(ctx)))
147 }
Colin Crossc9a4c362019-02-26 21:13:48 -0800148
149 dumpOatRules(ctx, d.defaultBootImage)
Colin Cross44df5812019-02-15 23:06:46 -0800150}
151
152// buildBootImage takes a bootImageConfig, creates rules to build it, and returns a *bootImage.
153func buildBootImage(ctx android.SingletonContext, config bootImageConfig) *bootImage {
154 global := dexpreoptGlobalConfig(ctx)
155
156 image := newBootImage(ctx, config)
157
158 bootDexJars := make(android.Paths, len(image.modules))
Colin Cross800fe132019-02-11 14:21:24 -0800159
160 ctx.VisitAllModules(func(module android.Module) {
161 // Collect dex jar paths for the modules listed above.
Colin Cross42be7612019-02-21 18:12:14 -0800162 if j, ok := module.(interface{ DexJar() android.Path }); ok {
Colin Cross800fe132019-02-11 14:21:24 -0800163 name := ctx.ModuleName(module)
Colin Cross44df5812019-02-15 23:06:46 -0800164 if i := android.IndexList(name, image.modules); i != -1 {
Colin Cross800fe132019-02-11 14:21:24 -0800165 bootDexJars[i] = j.DexJar()
166 }
167 }
168 })
169
170 var missingDeps []string
171 // Ensure all modules were converted to paths
172 for i := range bootDexJars {
173 if bootDexJars[i] == nil {
174 if ctx.Config().AllowMissingDependencies() {
Colin Cross44df5812019-02-15 23:06:46 -0800175 missingDeps = append(missingDeps, image.modules[i])
Colin Cross800fe132019-02-11 14:21:24 -0800176 bootDexJars[i] = android.PathForOutput(ctx, "missing")
177 } else {
178 ctx.Errorf("failed to find dex jar path for module %q",
Colin Cross44df5812019-02-15 23:06:46 -0800179 image.modules[i])
Colin Cross800fe132019-02-11 14:21:24 -0800180 }
181 }
182 }
183
184 // The path to bootclasspath dex files needs to be known at module GenerateAndroidBuildAction time, before
185 // the bootclasspath modules have been compiled. Copy the dex jars there so the module rules that have
186 // already been set up can find them.
187 for i := range bootDexJars {
188 ctx.Build(pctx, android.BuildParams{
189 Rule: android.Cp,
190 Input: bootDexJars[i],
Colin Cross44df5812019-02-15 23:06:46 -0800191 Output: image.dexPaths[i],
Colin Cross800fe132019-02-11 14:21:24 -0800192 })
193 }
194
Colin Cross44df5812019-02-15 23:06:46 -0800195 profile := bootImageProfileRule(ctx, image, missingDeps)
Colin Cross800fe132019-02-11 14:21:24 -0800196
Colin Crossdf8eebe2019-04-09 15:29:41 -0700197 var allFiles android.Paths
198
Colin Cross44df5812019-02-15 23:06:46 -0800199 if !global.DisablePreopt {
Colin Crossc11e0c52019-05-08 15:18:22 -0700200 for _, target := range image.targets {
201 files := buildBootImageRuleForArch(ctx, image, target.Arch.ArchType, profile, missingDeps)
202 allFiles = append(allFiles, files.Paths()...)
Colin Cross800fe132019-02-11 14:21:24 -0800203 }
204 }
Colin Cross44df5812019-02-15 23:06:46 -0800205
Colin Crossdf8eebe2019-04-09 15:29:41 -0700206 if image.zip != nil {
207 rule := android.NewRuleBuilder()
208 rule.Command().
209 Tool(ctx.Config().HostToolPath(ctx, "soong_zip")).
210 FlagWithOutput("-o ", image.zip).
211 FlagWithArg("-C ", image.dir.String()).
212 FlagWithInputList("-f ", allFiles, " -f ")
213
214 rule.Build(pctx, ctx, "zip_"+image.name, "zip "+image.name+" image")
215 }
216
Colin Cross44df5812019-02-15 23:06:46 -0800217 return image
Colin Cross800fe132019-02-11 14:21:24 -0800218}
219
Colin Cross44df5812019-02-15 23:06:46 -0800220func buildBootImageRuleForArch(ctx android.SingletonContext, image *bootImage,
Colin Crossdf8eebe2019-04-09 15:29:41 -0700221 arch android.ArchType, profile android.Path, missingDeps []string) android.WritablePaths {
Colin Cross800fe132019-02-11 14:21:24 -0800222
Colin Cross44df5812019-02-15 23:06:46 -0800223 global := dexpreoptGlobalConfig(ctx)
224
225 symbolsDir := image.symbolsDir.Join(ctx, "system/framework", arch.String())
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000226 symbolsFile := symbolsDir.Join(ctx, image.name+".oat")
Colin Cross44df5812019-02-15 23:06:46 -0800227 outputDir := image.dir.Join(ctx, "system/framework", arch.String())
228 outputPath := image.images[arch]
Colin Cross69f59a32019-02-15 10:39:37 -0800229 oatLocation := pathtools.ReplaceExtension(dexpreopt.PathToLocation(outputPath, arch), "oat")
Colin Cross800fe132019-02-11 14:21:24 -0800230
231 rule := android.NewRuleBuilder()
232 rule.MissingDeps(missingDeps)
233
234 rule.Command().Text("mkdir").Flag("-p").Flag(symbolsDir.String())
235 rule.Command().Text("rm").Flag("-f").
236 Flag(symbolsDir.Join(ctx, "*.art").String()).
237 Flag(symbolsDir.Join(ctx, "*.oat").String()).
238 Flag(symbolsDir.Join(ctx, "*.invocation").String())
239 rule.Command().Text("rm").Flag("-f").
240 Flag(outputDir.Join(ctx, "*.art").String()).
241 Flag(outputDir.Join(ctx, "*.oat").String()).
242 Flag(outputDir.Join(ctx, "*.invocation").String())
243
244 cmd := rule.Command()
245
246 extraFlags := ctx.Config().Getenv("ART_BOOT_IMAGE_EXTRA_ARGS")
247 if extraFlags == "" {
248 // Use ANDROID_LOG_TAGS to suppress most logging by default...
249 cmd.Text(`ANDROID_LOG_TAGS="*:e"`)
250 } else {
251 // ...unless the boot image is generated specifically for testing, then allow all logging.
252 cmd.Text(`ANDROID_LOG_TAGS="*:v"`)
253 }
254
255 invocationPath := outputPath.ReplaceExtension(ctx, "invocation")
256
Colin Cross44df5812019-02-15 23:06:46 -0800257 cmd.Tool(global.Tools.Dex2oat).
Colin Cross800fe132019-02-11 14:21:24 -0800258 Flag("--avoid-storing-invocation").
Colin Cross69f59a32019-02-15 10:39:37 -0800259 FlagWithOutput("--write-invocation-to=", invocationPath).ImplicitOutput(invocationPath).
Colin Cross44df5812019-02-15 23:06:46 -0800260 Flag("--runtime-arg").FlagWithArg("-Xms", global.Dex2oatImageXms).
261 Flag("--runtime-arg").FlagWithArg("-Xmx", global.Dex2oatImageXmx)
Colin Cross800fe132019-02-11 14:21:24 -0800262
Colin Cross69f59a32019-02-15 10:39:37 -0800263 if profile != nil {
Colin Cross800fe132019-02-11 14:21:24 -0800264 cmd.FlagWithArg("--compiler-filter=", "speed-profile")
Colin Cross69f59a32019-02-15 10:39:37 -0800265 cmd.FlagWithInput("--profile-file=", profile)
Colin Cross44df5812019-02-15 23:06:46 -0800266 } else if global.PreloadedClasses.Valid() {
267 cmd.FlagWithInput("--image-classes=", global.PreloadedClasses.Path())
Colin Cross800fe132019-02-11 14:21:24 -0800268 }
269
Colin Cross44df5812019-02-15 23:06:46 -0800270 if global.DirtyImageObjects.Valid() {
271 cmd.FlagWithInput("--dirty-image-objects=", global.DirtyImageObjects.Path())
Colin Cross800fe132019-02-11 14:21:24 -0800272 }
273
274 cmd.
Colin Cross44df5812019-02-15 23:06:46 -0800275 FlagForEachInput("--dex-file=", image.dexPaths.Paths()).
276 FlagForEachArg("--dex-location=", image.dexLocations).
Colin Cross800fe132019-02-11 14:21:24 -0800277 Flag("--generate-debug-info").
278 Flag("--generate-build-id").
Colin Cross69f59a32019-02-15 10:39:37 -0800279 FlagWithOutput("--oat-symbols=", symbolsFile).
Colin Cross800fe132019-02-11 14:21:24 -0800280 Flag("--strip").
Colin Cross69f59a32019-02-15 10:39:37 -0800281 FlagWithOutput("--oat-file=", outputPath.ReplaceExtension(ctx, "oat")).
Colin Cross800fe132019-02-11 14:21:24 -0800282 FlagWithArg("--oat-location=", oatLocation).
Colin Cross69f59a32019-02-15 10:39:37 -0800283 FlagWithOutput("--image=", outputPath).
Colin Cross800fe132019-02-11 14:21:24 -0800284 FlagWithArg("--base=", ctx.Config().LibartImgDeviceBaseAddress()).
285 FlagWithArg("--instruction-set=", arch.String()).
Colin Cross44df5812019-02-15 23:06:46 -0800286 FlagWithArg("--instruction-set-variant=", global.CpuVariant[arch]).
287 FlagWithArg("--instruction-set-features=", global.InstructionSetFeatures[arch]).
288 FlagWithArg("--android-root=", global.EmptyDirectory).
Colin Cross800fe132019-02-11 14:21:24 -0800289 FlagWithArg("--no-inline-from=", "core-oj.jar").
290 Flag("--abort-on-hard-verifier-error")
291
Colin Cross44df5812019-02-15 23:06:46 -0800292 if global.BootFlags != "" {
293 cmd.Flag(global.BootFlags)
Colin Cross800fe132019-02-11 14:21:24 -0800294 }
295
296 if extraFlags != "" {
297 cmd.Flag(extraFlags)
298 }
299
Colin Cross0b9f31f2019-02-28 11:00:01 -0800300 cmd.Textf(`|| ( echo %s ; false )`, proptools.ShellEscape(failureMessage))
Colin Cross800fe132019-02-11 14:21:24 -0800301
302 installDir := filepath.Join("/system/framework", arch.String())
303 vdexInstallDir := filepath.Join("/system/framework")
304
305 var extraFiles android.WritablePaths
306 var vdexInstalls android.RuleBuilderInstalls
307 var unstrippedInstalls android.RuleBuilderInstalls
308
Colin Crossdf8eebe2019-04-09 15:29:41 -0700309 var zipFiles android.WritablePaths
310
Colin Cross800fe132019-02-11 14:21:24 -0800311 // dex preopt on the bootclasspath produces multiple files. The first dex file
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000312 // is converted into to 'name'.art (to match the legacy assumption that 'name'.art
313 // exists), and the rest are converted to 'name'-<jar>.art.
Colin Cross800fe132019-02-11 14:21:24 -0800314 // In addition, each .art file has an associated .oat and .vdex file, and an
315 // unstripped .oat file
Colin Cross44df5812019-02-15 23:06:46 -0800316 for i, m := range image.modules {
317 name := image.name
Colin Cross800fe132019-02-11 14:21:24 -0800318 if i != 0 {
319 name += "-" + m
320 }
321
322 art := outputDir.Join(ctx, name+".art")
323 oat := outputDir.Join(ctx, name+".oat")
324 vdex := outputDir.Join(ctx, name+".vdex")
325 unstrippedOat := symbolsDir.Join(ctx, name+".oat")
326
327 extraFiles = append(extraFiles, art, oat, vdex, unstrippedOat)
328
Colin Crossdf8eebe2019-04-09 15:29:41 -0700329 zipFiles = append(zipFiles, art, oat, vdex)
330
Colin Cross800fe132019-02-11 14:21:24 -0800331 // Install the .oat and .art files.
Colin Cross69f59a32019-02-15 10:39:37 -0800332 rule.Install(art, filepath.Join(installDir, art.Base()))
333 rule.Install(oat, filepath.Join(installDir, oat.Base()))
Colin Cross800fe132019-02-11 14:21:24 -0800334
335 // The vdex files are identical between architectures, install them to a shared location. The Make rules will
336 // only use the install rules for one architecture, and will create symlinks into the architecture-specific
337 // directories.
338 vdexInstalls = append(vdexInstalls,
Colin Cross69f59a32019-02-15 10:39:37 -0800339 android.RuleBuilderInstall{vdex, filepath.Join(vdexInstallDir, vdex.Base())})
Colin Cross800fe132019-02-11 14:21:24 -0800340
341 // Install the unstripped oat files. The Make rules will put these in $(TARGET_OUT_UNSTRIPPED)
342 unstrippedInstalls = append(unstrippedInstalls,
Colin Cross69f59a32019-02-15 10:39:37 -0800343 android.RuleBuilderInstall{unstrippedOat, filepath.Join(installDir, unstrippedOat.Base())})
Colin Cross800fe132019-02-11 14:21:24 -0800344 }
345
Colin Cross69f59a32019-02-15 10:39:37 -0800346 cmd.ImplicitOutputs(extraFiles)
Colin Cross800fe132019-02-11 14:21:24 -0800347
Colin Cross44df5812019-02-15 23:06:46 -0800348 rule.Build(pctx, ctx, image.name+"JarsDexpreopt_"+arch.String(), "dexpreopt "+image.name+" jars "+arch.String())
Colin Cross800fe132019-02-11 14:21:24 -0800349
350 // save output and installed files for makevars
Colin Cross44df5812019-02-15 23:06:46 -0800351 image.installs[arch] = rule.Installs()
352 image.vdexInstalls[arch] = vdexInstalls
353 image.unstrippedInstalls[arch] = unstrippedInstalls
Colin Crossdf8eebe2019-04-09 15:29:41 -0700354
355 return zipFiles
Colin Cross800fe132019-02-11 14:21:24 -0800356}
357
358const failureMessage = `ERROR: Dex2oat failed to compile a boot image.
359It is likely that the boot classpath is inconsistent.
360Rebuild with ART_BOOT_IMAGE_EXTRA_ARGS="--runtime-arg -verbose:verifier" to see verification errors.`
361
Colin Cross44df5812019-02-15 23:06:46 -0800362func bootImageProfileRule(ctx android.SingletonContext, image *bootImage, missingDeps []string) android.WritablePath {
Nicolas Geoffray27c7cc62019-02-24 16:04:52 +0000363 global := dexpreoptGlobalConfig(ctx)
364
365 if !global.UseProfileForBootImage || ctx.Config().IsPdkBuild() || ctx.Config().UnbundledBuild() {
366 return nil
367 }
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000368 return ctx.Config().Once(bootImageProfileRuleKey, func() interface{} {
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000369 tools := global.Tools
Colin Cross800fe132019-02-11 14:21:24 -0800370
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000371 rule := android.NewRuleBuilder()
372 rule.MissingDeps(missingDeps)
Colin Cross800fe132019-02-11 14:21:24 -0800373
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000374 var bootImageProfile android.Path
375 if len(global.BootImageProfiles) > 1 {
376 combinedBootImageProfile := image.dir.Join(ctx, "boot-image-profile.txt")
377 rule.Command().Text("cat").Inputs(global.BootImageProfiles).Text(">").Output(combinedBootImageProfile)
378 bootImageProfile = combinedBootImageProfile
379 } else if len(global.BootImageProfiles) == 1 {
380 bootImageProfile = global.BootImageProfiles[0]
381 } else {
382 // If not set, use the default. Some branches like master-art-host don't have frameworks/base, so manually
383 // handle the case that the default is missing. Those branches won't attempt to build the profile rule,
384 // and if they do they'll get a missing deps error.
385 defaultProfile := "frameworks/base/config/boot-image-profile.txt"
386 path := android.ExistentPathForSource(ctx, defaultProfile)
387 if path.Valid() {
388 bootImageProfile = path.Path()
389 } else {
390 missingDeps = append(missingDeps, defaultProfile)
391 bootImageProfile = android.PathForOutput(ctx, "missing")
392 }
393 }
Colin Cross800fe132019-02-11 14:21:24 -0800394
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000395 profile := image.dir.Join(ctx, "boot.prof")
Colin Cross800fe132019-02-11 14:21:24 -0800396
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000397 rule.Command().
398 Text(`ANDROID_LOG_TAGS="*:e"`).
399 Tool(tools.Profman).
400 FlagWithInput("--create-profile-from=", bootImageProfile).
401 FlagForEachInput("--apk=", image.dexPaths.Paths()).
402 FlagForEachArg("--dex-location=", image.dexLocations).
403 FlagWithOutput("--reference-profile-file=", profile)
Colin Cross800fe132019-02-11 14:21:24 -0800404
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000405 rule.Install(profile, "/system/etc/boot-image.prof")
406
407 rule.Build(pctx, ctx, "bootJarsProfile", "profile boot jars")
408
409 image.profileInstalls = rule.Installs()
410
411 return profile
412 }).(android.WritablePath)
Colin Cross800fe132019-02-11 14:21:24 -0800413}
414
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000415var bootImageProfileRuleKey = android.NewOnceKey("bootImageProfileRule")
416
Colin Crossc9a4c362019-02-26 21:13:48 -0800417func dumpOatRules(ctx android.SingletonContext, image *bootImage) {
418 var archs []android.ArchType
419 for arch := range image.images {
420 archs = append(archs, arch)
421 }
422 sort.Slice(archs, func(i, j int) bool { return archs[i].String() < archs[j].String() })
423
424 var allPhonies android.Paths
425 for _, arch := range archs {
426 // Create a rule to call oatdump.
427 output := android.PathForOutput(ctx, "boot."+arch.String()+".oatdump.txt")
428 rule := android.NewRuleBuilder()
429 rule.Command().
430 // TODO: for now, use the debug version for better error reporting
431 Tool(ctx.Config().HostToolPath(ctx, "oatdumpd")).
432 FlagWithInputList("--runtime-arg -Xbootclasspath:", image.dexPaths.Paths(), ":").
433 FlagWithList("--runtime-arg -Xbootclasspath-locations:", image.dexLocations, ":").
434 FlagWithArg("--image=", dexpreopt.PathToLocation(image.images[arch], arch)).Implicit(image.images[arch]).
435 FlagWithOutput("--output=", output).
436 FlagWithArg("--instruction-set=", arch.String())
437 rule.Build(pctx, ctx, "dump-oat-boot-"+arch.String(), "dump oat boot "+arch.String())
438
439 // Create a phony rule that depends on the output file and prints the path.
440 phony := android.PathForPhony(ctx, "dump-oat-boot-"+arch.String())
441 rule = android.NewRuleBuilder()
442 rule.Command().
443 Implicit(output).
444 ImplicitOutput(phony).
445 Text("echo").FlagWithArg("Output in ", output.String())
446 rule.Build(pctx, ctx, "phony-dump-oat-boot-"+arch.String(), "dump oat boot "+arch.String())
447
448 allPhonies = append(allPhonies, phony)
449 }
450
451 phony := android.PathForPhony(ctx, "dump-oat-boot")
452 ctx.Build(pctx, android.BuildParams{
453 Rule: android.Phony,
454 Output: phony,
455 Inputs: allPhonies,
456 Description: "dump-oat-boot",
457 })
458
459}
460
Colin Cross2d00f0d2019-05-09 21:50:00 -0700461func writeGlobalConfigForMake(ctx android.SingletonContext, path android.WritablePath) {
462 data := dexpreoptGlobalConfigRaw(ctx).data
463
464 ctx.Build(pctx, android.BuildParams{
465 Rule: android.WriteFile,
466 Output: path,
467 Args: map[string]string{
468 "content": string(data),
469 },
470 })
471}
472
Colin Cross44df5812019-02-15 23:06:46 -0800473// Export paths for default boot image to Make
474func (d *dexpreoptBootJars) MakeVars(ctx android.MakeVarsContext) {
Colin Cross2d00f0d2019-05-09 21:50:00 -0700475 if d.dexpreoptConfigForMake != nil {
476 ctx.Strict("DEX_PREOPT_CONFIG_FOR_MAKE", d.dexpreoptConfigForMake.String())
477 }
478
Colin Cross44df5812019-02-15 23:06:46 -0800479 image := d.defaultBootImage
480 if image != nil {
Colin Cross44df5812019-02-15 23:06:46 -0800481 ctx.Strict("DEXPREOPT_IMAGE_PROFILE_BUILT_INSTALLED", image.profileInstalls.String())
Colin Cross44df5812019-02-15 23:06:46 -0800482 ctx.Strict("DEXPREOPT_BOOTCLASSPATH_DEX_FILES", strings.Join(image.dexPaths.Strings(), " "))
483 ctx.Strict("DEXPREOPT_BOOTCLASSPATH_DEX_LOCATIONS", strings.Join(image.dexLocations, " "))
Colin Crossdf8eebe2019-04-09 15:29:41 -0700484 ctx.Strict("DEXPREOPT_IMAGE_ZIP_"+image.name, image.zip.String())
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000485
486 var imageNames []string
487 for _, current := range append(d.otherImages, image) {
488 imageNames = append(imageNames, current.name)
Colin Cross91268c62019-04-11 14:07:04 -0700489 var arches []android.ArchType
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000490 for arch, _ := range current.images {
Colin Cross91268c62019-04-11 14:07:04 -0700491 arches = append(arches, arch)
492 }
493
494 sort.Slice(arches, func(i, j int) bool { return arches[i].String() < arches[j].String() })
495
496 for _, arch := range arches {
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000497 ctx.Strict("DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_"+current.name+"_"+arch.String(), current.vdexInstalls[arch].String())
498 ctx.Strict("DEXPREOPT_IMAGE_"+current.name+"_"+arch.String(), current.images[arch].String())
499 ctx.Strict("DEXPREOPT_IMAGE_BUILT_INSTALLED_"+current.name+"_"+arch.String(), current.installs[arch].String())
500 ctx.Strict("DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_"+current.name+"_"+arch.String(), current.unstrippedInstalls[arch].String())
Colin Crossdf8eebe2019-04-09 15:29:41 -0700501 if current.zip != nil {
502 }
Nicolas Geoffray72892f12019-02-22 15:34:40 +0000503 }
504 }
505 ctx.Strict("DEXPREOPT_IMAGE_NAMES", strings.Join(imageNames, " "))
Colin Cross800fe132019-02-11 14:21:24 -0800506 }
Colin Cross800fe132019-02-11 14:21:24 -0800507}