Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 1 | // 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 | |
| 15 | package java |
| 16 | |
| 17 | import ( |
| 18 | "path/filepath" |
| 19 | "strings" |
| 20 | |
| 21 | "android/soong/android" |
| 22 | "android/soong/dexpreopt" |
| 23 | |
| 24 | "github.com/google/blueprint/pathtools" |
| 25 | "github.com/google/blueprint/proptools" |
| 26 | ) |
| 27 | |
| 28 | func init() { |
| 29 | android.RegisterSingletonType("dex_bootjars", dexpreoptBootJarsFactory) |
| 30 | } |
| 31 | |
| 32 | // The image "location" is a symbolic path that with multiarchitecture |
| 33 | // support doesn't really exist on the device. Typically it is |
| 34 | // /system/framework/boot.art and should be the same for all supported |
| 35 | // architectures on the device. The concrete architecture specific |
| 36 | // content actually ends up in a "filename" that contains an |
| 37 | // architecture specific directory name such as arm, arm64, mips, |
| 38 | // mips64, x86, x86_64. |
| 39 | // |
| 40 | // Here are some example values for an x86_64 / x86 configuration: |
| 41 | // |
| 42 | // bootImages["x86_64"] = "out/soong/generic_x86_64/dex_bootjars/system/framework/x86_64/boot.art" |
| 43 | // dexpreopt.PathToLocation(bootImages["x86_64"], "x86_64") = "out/soong/generic_x86_64/dex_bootjars/system/framework/boot.art" |
| 44 | // |
| 45 | // bootImages["x86"] = "out/soong/generic_x86_64/dex_bootjars/system/framework/x86/boot.art" |
| 46 | // dexpreopt.PathToLocation(bootImages["x86"])= "out/soong/generic_x86_64/dex_bootjars/system/framework/boot.art" |
| 47 | // |
| 48 | // The location is passed as an argument to the ART tools like dex2oat instead of the real path. The ART tools |
| 49 | // will then reconstruct the real path, so the rules must have a dependency on the real path. |
| 50 | |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 51 | type bootImageConfig struct { |
| 52 | name string |
| 53 | modules []string |
| 54 | dexLocations []string |
| 55 | dexPaths android.WritablePaths |
| 56 | dir android.OutputPath |
| 57 | symbolsDir android.OutputPath |
| 58 | images map[android.ArchType]android.OutputPath |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 59 | } |
| 60 | |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 61 | type bootImage struct { |
| 62 | bootImageConfig |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 63 | |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 64 | installs map[android.ArchType]android.RuleBuilderInstalls |
| 65 | vdexInstalls map[android.ArchType]android.RuleBuilderInstalls |
| 66 | unstrippedInstalls map[android.ArchType]android.RuleBuilderInstalls |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 67 | |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 68 | profileInstalls android.RuleBuilderInstalls |
| 69 | } |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 70 | |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 71 | func newBootImage(ctx android.PathContext, config bootImageConfig) *bootImage { |
| 72 | image := &bootImage{ |
| 73 | bootImageConfig: defaultBootImageConfig(ctx), |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 74 | |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 75 | installs: make(map[android.ArchType]android.RuleBuilderInstalls), |
| 76 | vdexInstalls: make(map[android.ArchType]android.RuleBuilderInstalls), |
| 77 | unstrippedInstalls: make(map[android.ArchType]android.RuleBuilderInstalls), |
| 78 | } |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 79 | |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 80 | return image |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | func concat(lists ...[]string) []string { |
| 84 | var size int |
| 85 | for _, l := range lists { |
| 86 | size += len(l) |
| 87 | } |
| 88 | ret := make([]string, 0, size) |
| 89 | for _, l := range lists { |
| 90 | ret = append(ret, l...) |
| 91 | } |
| 92 | return ret |
| 93 | } |
| 94 | |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 95 | func dexpreoptBootJarsFactory() android.Singleton { |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 96 | return &dexpreoptBootJars{} |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | func skipDexpreoptBootJars(ctx android.PathContext) bool { |
| 100 | if ctx.Config().UnbundledBuild() { |
| 101 | return true |
| 102 | } |
| 103 | |
| 104 | if len(ctx.Config().Targets[android.Android]) == 0 { |
| 105 | // Host-only build |
| 106 | return true |
| 107 | } |
| 108 | |
| 109 | return false |
| 110 | } |
| 111 | |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 112 | type dexpreoptBootJars struct { |
| 113 | defaultBootImage *bootImage |
| 114 | } |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 115 | |
| 116 | // dexpreoptBoot singleton rules |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 117 | func (d *dexpreoptBootJars) GenerateBuildActions(ctx android.SingletonContext) { |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 118 | if skipDexpreoptBootJars(ctx) { |
| 119 | return |
| 120 | } |
| 121 | |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 122 | global := dexpreoptGlobalConfig(ctx) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 123 | |
| 124 | // Skip recompiling the boot image for the second sanitization phase. We'll get separate paths |
| 125 | // and invalidate first-stage artifacts which are crucial to SANITIZE_LITE builds. |
| 126 | // Note: this is technically incorrect. Compiled code contains stack checks which may depend |
| 127 | // on ASAN settings. |
| 128 | if len(ctx.Config().SanitizeDevice()) == 1 && |
| 129 | ctx.Config().SanitizeDevice()[0] == "address" && |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 130 | global.SanitizeLite { |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 131 | return |
| 132 | } |
| 133 | |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 134 | d.defaultBootImage = buildBootImage(ctx, defaultBootImageConfig(ctx)) |
| 135 | } |
| 136 | |
| 137 | // buildBootImage takes a bootImageConfig, creates rules to build it, and returns a *bootImage. |
| 138 | func buildBootImage(ctx android.SingletonContext, config bootImageConfig) *bootImage { |
| 139 | global := dexpreoptGlobalConfig(ctx) |
| 140 | |
| 141 | image := newBootImage(ctx, config) |
| 142 | |
| 143 | bootDexJars := make(android.Paths, len(image.modules)) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 144 | |
| 145 | ctx.VisitAllModules(func(module android.Module) { |
| 146 | // Collect dex jar paths for the modules listed above. |
| 147 | if j, ok := module.(Dependency); ok { |
| 148 | name := ctx.ModuleName(module) |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 149 | if i := android.IndexList(name, image.modules); i != -1 { |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 150 | bootDexJars[i] = j.DexJar() |
| 151 | } |
| 152 | } |
| 153 | }) |
| 154 | |
| 155 | var missingDeps []string |
| 156 | // Ensure all modules were converted to paths |
| 157 | for i := range bootDexJars { |
| 158 | if bootDexJars[i] == nil { |
| 159 | if ctx.Config().AllowMissingDependencies() { |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 160 | missingDeps = append(missingDeps, image.modules[i]) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 161 | bootDexJars[i] = android.PathForOutput(ctx, "missing") |
| 162 | } else { |
| 163 | ctx.Errorf("failed to find dex jar path for module %q", |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 164 | image.modules[i]) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 165 | } |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | // The path to bootclasspath dex files needs to be known at module GenerateAndroidBuildAction time, before |
| 170 | // the bootclasspath modules have been compiled. Copy the dex jars there so the module rules that have |
| 171 | // already been set up can find them. |
| 172 | for i := range bootDexJars { |
| 173 | ctx.Build(pctx, android.BuildParams{ |
| 174 | Rule: android.Cp, |
| 175 | Input: bootDexJars[i], |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 176 | Output: image.dexPaths[i], |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 177 | }) |
| 178 | } |
| 179 | |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 180 | profile := bootImageProfileRule(ctx, image, missingDeps) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 181 | |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 182 | if !global.DisablePreopt { |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 183 | targets := ctx.Config().Targets[android.Android] |
| 184 | if ctx.Config().SecondArchIsTranslated() { |
| 185 | targets = targets[:1] |
| 186 | } |
| 187 | |
| 188 | for _, target := range targets { |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 189 | buildBootImageRuleForArch(ctx, image, target.Arch.ArchType, profile, missingDeps) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 190 | } |
| 191 | } |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 192 | |
| 193 | return image |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 194 | } |
| 195 | |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 196 | func buildBootImageRuleForArch(ctx android.SingletonContext, image *bootImage, |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 197 | arch android.ArchType, profile android.Path, missingDeps []string) { |
| 198 | |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 199 | global := dexpreoptGlobalConfig(ctx) |
| 200 | |
| 201 | symbolsDir := image.symbolsDir.Join(ctx, "system/framework", arch.String()) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 202 | symbolsFile := symbolsDir.Join(ctx, "boot.oat") |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 203 | outputDir := image.dir.Join(ctx, "system/framework", arch.String()) |
| 204 | outputPath := image.images[arch] |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 205 | oatLocation := pathtools.ReplaceExtension(dexpreopt.PathToLocation(outputPath, arch), "oat") |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 206 | |
| 207 | rule := android.NewRuleBuilder() |
| 208 | rule.MissingDeps(missingDeps) |
| 209 | |
| 210 | rule.Command().Text("mkdir").Flag("-p").Flag(symbolsDir.String()) |
| 211 | rule.Command().Text("rm").Flag("-f"). |
| 212 | Flag(symbolsDir.Join(ctx, "*.art").String()). |
| 213 | Flag(symbolsDir.Join(ctx, "*.oat").String()). |
| 214 | Flag(symbolsDir.Join(ctx, "*.invocation").String()) |
| 215 | rule.Command().Text("rm").Flag("-f"). |
| 216 | Flag(outputDir.Join(ctx, "*.art").String()). |
| 217 | Flag(outputDir.Join(ctx, "*.oat").String()). |
| 218 | Flag(outputDir.Join(ctx, "*.invocation").String()) |
| 219 | |
| 220 | cmd := rule.Command() |
| 221 | |
| 222 | extraFlags := ctx.Config().Getenv("ART_BOOT_IMAGE_EXTRA_ARGS") |
| 223 | if extraFlags == "" { |
| 224 | // Use ANDROID_LOG_TAGS to suppress most logging by default... |
| 225 | cmd.Text(`ANDROID_LOG_TAGS="*:e"`) |
| 226 | } else { |
| 227 | // ...unless the boot image is generated specifically for testing, then allow all logging. |
| 228 | cmd.Text(`ANDROID_LOG_TAGS="*:v"`) |
| 229 | } |
| 230 | |
| 231 | invocationPath := outputPath.ReplaceExtension(ctx, "invocation") |
| 232 | |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 233 | cmd.Tool(global.Tools.Dex2oat). |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 234 | Flag("--avoid-storing-invocation"). |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 235 | FlagWithOutput("--write-invocation-to=", invocationPath).ImplicitOutput(invocationPath). |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 236 | Flag("--runtime-arg").FlagWithArg("-Xms", global.Dex2oatImageXms). |
| 237 | Flag("--runtime-arg").FlagWithArg("-Xmx", global.Dex2oatImageXmx) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 238 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 239 | if profile != nil { |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 240 | cmd.FlagWithArg("--compiler-filter=", "speed-profile") |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 241 | cmd.FlagWithInput("--profile-file=", profile) |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 242 | } else if global.PreloadedClasses.Valid() { |
| 243 | cmd.FlagWithInput("--image-classes=", global.PreloadedClasses.Path()) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 244 | } |
| 245 | |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 246 | if global.DirtyImageObjects.Valid() { |
| 247 | cmd.FlagWithInput("--dirty-image-objects=", global.DirtyImageObjects.Path()) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | cmd. |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 251 | FlagForEachInput("--dex-file=", image.dexPaths.Paths()). |
| 252 | FlagForEachArg("--dex-location=", image.dexLocations). |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 253 | Flag("--generate-debug-info"). |
| 254 | Flag("--generate-build-id"). |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 255 | FlagWithOutput("--oat-symbols=", symbolsFile). |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 256 | Flag("--strip"). |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 257 | FlagWithOutput("--oat-file=", outputPath.ReplaceExtension(ctx, "oat")). |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 258 | FlagWithArg("--oat-location=", oatLocation). |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 259 | FlagWithOutput("--image=", outputPath). |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 260 | FlagWithArg("--base=", ctx.Config().LibartImgDeviceBaseAddress()). |
| 261 | FlagWithArg("--instruction-set=", arch.String()). |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 262 | FlagWithArg("--instruction-set-variant=", global.CpuVariant[arch]). |
| 263 | FlagWithArg("--instruction-set-features=", global.InstructionSetFeatures[arch]). |
| 264 | FlagWithArg("--android-root=", global.EmptyDirectory). |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 265 | FlagWithArg("--no-inline-from=", "core-oj.jar"). |
| 266 | Flag("--abort-on-hard-verifier-error") |
| 267 | |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 268 | if global.BootFlags != "" { |
| 269 | cmd.Flag(global.BootFlags) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | if extraFlags != "" { |
| 273 | cmd.Flag(extraFlags) |
| 274 | } |
| 275 | |
| 276 | cmd.Textf(`|| ( echo %s ; false )`, proptools.ShellEscape([]string{failureMessage})[0]) |
| 277 | |
| 278 | installDir := filepath.Join("/system/framework", arch.String()) |
| 279 | vdexInstallDir := filepath.Join("/system/framework") |
| 280 | |
| 281 | var extraFiles android.WritablePaths |
| 282 | var vdexInstalls android.RuleBuilderInstalls |
| 283 | var unstrippedInstalls android.RuleBuilderInstalls |
| 284 | |
| 285 | // dex preopt on the bootclasspath produces multiple files. The first dex file |
| 286 | // is converted into to boot.art (to match the legacy assumption that boot.art |
| 287 | // exists), and the rest are converted to boot-<name>.art. |
| 288 | // In addition, each .art file has an associated .oat and .vdex file, and an |
| 289 | // unstripped .oat file |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 290 | for i, m := range image.modules { |
| 291 | name := image.name |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 292 | if i != 0 { |
| 293 | name += "-" + m |
| 294 | } |
| 295 | |
| 296 | art := outputDir.Join(ctx, name+".art") |
| 297 | oat := outputDir.Join(ctx, name+".oat") |
| 298 | vdex := outputDir.Join(ctx, name+".vdex") |
| 299 | unstrippedOat := symbolsDir.Join(ctx, name+".oat") |
| 300 | |
| 301 | extraFiles = append(extraFiles, art, oat, vdex, unstrippedOat) |
| 302 | |
| 303 | // Install the .oat and .art files. |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 304 | rule.Install(art, filepath.Join(installDir, art.Base())) |
| 305 | rule.Install(oat, filepath.Join(installDir, oat.Base())) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 306 | |
| 307 | // The vdex files are identical between architectures, install them to a shared location. The Make rules will |
| 308 | // only use the install rules for one architecture, and will create symlinks into the architecture-specific |
| 309 | // directories. |
| 310 | vdexInstalls = append(vdexInstalls, |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 311 | android.RuleBuilderInstall{vdex, filepath.Join(vdexInstallDir, vdex.Base())}) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 312 | |
| 313 | // Install the unstripped oat files. The Make rules will put these in $(TARGET_OUT_UNSTRIPPED) |
| 314 | unstrippedInstalls = append(unstrippedInstalls, |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 315 | android.RuleBuilderInstall{unstrippedOat, filepath.Join(installDir, unstrippedOat.Base())}) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 316 | } |
| 317 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 318 | cmd.ImplicitOutputs(extraFiles) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 319 | |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 320 | rule.Build(pctx, ctx, image.name+"JarsDexpreopt_"+arch.String(), "dexpreopt "+image.name+" jars "+arch.String()) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 321 | |
| 322 | // save output and installed files for makevars |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 323 | image.installs[arch] = rule.Installs() |
| 324 | image.vdexInstalls[arch] = vdexInstalls |
| 325 | image.unstrippedInstalls[arch] = unstrippedInstalls |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | const failureMessage = `ERROR: Dex2oat failed to compile a boot image. |
| 329 | It is likely that the boot classpath is inconsistent. |
| 330 | Rebuild with ART_BOOT_IMAGE_EXTRA_ARGS="--runtime-arg -verbose:verifier" to see verification errors.` |
| 331 | |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 332 | func bootImageProfileRule(ctx android.SingletonContext, image *bootImage, missingDeps []string) android.WritablePath { |
| 333 | global := dexpreoptGlobalConfig(ctx) |
| 334 | |
| 335 | if !global.UseProfileForBootImage || ctx.Config().IsPdkBuild() || ctx.Config().UnbundledBuild() { |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 336 | return nil |
| 337 | } |
| 338 | |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 339 | tools := global.Tools |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 340 | |
| 341 | rule := android.NewRuleBuilder() |
| 342 | rule.MissingDeps(missingDeps) |
| 343 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 344 | var bootImageProfile android.Path |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 345 | if len(global.BootImageProfiles) > 1 { |
| 346 | combinedBootImageProfile := image.dir.Join(ctx, "boot-image-profile.txt") |
| 347 | rule.Command().Text("cat").Inputs(global.BootImageProfiles).Text(">").Output(combinedBootImageProfile) |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 348 | bootImageProfile = combinedBootImageProfile |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 349 | } else if len(global.BootImageProfiles) == 1 { |
| 350 | bootImageProfile = global.BootImageProfiles[0] |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 351 | } else { |
| 352 | // If not set, use the default. Some branches like master-art-host don't have frameworks/base, so manually |
| 353 | // handle the case that the default is missing. Those branches won't attempt to build the profile rule, |
| 354 | // and if they do they'll get a missing deps error. |
| 355 | defaultProfile := "frameworks/base/config/boot-image-profile.txt" |
| 356 | path := android.ExistentPathForSource(ctx, defaultProfile) |
| 357 | if path.Valid() { |
| 358 | bootImageProfile = path.Path() |
| 359 | } else { |
| 360 | missingDeps = append(missingDeps, defaultProfile) |
| 361 | bootImageProfile = android.PathForOutput(ctx, "missing") |
| 362 | } |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 363 | } |
| 364 | |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 365 | profile := image.dir.Join(ctx, "boot.prof") |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 366 | |
| 367 | rule.Command(). |
| 368 | Text(`ANDROID_LOG_TAGS="*:e"`). |
| 369 | Tool(tools.Profman). |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 370 | FlagWithInput("--create-profile-from=", bootImageProfile). |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 371 | FlagForEachInput("--apk=", image.dexPaths.Paths()). |
| 372 | FlagForEachArg("--dex-location=", image.dexLocations). |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 373 | FlagWithOutput("--reference-profile-file=", profile) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 374 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 375 | rule.Install(profile, "/system/etc/boot-image.prof") |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 376 | |
| 377 | rule.Build(pctx, ctx, "bootJarsProfile", "profile boot jars") |
| 378 | |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 379 | image.profileInstalls = rule.Installs() |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 380 | |
| 381 | return profile |
| 382 | } |
| 383 | |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 384 | // Export paths for default boot image to Make |
| 385 | func (d *dexpreoptBootJars) MakeVars(ctx android.MakeVarsContext) { |
| 386 | image := d.defaultBootImage |
| 387 | if image != nil { |
| 388 | for arch, _ := range image.images { |
| 389 | ctx.Strict("DEXPREOPT_IMAGE_"+arch.String(), image.images[arch].String()) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 390 | |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame^] | 391 | ctx.Strict("DEXPREOPT_IMAGE_BUILT_INSTALLED_"+arch.String(), image.installs[arch].String()) |
| 392 | ctx.Strict("DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_"+arch.String(), image.unstrippedInstalls[arch].String()) |
| 393 | ctx.Strict("DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_"+arch.String(), image.vdexInstalls[arch].String()) |
| 394 | } |
| 395 | |
| 396 | ctx.Strict("DEXPREOPT_IMAGE_PROFILE_BUILT_INSTALLED", image.profileInstalls.String()) |
| 397 | |
| 398 | ctx.Strict("DEXPREOPT_BOOTCLASSPATH_DEX_FILES", strings.Join(image.dexPaths.Strings(), " ")) |
| 399 | ctx.Strict("DEXPREOPT_BOOTCLASSPATH_DEX_LOCATIONS", strings.Join(image.dexLocations, " ")) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 400 | } |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 401 | } |