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