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