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 | package dexpreopt |
| 16 | |
| 17 | import ( |
| 18 | "encoding/json" |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 19 | "fmt" |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 20 | "strings" |
Colin Cross | 74ba962 | 2019-02-11 15:11:14 -0800 | [diff] [blame] | 21 | |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 22 | "github.com/google/blueprint" |
| 23 | |
Colin Cross | 74ba962 | 2019-02-11 15:11:14 -0800 | [diff] [blame] | 24 | "android/soong/android" |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 25 | ) |
| 26 | |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 27 | // GlobalConfig stores the configuration for dex preopting. The fields are set |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 28 | // from product variables via dex_preopt_config.mk. |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 29 | type GlobalConfig struct { |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 30 | DisablePreopt bool // disable preopt for all modules |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 31 | DisablePreoptModules []string // modules with preopt disabled by product-specific config |
| 32 | |
| 33 | OnlyPreoptBootImageAndSystemServer bool // only preopt jars in the boot image or system server |
| 34 | |
Vladimir Marko | 40139d6 | 2020-02-06 15:14:29 +0000 | [diff] [blame] | 35 | UseArtImage bool // use the art image (use other boot class path dex files without image) |
| 36 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 37 | HasSystemOther bool // store odex files that match PatternsOnSystemOther on the system_other partition |
| 38 | PatternsOnSystemOther []string // patterns (using '%' to denote a prefix match) to put odex on the system_other partition |
| 39 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 40 | DisableGenerateProfile bool // don't generate profiles |
| 41 | ProfileDir string // directory to find profiles in |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 42 | |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 43 | BootJars android.ConfiguredJarList // modules for jars that form the boot class path |
| 44 | UpdatableBootJars android.ConfiguredJarList // jars within apex that form the boot class path |
Vladimir Marko | d2ee532 | 2018-12-19 17:57:57 +0000 | [diff] [blame] | 45 | |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 46 | ArtApexJars android.ConfiguredJarList // modules for jars that are in the ART APEX |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 47 | |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 48 | SystemServerJars []string // jars that form the system server |
| 49 | SystemServerApps []string // apps that are loaded into system server |
| 50 | UpdatableSystemServerJars android.ConfiguredJarList // jars within apex that are loaded into system server |
| 51 | SpeedApps []string // apps that should be speed optimized |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 52 | |
Ulya Trafimovich | cd3203f | 2020-03-27 11:30:00 +0000 | [diff] [blame] | 53 | BrokenSuboptimalOrderOfSystemServerJars bool // if true, sub-optimal order does not cause a build error |
| 54 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 55 | PreoptFlags []string // global dex2oat flags that should be used if no module-specific dex2oat flags are specified |
| 56 | |
| 57 | DefaultCompilerFilter string // default compiler filter to pass to dex2oat, overridden by --compiler-filter= in module-specific dex2oat flags |
| 58 | SystemServerCompilerFilter string // default compiler filter to pass to dex2oat for system server jars |
| 59 | |
Nicolas Geoffray | c1bf724 | 2019-10-18 14:51:38 +0100 | [diff] [blame] | 60 | GenerateDMFiles bool // generate Dex Metadata files |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 61 | |
| 62 | NoDebugInfo bool // don't generate debug info by default |
Mathieu Chartier | 3f7ddbb | 2019-04-29 09:33:50 -0700 | [diff] [blame] | 63 | DontResolveStartupStrings bool // don't resolve string literals loaded during application startup. |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 64 | AlwaysSystemServerDebugInfo bool // always generate mini debug info for system server modules (overrides NoDebugInfo=true) |
| 65 | NeverSystemServerDebugInfo bool // never generate mini debug info for system server modules (overrides NoDebugInfo=false) |
| 66 | AlwaysOtherDebugInfo bool // always generate mini debug info for non-system server modules (overrides NoDebugInfo=true) |
| 67 | NeverOtherDebugInfo bool // never generate mini debug info for non-system server modules (overrides NoDebugInfo=true) |
| 68 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 69 | IsEng bool // build is a eng variant |
| 70 | SanitizeLite bool // build is the second phase of a SANITIZE_LITE build |
| 71 | |
| 72 | DefaultAppImages bool // build app images (TODO: .art files?) by default |
| 73 | |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 74 | Dex2oatXmx string // max heap size for dex2oat |
| 75 | Dex2oatXms string // initial heap size for dex2oat |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 76 | |
| 77 | EmptyDirectory string // path to an empty directory |
| 78 | |
Colin Cross | 74ba962 | 2019-02-11 15:11:14 -0800 | [diff] [blame] | 79 | CpuVariant map[android.ArchType]string // cpu variant for each architecture |
| 80 | InstructionSetFeatures map[android.ArchType]string // instruction set for each architecture |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 81 | |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 82 | // Only used for boot image |
Mathieu Chartier | 6adeee1 | 2019-06-26 10:01:36 -0700 | [diff] [blame] | 83 | DirtyImageObjects android.OptionalPath // path to a dirty-image-objects file |
| 84 | BootImageProfiles android.Paths // path to a boot-image-profile.txt file |
| 85 | BootFlags string // extra flags to pass to dex2oat for the boot image |
| 86 | Dex2oatImageXmx string // max heap size for dex2oat for the boot image |
| 87 | Dex2oatImageXms string // initial heap size for dex2oat for the boot image |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 88 | } |
| 89 | |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 90 | // GlobalSoongConfig contains the global config that is generated from Soong, |
| 91 | // stored in dexpreopt_soong.config. |
| 92 | type GlobalSoongConfig struct { |
| 93 | // Paths to tools possibly used by the generated commands. |
| 94 | Profman android.Path |
| 95 | Dex2oat android.Path |
| 96 | Aapt android.Path |
| 97 | SoongZip android.Path |
| 98 | Zip2zip android.Path |
| 99 | ManifestCheck android.Path |
Colin Cross | 38b9685 | 2019-05-22 10:21:09 -0700 | [diff] [blame] | 100 | ConstructContext android.Path |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 101 | } |
| 102 | |
Ulya Trafimovich | 24813e1 | 2020-10-07 15:05:21 +0100 | [diff] [blame^] | 103 | // These libs are added as <uses-library> dependencies for apps if the targetSdkVersion in the |
| 104 | // app manifest is less than the specified version. This is needed because these libraries haven't |
| 105 | // existed prior to certain SDK version, but classes in them were in bootclasspath jars, etc. |
| 106 | // Some of the compatibility libraries are optional (their <uses-library> tag has "required=false"), |
| 107 | // so that if this library is missing this in not a build or run-time error. |
| 108 | var OrgApacheHttpLegacy = "org.apache.http.legacy" |
| 109 | var AndroidTestBase = "android.test.base" |
| 110 | var AndroidTestMock = "android.test.mock" |
| 111 | var AndroidHidlBase = "android.hidl.base-V1.0-java" |
| 112 | var AndroidHidlManager = "android.hidl.manager-V1.0-java" |
Ulya Trafimovich | 663dc53 | 2020-09-10 12:48:53 +0100 | [diff] [blame] | 113 | |
Ulya Trafimovich | 24813e1 | 2020-10-07 15:05:21 +0100 | [diff] [blame^] | 114 | var OptionalCompatUsesLibs28 = []string{ |
| 115 | OrgApacheHttpLegacy, |
Ulya Trafimovich | 663dc53 | 2020-09-10 12:48:53 +0100 | [diff] [blame] | 116 | } |
Ulya Trafimovich | 24813e1 | 2020-10-07 15:05:21 +0100 | [diff] [blame^] | 117 | var OptionalCompatUsesLibs30 = []string{ |
| 118 | AndroidTestBase, |
| 119 | AndroidTestMock, |
| 120 | } |
| 121 | var CompatUsesLibs29 = []string{ |
| 122 | AndroidHidlBase, |
| 123 | AndroidHidlManager, |
| 124 | } |
| 125 | var OptionalCompatUsesLibs = append(android.CopyOf(OptionalCompatUsesLibs28), OptionalCompatUsesLibs30...) |
| 126 | var CompatUsesLibs = android.CopyOf(CompatUsesLibs29) |
Ulya Trafimovich | 663dc53 | 2020-09-10 12:48:53 +0100 | [diff] [blame] | 127 | |
Ulya Trafimovich | 31e444e | 2020-08-14 17:32:16 +0100 | [diff] [blame] | 128 | const UnknownInstallLibraryPath = "error" |
| 129 | |
Ulya Trafimovich | d4bcea4 | 2020-06-03 14:57:22 +0100 | [diff] [blame] | 130 | // LibraryPath contains paths to the library DEX jar on host and on device. |
| 131 | type LibraryPath struct { |
| 132 | Host android.Path |
| 133 | Device string |
| 134 | } |
| 135 | |
| 136 | // LibraryPaths is a map from library name to on-host and on-device paths to its DEX jar. |
| 137 | type LibraryPaths map[string]*LibraryPath |
| 138 | |
Ulya Trafimovich | fc24ad3 | 2020-08-19 16:32:54 +0100 | [diff] [blame] | 139 | // Add a new library path to the map, unless a path for this library already exists. |
Ulya Trafimovich | 663dc53 | 2020-09-10 12:48:53 +0100 | [diff] [blame] | 140 | // If necessary, check that the build and install paths exist. |
| 141 | func (libPaths LibraryPaths) addLibraryPath(ctx android.ModuleContext, lib string, |
| 142 | hostPath, installPath android.Path, strict bool) { |
| 143 | |
| 144 | // If missing dependencies are allowed, the build shouldn't fail when a <uses-library> is |
| 145 | // not found. However, this is likely to result is disabling dexpreopt, as it won't be |
| 146 | // possible to construct class loader context without on-host and on-device library paths. |
| 147 | strict = strict && !ctx.Config().AllowMissingDependencies() |
| 148 | |
| 149 | if hostPath == nil && strict { |
| 150 | android.ReportPathErrorf(ctx, "unknown build path to <uses-library> '%s'", lib) |
| 151 | } |
| 152 | |
| 153 | if installPath == nil { |
| 154 | if android.InList(lib, CompatUsesLibs) || android.InList(lib, OptionalCompatUsesLibs) { |
| 155 | // Assume that compatibility libraries are installed in /system/framework. |
| 156 | installPath = android.PathForModuleInstall(ctx, "framework", lib+".jar") |
| 157 | } else if strict { |
| 158 | android.ReportPathErrorf(ctx, "unknown install path to <uses-library> '%s'", lib) |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | // Add a library only if the build and install path to it is known. |
Ulya Trafimovich | fc24ad3 | 2020-08-19 16:32:54 +0100 | [diff] [blame] | 163 | if _, present := libPaths[lib]; !present { |
Ulya Trafimovich | 31e444e | 2020-08-14 17:32:16 +0100 | [diff] [blame] | 164 | var devicePath string |
| 165 | if installPath != nil { |
| 166 | devicePath = android.InstallPathToOnDevicePath(ctx, installPath.(android.InstallPath)) |
| 167 | } else { |
| 168 | // For some stub libraries the only known thing is the name of their implementation |
| 169 | // library, but the library itself is unavailable (missing or part of a prebuilt). In |
| 170 | // such cases we still need to add the library to <uses-library> tags in the manifest, |
| 171 | // but we cannot use if for dexpreopt. |
| 172 | devicePath = UnknownInstallLibraryPath |
| 173 | } |
Ulya Trafimovich | fc24ad3 | 2020-08-19 16:32:54 +0100 | [diff] [blame] | 174 | libPaths[lib] = &LibraryPath{hostPath, devicePath} |
Ulya Trafimovich | 31e444e | 2020-08-14 17:32:16 +0100 | [diff] [blame] | 175 | } |
Ulya Trafimovich | fc24ad3 | 2020-08-19 16:32:54 +0100 | [diff] [blame] | 176 | } |
| 177 | |
Ulya Trafimovich | 663dc53 | 2020-09-10 12:48:53 +0100 | [diff] [blame] | 178 | // Add a new library path to the map. Enforce checks that the library paths exist. |
| 179 | func (libPaths LibraryPaths) AddLibraryPath(ctx android.ModuleContext, lib string, hostPath, installPath android.Path) { |
| 180 | libPaths.addLibraryPath(ctx, lib, hostPath, installPath, true) |
Ulya Trafimovich | fc24ad3 | 2020-08-19 16:32:54 +0100 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | // Add a new library path to the map, if the library exists (name is not nil). |
Ulya Trafimovich | 663dc53 | 2020-09-10 12:48:53 +0100 | [diff] [blame] | 184 | // Don't enforce checks that the library paths exist. Some libraries may be missing from the build, |
| 185 | // but their names still need to be added to <uses-library> tags in the manifest. |
| 186 | func (libPaths LibraryPaths) MaybeAddLibraryPath(ctx android.ModuleContext, lib *string, hostPath, installPath android.Path) { |
Ulya Trafimovich | fc24ad3 | 2020-08-19 16:32:54 +0100 | [diff] [blame] | 187 | if lib != nil { |
Ulya Trafimovich | 663dc53 | 2020-09-10 12:48:53 +0100 | [diff] [blame] | 188 | libPaths.addLibraryPath(ctx, *lib, hostPath, installPath, false) |
Ulya Trafimovich | fc24ad3 | 2020-08-19 16:32:54 +0100 | [diff] [blame] | 189 | } |
Ulya Trafimovich | 31e444e | 2020-08-14 17:32:16 +0100 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | // Add library paths from the second map to the first map (do not override existing entries). |
| 193 | func (libPaths LibraryPaths) AddLibraryPaths(otherPaths LibraryPaths) { |
| 194 | for lib, path := range otherPaths { |
| 195 | if _, present := libPaths[lib]; !present { |
| 196 | libPaths[lib] = path |
| 197 | } |
| 198 | } |
| 199 | } |
| 200 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 201 | type ModuleConfig struct { |
Victor Hsieh | d181c8b | 2019-01-29 13:00:33 -0800 | [diff] [blame] | 202 | Name string |
| 203 | DexLocation string // dex location on device |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 204 | BuildPath android.OutputPath |
| 205 | DexPath android.Path |
Colin Cross | 38b9685 | 2019-05-22 10:21:09 -0700 | [diff] [blame] | 206 | ManifestPath android.Path |
Victor Hsieh | d181c8b | 2019-01-29 13:00:33 -0800 | [diff] [blame] | 207 | UncompressedDex bool |
| 208 | HasApkLibraries bool |
| 209 | PreoptFlags []string |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 210 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 211 | ProfileClassListing android.OptionalPath |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 212 | ProfileIsTextListing bool |
Nicolas Geoffray | e710242 | 2019-07-24 13:19:29 +0100 | [diff] [blame] | 213 | ProfileBootListing android.OptionalPath |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 214 | |
Ulya Trafimovich | 6e82748 | 2020-06-12 14:32:24 +0100 | [diff] [blame] | 215 | EnforceUsesLibraries bool |
| 216 | OptionalUsesLibraries []string |
| 217 | UsesLibraries []string |
| 218 | LibraryPaths LibraryPaths |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 219 | |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 220 | Archs []android.ArchType |
| 221 | DexPreoptImages []android.Path |
| 222 | DexPreoptImagesDeps []android.OutputPaths |
| 223 | DexPreoptImageLocations []string |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 224 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 225 | PreoptBootClassPathDexFiles android.Paths // file paths of boot class path files |
| 226 | PreoptBootClassPathDexLocations []string // virtual locations of boot class path files |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 227 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 228 | PreoptExtractedApk bool // Overrides OnlyPreoptModules |
| 229 | |
| 230 | NoCreateAppImage bool |
| 231 | ForceCreateAppImage bool |
| 232 | |
| 233 | PresignedPrebuilt bool |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 234 | } |
| 235 | |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 236 | type globalSoongConfigSingleton struct{} |
| 237 | |
| 238 | var pctx = android.NewPackageContext("android/soong/dexpreopt") |
| 239 | |
| 240 | func init() { |
| 241 | pctx.Import("android/soong/android") |
| 242 | android.RegisterSingletonType("dexpreopt-soong-config", func() android.Singleton { |
| 243 | return &globalSoongConfigSingleton{} |
| 244 | }) |
| 245 | } |
| 246 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 247 | func constructPath(ctx android.PathContext, path string) android.Path { |
| 248 | buildDirPrefix := ctx.Config().BuildDir() + "/" |
| 249 | if path == "" { |
| 250 | return nil |
| 251 | } else if strings.HasPrefix(path, buildDirPrefix) { |
| 252 | return android.PathForOutput(ctx, strings.TrimPrefix(path, buildDirPrefix)) |
| 253 | } else { |
| 254 | return android.PathForSource(ctx, path) |
| 255 | } |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 256 | } |
| 257 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 258 | func constructPaths(ctx android.PathContext, paths []string) android.Paths { |
| 259 | var ret android.Paths |
| 260 | for _, path := range paths { |
| 261 | ret = append(ret, constructPath(ctx, path)) |
| 262 | } |
| 263 | return ret |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 264 | } |
| 265 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 266 | func constructWritablePath(ctx android.PathContext, path string) android.WritablePath { |
| 267 | if path == "" { |
| 268 | return nil |
| 269 | } |
| 270 | return constructPath(ctx, path).(android.WritablePath) |
| 271 | } |
| 272 | |
Martin Stjernholm | 40f9f3c | 2020-01-20 18:12:23 +0000 | [diff] [blame] | 273 | // ParseGlobalConfig parses the given data assumed to be read from the global |
| 274 | // dexpreopt.config file into a GlobalConfig struct. |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 275 | func ParseGlobalConfig(ctx android.PathContext, data []byte) (*GlobalConfig, error) { |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 276 | type GlobalJSONConfig struct { |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 277 | *GlobalConfig |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 278 | |
| 279 | // Copies of entries in GlobalConfig that are not constructable without extra parameters. They will be |
| 280 | // used to construct the real value manually below. |
Paul Duffin | 7ccacae | 2020-10-23 21:14:20 +0100 | [diff] [blame] | 281 | DirtyImageObjects string |
| 282 | BootImageProfiles []string |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | config := GlobalJSONConfig{} |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 286 | err := json.Unmarshal(data, &config) |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 287 | if err != nil { |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 288 | return config.GlobalConfig, err |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | // Construct paths that require a PathContext. |
| 292 | config.GlobalConfig.DirtyImageObjects = android.OptionalPathForPath(constructPath(ctx, config.DirtyImageObjects)) |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 293 | config.GlobalConfig.BootImageProfiles = constructPaths(ctx, config.BootImageProfiles) |
| 294 | |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 295 | return config.GlobalConfig, nil |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 296 | } |
| 297 | |
Martin Stjernholm | 40f9f3c | 2020-01-20 18:12:23 +0000 | [diff] [blame] | 298 | type globalConfigAndRaw struct { |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 299 | global *GlobalConfig |
Martin Stjernholm | 40f9f3c | 2020-01-20 18:12:23 +0000 | [diff] [blame] | 300 | data []byte |
| 301 | } |
| 302 | |
| 303 | // GetGlobalConfig returns the global dexpreopt.config that's created in the |
| 304 | // make config phase. It is loaded once the first time it is called for any |
| 305 | // ctx.Config(), and returns the same data for all future calls with the same |
| 306 | // ctx.Config(). A value can be inserted for tests using |
| 307 | // setDexpreoptTestGlobalConfig. |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 308 | func GetGlobalConfig(ctx android.PathContext) *GlobalConfig { |
Martin Stjernholm | 40f9f3c | 2020-01-20 18:12:23 +0000 | [diff] [blame] | 309 | return getGlobalConfigRaw(ctx).global |
| 310 | } |
| 311 | |
| 312 | // GetGlobalConfigRawData is the same as GetGlobalConfig, except that it returns |
| 313 | // the literal content of dexpreopt.config. |
| 314 | func GetGlobalConfigRawData(ctx android.PathContext) []byte { |
| 315 | return getGlobalConfigRaw(ctx).data |
| 316 | } |
| 317 | |
| 318 | var globalConfigOnceKey = android.NewOnceKey("DexpreoptGlobalConfig") |
| 319 | var testGlobalConfigOnceKey = android.NewOnceKey("TestDexpreoptGlobalConfig") |
| 320 | |
| 321 | func getGlobalConfigRaw(ctx android.PathContext) globalConfigAndRaw { |
| 322 | return ctx.Config().Once(globalConfigOnceKey, func() interface{} { |
| 323 | if data, err := ctx.Config().DexpreoptGlobalConfig(ctx); err != nil { |
| 324 | panic(err) |
| 325 | } else if data != nil { |
| 326 | globalConfig, err := ParseGlobalConfig(ctx, data) |
| 327 | if err != nil { |
| 328 | panic(err) |
| 329 | } |
| 330 | return globalConfigAndRaw{globalConfig, data} |
| 331 | } |
| 332 | |
| 333 | // No global config filename set, see if there is a test config set |
| 334 | return ctx.Config().Once(testGlobalConfigOnceKey, func() interface{} { |
| 335 | // Nope, return a config with preopting disabled |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 336 | return globalConfigAndRaw{&GlobalConfig{ |
Martin Stjernholm | 40f9f3c | 2020-01-20 18:12:23 +0000 | [diff] [blame] | 337 | DisablePreopt: true, |
| 338 | DisableGenerateProfile: true, |
| 339 | }, nil} |
| 340 | }) |
| 341 | }).(globalConfigAndRaw) |
| 342 | } |
| 343 | |
| 344 | // SetTestGlobalConfig sets a GlobalConfig that future calls to GetGlobalConfig |
| 345 | // will return. It must be called before the first call to GetGlobalConfig for |
| 346 | // the config. |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 347 | func SetTestGlobalConfig(config android.Config, globalConfig *GlobalConfig) { |
Martin Stjernholm | 40f9f3c | 2020-01-20 18:12:23 +0000 | [diff] [blame] | 348 | config.Once(testGlobalConfigOnceKey, func() interface{} { return globalConfigAndRaw{globalConfig, nil} }) |
| 349 | } |
| 350 | |
| 351 | // ParseModuleConfig parses a per-module dexpreopt.config file into a |
| 352 | // ModuleConfig struct. It is not used in Soong, which receives a ModuleConfig |
| 353 | // struct directly from java/dexpreopt.go. It is used in dexpreopt_gen called |
| 354 | // from Make to read the module dexpreopt.config written in the Make config |
| 355 | // stage. |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 356 | func ParseModuleConfig(ctx android.PathContext, data []byte) (*ModuleConfig, error) { |
Ulya Trafimovich | d4bcea4 | 2020-06-03 14:57:22 +0100 | [diff] [blame] | 357 | type jsonLibraryPath struct { |
| 358 | Host string |
| 359 | Device string |
| 360 | } |
| 361 | |
| 362 | type jsonLibraryPaths map[string]jsonLibraryPath |
| 363 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 364 | type ModuleJSONConfig struct { |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 365 | *ModuleConfig |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 366 | |
| 367 | // Copies of entries in ModuleConfig that are not constructable without extra parameters. They will be |
| 368 | // used to construct the real value manually below. |
| 369 | BuildPath string |
| 370 | DexPath string |
Colin Cross | 38b9685 | 2019-05-22 10:21:09 -0700 | [diff] [blame] | 371 | ManifestPath string |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 372 | ProfileClassListing string |
Ulya Trafimovich | d4bcea4 | 2020-06-03 14:57:22 +0100 | [diff] [blame] | 373 | LibraryPaths jsonLibraryPaths |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 374 | DexPreoptImages []string |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 375 | DexPreoptImageLocations []string |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 376 | PreoptBootClassPathDexFiles []string |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 377 | } |
| 378 | |
Ulya Trafimovich | d4bcea4 | 2020-06-03 14:57:22 +0100 | [diff] [blame] | 379 | // convert JSON map of library paths to LibraryPaths |
| 380 | constructLibraryPaths := func(ctx android.PathContext, paths jsonLibraryPaths) LibraryPaths { |
| 381 | m := LibraryPaths{} |
| 382 | for lib, path := range paths { |
| 383 | m[lib] = &LibraryPath{ |
| 384 | constructPath(ctx, path.Host), |
| 385 | path.Device, |
| 386 | } |
| 387 | } |
| 388 | return m |
| 389 | } |
| 390 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 391 | config := ModuleJSONConfig{} |
| 392 | |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 393 | err := json.Unmarshal(data, &config) |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 394 | if err != nil { |
| 395 | return config.ModuleConfig, err |
| 396 | } |
| 397 | |
| 398 | // Construct paths that require a PathContext. |
| 399 | config.ModuleConfig.BuildPath = constructPath(ctx, config.BuildPath).(android.OutputPath) |
| 400 | config.ModuleConfig.DexPath = constructPath(ctx, config.DexPath) |
Colin Cross | 38b9685 | 2019-05-22 10:21:09 -0700 | [diff] [blame] | 401 | config.ModuleConfig.ManifestPath = constructPath(ctx, config.ManifestPath) |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 402 | config.ModuleConfig.ProfileClassListing = android.OptionalPathForPath(constructPath(ctx, config.ProfileClassListing)) |
Ulya Trafimovich | d4bcea4 | 2020-06-03 14:57:22 +0100 | [diff] [blame] | 403 | config.ModuleConfig.LibraryPaths = constructLibraryPaths(ctx, config.LibraryPaths) |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 404 | config.ModuleConfig.DexPreoptImages = constructPaths(ctx, config.DexPreoptImages) |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 405 | config.ModuleConfig.DexPreoptImageLocations = config.DexPreoptImageLocations |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 406 | config.ModuleConfig.PreoptBootClassPathDexFiles = constructPaths(ctx, config.PreoptBootClassPathDexFiles) |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 407 | |
Dan Willemsen | 0f41678 | 2019-06-13 21:44:53 +0000 | [diff] [blame] | 408 | // This needs to exist, but dependencies are already handled in Make, so we don't need to pass them through JSON. |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 409 | config.ModuleConfig.DexPreoptImagesDeps = make([]android.OutputPaths, len(config.ModuleConfig.DexPreoptImages)) |
Dan Willemsen | 0f41678 | 2019-06-13 21:44:53 +0000 | [diff] [blame] | 410 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 411 | return config.ModuleConfig, nil |
| 412 | } |
| 413 | |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 414 | // dex2oatModuleName returns the name of the module to use for the dex2oat host |
| 415 | // tool. It should be a binary module with public visibility that is compiled |
| 416 | // and installed for host. |
| 417 | func dex2oatModuleName(config android.Config) string { |
| 418 | // Default to the debug variant of dex2oat to help find bugs. |
| 419 | // Set USE_DEX2OAT_DEBUG to false for only building non-debug versions. |
| 420 | if config.Getenv("USE_DEX2OAT_DEBUG") == "false" { |
| 421 | return "dex2oat" |
| 422 | } else { |
| 423 | return "dex2oatd" |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | var dex2oatDepTag = struct { |
| 428 | blueprint.BaseDependencyTag |
| 429 | }{} |
| 430 | |
Martin Stjernholm | 6d41527 | 2020-01-31 17:10:36 +0000 | [diff] [blame] | 431 | // RegisterToolDeps adds the necessary dependencies to binary modules for tools |
| 432 | // that are required later when Get(Cached)GlobalSoongConfig is called. It |
| 433 | // should be called from a mutator that's registered with |
| 434 | // android.RegistrationContext.FinalDepsMutators. |
| 435 | func RegisterToolDeps(ctx android.BottomUpMutatorContext) { |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 436 | dex2oatBin := dex2oatModuleName(ctx.Config()) |
| 437 | v := ctx.Config().BuildOSTarget.Variations() |
| 438 | ctx.AddFarVariationDependencies(v, dex2oatDepTag, dex2oatBin) |
| 439 | } |
| 440 | |
| 441 | func dex2oatPathFromDep(ctx android.ModuleContext) android.Path { |
| 442 | dex2oatBin := dex2oatModuleName(ctx.Config()) |
| 443 | |
Martin Stjernholm | c004862 | 2020-08-18 17:37:41 +0100 | [diff] [blame] | 444 | // Find the right dex2oat module, trying to follow PrebuiltDepTag from source |
| 445 | // to prebuilt if there is one. We wouldn't have to do this if the |
| 446 | // prebuilt_postdeps mutator that replaces source deps with prebuilt deps was |
| 447 | // run after RegisterToolDeps above, but changing that leads to ordering |
| 448 | // problems between mutators (RegisterToolDeps needs to run late to act on |
| 449 | // final variants, while prebuilt_postdeps needs to run before many of the |
| 450 | // PostDeps mutators, like the APEX mutators). Hence we need to dig out the |
| 451 | // prebuilt explicitly here instead. |
| 452 | var dex2oatModule android.Module |
| 453 | ctx.WalkDeps(func(child, parent android.Module) bool { |
| 454 | if parent == ctx.Module() && ctx.OtherModuleDependencyTag(child) == dex2oatDepTag { |
| 455 | // Found the source module, or prebuilt module that has replaced the source. |
| 456 | dex2oatModule = child |
| 457 | if p, ok := child.(android.PrebuiltInterface); ok && p.Prebuilt() != nil { |
| 458 | return false // If it's the prebuilt we're done. |
| 459 | } else { |
| 460 | return true // Recurse to check if the source has a prebuilt dependency. |
| 461 | } |
| 462 | } |
| 463 | if parent == dex2oatModule && ctx.OtherModuleDependencyTag(child) == android.PrebuiltDepTag { |
| 464 | if p, ok := child.(android.PrebuiltInterface); ok && p.Prebuilt() != nil && p.Prebuilt().UsePrebuilt() { |
| 465 | dex2oatModule = child // Found a prebuilt that should be used. |
| 466 | } |
| 467 | } |
| 468 | return false |
| 469 | }) |
| 470 | |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 471 | if dex2oatModule == nil { |
| 472 | // If this happens there's probably a missing call to AddToolDeps in DepsMutator. |
| 473 | panic(fmt.Sprintf("Failed to lookup %s dependency", dex2oatBin)) |
| 474 | } |
| 475 | |
| 476 | dex2oatPath := dex2oatModule.(android.HostToolProvider).HostToolPath() |
| 477 | if !dex2oatPath.Valid() { |
| 478 | panic(fmt.Sprintf("Failed to find host tool path in %s", dex2oatModule)) |
| 479 | } |
| 480 | |
| 481 | return dex2oatPath.Path() |
| 482 | } |
| 483 | |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 484 | // createGlobalSoongConfig creates a GlobalSoongConfig from the current context. |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 485 | // Should not be used in dexpreopt_gen. |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 486 | func createGlobalSoongConfig(ctx android.ModuleContext) *GlobalSoongConfig { |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 487 | if ctx.Config().TestProductVariables != nil { |
| 488 | // If we're called in a test there'll be a confusing error from the path |
| 489 | // functions below that gets reported without a stack trace, so let's panic |
| 490 | // properly with a more helpful message. |
| 491 | panic("This should not be called from tests. Please call GlobalSoongConfigForTests somewhere in the test setup.") |
| 492 | } |
| 493 | |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 494 | return &GlobalSoongConfig{ |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 495 | Profman: ctx.Config().HostToolPath(ctx, "profman"), |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 496 | Dex2oat: dex2oatPathFromDep(ctx), |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 497 | Aapt: ctx.Config().HostToolPath(ctx, "aapt"), |
| 498 | SoongZip: ctx.Config().HostToolPath(ctx, "soong_zip"), |
| 499 | Zip2zip: ctx.Config().HostToolPath(ctx, "zip2zip"), |
| 500 | ManifestCheck: ctx.Config().HostToolPath(ctx, "manifest_check"), |
Ulya Trafimovich | 5f364b6 | 2020-06-30 12:39:01 +0100 | [diff] [blame] | 501 | ConstructContext: ctx.Config().HostToolPath(ctx, "construct_context"), |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 502 | } |
| 503 | } |
| 504 | |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 505 | // The main reason for this Once cache for GlobalSoongConfig is to make the |
| 506 | // dex2oat path available to singletons. In ordinary modules we get it through a |
| 507 | // dex2oatDepTag dependency, but in singletons there's no simple way to do the |
| 508 | // same thing and ensure the right variant is selected, hence this cache to make |
| 509 | // the resolved path available to singletons. This means we depend on there |
| 510 | // being at least one ordinary module with a dex2oatDepTag dependency. |
| 511 | // |
| 512 | // TODO(b/147613152): Implement a way to deal with dependencies from singletons, |
| 513 | // and then possibly remove this cache altogether (but the use in |
| 514 | // GlobalSoongConfigForTests also needs to be rethought). |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 515 | var globalSoongConfigOnceKey = android.NewOnceKey("DexpreoptGlobalSoongConfig") |
| 516 | |
| 517 | // GetGlobalSoongConfig creates a GlobalSoongConfig the first time it's called, |
| 518 | // and later returns the same cached instance. |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 519 | func GetGlobalSoongConfig(ctx android.ModuleContext) *GlobalSoongConfig { |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 520 | globalSoong := ctx.Config().Once(globalSoongConfigOnceKey, func() interface{} { |
| 521 | return createGlobalSoongConfig(ctx) |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 522 | }).(*GlobalSoongConfig) |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 523 | |
| 524 | // Always resolve the tool path from the dependency, to ensure that every |
| 525 | // module has the dependency added properly. |
| 526 | myDex2oat := dex2oatPathFromDep(ctx) |
| 527 | if myDex2oat != globalSoong.Dex2oat { |
| 528 | panic(fmt.Sprintf("Inconsistent dex2oat path in cached config: expected %s, got %s", globalSoong.Dex2oat, myDex2oat)) |
| 529 | } |
| 530 | |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 531 | return globalSoong |
| 532 | } |
| 533 | |
| 534 | // GetCachedGlobalSoongConfig returns a cached GlobalSoongConfig created by an |
| 535 | // earlier GetGlobalSoongConfig call. This function works with any context |
| 536 | // compatible with a basic PathContext, since it doesn't try to create a |
Martin Stjernholm | 6d41527 | 2020-01-31 17:10:36 +0000 | [diff] [blame] | 537 | // GlobalSoongConfig with the proper paths (which requires a full |
| 538 | // ModuleContext). If there has been no prior call to GetGlobalSoongConfig, nil |
| 539 | // is returned. |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 540 | func GetCachedGlobalSoongConfig(ctx android.PathContext) *GlobalSoongConfig { |
Martin Stjernholm | 6d41527 | 2020-01-31 17:10:36 +0000 | [diff] [blame] | 541 | return ctx.Config().Once(globalSoongConfigOnceKey, func() interface{} { |
| 542 | return (*GlobalSoongConfig)(nil) |
| 543 | }).(*GlobalSoongConfig) |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 544 | } |
| 545 | |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 546 | type globalJsonSoongConfig struct { |
| 547 | Profman string |
| 548 | Dex2oat string |
| 549 | Aapt string |
| 550 | SoongZip string |
| 551 | Zip2zip string |
| 552 | ManifestCheck string |
| 553 | ConstructContext string |
| 554 | } |
| 555 | |
Martin Stjernholm | 40f9f3c | 2020-01-20 18:12:23 +0000 | [diff] [blame] | 556 | // ParseGlobalSoongConfig parses the given data assumed to be read from the |
| 557 | // global dexpreopt_soong.config file into a GlobalSoongConfig struct. It is |
| 558 | // only used in dexpreopt_gen. |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 559 | func ParseGlobalSoongConfig(ctx android.PathContext, data []byte) (*GlobalSoongConfig, error) { |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 560 | var jc globalJsonSoongConfig |
| 561 | |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 562 | err := json.Unmarshal(data, &jc) |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 563 | if err != nil { |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 564 | return &GlobalSoongConfig{}, err |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 565 | } |
| 566 | |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 567 | config := &GlobalSoongConfig{ |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 568 | Profman: constructPath(ctx, jc.Profman), |
| 569 | Dex2oat: constructPath(ctx, jc.Dex2oat), |
| 570 | Aapt: constructPath(ctx, jc.Aapt), |
| 571 | SoongZip: constructPath(ctx, jc.SoongZip), |
| 572 | Zip2zip: constructPath(ctx, jc.Zip2zip), |
| 573 | ManifestCheck: constructPath(ctx, jc.ManifestCheck), |
| 574 | ConstructContext: constructPath(ctx, jc.ConstructContext), |
| 575 | } |
| 576 | |
| 577 | return config, nil |
| 578 | } |
| 579 | |
| 580 | func (s *globalSoongConfigSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 581 | if GetGlobalConfig(ctx).DisablePreopt { |
| 582 | return |
| 583 | } |
| 584 | |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 585 | config := GetCachedGlobalSoongConfig(ctx) |
Martin Stjernholm | 6d41527 | 2020-01-31 17:10:36 +0000 | [diff] [blame] | 586 | if config == nil { |
| 587 | // No module has enabled dexpreopting, so we assume there will be no calls |
| 588 | // to dexpreopt_gen. |
| 589 | return |
| 590 | } |
| 591 | |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 592 | jc := globalJsonSoongConfig{ |
| 593 | Profman: config.Profman.String(), |
| 594 | Dex2oat: config.Dex2oat.String(), |
| 595 | Aapt: config.Aapt.String(), |
| 596 | SoongZip: config.SoongZip.String(), |
| 597 | Zip2zip: config.Zip2zip.String(), |
| 598 | ManifestCheck: config.ManifestCheck.String(), |
| 599 | ConstructContext: config.ConstructContext.String(), |
| 600 | } |
| 601 | |
| 602 | data, err := json.Marshal(jc) |
| 603 | if err != nil { |
| 604 | ctx.Errorf("failed to JSON marshal GlobalSoongConfig: %v", err) |
| 605 | return |
| 606 | } |
| 607 | |
| 608 | ctx.Build(pctx, android.BuildParams{ |
| 609 | Rule: android.WriteFile, |
| 610 | Output: android.PathForOutput(ctx, "dexpreopt_soong.config"), |
| 611 | Args: map[string]string{ |
| 612 | "content": string(data), |
| 613 | }, |
| 614 | }) |
| 615 | } |
| 616 | |
| 617 | func (s *globalSoongConfigSingleton) MakeVars(ctx android.MakeVarsContext) { |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 618 | if GetGlobalConfig(ctx).DisablePreopt { |
| 619 | return |
| 620 | } |
| 621 | |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 622 | config := GetCachedGlobalSoongConfig(ctx) |
Martin Stjernholm | 6d41527 | 2020-01-31 17:10:36 +0000 | [diff] [blame] | 623 | if config == nil { |
| 624 | return |
| 625 | } |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 626 | |
| 627 | ctx.Strict("DEX2OAT", config.Dex2oat.String()) |
| 628 | ctx.Strict("DEXPREOPT_GEN_DEPS", strings.Join([]string{ |
| 629 | config.Profman.String(), |
| 630 | config.Dex2oat.String(), |
| 631 | config.Aapt.String(), |
| 632 | config.SoongZip.String(), |
| 633 | config.Zip2zip.String(), |
| 634 | config.ManifestCheck.String(), |
| 635 | config.ConstructContext.String(), |
| 636 | }, " ")) |
| 637 | } |
| 638 | |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 639 | func GlobalConfigForTests(ctx android.PathContext) *GlobalConfig { |
| 640 | return &GlobalConfig{ |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 641 | DisablePreopt: false, |
| 642 | DisablePreoptModules: nil, |
| 643 | OnlyPreoptBootImageAndSystemServer: false, |
| 644 | HasSystemOther: false, |
| 645 | PatternsOnSystemOther: nil, |
| 646 | DisableGenerateProfile: false, |
| 647 | ProfileDir: "", |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 648 | BootJars: android.EmptyConfiguredJarList(), |
| 649 | UpdatableBootJars: android.EmptyConfiguredJarList(), |
| 650 | ArtApexJars: android.EmptyConfiguredJarList(), |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 651 | SystemServerJars: nil, |
| 652 | SystemServerApps: nil, |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 653 | UpdatableSystemServerJars: android.EmptyConfiguredJarList(), |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 654 | SpeedApps: nil, |
| 655 | PreoptFlags: nil, |
| 656 | DefaultCompilerFilter: "", |
| 657 | SystemServerCompilerFilter: "", |
| 658 | GenerateDMFiles: false, |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 659 | NoDebugInfo: false, |
Mathieu Chartier | 3f7ddbb | 2019-04-29 09:33:50 -0700 | [diff] [blame] | 660 | DontResolveStartupStrings: false, |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 661 | AlwaysSystemServerDebugInfo: false, |
| 662 | NeverSystemServerDebugInfo: false, |
| 663 | AlwaysOtherDebugInfo: false, |
| 664 | NeverOtherDebugInfo: false, |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 665 | IsEng: false, |
| 666 | SanitizeLite: false, |
| 667 | DefaultAppImages: false, |
| 668 | Dex2oatXmx: "", |
| 669 | Dex2oatXms: "", |
| 670 | EmptyDirectory: "empty_dir", |
| 671 | CpuVariant: nil, |
| 672 | InstructionSetFeatures: nil, |
| 673 | DirtyImageObjects: android.OptionalPath{}, |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 674 | BootImageProfiles: nil, |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 675 | BootFlags: "", |
| 676 | Dex2oatImageXmx: "", |
| 677 | Dex2oatImageXms: "", |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 678 | } |
| 679 | } |
| 680 | |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 681 | func GlobalSoongConfigForTests(config android.Config) *GlobalSoongConfig { |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 682 | // Install the test GlobalSoongConfig in the Once cache so that later calls to |
| 683 | // Get(Cached)GlobalSoongConfig returns it without trying to create a real one. |
| 684 | return config.Once(globalSoongConfigOnceKey, func() interface{} { |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 685 | return &GlobalSoongConfig{ |
Colin Cross | 38b9685 | 2019-05-22 10:21:09 -0700 | [diff] [blame] | 686 | Profman: android.PathForTesting("profman"), |
| 687 | Dex2oat: android.PathForTesting("dex2oat"), |
| 688 | Aapt: android.PathForTesting("aapt"), |
| 689 | SoongZip: android.PathForTesting("soong_zip"), |
| 690 | Zip2zip: android.PathForTesting("zip2zip"), |
| 691 | ManifestCheck: android.PathForTesting("manifest_check"), |
Ulya Trafimovich | 5f364b6 | 2020-06-30 12:39:01 +0100 | [diff] [blame] | 692 | ConstructContext: android.PathForTesting("construct_context"), |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 693 | } |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 694 | }).(*GlobalSoongConfig) |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 695 | } |