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 | |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 24 | "github.com/google/blueprint/proptools" |
| 25 | ) |
| 26 | |
| 27 | func init() { |
| 28 | android.RegisterSingletonType("dex_bootjars", dexpreoptBootJarsFactory) |
| 29 | } |
| 30 | |
David Srbecky | c177ebe | 2020-02-18 20:43:06 +0000 | [diff] [blame] | 31 | // Target-independent description of pre-compiled boot image. |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame] | 32 | type bootImageConfig struct { |
David Srbecky | 1aacc6c | 2020-03-26 11:10:45 +0000 | [diff] [blame] | 33 | // If this image is an extension, the image that it extends. |
| 34 | extends *bootImageConfig |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 35 | |
| 36 | // Image name (used in directory names and ninja rule names). |
| 37 | name string |
| 38 | |
| 39 | // Basename of the image: the resulting filenames are <stem>[-<jar>].{art,oat,vdex}. |
| 40 | stem string |
| 41 | |
| 42 | // Output directory for the image files. |
| 43 | dir android.OutputPath |
| 44 | |
| 45 | // Output directory for the image files with debug symbols. |
| 46 | symbolsDir android.OutputPath |
| 47 | |
| 48 | // Subdirectory where the image files are installed. |
| 49 | installSubdir string |
| 50 | |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 51 | // The names of jars that constitute this image. |
| 52 | modules []string |
| 53 | |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 54 | // File paths to jars. |
| 55 | dexPaths android.WritablePaths // for this image |
| 56 | dexPathsDeps android.WritablePaths // for the dependency images and in this image |
| 57 | |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 58 | // File path to a zip archive with all image files (or nil, if not needed). |
| 59 | zip android.WritablePath |
David Srbecky | c177ebe | 2020-02-18 20:43:06 +0000 | [diff] [blame] | 60 | |
| 61 | // Rules which should be used in make to install the outputs. |
| 62 | profileInstalls android.RuleBuilderInstalls |
| 63 | |
| 64 | // Target-dependent fields. |
| 65 | variants []*bootImageVariant |
| 66 | } |
| 67 | |
| 68 | // Target-dependent description of pre-compiled boot image. |
| 69 | type bootImageVariant struct { |
| 70 | *bootImageConfig |
| 71 | |
| 72 | // Target for which the image is generated. |
| 73 | target android.Target |
| 74 | |
David Srbecky | ab99498 | 2020-03-30 17:24:13 +0100 | [diff] [blame^] | 75 | // The "locations" of jars. |
| 76 | dexLocations []string // for this image |
| 77 | dexLocationsDeps []string // for the dependency images and in this image |
| 78 | |
David Srbecky | c177ebe | 2020-02-18 20:43:06 +0000 | [diff] [blame] | 79 | // Paths to image files. |
| 80 | images android.OutputPath // first image file |
| 81 | imagesDeps android.OutputPaths // all files |
| 82 | |
| 83 | // Only for extensions, paths to the primary boot images. |
| 84 | primaryImages android.OutputPath |
| 85 | |
| 86 | // Rules which should be used in make to install the outputs. |
| 87 | installs android.RuleBuilderInstalls |
| 88 | vdexInstalls android.RuleBuilderInstalls |
| 89 | unstrippedInstalls android.RuleBuilderInstalls |
| 90 | } |
| 91 | |
| 92 | func (image bootImageConfig) getVariant(target android.Target) *bootImageVariant { |
| 93 | for _, variant := range image.variants { |
| 94 | if variant.target.Os == target.Os && variant.target.Arch.ArchType == target.Arch.ArchType { |
| 95 | return variant |
| 96 | } |
| 97 | } |
| 98 | return nil |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 99 | } |
| 100 | |
David Srbecky | ab99498 | 2020-03-30 17:24:13 +0100 | [diff] [blame^] | 101 | // Return any (the first) variant which is for the device (as opposed to for the host) |
| 102 | func (image bootImageConfig) getAnyAndroidVariant() *bootImageVariant { |
| 103 | for _, variant := range image.variants { |
| 104 | if variant.target.Os == android.Android { |
| 105 | return variant |
| 106 | } |
| 107 | } |
| 108 | return nil |
| 109 | } |
| 110 | |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 111 | func (image bootImageConfig) moduleName(idx int) string { |
| 112 | // Dexpreopt on the boot class path produces multiple files. The first dex file |
| 113 | // is converted into 'name'.art (to match the legacy assumption that 'name'.art |
Dan Willemsen | 0f41678 | 2019-06-13 21:44:53 +0000 | [diff] [blame] | 114 | // exists), and the rest are converted to 'name'-<jar>.art. |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 115 | m := image.modules[idx] |
| 116 | name := image.stem |
David Srbecky | 1aacc6c | 2020-03-26 11:10:45 +0000 | [diff] [blame] | 117 | if idx != 0 || image.extends != nil { |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 118 | name += "-" + stemOf(m) |
| 119 | } |
| 120 | return name |
| 121 | } |
Dan Willemsen | 0f41678 | 2019-06-13 21:44:53 +0000 | [diff] [blame] | 122 | |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 123 | func (image bootImageConfig) firstModuleNameOrStem() string { |
| 124 | if len(image.modules) > 0 { |
| 125 | return image.moduleName(0) |
| 126 | } else { |
| 127 | return image.stem |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | func (image bootImageConfig) moduleFiles(ctx android.PathContext, dir android.OutputPath, exts ...string) android.OutputPaths { |
| 132 | ret := make(android.OutputPaths, 0, len(image.modules)*len(exts)) |
| 133 | for i := range image.modules { |
| 134 | name := image.moduleName(i) |
Dan Willemsen | 0f41678 | 2019-06-13 21:44:53 +0000 | [diff] [blame] | 135 | for _, ext := range exts { |
| 136 | ret = append(ret, dir.Join(ctx, name+ext)) |
| 137 | } |
| 138 | } |
Dan Willemsen | 0f41678 | 2019-06-13 21:44:53 +0000 | [diff] [blame] | 139 | return ret |
| 140 | } |
| 141 | |
David Srbecky | 1aacc6c | 2020-03-26 11:10:45 +0000 | [diff] [blame] | 142 | // The image "location" is a symbolic path that, with multiarchitecture support, doesn't really |
| 143 | // exist on the device. Typically it is /apex/com.android.art/javalib/boot.art and should be the |
| 144 | // same for all supported architectures on the device. The concrete architecture specific files |
| 145 | // actually end up in architecture-specific sub-directory such as arm, arm64, x86, or x86_64. |
| 146 | // |
| 147 | // For example a physical file |
| 148 | // "/apex/com.android.art/javalib/x86/boot.art" has "image location" |
| 149 | // "/apex/com.android.art/javalib/boot.art" (which is not an actual file). |
| 150 | // |
| 151 | // The location is passed as an argument to the ART tools like dex2oat instead of the real path. |
| 152 | // ART tools will then reconstruct the architecture-specific real path. |
| 153 | func (image *bootImageVariant) imageLocations() (imageLocations []string) { |
| 154 | if image.extends != nil { |
| 155 | imageLocations = image.extends.getVariant(image.target).imageLocations() |
| 156 | } |
| 157 | return append(imageLocations, dexpreopt.PathToLocation(image.images, image.target.Arch.ArchType)) |
| 158 | } |
| 159 | |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 160 | func concat(lists ...[]string) []string { |
| 161 | var size int |
| 162 | for _, l := range lists { |
| 163 | size += len(l) |
| 164 | } |
| 165 | ret := make([]string, 0, size) |
| 166 | for _, l := range lists { |
| 167 | ret = append(ret, l...) |
| 168 | } |
| 169 | return ret |
| 170 | } |
| 171 | |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 172 | func dexpreoptBootJarsFactory() android.Singleton { |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame] | 173 | return &dexpreoptBootJars{} |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | func skipDexpreoptBootJars(ctx android.PathContext) bool { |
Martin Stjernholm | 40f9f3c | 2020-01-20 18:12:23 +0000 | [diff] [blame] | 177 | if dexpreopt.GetGlobalConfig(ctx).DisablePreopt { |
Ulya Trafimovich | acb33e0 | 2019-11-01 17:57:29 +0000 | [diff] [blame] | 178 | return true |
| 179 | } |
| 180 | |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 181 | if ctx.Config().UnbundledBuild() { |
| 182 | return true |
| 183 | } |
| 184 | |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 185 | return false |
| 186 | } |
| 187 | |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame] | 188 | type dexpreoptBootJars struct { |
David Srbecky | c177ebe | 2020-02-18 20:43:06 +0000 | [diff] [blame] | 189 | defaultBootImage *bootImageConfig |
| 190 | otherImages []*bootImageConfig |
Colin Cross | 2d00f0d | 2019-05-09 21:50:00 -0700 | [diff] [blame] | 191 | |
| 192 | dexpreoptConfigForMake android.WritablePath |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame] | 193 | } |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 194 | |
Ulyana Trafimovich | de53441 | 2019-11-08 10:51:01 +0000 | [diff] [blame] | 195 | // Accessor function for the apex package. Returns nil if dexpreopt is disabled. |
Tim Joines | c1ef1bb | 2020-03-18 18:00:41 +0000 | [diff] [blame] | 196 | func DexpreoptedArtApexJars(ctx android.BuilderContext) map[android.ArchType]android.OutputPaths { |
Ulya Trafimovich | 4456188 | 2020-01-03 13:25:54 +0000 | [diff] [blame] | 197 | if skipDexpreoptBootJars(ctx) { |
Tim Joines | c1ef1bb | 2020-03-18 18:00:41 +0000 | [diff] [blame] | 198 | return nil |
Ulyana Trafimovich | de53441 | 2019-11-08 10:51:01 +0000 | [diff] [blame] | 199 | } |
Tim Joines | c1ef1bb | 2020-03-18 18:00:41 +0000 | [diff] [blame] | 200 | // Include dexpreopt files for the primary boot image. |
| 201 | files := map[android.ArchType]android.OutputPaths{} |
| 202 | for _, variant := range artBootImageConfig(ctx).variants { |
David Srbecky | 7f8dac1 | 2020-02-13 16:00:45 +0000 | [diff] [blame] | 203 | // We also generate boot images for host (for testing), but we don't need those in the apex. |
Tim Joines | c1ef1bb | 2020-03-18 18:00:41 +0000 | [diff] [blame] | 204 | if variant.target.Os == android.Android { |
| 205 | files[variant.target.Arch.ArchType] = variant.imagesDeps |
David Srbecky | 7f8dac1 | 2020-02-13 16:00:45 +0000 | [diff] [blame] | 206 | } |
David Srbecky | c177ebe | 2020-02-18 20:43:06 +0000 | [diff] [blame] | 207 | } |
Tim Joines | c1ef1bb | 2020-03-18 18:00:41 +0000 | [diff] [blame] | 208 | return files |
Ulyana Trafimovich | de53441 | 2019-11-08 10:51:01 +0000 | [diff] [blame] | 209 | } |
| 210 | |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 211 | // dexpreoptBoot singleton rules |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame] | 212 | func (d *dexpreoptBootJars) GenerateBuildActions(ctx android.SingletonContext) { |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 213 | if skipDexpreoptBootJars(ctx) { |
| 214 | return |
| 215 | } |
Martin Stjernholm | 6d41527 | 2020-01-31 17:10:36 +0000 | [diff] [blame] | 216 | if dexpreopt.GetCachedGlobalSoongConfig(ctx) == nil { |
| 217 | // No module has enabled dexpreopting, so we assume there will be no boot image to make. |
| 218 | return |
| 219 | } |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 220 | |
Colin Cross | 2d00f0d | 2019-05-09 21:50:00 -0700 | [diff] [blame] | 221 | d.dexpreoptConfigForMake = android.PathForOutput(ctx, ctx.Config().DeviceName(), "dexpreopt.config") |
| 222 | writeGlobalConfigForMake(ctx, d.dexpreoptConfigForMake) |
| 223 | |
Martin Stjernholm | 40f9f3c | 2020-01-20 18:12:23 +0000 | [diff] [blame] | 224 | global := dexpreopt.GetGlobalConfig(ctx) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 225 | |
| 226 | // Skip recompiling the boot image for the second sanitization phase. We'll get separate paths |
| 227 | // and invalidate first-stage artifacts which are crucial to SANITIZE_LITE builds. |
| 228 | // Note: this is technically incorrect. Compiled code contains stack checks which may depend |
| 229 | // on ASAN settings. |
| 230 | if len(ctx.Config().SanitizeDevice()) == 1 && |
| 231 | ctx.Config().SanitizeDevice()[0] == "address" && |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame] | 232 | global.SanitizeLite { |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 233 | return |
| 234 | } |
| 235 | |
Lingfeng Yang | 54191fa | 2019-12-19 16:40:09 +0000 | [diff] [blame] | 236 | // Always create the default boot image first, to get a unique profile rule for all images. |
| 237 | d.defaultBootImage = buildBootImage(ctx, defaultBootImageConfig(ctx)) |
Ulya Trafimovich | 4456188 | 2020-01-03 13:25:54 +0000 | [diff] [blame] | 238 | // Create boot image for the ART apex (build artifacts are accessed via the global boot image config). |
| 239 | d.otherImages = append(d.otherImages, buildBootImage(ctx, artBootImageConfig(ctx))) |
Colin Cross | c9a4c36 | 2019-02-26 21:13:48 -0800 | [diff] [blame] | 240 | |
| 241 | dumpOatRules(ctx, d.defaultBootImage) |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame] | 242 | } |
| 243 | |
David Srbecky | c177ebe | 2020-02-18 20:43:06 +0000 | [diff] [blame] | 244 | // buildBootImage takes a bootImageConfig, creates rules to build it, and returns the image. |
| 245 | func buildBootImage(ctx android.SingletonContext, image *bootImageConfig) *bootImageConfig { |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame] | 246 | bootDexJars := make(android.Paths, len(image.modules)) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 247 | ctx.VisitAllModules(func(module android.Module) { |
| 248 | // Collect dex jar paths for the modules listed above. |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 249 | if j, ok := module.(interface{ DexJar() android.Path }); ok { |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 250 | name := ctx.ModuleName(module) |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame] | 251 | if i := android.IndexList(name, image.modules); i != -1 { |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 252 | bootDexJars[i] = j.DexJar() |
| 253 | } |
| 254 | } |
| 255 | }) |
| 256 | |
| 257 | var missingDeps []string |
| 258 | // Ensure all modules were converted to paths |
| 259 | for i := range bootDexJars { |
| 260 | if bootDexJars[i] == nil { |
| 261 | if ctx.Config().AllowMissingDependencies() { |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame] | 262 | missingDeps = append(missingDeps, image.modules[i]) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 263 | bootDexJars[i] = android.PathForOutput(ctx, "missing") |
| 264 | } else { |
| 265 | ctx.Errorf("failed to find dex jar path for module %q", |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame] | 266 | image.modules[i]) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 267 | } |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | // The path to bootclasspath dex files needs to be known at module GenerateAndroidBuildAction time, before |
| 272 | // the bootclasspath modules have been compiled. Copy the dex jars there so the module rules that have |
| 273 | // already been set up can find them. |
| 274 | for i := range bootDexJars { |
| 275 | ctx.Build(pctx, android.BuildParams{ |
| 276 | Rule: android.Cp, |
| 277 | Input: bootDexJars[i], |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame] | 278 | Output: image.dexPaths[i], |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 279 | }) |
| 280 | } |
| 281 | |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame] | 282 | profile := bootImageProfileRule(ctx, image, missingDeps) |
Nicolas Geoffray | e710242 | 2019-07-24 13:19:29 +0100 | [diff] [blame] | 283 | bootFrameworkProfileRule(ctx, image, missingDeps) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 284 | |
Colin Cross | df8eebe | 2019-04-09 15:29:41 -0700 | [diff] [blame] | 285 | var allFiles android.Paths |
David Srbecky | c177ebe | 2020-02-18 20:43:06 +0000 | [diff] [blame] | 286 | for _, variant := range image.variants { |
| 287 | files := buildBootImageVariant(ctx, variant, profile, missingDeps) |
Ulyana Trafimovich | de53441 | 2019-11-08 10:51:01 +0000 | [diff] [blame] | 288 | allFiles = append(allFiles, files.Paths()...) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 289 | } |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame] | 290 | |
Colin Cross | df8eebe | 2019-04-09 15:29:41 -0700 | [diff] [blame] | 291 | if image.zip != nil { |
| 292 | rule := android.NewRuleBuilder() |
| 293 | rule.Command(). |
Colin Cross | ee94d6a | 2019-07-08 17:08:34 -0700 | [diff] [blame] | 294 | BuiltTool(ctx, "soong_zip"). |
Colin Cross | df8eebe | 2019-04-09 15:29:41 -0700 | [diff] [blame] | 295 | FlagWithOutput("-o ", image.zip). |
| 296 | FlagWithArg("-C ", image.dir.String()). |
| 297 | FlagWithInputList("-f ", allFiles, " -f ") |
| 298 | |
| 299 | rule.Build(pctx, ctx, "zip_"+image.name, "zip "+image.name+" image") |
| 300 | } |
| 301 | |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame] | 302 | return image |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 303 | } |
| 304 | |
David Srbecky | c177ebe | 2020-02-18 20:43:06 +0000 | [diff] [blame] | 305 | func buildBootImageVariant(ctx android.SingletonContext, image *bootImageVariant, |
| 306 | profile android.Path, missingDeps []string) android.WritablePaths { |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 307 | |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 308 | globalSoong := dexpreopt.GetCachedGlobalSoongConfig(ctx) |
Martin Stjernholm | 40f9f3c | 2020-01-20 18:12:23 +0000 | [diff] [blame] | 309 | global := dexpreopt.GetGlobalConfig(ctx) |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame] | 310 | |
David Srbecky | c177ebe | 2020-02-18 20:43:06 +0000 | [diff] [blame] | 311 | arch := image.target.Arch.ArchType |
David Srbecky | 7f8dac1 | 2020-02-13 16:00:45 +0000 | [diff] [blame] | 312 | os := image.target.Os.String() // We need to distinguish host-x86 and device-x86. |
| 313 | symbolsDir := image.symbolsDir.Join(ctx, os, image.installSubdir, arch.String()) |
Ulyana Trafimovich | de53441 | 2019-11-08 10:51:01 +0000 | [diff] [blame] | 314 | symbolsFile := symbolsDir.Join(ctx, image.stem+".oat") |
David Srbecky | 7f8dac1 | 2020-02-13 16:00:45 +0000 | [diff] [blame] | 315 | outputDir := image.dir.Join(ctx, os, image.installSubdir, arch.String()) |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 316 | outputPath := outputDir.Join(ctx, image.stem+".oat") |
| 317 | oatLocation := dexpreopt.PathToLocation(outputPath, arch) |
| 318 | imagePath := outputPath.ReplaceExtension(ctx, "art") |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 319 | |
| 320 | rule := android.NewRuleBuilder() |
| 321 | rule.MissingDeps(missingDeps) |
| 322 | |
| 323 | rule.Command().Text("mkdir").Flag("-p").Flag(symbolsDir.String()) |
| 324 | rule.Command().Text("rm").Flag("-f"). |
| 325 | Flag(symbolsDir.Join(ctx, "*.art").String()). |
| 326 | Flag(symbolsDir.Join(ctx, "*.oat").String()). |
| 327 | Flag(symbolsDir.Join(ctx, "*.invocation").String()) |
| 328 | rule.Command().Text("rm").Flag("-f"). |
| 329 | Flag(outputDir.Join(ctx, "*.art").String()). |
| 330 | Flag(outputDir.Join(ctx, "*.oat").String()). |
| 331 | Flag(outputDir.Join(ctx, "*.invocation").String()) |
| 332 | |
| 333 | cmd := rule.Command() |
| 334 | |
| 335 | extraFlags := ctx.Config().Getenv("ART_BOOT_IMAGE_EXTRA_ARGS") |
| 336 | if extraFlags == "" { |
| 337 | // Use ANDROID_LOG_TAGS to suppress most logging by default... |
| 338 | cmd.Text(`ANDROID_LOG_TAGS="*:e"`) |
| 339 | } else { |
| 340 | // ...unless the boot image is generated specifically for testing, then allow all logging. |
| 341 | cmd.Text(`ANDROID_LOG_TAGS="*:v"`) |
| 342 | } |
| 343 | |
| 344 | invocationPath := outputPath.ReplaceExtension(ctx, "invocation") |
| 345 | |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 346 | cmd.Tool(globalSoong.Dex2oat). |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 347 | Flag("--avoid-storing-invocation"). |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 348 | FlagWithOutput("--write-invocation-to=", invocationPath).ImplicitOutput(invocationPath). |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame] | 349 | Flag("--runtime-arg").FlagWithArg("-Xms", global.Dex2oatImageXms). |
| 350 | Flag("--runtime-arg").FlagWithArg("-Xmx", global.Dex2oatImageXmx) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 351 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 352 | if profile != nil { |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 353 | cmd.FlagWithArg("--compiler-filter=", "speed-profile") |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 354 | cmd.FlagWithInput("--profile-file=", profile) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 355 | } |
| 356 | |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame] | 357 | if global.DirtyImageObjects.Valid() { |
| 358 | cmd.FlagWithInput("--dirty-image-objects=", global.DirtyImageObjects.Path()) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 359 | } |
| 360 | |
David Srbecky | 1aacc6c | 2020-03-26 11:10:45 +0000 | [diff] [blame] | 361 | if image.extends != nil { |
David Srbecky | c177ebe | 2020-02-18 20:43:06 +0000 | [diff] [blame] | 362 | artImage := image.primaryImages |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 363 | cmd. |
| 364 | Flag("--runtime-arg").FlagWithInputList("-Xbootclasspath:", image.dexPathsDeps.Paths(), ":"). |
| 365 | Flag("--runtime-arg").FlagWithList("-Xbootclasspath-locations:", image.dexLocationsDeps, ":"). |
| 366 | FlagWithArg("--boot-image=", dexpreopt.PathToLocation(artImage, arch)).Implicit(artImage) |
| 367 | } else { |
| 368 | cmd.FlagWithArg("--base=", ctx.Config().LibartImgDeviceBaseAddress()) |
| 369 | } |
| 370 | |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 371 | cmd. |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame] | 372 | FlagForEachInput("--dex-file=", image.dexPaths.Paths()). |
| 373 | FlagForEachArg("--dex-location=", image.dexLocations). |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 374 | Flag("--generate-debug-info"). |
| 375 | Flag("--generate-build-id"). |
Mathieu Chartier | 54fd807 | 2019-07-26 13:50:04 -0700 | [diff] [blame] | 376 | Flag("--image-format=lz4hc"). |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 377 | FlagWithArg("--oat-symbols=", symbolsFile.String()). |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 378 | Flag("--strip"). |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 379 | FlagWithArg("--oat-file=", outputPath.String()). |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 380 | FlagWithArg("--oat-location=", oatLocation). |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 381 | FlagWithArg("--image=", imagePath.String()). |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 382 | FlagWithArg("--instruction-set=", arch.String()). |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame] | 383 | FlagWithArg("--android-root=", global.EmptyDirectory). |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 384 | FlagWithArg("--no-inline-from=", "core-oj.jar"). |
Ulya Trafimovich | c0c98d5 | 2020-03-09 12:46:06 +0000 | [diff] [blame] | 385 | Flag("--force-determinism"). |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 386 | Flag("--abort-on-hard-verifier-error") |
| 387 | |
David Srbecky | 7f8dac1 | 2020-02-13 16:00:45 +0000 | [diff] [blame] | 388 | // Use the default variant/features for host builds. |
| 389 | // The map below contains only device CPU info (which might be x86 on some devices). |
| 390 | if image.target.Os == android.Android { |
| 391 | cmd.FlagWithArg("--instruction-set-variant=", global.CpuVariant[arch]) |
| 392 | cmd.FlagWithArg("--instruction-set-features=", global.InstructionSetFeatures[arch]) |
| 393 | } |
| 394 | |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame] | 395 | if global.BootFlags != "" { |
| 396 | cmd.Flag(global.BootFlags) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | if extraFlags != "" { |
| 400 | cmd.Flag(extraFlags) |
| 401 | } |
| 402 | |
Colin Cross | 0b9f31f | 2019-02-28 11:00:01 -0800 | [diff] [blame] | 403 | cmd.Textf(`|| ( echo %s ; false )`, proptools.ShellEscape(failureMessage)) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 404 | |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 405 | installDir := filepath.Join("/", image.installSubdir, arch.String()) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 406 | |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 407 | var vdexInstalls android.RuleBuilderInstalls |
| 408 | var unstrippedInstalls android.RuleBuilderInstalls |
| 409 | |
Colin Cross | df8eebe | 2019-04-09 15:29:41 -0700 | [diff] [blame] | 410 | var zipFiles android.WritablePaths |
| 411 | |
Dan Willemsen | 0f41678 | 2019-06-13 21:44:53 +0000 | [diff] [blame] | 412 | for _, artOrOat := range image.moduleFiles(ctx, outputDir, ".art", ".oat") { |
| 413 | cmd.ImplicitOutput(artOrOat) |
| 414 | zipFiles = append(zipFiles, artOrOat) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 415 | |
Dan Willemsen | 0f41678 | 2019-06-13 21:44:53 +0000 | [diff] [blame] | 416 | // Install the .oat and .art files |
| 417 | rule.Install(artOrOat, filepath.Join(installDir, artOrOat.Base())) |
| 418 | } |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 419 | |
Dan Willemsen | 0f41678 | 2019-06-13 21:44:53 +0000 | [diff] [blame] | 420 | for _, vdex := range image.moduleFiles(ctx, outputDir, ".vdex") { |
| 421 | cmd.ImplicitOutput(vdex) |
| 422 | zipFiles = append(zipFiles, vdex) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 423 | |
David Srbecky | 7f8dac1 | 2020-02-13 16:00:45 +0000 | [diff] [blame] | 424 | // Note that the vdex files are identical between architectures. |
| 425 | // Make rules will create symlinks to share them between architectures. |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 426 | vdexInstalls = append(vdexInstalls, |
David Srbecky | 7f8dac1 | 2020-02-13 16:00:45 +0000 | [diff] [blame] | 427 | android.RuleBuilderInstall{vdex, filepath.Join(installDir, vdex.Base())}) |
Dan Willemsen | 0f41678 | 2019-06-13 21:44:53 +0000 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | for _, unstrippedOat := range image.moduleFiles(ctx, symbolsDir, ".oat") { |
| 431 | cmd.ImplicitOutput(unstrippedOat) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 432 | |
| 433 | // Install the unstripped oat files. The Make rules will put these in $(TARGET_OUT_UNSTRIPPED) |
| 434 | unstrippedInstalls = append(unstrippedInstalls, |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 435 | android.RuleBuilderInstall{unstrippedOat, filepath.Join(installDir, unstrippedOat.Base())}) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 436 | } |
| 437 | |
David Srbecky | 7f8dac1 | 2020-02-13 16:00:45 +0000 | [diff] [blame] | 438 | rule.Build(pctx, ctx, image.name+"JarsDexpreopt_"+image.target.String(), "dexpreopt "+image.name+" jars "+arch.String()) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 439 | |
| 440 | // save output and installed files for makevars |
David Srbecky | c177ebe | 2020-02-18 20:43:06 +0000 | [diff] [blame] | 441 | image.installs = rule.Installs() |
| 442 | image.vdexInstalls = vdexInstalls |
| 443 | image.unstrippedInstalls = unstrippedInstalls |
Colin Cross | df8eebe | 2019-04-09 15:29:41 -0700 | [diff] [blame] | 444 | |
| 445 | return zipFiles |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | const failureMessage = `ERROR: Dex2oat failed to compile a boot image. |
| 449 | It is likely that the boot classpath is inconsistent. |
| 450 | Rebuild with ART_BOOT_IMAGE_EXTRA_ARGS="--runtime-arg -verbose:verifier" to see verification errors.` |
| 451 | |
David Srbecky | c177ebe | 2020-02-18 20:43:06 +0000 | [diff] [blame] | 452 | func bootImageProfileRule(ctx android.SingletonContext, image *bootImageConfig, missingDeps []string) android.WritablePath { |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 453 | globalSoong := dexpreopt.GetCachedGlobalSoongConfig(ctx) |
Martin Stjernholm | 40f9f3c | 2020-01-20 18:12:23 +0000 | [diff] [blame] | 454 | global := dexpreopt.GetGlobalConfig(ctx) |
Nicolas Geoffray | 27c7cc6 | 2019-02-24 16:04:52 +0000 | [diff] [blame] | 455 | |
Mathieu Chartier | 6adeee1 | 2019-06-26 10:01:36 -0700 | [diff] [blame] | 456 | if global.DisableGenerateProfile || ctx.Config().IsPdkBuild() || ctx.Config().UnbundledBuild() { |
Nicolas Geoffray | 27c7cc6 | 2019-02-24 16:04:52 +0000 | [diff] [blame] | 457 | return nil |
| 458 | } |
Ulyana Trafimovich | de53441 | 2019-11-08 10:51:01 +0000 | [diff] [blame] | 459 | profile := ctx.Config().Once(bootImageProfileRuleKey, func() interface{} { |
Ulyana Trafimovich | de53441 | 2019-11-08 10:51:01 +0000 | [diff] [blame] | 460 | defaultProfile := "frameworks/base/config/boot-image-profile.txt" |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 461 | |
Nicolas Geoffray | 72892f1 | 2019-02-22 15:34:40 +0000 | [diff] [blame] | 462 | rule := android.NewRuleBuilder() |
| 463 | rule.MissingDeps(missingDeps) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 464 | |
Nicolas Geoffray | 72892f1 | 2019-02-22 15:34:40 +0000 | [diff] [blame] | 465 | var bootImageProfile android.Path |
| 466 | if len(global.BootImageProfiles) > 1 { |
| 467 | combinedBootImageProfile := image.dir.Join(ctx, "boot-image-profile.txt") |
| 468 | rule.Command().Text("cat").Inputs(global.BootImageProfiles).Text(">").Output(combinedBootImageProfile) |
| 469 | bootImageProfile = combinedBootImageProfile |
| 470 | } else if len(global.BootImageProfiles) == 1 { |
| 471 | bootImageProfile = global.BootImageProfiles[0] |
Ulyana Trafimovich | de53441 | 2019-11-08 10:51:01 +0000 | [diff] [blame] | 472 | } else if path := android.ExistentPathForSource(ctx, defaultProfile); path.Valid() { |
| 473 | bootImageProfile = path.Path() |
Nicolas Geoffray | 72892f1 | 2019-02-22 15:34:40 +0000 | [diff] [blame] | 474 | } else { |
Ulyana Trafimovich | de53441 | 2019-11-08 10:51:01 +0000 | [diff] [blame] | 475 | // No profile (not even a default one, which is the case on some branches |
| 476 | // like master-art-host that don't have frameworks/base). |
| 477 | // Return nil and continue without profile. |
| 478 | return nil |
Nicolas Geoffray | 72892f1 | 2019-02-22 15:34:40 +0000 | [diff] [blame] | 479 | } |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 480 | |
Nicolas Geoffray | 72892f1 | 2019-02-22 15:34:40 +0000 | [diff] [blame] | 481 | profile := image.dir.Join(ctx, "boot.prof") |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 482 | |
Nicolas Geoffray | 72892f1 | 2019-02-22 15:34:40 +0000 | [diff] [blame] | 483 | rule.Command(). |
| 484 | Text(`ANDROID_LOG_TAGS="*:e"`). |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 485 | Tool(globalSoong.Profman). |
Nicolas Geoffray | 72892f1 | 2019-02-22 15:34:40 +0000 | [diff] [blame] | 486 | FlagWithInput("--create-profile-from=", bootImageProfile). |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 487 | FlagForEachInput("--apk=", image.dexPathsDeps.Paths()). |
David Srbecky | ab99498 | 2020-03-30 17:24:13 +0100 | [diff] [blame^] | 488 | FlagForEachArg("--dex-location=", image.getAnyAndroidVariant().dexLocationsDeps). |
Nicolas Geoffray | 72892f1 | 2019-02-22 15:34:40 +0000 | [diff] [blame] | 489 | FlagWithOutput("--reference-profile-file=", profile) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 490 | |
Nicolas Geoffray | 72892f1 | 2019-02-22 15:34:40 +0000 | [diff] [blame] | 491 | rule.Install(profile, "/system/etc/boot-image.prof") |
| 492 | |
| 493 | rule.Build(pctx, ctx, "bootJarsProfile", "profile boot jars") |
| 494 | |
| 495 | image.profileInstalls = rule.Installs() |
| 496 | |
| 497 | return profile |
Ulyana Trafimovich | de53441 | 2019-11-08 10:51:01 +0000 | [diff] [blame] | 498 | }) |
| 499 | if profile == nil { |
| 500 | return nil // wrap nil into a typed pointer with value nil |
| 501 | } |
| 502 | return profile.(android.WritablePath) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 503 | } |
| 504 | |
Nicolas Geoffray | 72892f1 | 2019-02-22 15:34:40 +0000 | [diff] [blame] | 505 | var bootImageProfileRuleKey = android.NewOnceKey("bootImageProfileRule") |
| 506 | |
David Srbecky | c177ebe | 2020-02-18 20:43:06 +0000 | [diff] [blame] | 507 | func bootFrameworkProfileRule(ctx android.SingletonContext, image *bootImageConfig, missingDeps []string) android.WritablePath { |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 508 | globalSoong := dexpreopt.GetCachedGlobalSoongConfig(ctx) |
Martin Stjernholm | 40f9f3c | 2020-01-20 18:12:23 +0000 | [diff] [blame] | 509 | global := dexpreopt.GetGlobalConfig(ctx) |
Nicolas Geoffray | e710242 | 2019-07-24 13:19:29 +0100 | [diff] [blame] | 510 | |
| 511 | if global.DisableGenerateProfile || ctx.Config().IsPdkBuild() || ctx.Config().UnbundledBuild() { |
| 512 | return nil |
| 513 | } |
| 514 | return ctx.Config().Once(bootFrameworkProfileRuleKey, func() interface{} { |
Nicolas Geoffray | e710242 | 2019-07-24 13:19:29 +0100 | [diff] [blame] | 515 | rule := android.NewRuleBuilder() |
| 516 | rule.MissingDeps(missingDeps) |
| 517 | |
| 518 | // Some branches like master-art-host don't have frameworks/base, so manually |
| 519 | // handle the case that the default is missing. Those branches won't attempt to build the profile rule, |
| 520 | // and if they do they'll get a missing deps error. |
| 521 | defaultProfile := "frameworks/base/config/boot-profile.txt" |
| 522 | path := android.ExistentPathForSource(ctx, defaultProfile) |
| 523 | var bootFrameworkProfile android.Path |
| 524 | if path.Valid() { |
| 525 | bootFrameworkProfile = path.Path() |
| 526 | } else { |
| 527 | missingDeps = append(missingDeps, defaultProfile) |
| 528 | bootFrameworkProfile = android.PathForOutput(ctx, "missing") |
| 529 | } |
| 530 | |
| 531 | profile := image.dir.Join(ctx, "boot.bprof") |
| 532 | |
| 533 | rule.Command(). |
| 534 | Text(`ANDROID_LOG_TAGS="*:e"`). |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 535 | Tool(globalSoong.Profman). |
Nicolas Geoffray | e710242 | 2019-07-24 13:19:29 +0100 | [diff] [blame] | 536 | Flag("--generate-boot-profile"). |
| 537 | FlagWithInput("--create-profile-from=", bootFrameworkProfile). |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 538 | FlagForEachInput("--apk=", image.dexPathsDeps.Paths()). |
David Srbecky | ab99498 | 2020-03-30 17:24:13 +0100 | [diff] [blame^] | 539 | FlagForEachArg("--dex-location=", image.getAnyAndroidVariant().dexLocationsDeps). |
Nicolas Geoffray | e710242 | 2019-07-24 13:19:29 +0100 | [diff] [blame] | 540 | FlagWithOutput("--reference-profile-file=", profile) |
| 541 | |
| 542 | rule.Install(profile, "/system/etc/boot-image.bprof") |
| 543 | rule.Build(pctx, ctx, "bootFrameworkProfile", "profile boot framework jars") |
| 544 | image.profileInstalls = append(image.profileInstalls, rule.Installs()...) |
| 545 | |
| 546 | return profile |
| 547 | }).(android.WritablePath) |
| 548 | } |
| 549 | |
| 550 | var bootFrameworkProfileRuleKey = android.NewOnceKey("bootFrameworkProfileRule") |
| 551 | |
David Srbecky | c177ebe | 2020-02-18 20:43:06 +0000 | [diff] [blame] | 552 | func dumpOatRules(ctx android.SingletonContext, image *bootImageConfig) { |
Colin Cross | c9a4c36 | 2019-02-26 21:13:48 -0800 | [diff] [blame] | 553 | var allPhonies android.Paths |
David Srbecky | c177ebe | 2020-02-18 20:43:06 +0000 | [diff] [blame] | 554 | for _, image := range image.variants { |
| 555 | arch := image.target.Arch.ArchType |
David Srbecky | 4667232 | 2020-03-16 13:27:55 +0000 | [diff] [blame] | 556 | suffix := arch.String() |
| 557 | // Host and target might both use x86 arch. We need to ensure the names are unique. |
| 558 | if image.target.Os.Class == android.Host { |
| 559 | suffix = "host-" + suffix |
| 560 | } |
Colin Cross | c9a4c36 | 2019-02-26 21:13:48 -0800 | [diff] [blame] | 561 | // Create a rule to call oatdump. |
David Srbecky | 7f8dac1 | 2020-02-13 16:00:45 +0000 | [diff] [blame] | 562 | output := android.PathForOutput(ctx, "boot."+suffix+".oatdump.txt") |
Colin Cross | c9a4c36 | 2019-02-26 21:13:48 -0800 | [diff] [blame] | 563 | rule := android.NewRuleBuilder() |
| 564 | rule.Command(). |
| 565 | // TODO: for now, use the debug version for better error reporting |
Colin Cross | ee94d6a | 2019-07-08 17:08:34 -0700 | [diff] [blame] | 566 | BuiltTool(ctx, "oatdumpd"). |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 567 | FlagWithInputList("--runtime-arg -Xbootclasspath:", image.dexPathsDeps.Paths(), ":"). |
| 568 | FlagWithList("--runtime-arg -Xbootclasspath-locations:", image.dexLocationsDeps, ":"). |
David Srbecky | 1aacc6c | 2020-03-26 11:10:45 +0000 | [diff] [blame] | 569 | FlagWithArg("--image=", strings.Join(image.imageLocations(), ":")).Implicits(image.imagesDeps.Paths()). |
Colin Cross | c9a4c36 | 2019-02-26 21:13:48 -0800 | [diff] [blame] | 570 | FlagWithOutput("--output=", output). |
| 571 | FlagWithArg("--instruction-set=", arch.String()) |
David Srbecky | 7f8dac1 | 2020-02-13 16:00:45 +0000 | [diff] [blame] | 572 | rule.Build(pctx, ctx, "dump-oat-boot-"+suffix, "dump oat boot "+arch.String()) |
Colin Cross | c9a4c36 | 2019-02-26 21:13:48 -0800 | [diff] [blame] | 573 | |
| 574 | // Create a phony rule that depends on the output file and prints the path. |
David Srbecky | 7f8dac1 | 2020-02-13 16:00:45 +0000 | [diff] [blame] | 575 | phony := android.PathForPhony(ctx, "dump-oat-boot-"+suffix) |
Colin Cross | c9a4c36 | 2019-02-26 21:13:48 -0800 | [diff] [blame] | 576 | rule = android.NewRuleBuilder() |
| 577 | rule.Command(). |
| 578 | Implicit(output). |
| 579 | ImplicitOutput(phony). |
| 580 | Text("echo").FlagWithArg("Output in ", output.String()) |
David Srbecky | 7f8dac1 | 2020-02-13 16:00:45 +0000 | [diff] [blame] | 581 | rule.Build(pctx, ctx, "phony-dump-oat-boot-"+suffix, "dump oat boot "+arch.String()) |
Colin Cross | c9a4c36 | 2019-02-26 21:13:48 -0800 | [diff] [blame] | 582 | |
David Srbecky | 1aacc6c | 2020-03-26 11:10:45 +0000 | [diff] [blame] | 583 | allPhonies = append(allPhonies, phony) |
Colin Cross | c9a4c36 | 2019-02-26 21:13:48 -0800 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | phony := android.PathForPhony(ctx, "dump-oat-boot") |
| 587 | ctx.Build(pctx, android.BuildParams{ |
| 588 | Rule: android.Phony, |
| 589 | Output: phony, |
| 590 | Inputs: allPhonies, |
| 591 | Description: "dump-oat-boot", |
| 592 | }) |
| 593 | |
| 594 | } |
| 595 | |
Colin Cross | 2d00f0d | 2019-05-09 21:50:00 -0700 | [diff] [blame] | 596 | func writeGlobalConfigForMake(ctx android.SingletonContext, path android.WritablePath) { |
Martin Stjernholm | 40f9f3c | 2020-01-20 18:12:23 +0000 | [diff] [blame] | 597 | data := dexpreopt.GetGlobalConfigRawData(ctx) |
Colin Cross | 2d00f0d | 2019-05-09 21:50:00 -0700 | [diff] [blame] | 598 | |
| 599 | ctx.Build(pctx, android.BuildParams{ |
| 600 | Rule: android.WriteFile, |
| 601 | Output: path, |
| 602 | Args: map[string]string{ |
| 603 | "content": string(data), |
| 604 | }, |
| 605 | }) |
| 606 | } |
| 607 | |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame] | 608 | // Export paths for default boot image to Make |
| 609 | func (d *dexpreoptBootJars) MakeVars(ctx android.MakeVarsContext) { |
Colin Cross | 2d00f0d | 2019-05-09 21:50:00 -0700 | [diff] [blame] | 610 | if d.dexpreoptConfigForMake != nil { |
| 611 | ctx.Strict("DEX_PREOPT_CONFIG_FOR_MAKE", d.dexpreoptConfigForMake.String()) |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 612 | ctx.Strict("DEX_PREOPT_SOONG_CONFIG_FOR_MAKE", android.PathForOutput(ctx, "dexpreopt_soong.config").String()) |
Colin Cross | 2d00f0d | 2019-05-09 21:50:00 -0700 | [diff] [blame] | 613 | } |
| 614 | |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame] | 615 | image := d.defaultBootImage |
| 616 | if image != nil { |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame] | 617 | ctx.Strict("DEXPREOPT_IMAGE_PROFILE_BUILT_INSTALLED", image.profileInstalls.String()) |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 618 | ctx.Strict("DEXPREOPT_BOOTCLASSPATH_DEX_FILES", strings.Join(image.dexPathsDeps.Strings(), " ")) |
David Srbecky | ab99498 | 2020-03-30 17:24:13 +0100 | [diff] [blame^] | 619 | ctx.Strict("DEXPREOPT_BOOTCLASSPATH_DEX_LOCATIONS", strings.Join(image.getAnyAndroidVariant().dexLocationsDeps, " ")) |
Nicolas Geoffray | 72892f1 | 2019-02-22 15:34:40 +0000 | [diff] [blame] | 620 | |
| 621 | var imageNames []string |
| 622 | for _, current := range append(d.otherImages, image) { |
| 623 | imageNames = append(imageNames, current.name) |
David Srbecky | 1aacc6c | 2020-03-26 11:10:45 +0000 | [diff] [blame] | 624 | for _, variant := range current.variants { |
David Srbecky | 7f8dac1 | 2020-02-13 16:00:45 +0000 | [diff] [blame] | 625 | suffix := "" |
David Srbecky | 1aacc6c | 2020-03-26 11:10:45 +0000 | [diff] [blame] | 626 | if variant.target.Os.Class == android.Host { |
David Srbecky | 7f8dac1 | 2020-02-13 16:00:45 +0000 | [diff] [blame] | 627 | suffix = "_host" |
| 628 | } |
David Srbecky | 1aacc6c | 2020-03-26 11:10:45 +0000 | [diff] [blame] | 629 | sfx := variant.name + suffix + "_" + variant.target.Arch.ArchType.String() |
| 630 | ctx.Strict("DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_"+sfx, variant.vdexInstalls.String()) |
| 631 | ctx.Strict("DEXPREOPT_IMAGE_"+sfx, variant.images.String()) |
| 632 | ctx.Strict("DEXPREOPT_IMAGE_DEPS_"+sfx, strings.Join(variant.imagesDeps.Strings(), " ")) |
| 633 | ctx.Strict("DEXPREOPT_IMAGE_BUILT_INSTALLED_"+sfx, variant.installs.String()) |
| 634 | ctx.Strict("DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_"+sfx, variant.unstrippedInstalls.String()) |
Nicolas Geoffray | 72892f1 | 2019-02-22 15:34:40 +0000 | [diff] [blame] | 635 | } |
David Srbecky | ab99498 | 2020-03-30 17:24:13 +0100 | [diff] [blame^] | 636 | imageLocations := current.getAnyAndroidVariant().imageLocations() |
David Srbecky | 1aacc6c | 2020-03-26 11:10:45 +0000 | [diff] [blame] | 637 | ctx.Strict("DEXPREOPT_IMAGE_LOCATIONS_"+current.name, strings.Join(imageLocations, ":")) |
Colin Cross | 31bf00d | 2019-12-04 13:16:01 -0800 | [diff] [blame] | 638 | ctx.Strict("DEXPREOPT_IMAGE_ZIP_"+current.name, current.zip.String()) |
Nicolas Geoffray | 72892f1 | 2019-02-22 15:34:40 +0000 | [diff] [blame] | 639 | } |
| 640 | ctx.Strict("DEXPREOPT_IMAGE_NAMES", strings.Join(imageNames, " ")) |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 641 | } |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 642 | } |