Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 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 |
Nicolas Geoffray | c1bf724 | 2019-10-18 14:51:38 +0100 | [diff] [blame] | 16 | // dexpreopting. |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 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 |
Nicolas Geoffray | c1bf724 | 2019-10-18 14:51:38 +0100 | [diff] [blame] | 25 | // as necessary. The zip file may be empty if preopting was disabled for any reason. |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 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. |
| 34 | package dexpreopt |
| 35 | |
| 36 | import ( |
| 37 | "fmt" |
| 38 | "path/filepath" |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 39 | "runtime" |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 40 | "strings" |
| 41 | |
Colin Cross | feec25b | 2019-01-30 17:32:39 -0800 | [diff] [blame] | 42 | "android/soong/android" |
| 43 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 44 | "github.com/google/blueprint/pathtools" |
| 45 | ) |
| 46 | |
| 47 | const SystemPartition = "/system/" |
| 48 | const SystemOtherPartition = "/system_other/" |
| 49 | |
Ulya Trafimovich | 6cf2c0c | 2020-04-24 12:15:20 +0100 | [diff] [blame] | 50 | var DexpreoptRunningInSoong = false |
| 51 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 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(). |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 54 | func GenerateDexpreoptRule(ctx android.PathContext, globalSoong *GlobalSoongConfig, |
| 55 | global *GlobalConfig, module *ModuleConfig) (rule *android.RuleBuilder, err error) { |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 56 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 57 | defer func() { |
| 58 | if r := recover(); r != nil { |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 59 | if _, ok := r.(runtime.Error); ok { |
| 60 | panic(r) |
| 61 | } else if e, ok := r.(error); ok { |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 62 | err = e |
| 63 | rule = nil |
| 64 | } else { |
| 65 | panic(r) |
| 66 | } |
| 67 | } |
| 68 | }() |
| 69 | |
Colin Cross | 758290d | 2019-02-01 16:42:32 -0800 | [diff] [blame] | 70 | rule = android.NewRuleBuilder() |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 71 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 72 | generateProfile := module.ProfileClassListing.Valid() && !global.DisableGenerateProfile |
Nicolas Geoffray | e710242 | 2019-07-24 13:19:29 +0100 | [diff] [blame] | 73 | generateBootProfile := module.ProfileBootListing.Valid() && !global.DisableGenerateProfile |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 74 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 75 | var profile android.WritablePath |
Colin Cross | cbed657 | 2019-01-08 17:38:37 -0800 | [diff] [blame] | 76 | if generateProfile { |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 77 | profile = profileCommand(ctx, globalSoong, global, module, rule) |
Colin Cross | cbed657 | 2019-01-08 17:38:37 -0800 | [diff] [blame] | 78 | } |
Nicolas Geoffray | e710242 | 2019-07-24 13:19:29 +0100 | [diff] [blame] | 79 | if generateBootProfile { |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 80 | bootProfileCommand(ctx, globalSoong, global, module, rule) |
Nicolas Geoffray | e710242 | 2019-07-24 13:19:29 +0100 | [diff] [blame] | 81 | } |
Colin Cross | cbed657 | 2019-01-08 17:38:37 -0800 | [diff] [blame] | 82 | |
Ulya Trafimovich | f3ff010 | 2019-12-03 15:39:23 +0000 | [diff] [blame] | 83 | if !dexpreoptDisabled(ctx, global, module) { |
Colin Cross | cbed657 | 2019-01-08 17:38:37 -0800 | [diff] [blame] | 84 | // Don't preopt individual boot jars, they will be preopted together. |
Ulya Trafimovich | 8640ab9 | 2020-05-11 18:06:15 +0100 | [diff] [blame] | 85 | if !contains(android.GetJarsFromApexJarPairs(ctx, global.BootJars), module.Name) { |
Colin Cross | cbed657 | 2019-01-08 17:38:37 -0800 | [diff] [blame] | 86 | appImage := (generateProfile || module.ForceCreateAppImage || global.DefaultAppImages) && |
| 87 | !module.NoCreateAppImage |
| 88 | |
| 89 | generateDM := shouldGenerateDM(module, global) |
| 90 | |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 91 | for archIdx, _ := range module.Archs { |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 92 | dexpreoptCommand(ctx, globalSoong, global, module, rule, archIdx, profile, appImage, generateDM) |
Colin Cross | cbed657 | 2019-01-08 17:38:37 -0800 | [diff] [blame] | 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | return rule, nil |
| 98 | } |
| 99 | |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 100 | func dexpreoptDisabled(ctx android.PathContext, global *GlobalConfig, module *ModuleConfig) bool { |
Colin Cross | cbed657 | 2019-01-08 17:38:37 -0800 | [diff] [blame] | 101 | if contains(global.DisablePreoptModules, module.Name) { |
| 102 | return true |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 103 | } |
| 104 | |
Ulyana Trafimovich | f2cb7e9 | 2019-11-27 12:26:49 +0000 | [diff] [blame] | 105 | // Don't preopt system server jars that are updatable. |
| 106 | for _, p := range global.UpdatableSystemServerJars { |
Ulya Trafimovich | 8640ab9 | 2020-05-11 18:06:15 +0100 | [diff] [blame] | 107 | if _, jar := android.SplitApexJarPair(ctx, p); jar == module.Name { |
Ulyana Trafimovich | f2cb7e9 | 2019-11-27 12:26:49 +0000 | [diff] [blame] | 108 | return true |
| 109 | } |
| 110 | } |
| 111 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 112 | // If OnlyPreoptBootImageAndSystemServer=true and module is not in boot class path skip |
| 113 | // Also preopt system server jars since selinux prevents system server from loading anything from |
| 114 | // /data. If we don't do this they will need to be extracted which is not favorable for RAM usage |
| 115 | // or performance. If PreoptExtractedApk is true, we ignore the only preopt boot image options. |
Ulya Trafimovich | 8640ab9 | 2020-05-11 18:06:15 +0100 | [diff] [blame] | 116 | if global.OnlyPreoptBootImageAndSystemServer && !contains(android.GetJarsFromApexJarPairs(ctx, global.BootJars), module.Name) && |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 117 | !contains(global.SystemServerJars, module.Name) && !module.PreoptExtractedApk { |
Colin Cross | cbed657 | 2019-01-08 17:38:37 -0800 | [diff] [blame] | 118 | return true |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 119 | } |
| 120 | |
Colin Cross | cbed657 | 2019-01-08 17:38:37 -0800 | [diff] [blame] | 121 | return false |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 122 | } |
| 123 | |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 124 | func profileCommand(ctx android.PathContext, globalSoong *GlobalSoongConfig, global *GlobalConfig, |
| 125 | module *ModuleConfig, rule *android.RuleBuilder) android.WritablePath { |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 126 | |
| 127 | profilePath := module.BuildPath.InSameDir(ctx, "profile.prof") |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 128 | profileInstalledPath := module.DexLocation + ".prof" |
| 129 | |
| 130 | if !module.ProfileIsTextListing { |
| 131 | rule.Command().FlagWithOutput("touch ", profilePath) |
| 132 | } |
| 133 | |
| 134 | cmd := rule.Command(). |
| 135 | Text(`ANDROID_LOG_TAGS="*:e"`). |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 136 | Tool(globalSoong.Profman) |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 137 | |
| 138 | if module.ProfileIsTextListing { |
| 139 | // The profile is a test listing of classes (used for framework jars). |
| 140 | // We need to generate the actual binary profile before being able to compile. |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 141 | cmd.FlagWithInput("--create-profile-from=", module.ProfileClassListing.Path()) |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 142 | } else { |
| 143 | // The profile is binary profile (used for apps). Run it through profman to |
| 144 | // ensure the profile keys match the apk. |
| 145 | cmd. |
| 146 | Flag("--copy-and-update-profile-key"). |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 147 | FlagWithInput("--profile-file=", module.ProfileClassListing.Path()) |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | cmd. |
| 151 | FlagWithInput("--apk=", module.DexPath). |
| 152 | Flag("--dex-location="+module.DexLocation). |
| 153 | FlagWithOutput("--reference-profile-file=", profilePath) |
| 154 | |
| 155 | if !module.ProfileIsTextListing { |
| 156 | cmd.Text(fmt.Sprintf(`|| echo "Profile out of date for %s"`, module.DexPath)) |
| 157 | } |
| 158 | rule.Install(profilePath, profileInstalledPath) |
| 159 | |
| 160 | return profilePath |
| 161 | } |
| 162 | |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 163 | func bootProfileCommand(ctx android.PathContext, globalSoong *GlobalSoongConfig, global *GlobalConfig, |
| 164 | module *ModuleConfig, rule *android.RuleBuilder) android.WritablePath { |
Nicolas Geoffray | e710242 | 2019-07-24 13:19:29 +0100 | [diff] [blame] | 165 | |
| 166 | profilePath := module.BuildPath.InSameDir(ctx, "profile.bprof") |
| 167 | profileInstalledPath := module.DexLocation + ".bprof" |
| 168 | |
| 169 | if !module.ProfileIsTextListing { |
| 170 | rule.Command().FlagWithOutput("touch ", profilePath) |
| 171 | } |
| 172 | |
| 173 | cmd := rule.Command(). |
| 174 | Text(`ANDROID_LOG_TAGS="*:e"`). |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 175 | Tool(globalSoong.Profman) |
Nicolas Geoffray | e710242 | 2019-07-24 13:19:29 +0100 | [diff] [blame] | 176 | |
| 177 | // The profile is a test listing of methods. |
| 178 | // We need to generate the actual binary profile. |
| 179 | cmd.FlagWithInput("--create-profile-from=", module.ProfileBootListing.Path()) |
| 180 | |
| 181 | cmd. |
| 182 | Flag("--generate-boot-profile"). |
| 183 | FlagWithInput("--apk=", module.DexPath). |
| 184 | Flag("--dex-location="+module.DexLocation). |
| 185 | FlagWithOutput("--reference-profile-file=", profilePath) |
| 186 | |
| 187 | if !module.ProfileIsTextListing { |
| 188 | cmd.Text(fmt.Sprintf(`|| echo "Profile out of date for %s"`, module.DexPath)) |
| 189 | } |
| 190 | rule.Install(profilePath, profileInstalledPath) |
| 191 | |
| 192 | return profilePath |
| 193 | } |
| 194 | |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 195 | func dexpreoptCommand(ctx android.PathContext, globalSoong *GlobalSoongConfig, global *GlobalConfig, |
| 196 | module *ModuleConfig, rule *android.RuleBuilder, archIdx int, profile android.WritablePath, |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 197 | appImage bool, generateDM bool) { |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 198 | |
| 199 | arch := module.Archs[archIdx] |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 200 | |
| 201 | // HACK: make soname in Soong-generated .odex files match Make. |
| 202 | base := filepath.Base(module.DexLocation) |
| 203 | if filepath.Ext(base) == ".jar" { |
| 204 | base = "javalib.jar" |
| 205 | } else if filepath.Ext(base) == ".apk" { |
| 206 | base = "package.apk" |
| 207 | } |
| 208 | |
| 209 | toOdexPath := func(path string) string { |
| 210 | return filepath.Join( |
| 211 | filepath.Dir(path), |
| 212 | "oat", |
Colin Cross | 74ba962 | 2019-02-11 15:11:14 -0800 | [diff] [blame] | 213 | arch.String(), |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 214 | pathtools.ReplaceExtension(filepath.Base(path), "odex")) |
| 215 | } |
| 216 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 217 | odexPath := module.BuildPath.InSameDir(ctx, "oat", arch.String(), pathtools.ReplaceExtension(base, "odex")) |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 218 | odexInstallPath := toOdexPath(module.DexLocation) |
| 219 | if odexOnSystemOther(module, global) { |
Anton Hansson | 43ab0bc | 2019-10-03 14:18:45 +0100 | [diff] [blame] | 220 | odexInstallPath = filepath.Join(SystemOtherPartition, odexInstallPath) |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 221 | } |
| 222 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 223 | vdexPath := odexPath.ReplaceExtension(ctx, "vdex") |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 224 | vdexInstallPath := pathtools.ReplaceExtension(odexInstallPath, "vdex") |
| 225 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 226 | invocationPath := odexPath.ReplaceExtension(ctx, "invocation") |
Alex Light | 5de4196 | 2018-12-18 15:16:26 -0800 | [diff] [blame] | 227 | |
Ulya Trafimovich | dacc6c5 | 2020-03-11 11:59:34 +0000 | [diff] [blame] | 228 | systemServerJars := NonUpdatableSystemServerJars(ctx, global) |
| 229 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 230 | // The class loader context using paths in the build |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 231 | var classLoaderContextHost android.Paths |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 232 | |
| 233 | // The class loader context using paths as they will be on the device |
| 234 | var classLoaderContextTarget []string |
| 235 | |
| 236 | // Extra paths that will be appended to the class loader if the APK manifest has targetSdkVersion < 28 |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 237 | var conditionalClassLoaderContextHost28 android.Paths |
Nicolas Geoffray | 05aa7d2 | 2018-12-18 14:15:12 +0000 | [diff] [blame] | 238 | var conditionalClassLoaderContextTarget28 []string |
| 239 | |
| 240 | // Extra paths that will be appended to the class loader if the APK manifest has targetSdkVersion < 29 |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 241 | var conditionalClassLoaderContextHost29 android.Paths |
Nicolas Geoffray | 05aa7d2 | 2018-12-18 14:15:12 +0000 | [diff] [blame] | 242 | var conditionalClassLoaderContextTarget29 []string |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 243 | |
Ulya Trafimovich | c9af538 | 2020-05-29 15:35:06 +0100 | [diff] [blame^] | 244 | // Extra paths that will be appended to the class loader if the APK manifest has targetSdkVersion < 30 |
| 245 | var conditionalClassLoaderContextHost30 android.Paths |
| 246 | var conditionalClassLoaderContextTarget30 []string |
| 247 | |
Ulya Trafimovich | dacc6c5 | 2020-03-11 11:59:34 +0000 | [diff] [blame] | 248 | // A flag indicating if the '&' class loader context is used. |
| 249 | unknownClassLoaderContext := false |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 250 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 251 | if module.EnforceUsesLibraries { |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 252 | usesLibs := append(copyOf(module.UsesLibraries), module.PresentOptionalUsesLibraries...) |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 253 | |
| 254 | // Create class loader context for dex2oat from uses libraries and filtered optional libraries |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 255 | for _, l := range usesLibs { |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 256 | |
| 257 | classLoaderContextHost = append(classLoaderContextHost, |
| 258 | pathForLibrary(module, l)) |
| 259 | classLoaderContextTarget = append(classLoaderContextTarget, |
| 260 | filepath.Join("/system/framework", l+".jar")) |
| 261 | } |
| 262 | |
Ulya Trafimovich | df00dde | 2020-05-29 14:55:02 +0100 | [diff] [blame] | 263 | // org.apache.http.legacy contains classes that were in the default classpath until API 28. |
| 264 | // If the targetSdkVersion in the manifest or APK is < 28, and the module does not explicitly |
| 265 | // depend on org.apache.http.legacy, then implicitly add it to the classpath for dexpreopt. |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 266 | const httpLegacy = "org.apache.http.legacy" |
Ulya Trafimovich | df00dde | 2020-05-29 14:55:02 +0100 | [diff] [blame] | 267 | if !contains(usesLibs, httpLegacy) { |
Nicolas Geoffray | 05aa7d2 | 2018-12-18 14:15:12 +0000 | [diff] [blame] | 268 | conditionalClassLoaderContextHost28 = append(conditionalClassLoaderContextHost28, |
Ulya Trafimovich | df00dde | 2020-05-29 14:55:02 +0100 | [diff] [blame] | 269 | pathForLibrary(module, httpLegacy)) |
Nicolas Geoffray | 05aa7d2 | 2018-12-18 14:15:12 +0000 | [diff] [blame] | 270 | conditionalClassLoaderContextTarget28 = append(conditionalClassLoaderContextTarget28, |
Ulya Trafimovich | df00dde | 2020-05-29 14:55:02 +0100 | [diff] [blame] | 271 | filepath.Join("/system/framework", httpLegacy+".jar")) |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 272 | } |
Nicolas Geoffray | 05aa7d2 | 2018-12-18 14:15:12 +0000 | [diff] [blame] | 273 | |
Colin Cross | 38b9685 | 2019-05-22 10:21:09 -0700 | [diff] [blame] | 274 | // android.hidl.base-V1.0-java and android.hidl.manager-V1.0 contain classes that were in the default |
| 275 | // classpath until API 29. If the targetSdkVersion in the manifest or APK is < 29 then implicitly add |
| 276 | // the classes to the classpath for dexpreopt. |
Ulya Trafimovich | df00dde | 2020-05-29 14:55:02 +0100 | [diff] [blame] | 277 | const hidlBase = "android.hidl.base-V1.0-java" |
| 278 | const hidlManager = "android.hidl.manager-V1.0-java" |
Nicolas Geoffray | 05aa7d2 | 2018-12-18 14:15:12 +0000 | [diff] [blame] | 279 | conditionalClassLoaderContextHost29 = append(conditionalClassLoaderContextHost29, |
Alex Light | 5de4196 | 2018-12-18 15:16:26 -0800 | [diff] [blame] | 280 | pathForLibrary(module, hidlManager)) |
Nicolas Geoffray | 05aa7d2 | 2018-12-18 14:15:12 +0000 | [diff] [blame] | 281 | conditionalClassLoaderContextTarget29 = append(conditionalClassLoaderContextTarget29, |
| 282 | filepath.Join("/system/framework", hidlManager+".jar")) |
| 283 | conditionalClassLoaderContextHost29 = append(conditionalClassLoaderContextHost29, |
Alex Light | 5de4196 | 2018-12-18 15:16:26 -0800 | [diff] [blame] | 284 | pathForLibrary(module, hidlBase)) |
Nicolas Geoffray | 05aa7d2 | 2018-12-18 14:15:12 +0000 | [diff] [blame] | 285 | conditionalClassLoaderContextTarget29 = append(conditionalClassLoaderContextTarget29, |
| 286 | filepath.Join("/system/framework", hidlBase+".jar")) |
Ulya Trafimovich | c9af538 | 2020-05-29 15:35:06 +0100 | [diff] [blame^] | 287 | |
| 288 | // android.test.base contains classes that were in the default classpath until API 30. |
| 289 | // If the targetSdkVersion in the manifest or APK is < 30 then implicitly add it to the |
| 290 | // classpath for dexpreopt. |
| 291 | const testBase = "android.test.base" |
| 292 | if !contains(usesLibs, testBase) { |
| 293 | conditionalClassLoaderContextHost30 = append(conditionalClassLoaderContextHost30, |
| 294 | pathForLibrary(module, testBase)) |
| 295 | conditionalClassLoaderContextTarget30 = append(conditionalClassLoaderContextTarget30, |
| 296 | filepath.Join("/system/framework", testBase+".jar")) |
| 297 | } |
Ulya Trafimovich | dacc6c5 | 2020-03-11 11:59:34 +0000 | [diff] [blame] | 298 | } else if jarIndex := android.IndexList(module.Name, systemServerJars); jarIndex >= 0 { |
| 299 | // System server jars should be dexpreopted together: class loader context of each jar |
| 300 | // should include all preceding jars on the system server classpath. |
| 301 | for _, otherJar := range systemServerJars[:jarIndex] { |
| 302 | classLoaderContextHost = append(classLoaderContextHost, SystemServerDexJarHostPath(ctx, otherJar)) |
| 303 | classLoaderContextTarget = append(classLoaderContextTarget, "/system/framework/"+otherJar+".jar") |
Ulya Trafimovich | f3ff010 | 2019-12-03 15:39:23 +0000 | [diff] [blame] | 304 | } |
| 305 | |
Ulya Trafimovich | dacc6c5 | 2020-03-11 11:59:34 +0000 | [diff] [blame] | 306 | // Copy the system server jar to a predefined location where dex2oat will find it. |
| 307 | dexPathHost := SystemServerDexJarHostPath(ctx, module.Name) |
| 308 | rule.Command().Text("mkdir -p").Flag(filepath.Dir(dexPathHost.String())) |
| 309 | rule.Command().Text("cp -f").Input(module.DexPath).Output(dexPathHost) |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 310 | } else { |
| 311 | // Pass special class loader context to skip the classpath and collision check. |
| 312 | // This will get removed once LOCAL_USES_LIBRARIES is enforced. |
| 313 | // Right now LOCAL_USES_LIBRARIES is opt in, for the case where it's not specified we still default |
| 314 | // to the &. |
Ulya Trafimovich | dacc6c5 | 2020-03-11 11:59:34 +0000 | [diff] [blame] | 315 | unknownClassLoaderContext = true |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 316 | } |
| 317 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 318 | rule.Command().FlagWithArg("mkdir -p ", filepath.Dir(odexPath.String())) |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 319 | rule.Command().FlagWithOutput("rm -f ", odexPath) |
| 320 | // Set values in the environment of the rule. These may be modified by construct_context.sh. |
Ulya Trafimovich | dacc6c5 | 2020-03-11 11:59:34 +0000 | [diff] [blame] | 321 | if unknownClassLoaderContext { |
| 322 | rule.Command(). |
| 323 | Text(`class_loader_context_arg=--class-loader-context=\&`). |
| 324 | Text(`stored_class_loader_context_arg=""`) |
Ulya Trafimovich | f3ff010 | 2019-12-03 15:39:23 +0000 | [diff] [blame] | 325 | } else { |
Ulya Trafimovich | dacc6c5 | 2020-03-11 11:59:34 +0000 | [diff] [blame] | 326 | rule.Command(). |
| 327 | Text("class_loader_context_arg=--class-loader-context=PCL[" + strings.Join(classLoaderContextHost.Strings(), ":") + "]"). |
| 328 | Implicits(classLoaderContextHost). |
| 329 | Text("stored_class_loader_context_arg=--stored-class-loader-context=PCL[" + strings.Join(classLoaderContextTarget, ":") + "]") |
Ulya Trafimovich | f3ff010 | 2019-12-03 15:39:23 +0000 | [diff] [blame] | 330 | } |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 331 | |
| 332 | if module.EnforceUsesLibraries { |
Colin Cross | 38b9685 | 2019-05-22 10:21:09 -0700 | [diff] [blame] | 333 | if module.ManifestPath != nil { |
| 334 | rule.Command().Text(`target_sdk_version="$(`). |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 335 | Tool(globalSoong.ManifestCheck). |
Colin Cross | 38b9685 | 2019-05-22 10:21:09 -0700 | [diff] [blame] | 336 | Flag("--extract-target-sdk-version"). |
| 337 | Input(module.ManifestPath). |
| 338 | Text(`)"`) |
| 339 | } else { |
| 340 | // No manifest to extract targetSdkVersion from, hope that DexJar is an APK |
| 341 | rule.Command().Text(`target_sdk_version="$(`). |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 342 | Tool(globalSoong.Aapt). |
Colin Cross | 38b9685 | 2019-05-22 10:21:09 -0700 | [diff] [blame] | 343 | Flag("dump badging"). |
| 344 | Input(module.DexPath). |
| 345 | Text(`| grep "targetSdkVersion" | sed -n "s/targetSdkVersion:'\(.*\)'/\1/p"`). |
| 346 | Text(`)"`) |
| 347 | } |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 348 | rule.Command().Textf(`dex_preopt_host_libraries="%s"`, |
| 349 | strings.Join(classLoaderContextHost.Strings(), " ")). |
| 350 | Implicits(classLoaderContextHost) |
| 351 | rule.Command().Textf(`dex_preopt_target_libraries="%s"`, |
| 352 | strings.Join(classLoaderContextTarget, " ")) |
| 353 | rule.Command().Textf(`conditional_host_libs_28="%s"`, |
| 354 | strings.Join(conditionalClassLoaderContextHost28.Strings(), " ")). |
| 355 | Implicits(conditionalClassLoaderContextHost28) |
| 356 | rule.Command().Textf(`conditional_target_libs_28="%s"`, |
| 357 | strings.Join(conditionalClassLoaderContextTarget28, " ")) |
| 358 | rule.Command().Textf(`conditional_host_libs_29="%s"`, |
| 359 | strings.Join(conditionalClassLoaderContextHost29.Strings(), " ")). |
| 360 | Implicits(conditionalClassLoaderContextHost29) |
| 361 | rule.Command().Textf(`conditional_target_libs_29="%s"`, |
| 362 | strings.Join(conditionalClassLoaderContextTarget29, " ")) |
Ulya Trafimovich | c9af538 | 2020-05-29 15:35:06 +0100 | [diff] [blame^] | 363 | rule.Command().Textf(`conditional_host_libs_30="%s"`, |
| 364 | strings.Join(conditionalClassLoaderContextHost30.Strings(), " ")). |
| 365 | Implicits(conditionalClassLoaderContextHost30) |
| 366 | rule.Command().Textf(`conditional_target_libs_30="%s"`, |
| 367 | strings.Join(conditionalClassLoaderContextTarget30, " ")) |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 368 | rule.Command().Text("source").Tool(globalSoong.ConstructContext).Input(module.DexPath) |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 369 | } |
| 370 | |
Nicolas Geoffray | 2464ef4 | 2019-03-05 14:07:07 +0000 | [diff] [blame] | 371 | // Devices that do not have a product partition use a symlink from /product to /system/product. |
| 372 | // Because on-device dexopt will see dex locations starting with /product, we change the paths |
| 373 | // to mimic this behavior. |
| 374 | dexLocationArg := module.DexLocation |
| 375 | if strings.HasPrefix(dexLocationArg, "/system/product/") { |
| 376 | dexLocationArg = strings.TrimPrefix(dexLocationArg, "/system") |
| 377 | } |
| 378 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 379 | cmd := rule.Command(). |
| 380 | Text(`ANDROID_LOG_TAGS="*:e"`). |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 381 | Tool(globalSoong.Dex2oat). |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 382 | Flag("--avoid-storing-invocation"). |
Alex Light | 5de4196 | 2018-12-18 15:16:26 -0800 | [diff] [blame] | 383 | FlagWithOutput("--write-invocation-to=", invocationPath).ImplicitOutput(invocationPath). |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 384 | Flag("--runtime-arg").FlagWithArg("-Xms", global.Dex2oatXms). |
| 385 | Flag("--runtime-arg").FlagWithArg("-Xmx", global.Dex2oatXmx). |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 386 | Flag("--runtime-arg").FlagWithInputList("-Xbootclasspath:", module.PreoptBootClassPathDexFiles, ":"). |
| 387 | Flag("--runtime-arg").FlagWithList("-Xbootclasspath-locations:", module.PreoptBootClassPathDexLocations, ":"). |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 388 | Flag("${class_loader_context_arg}"). |
Ulya Trafimovich | dacc6c5 | 2020-03-11 11:59:34 +0000 | [diff] [blame] | 389 | Flag("${stored_class_loader_context_arg}"). |
Ulya Trafimovich | 3391a1e | 2020-01-03 17:33:17 +0000 | [diff] [blame] | 390 | FlagWithArg("--boot-image=", strings.Join(module.DexPreoptImageLocations, ":")).Implicits(module.DexPreoptImagesDeps[archIdx].Paths()). |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 391 | FlagWithInput("--dex-file=", module.DexPath). |
Nicolas Geoffray | 2464ef4 | 2019-03-05 14:07:07 +0000 | [diff] [blame] | 392 | FlagWithArg("--dex-location=", dexLocationArg). |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 393 | FlagWithOutput("--oat-file=", odexPath).ImplicitOutput(vdexPath). |
| 394 | // Pass an empty directory, dex2oat shouldn't be reading arbitrary files |
| 395 | FlagWithArg("--android-root=", global.EmptyDirectory). |
Colin Cross | 74ba962 | 2019-02-11 15:11:14 -0800 | [diff] [blame] | 396 | FlagWithArg("--instruction-set=", arch.String()). |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 397 | FlagWithArg("--instruction-set-variant=", global.CpuVariant[arch]). |
| 398 | FlagWithArg("--instruction-set-features=", global.InstructionSetFeatures[arch]). |
| 399 | Flag("--no-generate-debug-info"). |
| 400 | Flag("--generate-build-id"). |
| 401 | Flag("--abort-on-hard-verifier-error"). |
| 402 | Flag("--force-determinism"). |
| 403 | FlagWithArg("--no-inline-from=", "core-oj.jar") |
| 404 | |
| 405 | var preoptFlags []string |
| 406 | if len(module.PreoptFlags) > 0 { |
| 407 | preoptFlags = module.PreoptFlags |
| 408 | } else if len(global.PreoptFlags) > 0 { |
| 409 | preoptFlags = global.PreoptFlags |
| 410 | } |
| 411 | |
| 412 | if len(preoptFlags) > 0 { |
| 413 | cmd.Text(strings.Join(preoptFlags, " ")) |
| 414 | } |
| 415 | |
| 416 | if module.UncompressedDex { |
| 417 | cmd.FlagWithArg("--copy-dex-files=", "false") |
| 418 | } |
| 419 | |
Jaewoong Jung | 3aff578 | 2020-02-11 07:54:35 -0800 | [diff] [blame] | 420 | if !android.PrefixInList(preoptFlags, "--compiler-filter=") { |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 421 | var compilerFilter string |
| 422 | if contains(global.SystemServerJars, module.Name) { |
| 423 | // Jars of system server, use the product option if it is set, speed otherwise. |
| 424 | if global.SystemServerCompilerFilter != "" { |
| 425 | compilerFilter = global.SystemServerCompilerFilter |
| 426 | } else { |
| 427 | compilerFilter = "speed" |
| 428 | } |
| 429 | } else if contains(global.SpeedApps, module.Name) || contains(global.SystemServerApps, module.Name) { |
| 430 | // Apps loaded into system server, and apps the product default to being compiled with the |
| 431 | // 'speed' compiler filter. |
| 432 | compilerFilter = "speed" |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 433 | } else if profile != nil { |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 434 | // For non system server jars, use speed-profile when we have a profile. |
| 435 | compilerFilter = "speed-profile" |
| 436 | } else if global.DefaultCompilerFilter != "" { |
| 437 | compilerFilter = global.DefaultCompilerFilter |
| 438 | } else { |
| 439 | compilerFilter = "quicken" |
| 440 | } |
| 441 | cmd.FlagWithArg("--compiler-filter=", compilerFilter) |
| 442 | } |
| 443 | |
| 444 | if generateDM { |
| 445 | cmd.FlagWithArg("--copy-dex-files=", "false") |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 446 | dmPath := module.BuildPath.InSameDir(ctx, "generated.dm") |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 447 | dmInstalledPath := pathtools.ReplaceExtension(module.DexLocation, "dm") |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 448 | tmpPath := module.BuildPath.InSameDir(ctx, "primary.vdex") |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 449 | rule.Command().Text("cp -f").Input(vdexPath).Output(tmpPath) |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 450 | rule.Command().Tool(globalSoong.SoongZip). |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 451 | FlagWithArg("-L", "9"). |
| 452 | FlagWithOutput("-o", dmPath). |
| 453 | Flag("-j"). |
| 454 | Input(tmpPath) |
| 455 | rule.Install(dmPath, dmInstalledPath) |
| 456 | } |
| 457 | |
| 458 | // By default, emit debug info. |
| 459 | debugInfo := true |
| 460 | if global.NoDebugInfo { |
| 461 | // If the global setting suppresses mini-debug-info, disable it. |
| 462 | debugInfo = false |
| 463 | } |
| 464 | |
| 465 | // PRODUCT_SYSTEM_SERVER_DEBUG_INFO overrides WITH_DEXPREOPT_DEBUG_INFO. |
| 466 | // PRODUCT_OTHER_JAVA_DEBUG_INFO overrides WITH_DEXPREOPT_DEBUG_INFO. |
| 467 | if contains(global.SystemServerJars, module.Name) { |
| 468 | if global.AlwaysSystemServerDebugInfo { |
| 469 | debugInfo = true |
| 470 | } else if global.NeverSystemServerDebugInfo { |
| 471 | debugInfo = false |
| 472 | } |
| 473 | } else { |
| 474 | if global.AlwaysOtherDebugInfo { |
| 475 | debugInfo = true |
| 476 | } else if global.NeverOtherDebugInfo { |
| 477 | debugInfo = false |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | // Never enable on eng. |
| 482 | if global.IsEng { |
| 483 | debugInfo = false |
| 484 | } |
| 485 | |
| 486 | if debugInfo { |
| 487 | cmd.Flag("--generate-mini-debug-info") |
| 488 | } else { |
| 489 | cmd.Flag("--no-generate-mini-debug-info") |
| 490 | } |
| 491 | |
| 492 | // Set the compiler reason to 'prebuilt' to identify the oat files produced |
| 493 | // during the build, as opposed to compiled on the device. |
| 494 | cmd.FlagWithArg("--compilation-reason=", "prebuilt") |
| 495 | |
| 496 | if appImage { |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 497 | appImagePath := odexPath.ReplaceExtension(ctx, "art") |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 498 | appImageInstallPath := pathtools.ReplaceExtension(odexInstallPath, "art") |
| 499 | cmd.FlagWithOutput("--app-image-file=", appImagePath). |
| 500 | FlagWithArg("--image-format=", "lz4") |
Mathieu Chartier | 3f7ddbb | 2019-04-29 09:33:50 -0700 | [diff] [blame] | 501 | if !global.DontResolveStartupStrings { |
| 502 | cmd.FlagWithArg("--resolve-startup-const-strings=", "true") |
| 503 | } |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 504 | rule.Install(appImagePath, appImageInstallPath) |
| 505 | } |
| 506 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 507 | if profile != nil { |
| 508 | cmd.FlagWithInput("--profile-file=", profile) |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | rule.Install(odexPath, odexInstallPath) |
| 512 | rule.Install(vdexPath, vdexInstallPath) |
| 513 | } |
| 514 | |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 515 | func shouldGenerateDM(module *ModuleConfig, global *GlobalConfig) bool { |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 516 | // Generating DM files only makes sense for verify, avoid doing for non verify compiler filter APKs. |
| 517 | // No reason to use a dm file if the dex is already uncompressed. |
| 518 | return global.GenerateDMFiles && !module.UncompressedDex && |
| 519 | contains(module.PreoptFlags, "--compiler-filter=verify") |
| 520 | } |
| 521 | |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 522 | func OdexOnSystemOtherByName(name string, dexLocation string, global *GlobalConfig) bool { |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 523 | if !global.HasSystemOther { |
| 524 | return false |
| 525 | } |
| 526 | |
| 527 | if global.SanitizeLite { |
| 528 | return false |
| 529 | } |
| 530 | |
Nicolas Geoffray | fa6e9ec | 2019-02-12 13:12:16 +0000 | [diff] [blame] | 531 | if contains(global.SpeedApps, name) || contains(global.SystemServerApps, name) { |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 532 | return false |
| 533 | } |
| 534 | |
| 535 | for _, f := range global.PatternsOnSystemOther { |
Anton Hansson | d57bd3c | 2019-10-14 16:53:02 +0100 | [diff] [blame] | 536 | if makefileMatch(filepath.Join(SystemPartition, f), dexLocation) { |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 537 | return true |
| 538 | } |
| 539 | } |
| 540 | |
| 541 | return false |
| 542 | } |
| 543 | |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 544 | func odexOnSystemOther(module *ModuleConfig, global *GlobalConfig) bool { |
Nicolas Geoffray | fa6e9ec | 2019-02-12 13:12:16 +0000 | [diff] [blame] | 545 | return OdexOnSystemOtherByName(module.Name, module.DexLocation, global) |
| 546 | } |
| 547 | |
Colin Cross | c7e40aa | 2019-02-08 21:37:00 -0800 | [diff] [blame] | 548 | // PathToLocation converts .../system/framework/arm64/boot.art to .../system/framework/boot.art |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 549 | func PathToLocation(path android.Path, arch android.ArchType) string { |
| 550 | pathArch := filepath.Base(filepath.Dir(path.String())) |
Colin Cross | 74ba962 | 2019-02-11 15:11:14 -0800 | [diff] [blame] | 551 | if pathArch != arch.String() { |
| 552 | panic(fmt.Errorf("last directory in %q must be %q", path, arch.String())) |
Colin Cross | c7e40aa | 2019-02-08 21:37:00 -0800 | [diff] [blame] | 553 | } |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 554 | return filepath.Join(filepath.Dir(filepath.Dir(path.String())), filepath.Base(path.String())) |
Colin Cross | c7e40aa | 2019-02-08 21:37:00 -0800 | [diff] [blame] | 555 | } |
| 556 | |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 557 | func pathForLibrary(module *ModuleConfig, lib string) android.Path { |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 558 | path, ok := module.LibraryPaths[lib] |
| 559 | if !ok { |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 560 | panic(fmt.Errorf("unknown library path for %q", lib)) |
| 561 | } |
| 562 | return path |
| 563 | } |
| 564 | |
| 565 | func makefileMatch(pattern, s string) bool { |
| 566 | percent := strings.IndexByte(pattern, '%') |
| 567 | switch percent { |
| 568 | case -1: |
| 569 | return pattern == s |
| 570 | case len(pattern) - 1: |
| 571 | return strings.HasPrefix(s, pattern[:len(pattern)-1]) |
| 572 | default: |
| 573 | panic(fmt.Errorf("unsupported makefile pattern %q", pattern)) |
| 574 | } |
| 575 | } |
| 576 | |
Ulyana Trafimovich | f2cb7e9 | 2019-11-27 12:26:49 +0000 | [diff] [blame] | 577 | // Expected format for apexJarValue = <apex name>:<jar name> |
Ulya Trafimovich | 8640ab9 | 2020-05-11 18:06:15 +0100 | [diff] [blame] | 578 | func GetJarLocationFromApexJarPair(ctx android.PathContext, apexJarValue string) string { |
| 579 | apex, jar := android.SplitApexJarPair(ctx, apexJarValue) |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 580 | return filepath.Join("/apex", apex, "javalib", jar+".jar") |
Roshan Pius | ccc26ef | 2019-11-27 09:37:46 -0800 | [diff] [blame] | 581 | } |
| 582 | |
Ulya Trafimovich | f3ff010 | 2019-12-03 15:39:23 +0000 | [diff] [blame] | 583 | var nonUpdatableSystemServerJarsKey = android.NewOnceKey("nonUpdatableSystemServerJars") |
| 584 | |
| 585 | // TODO: eliminate the superficial global config parameter by moving global config definition |
| 586 | // from java subpackage to dexpreopt. |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 587 | func NonUpdatableSystemServerJars(ctx android.PathContext, global *GlobalConfig) []string { |
Ulya Trafimovich | f3ff010 | 2019-12-03 15:39:23 +0000 | [diff] [blame] | 588 | return ctx.Config().Once(nonUpdatableSystemServerJarsKey, func() interface{} { |
| 589 | return android.RemoveListFromList(global.SystemServerJars, |
Ulya Trafimovich | 8640ab9 | 2020-05-11 18:06:15 +0100 | [diff] [blame] | 590 | android.GetJarsFromApexJarPairs(ctx, global.UpdatableSystemServerJars)) |
Ulya Trafimovich | f3ff010 | 2019-12-03 15:39:23 +0000 | [diff] [blame] | 591 | }).([]string) |
| 592 | } |
| 593 | |
Ulya Trafimovich | dacc6c5 | 2020-03-11 11:59:34 +0000 | [diff] [blame] | 594 | // A predefined location for the system server dex jars. This is needed in order to generate |
| 595 | // class loader context for dex2oat, as the path to the jar in the Soong module may be unknown |
| 596 | // at that time (Soong processes the jars in dependency order, which may be different from the |
| 597 | // the system server classpath order). |
| 598 | func SystemServerDexJarHostPath(ctx android.PathContext, jar string) android.OutputPath { |
Ulya Trafimovich | 6cf2c0c | 2020-04-24 12:15:20 +0100 | [diff] [blame] | 599 | if DexpreoptRunningInSoong { |
| 600 | // Soong module, just use the default output directory $OUT/soong. |
| 601 | return android.PathForOutput(ctx, "system_server_dexjars", jar+".jar") |
| 602 | } else { |
| 603 | // Make module, default output directory is $OUT (passed via the "null config" created |
| 604 | // by dexpreopt_gen). Append Soong subdirectory to match Soong module paths. |
| 605 | return android.PathForOutput(ctx, "soong", "system_server_dexjars", jar+".jar") |
| 606 | } |
Ulya Trafimovich | dacc6c5 | 2020-03-11 11:59:34 +0000 | [diff] [blame] | 607 | } |
| 608 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 609 | func contains(l []string, s string) bool { |
| 610 | for _, e := range l { |
| 611 | if e == s { |
| 612 | return true |
| 613 | } |
| 614 | } |
| 615 | return false |
| 616 | } |
| 617 | |
Colin Cross | 454c087 | 2019-02-15 23:03:34 -0800 | [diff] [blame] | 618 | var copyOf = android.CopyOf |