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