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