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