1// Copyright 2018 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// The dexpreopt package converts a global dexpreopt config and a module dexpreopt config into rules to perform 16// dexpreopting. 17// 18// It is used in two places; in the dexpeopt_gen binary for modules defined in Make, and directly linked into Soong. 19// 20// For Make modules it is built into the dexpreopt_gen binary, which is executed as a Make rule using global config and 21// module config specified in JSON files. The binary writes out two shell scripts, only updating them if they have 22// changed. One script takes an APK or JAR as an input and produces a zip file containing any outputs of preopting, 23// in the location they should be on the device. The Make build rules will unzip the zip file into $(PRODUCT_OUT) when 24// installing the APK, which will install the preopt outputs into $(PRODUCT_OUT)/system or $(PRODUCT_OUT)/system_other 25// as necessary. The zip file may be empty if preopting was disabled for any reason. 26// 27// The intermediate shell scripts allow changes to this package or to the global config to regenerate the shell scripts 28// but only require re-executing preopting if the script has changed. 29// 30// For Soong modules this package is linked directly into Soong and run from the java package. It generates the same 31// commands as for make, using athe same global config JSON file used by make, but using a module config structure 32// provided by Soong. The generated commands are then converted into Soong rule and written directly to the ninja file, 33// with no extra shell scripts involved. 34package dexpreopt 35 36import ( 37 "fmt" 38 "path/filepath" 39 "runtime" 40 "strings" 41 42 "android/soong/android" 43 44 "github.com/google/blueprint/pathtools" 45) 46 47const SystemPartition = "/system/" 48const SystemOtherPartition = "/system_other/" 49 50var DexpreoptRunningInSoong = false 51 52// GenerateDexpreoptRule generates a set of commands that will preopt a module based on a GlobalConfig and a 53// ModuleConfig. The produced files and their install locations will be available through rule.Installs(). 54func GenerateDexpreoptRule(ctx android.BuilderContext, globalSoong *GlobalSoongConfig, 55 global *GlobalConfig, module *ModuleConfig) (rule *android.RuleBuilder, err error) { 56 57 defer func() { 58 if r := recover(); r != nil { 59 if _, ok := r.(runtime.Error); ok { 60 panic(r) 61 } else if e, ok := r.(error); ok { 62 err = e 63 rule = nil 64 } else { 65 panic(r) 66 } 67 } 68 }() 69 70 rule = android.NewRuleBuilder(pctx, ctx) 71 72 generateProfile := module.ProfileClassListing.Valid() && !global.DisableGenerateProfile 73 generateBootProfile := module.ProfileBootListing.Valid() && !global.DisableGenerateProfile 74 75 var profile android.WritablePath 76 if generateProfile { 77 profile = profileCommand(ctx, globalSoong, global, module, rule) 78 } 79 if generateBootProfile { 80 bootProfileCommand(ctx, globalSoong, global, module, rule) 81 } 82 83 if !dexpreoptDisabled(ctx, global, module) { 84 if valid, err := validateClassLoaderContext(module.ClassLoaderContexts); err != nil { 85 android.ReportPathErrorf(ctx, err.Error()) 86 } else if valid { 87 fixClassLoaderContext(module.ClassLoaderContexts) 88 89 appImage := (generateProfile || module.ForceCreateAppImage || global.DefaultAppImages) && 90 !module.NoCreateAppImage 91 92 generateDM := shouldGenerateDM(module, global) 93 94 for archIdx, _ := range module.Archs { 95 dexpreoptCommand(ctx, globalSoong, global, module, rule, archIdx, profile, appImage, generateDM) 96 } 97 } 98 } 99 100 return rule, nil 101} 102 103func dexpreoptDisabled(ctx android.PathContext, global *GlobalConfig, module *ModuleConfig) bool { 104 if contains(global.DisablePreoptModules, module.Name) { 105 return true 106 } 107 108 // Don't preopt individual boot jars, they will be preopted together. 109 if global.BootJars.ContainsJar(module.Name) { 110 return true 111 } 112 113 // If OnlyPreoptBootImageAndSystemServer=true and module is not in boot class path skip 114 // Also preopt system server jars since selinux prevents system server from loading anything from 115 // /data. If we don't do this they will need to be extracted which is not favorable for RAM usage 116 // or performance. If PreoptExtractedApk is true, we ignore the only preopt boot image options. 117 if global.OnlyPreoptBootImageAndSystemServer && !global.BootJars.ContainsJar(module.Name) && 118 !global.AllSystemServerJars(ctx).ContainsJar(module.Name) && !module.PreoptExtractedApk { 119 return true 120 } 121 122 return false 123} 124 125func profileCommand(ctx android.PathContext, globalSoong *GlobalSoongConfig, global *GlobalConfig, 126 module *ModuleConfig, rule *android.RuleBuilder) android.WritablePath { 127 128 profilePath := module.BuildPath.InSameDir(ctx, "profile.prof") 129 profileInstalledPath := module.DexLocation + ".prof" 130 131 if !module.ProfileIsTextListing { 132 rule.Command().Text("rm -f").Output(profilePath) 133 rule.Command().Text("touch").Output(profilePath) 134 } 135 136 cmd := rule.Command(). 137 Text(`ANDROID_LOG_TAGS="*:e"`). 138 Tool(globalSoong.Profman) 139 140 if module.ProfileIsTextListing { 141 // The profile is a test listing of classes (used for framework jars). 142 // We need to generate the actual binary profile before being able to compile. 143 cmd.FlagWithInput("--create-profile-from=", module.ProfileClassListing.Path()) 144 } else { 145 // The profile is binary profile (used for apps). Run it through profman to 146 // ensure the profile keys match the apk. 147 cmd. 148 Flag("--copy-and-update-profile-key"). 149 FlagWithInput("--profile-file=", module.ProfileClassListing.Path()) 150 } 151 152 cmd. 153 Flag("--output-profile-type=app"). 154 FlagWithInput("--apk=", module.DexPath). 155 Flag("--dex-location="+module.DexLocation). 156 FlagWithOutput("--reference-profile-file=", profilePath) 157 158 if !module.ProfileIsTextListing { 159 cmd.Text(fmt.Sprintf(`|| echo "Profile out of date for %s"`, module.DexPath)) 160 } 161 rule.Install(profilePath, profileInstalledPath) 162 163 return profilePath 164} 165 166func bootProfileCommand(ctx android.PathContext, globalSoong *GlobalSoongConfig, global *GlobalConfig, 167 module *ModuleConfig, rule *android.RuleBuilder) android.WritablePath { 168 169 profilePath := module.BuildPath.InSameDir(ctx, "profile.bprof") 170 profileInstalledPath := module.DexLocation + ".bprof" 171 172 if !module.ProfileIsTextListing { 173 rule.Command().Text("rm -f").Output(profilePath) 174 rule.Command().Text("touch").Output(profilePath) 175 } 176 177 cmd := rule.Command(). 178 Text(`ANDROID_LOG_TAGS="*:e"`). 179 Tool(globalSoong.Profman) 180 181 // The profile is a test listing of methods. 182 // We need to generate the actual binary profile. 183 cmd.FlagWithInput("--create-profile-from=", module.ProfileBootListing.Path()) 184 185 cmd. 186 Flag("--output-profile-type=bprof"). 187 FlagWithInput("--apk=", module.DexPath). 188 Flag("--dex-location="+module.DexLocation). 189 FlagWithOutput("--reference-profile-file=", profilePath) 190 191 if !module.ProfileIsTextListing { 192 cmd.Text(fmt.Sprintf(`|| echo "Profile out of date for %s"`, module.DexPath)) 193 } 194 rule.Install(profilePath, profileInstalledPath) 195 196 return profilePath 197} 198 199// Returns the dex location of a system server java library. 200func GetSystemServerDexLocation(ctx android.PathContext, global *GlobalConfig, lib string) string { 201 if apex := global.AllApexSystemServerJars(ctx).ApexOfJar(lib); apex != "" { 202 return fmt.Sprintf("/apex/%s/javalib/%s.jar", apex, lib) 203 } 204 return fmt.Sprintf("/system/framework/%s.jar", lib) 205} 206 207// Returns the location to the odex file for the dex file at `path`. 208func ToOdexPath(path string, arch android.ArchType) string { 209 if strings.HasPrefix(path, "/apex/") { 210 return filepath.Join("/system/framework/oat", arch.String(), 211 strings.ReplaceAll(path[1:], "/", "@")+"@classes.odex") 212 } 213 214 return filepath.Join(filepath.Dir(path), "oat", arch.String(), 215 pathtools.ReplaceExtension(filepath.Base(path), "odex")) 216} 217 218func dexpreoptCommand(ctx android.PathContext, globalSoong *GlobalSoongConfig, global *GlobalConfig, 219 module *ModuleConfig, rule *android.RuleBuilder, archIdx int, profile android.WritablePath, 220 appImage bool, generateDM bool) { 221 222 arch := module.Archs[archIdx] 223 224 // HACK: make soname in Soong-generated .odex files match Make. 225 base := filepath.Base(module.DexLocation) 226 if filepath.Ext(base) == ".jar" { 227 base = "javalib.jar" 228 } else if filepath.Ext(base) == ".apk" { 229 base = "package.apk" 230 } 231 232 odexPath := module.BuildPath.InSameDir(ctx, "oat", arch.String(), pathtools.ReplaceExtension(base, "odex")) 233 odexInstallPath := ToOdexPath(module.DexLocation, arch) 234 if odexOnSystemOther(module, global) { 235 odexInstallPath = filepath.Join(SystemOtherPartition, odexInstallPath) 236 } 237 238 vdexPath := odexPath.ReplaceExtension(ctx, "vdex") 239 vdexInstallPath := pathtools.ReplaceExtension(odexInstallPath, "vdex") 240 241 invocationPath := odexPath.ReplaceExtension(ctx, "invocation") 242 243 systemServerJars := global.AllSystemServerJars(ctx) 244 systemServerClasspathJars := global.AllSystemServerClasspathJars(ctx) 245 246 rule.Command().FlagWithArg("mkdir -p ", filepath.Dir(odexPath.String())) 247 rule.Command().FlagWithOutput("rm -f ", odexPath) 248 249 if jarIndex := systemServerJars.IndexOfJar(module.Name); jarIndex >= 0 { 250 // System server jars should be dexpreopted together: class loader context of each jar 251 // should include all preceding jars on the system server classpath. 252 253 var clcHost android.Paths 254 var clcTarget []string 255 endIndex := systemServerClasspathJars.IndexOfJar(module.Name) 256 if endIndex < 0 { 257 // The jar is a standalone one. Use the full classpath as the class loader context. 258 endIndex = systemServerClasspathJars.Len() 259 } 260 for i := 0; i < endIndex; i++ { 261 lib := systemServerClasspathJars.Jar(i) 262 clcHost = append(clcHost, SystemServerDexJarHostPath(ctx, lib)) 263 clcTarget = append(clcTarget, GetSystemServerDexLocation(ctx, global, lib)) 264 } 265 266 if DexpreoptRunningInSoong { 267 // Copy the system server jar to a predefined location where dex2oat will find it. 268 dexPathHost := SystemServerDexJarHostPath(ctx, module.Name) 269 rule.Command().Text("mkdir -p").Flag(filepath.Dir(dexPathHost.String())) 270 rule.Command().Text("cp -f").Input(module.DexPath).Output(dexPathHost) 271 } else { 272 // For Make modules the copy rule is generated in the makefiles, not in dexpreopt.sh. 273 // This is necessary to expose the rule to Ninja, otherwise it has rules that depend on 274 // the jar (namely, dexpreopt commands for all subsequent system server jars that have 275 // this one in their class loader context), but no rule that creates it (because Ninja 276 // cannot see the rule in the generated dexpreopt.sh script). 277 } 278 279 clcHostString := "PCL[" + strings.Join(clcHost.Strings(), ":") + "]" 280 clcTargetString := "PCL[" + strings.Join(clcTarget, ":") + "]" 281 282 if systemServerClasspathJars.ContainsJar(module.Name) { 283 checkSystemServerOrder(ctx, jarIndex) 284 } else { 285 // Standalone jars are loaded by separate class loaders with SYSTEMSERVERCLASSPATH as the 286 // parent. 287 clcHostString = "PCL[];" + clcHostString 288 clcTargetString = "PCL[];" + clcTargetString 289 } 290 291 rule.Command(). 292 Text(`class_loader_context_arg=--class-loader-context="` + clcHostString + `"`). 293 Implicits(clcHost). 294 Text(`stored_class_loader_context_arg=--stored-class-loader-context="` + clcTargetString + `"`) 295 296 } else { 297 // There are three categories of Java modules handled here: 298 // 299 // - Modules that have passed verify_uses_libraries check. They are AOT-compiled and 300 // expected to be loaded on device without CLC mismatch errors. 301 // 302 // - Modules that have failed the check in relaxed mode, so it didn't cause a build error. 303 // They are dexpreopted with "verify" filter and not AOT-compiled. 304 // TODO(b/132357300): ensure that CLC mismatch errors are ignored with "verify" filter. 305 // 306 // - Modules that didn't run the check. They are AOT-compiled, but it's unknown if they 307 // will have CLC mismatch errors on device (the check is disabled by default). 308 // 309 // TODO(b/132357300): enable the check by default and eliminate the last category, so that 310 // no time/space is wasted on AOT-compiling modules that will fail CLC check on device. 311 312 var manifestOrApk android.Path 313 if module.ManifestPath.Valid() { 314 // Ok, there is an XML manifest. 315 manifestOrApk = module.ManifestPath.Path() 316 } else if filepath.Ext(base) == ".apk" { 317 // Ok, there is is an APK with the manifest inside. 318 manifestOrApk = module.DexPath 319 } 320 321 // Generate command that saves target SDK version in a shell variable. 322 if manifestOrApk == nil { 323 // There is neither an XML manifest nor APK => nowhere to extract targetSdkVersion from. 324 // Set the latest ("any") version: then construct_context will not add any compatibility 325 // libraries (if this is incorrect, there will be a CLC mismatch and dexopt on device). 326 rule.Command().Textf(`target_sdk_version=%d`, AnySdkVersion) 327 } else { 328 rule.Command().Text(`target_sdk_version="$(`). 329 Tool(globalSoong.ManifestCheck). 330 Flag("--extract-target-sdk-version"). 331 Input(manifestOrApk). 332 FlagWithInput("--aapt ", globalSoong.Aapt). 333 Text(`)"`) 334 } 335 336 // Generate command that saves host and target class loader context in shell variables. 337 clc, paths := ComputeClassLoaderContext(module.ClassLoaderContexts) 338 rule.Command(). 339 Text(`eval "$(`).Tool(globalSoong.ConstructContext). 340 Text(` --target-sdk-version ${target_sdk_version}`). 341 Text(clc).Implicits(paths). 342 Text(`)"`) 343 } 344 345 // Devices that do not have a product partition use a symlink from /product to /system/product. 346 // Because on-device dexopt will see dex locations starting with /product, we change the paths 347 // to mimic this behavior. 348 dexLocationArg := module.DexLocation 349 if strings.HasPrefix(dexLocationArg, "/system/product/") { 350 dexLocationArg = strings.TrimPrefix(dexLocationArg, "/system") 351 } 352 353 cmd := rule.Command(). 354 Text(`ANDROID_LOG_TAGS="*:e"`). 355 Tool(globalSoong.Dex2oat). 356 Flag("--avoid-storing-invocation"). 357 FlagWithOutput("--write-invocation-to=", invocationPath).ImplicitOutput(invocationPath). 358 Flag("--runtime-arg").FlagWithArg("-Xms", global.Dex2oatXms). 359 Flag("--runtime-arg").FlagWithArg("-Xmx", global.Dex2oatXmx). 360 Flag("--runtime-arg").FlagWithInputList("-Xbootclasspath:", module.PreoptBootClassPathDexFiles, ":"). 361 Flag("--runtime-arg").FlagWithList("-Xbootclasspath-locations:", module.PreoptBootClassPathDexLocations, ":"). 362 Flag("${class_loader_context_arg}"). 363 Flag("${stored_class_loader_context_arg}"). 364 FlagWithArg("--boot-image=", strings.Join(module.DexPreoptImageLocationsOnHost, ":")).Implicits(module.DexPreoptImagesDeps[archIdx].Paths()). 365 FlagWithInput("--dex-file=", module.DexPath). 366 FlagWithArg("--dex-location=", dexLocationArg). 367 FlagWithOutput("--oat-file=", odexPath).ImplicitOutput(vdexPath). 368 // Pass an empty directory, dex2oat shouldn't be reading arbitrary files 369 FlagWithArg("--android-root=", global.EmptyDirectory). 370 FlagWithArg("--instruction-set=", arch.String()). 371 FlagWithArg("--instruction-set-variant=", global.CpuVariant[arch]). 372 FlagWithArg("--instruction-set-features=", global.InstructionSetFeatures[arch]). 373 Flag("--no-generate-debug-info"). 374 Flag("--generate-build-id"). 375 Flag("--abort-on-hard-verifier-error"). 376 Flag("--force-determinism"). 377 FlagWithArg("--no-inline-from=", "core-oj.jar") 378 379 var preoptFlags []string 380 if len(module.PreoptFlags) > 0 { 381 preoptFlags = module.PreoptFlags 382 } else if len(global.PreoptFlags) > 0 { 383 preoptFlags = global.PreoptFlags 384 } 385 386 if len(preoptFlags) > 0 { 387 cmd.Text(strings.Join(preoptFlags, " ")) 388 } 389 390 if module.UncompressedDex { 391 cmd.FlagWithArg("--copy-dex-files=", "false") 392 } 393 394 if !android.PrefixInList(preoptFlags, "--compiler-filter=") { 395 var compilerFilter string 396 if systemServerJars.ContainsJar(module.Name) { 397 // Jars of system server, use the product option if it is set, speed otherwise. 398 if global.SystemServerCompilerFilter != "" { 399 compilerFilter = global.SystemServerCompilerFilter 400 } else { 401 compilerFilter = "speed" 402 } 403 } else if contains(global.SpeedApps, module.Name) || contains(global.SystemServerApps, module.Name) { 404 // Apps loaded into system server, and apps the product default to being compiled with the 405 // 'speed' compiler filter. 406 compilerFilter = "speed" 407 } else if profile != nil { 408 // For non system server jars, use speed-profile when we have a profile. 409 compilerFilter = "speed-profile" 410 } else if global.DefaultCompilerFilter != "" { 411 compilerFilter = global.DefaultCompilerFilter 412 } else { 413 compilerFilter = "quicken" 414 } 415 if module.EnforceUsesLibraries { 416 // If the verify_uses_libraries check failed (in this case status file contains a 417 // non-empty error message), then use "verify" compiler filter to avoid compiling any 418 // code (it would be rejected on device because of a class loader context mismatch). 419 cmd.Text("--compiler-filter=$(if test -s "). 420 Input(module.EnforceUsesLibrariesStatusFile). 421 Text(" ; then echo verify ; else echo " + compilerFilter + " ; fi)") 422 } else { 423 cmd.FlagWithArg("--compiler-filter=", compilerFilter) 424 } 425 } 426 427 if generateDM { 428 cmd.FlagWithArg("--copy-dex-files=", "false") 429 dmPath := module.BuildPath.InSameDir(ctx, "generated.dm") 430 dmInstalledPath := pathtools.ReplaceExtension(module.DexLocation, "dm") 431 tmpPath := module.BuildPath.InSameDir(ctx, "primary.vdex") 432 rule.Command().Text("cp -f").Input(vdexPath).Output(tmpPath) 433 rule.Command().Tool(globalSoong.SoongZip). 434 FlagWithArg("-L", "9"). 435 FlagWithOutput("-o", dmPath). 436 Flag("-j"). 437 Input(tmpPath) 438 rule.Install(dmPath, dmInstalledPath) 439 } 440 441 // By default, emit debug info. 442 debugInfo := true 443 if global.NoDebugInfo { 444 // If the global setting suppresses mini-debug-info, disable it. 445 debugInfo = false 446 } 447 448 // PRODUCT_SYSTEM_SERVER_DEBUG_INFO overrides WITH_DEXPREOPT_DEBUG_INFO. 449 // PRODUCT_OTHER_JAVA_DEBUG_INFO overrides WITH_DEXPREOPT_DEBUG_INFO. 450 if systemServerJars.ContainsJar(module.Name) { 451 if global.AlwaysSystemServerDebugInfo { 452 debugInfo = true 453 } else if global.NeverSystemServerDebugInfo { 454 debugInfo = false 455 } 456 } else { 457 if global.AlwaysOtherDebugInfo { 458 debugInfo = true 459 } else if global.NeverOtherDebugInfo { 460 debugInfo = false 461 } 462 } 463 464 if debugInfo { 465 cmd.Flag("--generate-mini-debug-info") 466 } else { 467 cmd.Flag("--no-generate-mini-debug-info") 468 } 469 470 // Set the compiler reason to 'prebuilt' to identify the oat files produced 471 // during the build, as opposed to compiled on the device. 472 cmd.FlagWithArg("--compilation-reason=", "prebuilt") 473 474 if appImage { 475 appImagePath := odexPath.ReplaceExtension(ctx, "art") 476 appImageInstallPath := pathtools.ReplaceExtension(odexInstallPath, "art") 477 cmd.FlagWithOutput("--app-image-file=", appImagePath). 478 FlagWithArg("--image-format=", "lz4") 479 if !global.DontResolveStartupStrings { 480 cmd.FlagWithArg("--resolve-startup-const-strings=", "true") 481 } 482 rule.Install(appImagePath, appImageInstallPath) 483 } 484 485 if profile != nil { 486 cmd.FlagWithInput("--profile-file=", profile) 487 } 488 489 rule.Install(odexPath, odexInstallPath) 490 rule.Install(vdexPath, vdexInstallPath) 491} 492 493func shouldGenerateDM(module *ModuleConfig, global *GlobalConfig) bool { 494 // Generating DM files only makes sense for verify, avoid doing for non verify compiler filter APKs. 495 // No reason to use a dm file if the dex is already uncompressed. 496 return global.GenerateDMFiles && !module.UncompressedDex && 497 contains(module.PreoptFlags, "--compiler-filter=verify") 498} 499 500func OdexOnSystemOtherByName(name string, dexLocation string, global *GlobalConfig) bool { 501 if !global.HasSystemOther { 502 return false 503 } 504 505 if global.SanitizeLite { 506 return false 507 } 508 509 if contains(global.SpeedApps, name) || contains(global.SystemServerApps, name) { 510 return false 511 } 512 513 for _, f := range global.PatternsOnSystemOther { 514 if makefileMatch(filepath.Join(SystemPartition, f), dexLocation) { 515 return true 516 } 517 } 518 519 return false 520} 521 522func odexOnSystemOther(module *ModuleConfig, global *GlobalConfig) bool { 523 return OdexOnSystemOtherByName(module.Name, module.DexLocation, global) 524} 525 526// PathToLocation converts .../system/framework/arm64/boot.art to .../system/framework/boot.art 527func PathToLocation(path android.Path, arch android.ArchType) string { 528 return PathStringToLocation(path.String(), arch) 529} 530 531// PathStringToLocation converts .../system/framework/arm64/boot.art to .../system/framework/boot.art 532func PathStringToLocation(path string, arch android.ArchType) string { 533 pathArch := filepath.Base(filepath.Dir(path)) 534 if pathArch != arch.String() { 535 panic(fmt.Errorf("last directory in %q must be %q", path, arch.String())) 536 } 537 return filepath.Join(filepath.Dir(filepath.Dir(path)), filepath.Base(path)) 538} 539 540func makefileMatch(pattern, s string) bool { 541 percent := strings.IndexByte(pattern, '%') 542 switch percent { 543 case -1: 544 return pattern == s 545 case len(pattern) - 1: 546 return strings.HasPrefix(s, pattern[:len(pattern)-1]) 547 default: 548 panic(fmt.Errorf("unsupported makefile pattern %q", pattern)) 549 } 550} 551 552// A predefined location for the system server dex jars. This is needed in order to generate 553// class loader context for dex2oat, as the path to the jar in the Soong module may be unknown 554// at that time (Soong processes the jars in dependency order, which may be different from the 555// the system server classpath order). 556func SystemServerDexJarHostPath(ctx android.PathContext, jar string) android.OutputPath { 557 if DexpreoptRunningInSoong { 558 // Soong module, just use the default output directory $OUT/soong. 559 return android.PathForOutput(ctx, "system_server_dexjars", jar+".jar") 560 } else { 561 // Make module, default output directory is $OUT (passed via the "null config" created 562 // by dexpreopt_gen). Append Soong subdirectory to match Soong module paths. 563 return android.PathForOutput(ctx, "soong", "system_server_dexjars", jar+".jar") 564 } 565} 566 567// Check the order of jars on the system server classpath and give a warning/error if a jar precedes 568// one of its dependencies. This is not an error, but a missed optimization, as dexpreopt won't 569// have the dependency jar in the class loader context, and it won't be able to resolve any 570// references to its classes and methods. 571func checkSystemServerOrder(ctx android.PathContext, jarIndex int) { 572 mctx, isModule := ctx.(android.ModuleContext) 573 if isModule { 574 config := GetGlobalConfig(ctx) 575 jars := config.AllSystemServerClasspathJars(ctx) 576 mctx.WalkDeps(func(dep android.Module, parent android.Module) bool { 577 depIndex := jars.IndexOfJar(dep.Name()) 578 if jarIndex < depIndex && !config.BrokenSuboptimalOrderOfSystemServerJars { 579 jar := jars.Jar(jarIndex) 580 dep := jars.Jar(depIndex) 581 mctx.ModuleErrorf("non-optimal order of jars on the system server classpath:"+ 582 " '%s' precedes its dependency '%s', so dexpreopt is unable to resolve any"+ 583 " references from '%s' to '%s'.\n", jar, dep, jar, dep) 584 } 585 return true 586 }) 587 } 588} 589 590// Returns path to a file containing the reult of verify_uses_libraries check (empty if the check 591// has succeeded, or an error message if it failed). 592func UsesLibrariesStatusFile(ctx android.ModuleContext) android.WritablePath { 593 return android.PathForModuleOut(ctx, "enforce_uses_libraries.status") 594} 595 596func contains(l []string, s string) bool { 597 for _, e := range l { 598 if e == s { 599 return true 600 } 601 } 602 return false 603} 604 605var copyOf = android.CopyOf 606