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" |
Paul Duffin | 7d1d083 | 2021-04-23 11:39:41 +0100 | [diff] [blame] | 20 | "reflect" |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 21 | "strings" |
Colin Cross | 74ba962 | 2019-02-11 15:11:14 -0800 | [diff] [blame] | 22 | |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 23 | "github.com/google/blueprint" |
| 24 | |
Colin Cross | 74ba962 | 2019-02-11 15:11:14 -0800 | [diff] [blame] | 25 | "android/soong/android" |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 26 | ) |
| 27 | |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 28 | // GlobalConfig stores the configuration for dex preopting. The fields are set |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 29 | // from product variables via dex_preopt_config.mk. |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 30 | type GlobalConfig struct { |
Ulya Trafimovich | a4a1c4e | 2021-01-15 18:40:04 +0000 | [diff] [blame] | 31 | DisablePreopt bool // disable preopt for all modules (excluding boot images) |
| 32 | DisablePreoptBootImages bool // disable prepot for boot images |
| 33 | DisablePreoptModules []string // modules with preopt disabled by product-specific config |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 34 | |
| 35 | OnlyPreoptBootImageAndSystemServer bool // only preopt jars in the boot image or system server |
| 36 | |
Ulya Trafimovich | 9023b02 | 2021-03-22 16:02:28 +0000 | [diff] [blame] | 37 | PreoptWithUpdatableBcp bool // If updatable boot jars are included in dexpreopt or not. |
| 38 | |
Vladimir Marko | 40139d6 | 2020-02-06 15:14:29 +0000 | [diff] [blame] | 39 | UseArtImage bool // use the art image (use other boot class path dex files without image) |
| 40 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 41 | HasSystemOther bool // store odex files that match PatternsOnSystemOther on the system_other partition |
| 42 | PatternsOnSystemOther []string // patterns (using '%' to denote a prefix match) to put odex on the system_other partition |
| 43 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 44 | DisableGenerateProfile bool // don't generate profiles |
| 45 | ProfileDir string // directory to find profiles in |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 46 | |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 47 | BootJars android.ConfiguredJarList // modules for jars that form the boot class path |
| 48 | UpdatableBootJars android.ConfiguredJarList // jars within apex that form the boot class path |
Vladimir Marko | d2ee532 | 2018-12-19 17:57:57 +0000 | [diff] [blame] | 49 | |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 50 | ArtApexJars android.ConfiguredJarList // modules for jars that are in the ART APEX |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 51 | |
satayev | 9a6f87e | 2021-05-04 16:14:48 +0100 | [diff] [blame] | 52 | SystemServerJars android.ConfiguredJarList // jars that form the system server |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 53 | SystemServerApps []string // apps that are loaded into system server |
| 54 | UpdatableSystemServerJars android.ConfiguredJarList // jars within apex that are loaded into system server |
| 55 | SpeedApps []string // apps that should be speed optimized |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 56 | |
Ulya Trafimovich | cd3203f | 2020-03-27 11:30:00 +0000 | [diff] [blame] | 57 | BrokenSuboptimalOrderOfSystemServerJars bool // if true, sub-optimal order does not cause a build error |
| 58 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 59 | PreoptFlags []string // global dex2oat flags that should be used if no module-specific dex2oat flags are specified |
| 60 | |
| 61 | DefaultCompilerFilter string // default compiler filter to pass to dex2oat, overridden by --compiler-filter= in module-specific dex2oat flags |
| 62 | SystemServerCompilerFilter string // default compiler filter to pass to dex2oat for system server jars |
| 63 | |
Nicolas Geoffray | c1bf724 | 2019-10-18 14:51:38 +0100 | [diff] [blame] | 64 | GenerateDMFiles bool // generate Dex Metadata files |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 65 | |
| 66 | NoDebugInfo bool // don't generate debug info by default |
Mathieu Chartier | 3f7ddbb | 2019-04-29 09:33:50 -0700 | [diff] [blame] | 67 | DontResolveStartupStrings bool // don't resolve string literals loaded during application startup. |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 68 | AlwaysSystemServerDebugInfo bool // always generate mini debug info for system server modules (overrides NoDebugInfo=true) |
| 69 | NeverSystemServerDebugInfo bool // never generate mini debug info for system server modules (overrides NoDebugInfo=false) |
| 70 | AlwaysOtherDebugInfo bool // always generate mini debug info for non-system server modules (overrides NoDebugInfo=true) |
| 71 | NeverOtherDebugInfo bool // never generate mini debug info for non-system server modules (overrides NoDebugInfo=true) |
| 72 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 73 | IsEng bool // build is a eng variant |
| 74 | SanitizeLite bool // build is the second phase of a SANITIZE_LITE build |
| 75 | |
| 76 | DefaultAppImages bool // build app images (TODO: .art files?) by default |
| 77 | |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 78 | Dex2oatXmx string // max heap size for dex2oat |
| 79 | Dex2oatXms string // initial heap size for dex2oat |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 80 | |
| 81 | EmptyDirectory string // path to an empty directory |
| 82 | |
Colin Cross | 74ba962 | 2019-02-11 15:11:14 -0800 | [diff] [blame] | 83 | CpuVariant map[android.ArchType]string // cpu variant for each architecture |
| 84 | InstructionSetFeatures map[android.ArchType]string // instruction set for each architecture |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 85 | |
Nicolas Geoffray | 1086e60 | 2021-01-20 14:30:40 +0000 | [diff] [blame] | 86 | BootImageProfiles android.Paths // path to a boot-image-profile.txt file |
| 87 | BootFlags string // extra flags to pass to dex2oat for the boot image |
| 88 | Dex2oatImageXmx string // max heap size for dex2oat for the boot image |
| 89 | Dex2oatImageXms string // initial heap size for dex2oat for the boot image |
Ulya Trafimovich | 8c35fcf | 2021-02-17 16:23:28 +0000 | [diff] [blame] | 90 | |
Ulya Trafimovich | 4a13acb | 2021-03-02 12:25:02 +0000 | [diff] [blame] | 91 | // If true, downgrade the compiler filter of dexpreopt to "verify" when verify_uses_libraries |
Ulya Trafimovich | 8c35fcf | 2021-02-17 16:23:28 +0000 | [diff] [blame] | 92 | // check fails, instead of failing the build. This will disable any AOT-compilation. |
| 93 | // |
| 94 | // The intended use case for this flag is to have a smoother migration path for the Java |
| 95 | // modules that need to add <uses-library> information in their build files. The flag allows to |
| 96 | // quickly silence build errors. This flag should be used with caution and only as a temporary |
| 97 | // measure, as it masks real errors and affects performance. |
| 98 | RelaxUsesLibraryCheck bool |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 99 | } |
| 100 | |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 101 | // GlobalSoongConfig contains the global config that is generated from Soong, |
| 102 | // stored in dexpreopt_soong.config. |
| 103 | type GlobalSoongConfig struct { |
| 104 | // Paths to tools possibly used by the generated commands. |
| 105 | Profman android.Path |
| 106 | Dex2oat android.Path |
| 107 | Aapt android.Path |
| 108 | SoongZip android.Path |
| 109 | Zip2zip android.Path |
| 110 | ManifestCheck android.Path |
Colin Cross | 38b9685 | 2019-05-22 10:21:09 -0700 | [diff] [blame] | 111 | ConstructContext android.Path |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | type ModuleConfig struct { |
Victor Hsieh | d181c8b | 2019-01-29 13:00:33 -0800 | [diff] [blame] | 115 | Name string |
| 116 | DexLocation string // dex location on device |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 117 | BuildPath android.OutputPath |
| 118 | DexPath android.Path |
Jeongik Cha | 33a3a81 | 2021-04-15 09:12:49 +0900 | [diff] [blame] | 119 | ManifestPath android.OptionalPath |
Victor Hsieh | d181c8b | 2019-01-29 13:00:33 -0800 | [diff] [blame] | 120 | UncompressedDex bool |
| 121 | HasApkLibraries bool |
| 122 | PreoptFlags []string |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 123 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 124 | ProfileClassListing android.OptionalPath |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 125 | ProfileIsTextListing bool |
Nicolas Geoffray | e710242 | 2019-07-24 13:19:29 +0100 | [diff] [blame] | 126 | ProfileBootListing android.OptionalPath |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 127 | |
Ulya Trafimovich | 8c35fcf | 2021-02-17 16:23:28 +0000 | [diff] [blame] | 128 | EnforceUsesLibraries bool // turn on build-time verify_uses_libraries check |
| 129 | EnforceUsesLibrariesStatusFile android.Path // a file with verify_uses_libraries errors (if any) |
| 130 | ProvidesUsesLibrary string // library name (usually the same as module name) |
| 131 | ClassLoaderContexts ClassLoaderContextMap |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 132 | |
Jeongik Cha | 4dda75e | 2021-04-27 23:56:44 +0900 | [diff] [blame^] | 133 | Archs []android.ArchType |
| 134 | DexPreoptImagesDeps []android.OutputPaths |
| 135 | |
| 136 | DexPreoptImageLocationsOnHost []string // boot image location on host (file path without the arch subdirectory) |
| 137 | DexPreoptImageLocationsOnDevice []string // boot image location on device (file path without the arch subdirectory) |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 138 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 139 | PreoptBootClassPathDexFiles android.Paths // file paths of boot class path files |
| 140 | PreoptBootClassPathDexLocations []string // virtual locations of boot class path files |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 141 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 142 | PreoptExtractedApk bool // Overrides OnlyPreoptModules |
| 143 | |
| 144 | NoCreateAppImage bool |
| 145 | ForceCreateAppImage bool |
| 146 | |
| 147 | PresignedPrebuilt bool |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 148 | } |
| 149 | |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 150 | type globalSoongConfigSingleton struct{} |
| 151 | |
| 152 | var pctx = android.NewPackageContext("android/soong/dexpreopt") |
| 153 | |
| 154 | func init() { |
| 155 | pctx.Import("android/soong/android") |
| 156 | android.RegisterSingletonType("dexpreopt-soong-config", func() android.Singleton { |
| 157 | return &globalSoongConfigSingleton{} |
| 158 | }) |
| 159 | } |
| 160 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 161 | func constructPath(ctx android.PathContext, path string) android.Path { |
| 162 | buildDirPrefix := ctx.Config().BuildDir() + "/" |
| 163 | if path == "" { |
| 164 | return nil |
| 165 | } else if strings.HasPrefix(path, buildDirPrefix) { |
| 166 | return android.PathForOutput(ctx, strings.TrimPrefix(path, buildDirPrefix)) |
| 167 | } else { |
| 168 | return android.PathForSource(ctx, path) |
| 169 | } |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 170 | } |
| 171 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 172 | func constructPaths(ctx android.PathContext, paths []string) android.Paths { |
| 173 | var ret android.Paths |
| 174 | for _, path := range paths { |
| 175 | ret = append(ret, constructPath(ctx, path)) |
| 176 | } |
| 177 | return ret |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 178 | } |
| 179 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 180 | func constructWritablePath(ctx android.PathContext, path string) android.WritablePath { |
| 181 | if path == "" { |
| 182 | return nil |
| 183 | } |
| 184 | return constructPath(ctx, path).(android.WritablePath) |
| 185 | } |
| 186 | |
Martin Stjernholm | 40f9f3c | 2020-01-20 18:12:23 +0000 | [diff] [blame] | 187 | // ParseGlobalConfig parses the given data assumed to be read from the global |
| 188 | // dexpreopt.config file into a GlobalConfig struct. |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 189 | func ParseGlobalConfig(ctx android.PathContext, data []byte) (*GlobalConfig, error) { |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 190 | type GlobalJSONConfig struct { |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 191 | *GlobalConfig |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 192 | |
| 193 | // Copies of entries in GlobalConfig that are not constructable without extra parameters. They will be |
| 194 | // used to construct the real value manually below. |
Paul Duffin | 7ccacae | 2020-10-23 21:14:20 +0100 | [diff] [blame] | 195 | BootImageProfiles []string |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | config := GlobalJSONConfig{} |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 199 | err := json.Unmarshal(data, &config) |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 200 | if err != nil { |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 201 | return config.GlobalConfig, err |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | // Construct paths that require a PathContext. |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 205 | config.GlobalConfig.BootImageProfiles = constructPaths(ctx, config.BootImageProfiles) |
| 206 | |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 207 | return config.GlobalConfig, nil |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 208 | } |
| 209 | |
Martin Stjernholm | 40f9f3c | 2020-01-20 18:12:23 +0000 | [diff] [blame] | 210 | type globalConfigAndRaw struct { |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 211 | global *GlobalConfig |
Martin Stjernholm | 40f9f3c | 2020-01-20 18:12:23 +0000 | [diff] [blame] | 212 | data []byte |
| 213 | } |
| 214 | |
| 215 | // GetGlobalConfig returns the global dexpreopt.config that's created in the |
| 216 | // make config phase. It is loaded once the first time it is called for any |
| 217 | // ctx.Config(), and returns the same data for all future calls with the same |
| 218 | // ctx.Config(). A value can be inserted for tests using |
| 219 | // setDexpreoptTestGlobalConfig. |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 220 | func GetGlobalConfig(ctx android.PathContext) *GlobalConfig { |
Martin Stjernholm | 40f9f3c | 2020-01-20 18:12:23 +0000 | [diff] [blame] | 221 | return getGlobalConfigRaw(ctx).global |
| 222 | } |
| 223 | |
| 224 | // GetGlobalConfigRawData is the same as GetGlobalConfig, except that it returns |
| 225 | // the literal content of dexpreopt.config. |
| 226 | func GetGlobalConfigRawData(ctx android.PathContext) []byte { |
| 227 | return getGlobalConfigRaw(ctx).data |
| 228 | } |
| 229 | |
| 230 | var globalConfigOnceKey = android.NewOnceKey("DexpreoptGlobalConfig") |
| 231 | var testGlobalConfigOnceKey = android.NewOnceKey("TestDexpreoptGlobalConfig") |
| 232 | |
| 233 | func getGlobalConfigRaw(ctx android.PathContext) globalConfigAndRaw { |
| 234 | return ctx.Config().Once(globalConfigOnceKey, func() interface{} { |
| 235 | if data, err := ctx.Config().DexpreoptGlobalConfig(ctx); err != nil { |
| 236 | panic(err) |
| 237 | } else if data != nil { |
| 238 | globalConfig, err := ParseGlobalConfig(ctx, data) |
| 239 | if err != nil { |
| 240 | panic(err) |
| 241 | } |
| 242 | return globalConfigAndRaw{globalConfig, data} |
| 243 | } |
| 244 | |
| 245 | // No global config filename set, see if there is a test config set |
| 246 | return ctx.Config().Once(testGlobalConfigOnceKey, func() interface{} { |
| 247 | // Nope, return a config with preopting disabled |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 248 | return globalConfigAndRaw{&GlobalConfig{ |
Ulya Trafimovich | a4a1c4e | 2021-01-15 18:40:04 +0000 | [diff] [blame] | 249 | DisablePreopt: true, |
| 250 | DisablePreoptBootImages: true, |
| 251 | DisableGenerateProfile: true, |
Martin Stjernholm | 40f9f3c | 2020-01-20 18:12:23 +0000 | [diff] [blame] | 252 | }, nil} |
| 253 | }) |
| 254 | }).(globalConfigAndRaw) |
| 255 | } |
| 256 | |
| 257 | // SetTestGlobalConfig sets a GlobalConfig that future calls to GetGlobalConfig |
| 258 | // will return. It must be called before the first call to GetGlobalConfig for |
| 259 | // the config. |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 260 | func SetTestGlobalConfig(config android.Config, globalConfig *GlobalConfig) { |
Martin Stjernholm | 40f9f3c | 2020-01-20 18:12:23 +0000 | [diff] [blame] | 261 | config.Once(testGlobalConfigOnceKey, func() interface{} { return globalConfigAndRaw{globalConfig, nil} }) |
| 262 | } |
| 263 | |
Jeongik Cha | c624667 | 2021-04-08 00:00:19 +0900 | [diff] [blame] | 264 | // This struct is required to convert ModuleConfig from/to JSON. |
| 265 | // The types of fields in ModuleConfig are not convertible, |
| 266 | // so moduleJSONConfig has those fields as a convertible type. |
| 267 | type moduleJSONConfig struct { |
| 268 | *ModuleConfig |
| 269 | |
| 270 | BuildPath string |
| 271 | DexPath string |
| 272 | ManifestPath string |
| 273 | |
| 274 | ProfileClassListing string |
| 275 | ProfileBootListing string |
| 276 | |
| 277 | EnforceUsesLibrariesStatusFile string |
| 278 | ClassLoaderContexts jsonClassLoaderContextMap |
| 279 | |
Jeongik Cha | c624667 | 2021-04-08 00:00:19 +0900 | [diff] [blame] | 280 | DexPreoptImagesDeps [][]string |
| 281 | |
| 282 | PreoptBootClassPathDexFiles []string |
| 283 | } |
| 284 | |
Martin Stjernholm | 40f9f3c | 2020-01-20 18:12:23 +0000 | [diff] [blame] | 285 | // ParseModuleConfig parses a per-module dexpreopt.config file into a |
| 286 | // ModuleConfig struct. It is not used in Soong, which receives a ModuleConfig |
| 287 | // struct directly from java/dexpreopt.go. It is used in dexpreopt_gen called |
| 288 | // from Make to read the module dexpreopt.config written in the Make config |
| 289 | // stage. |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 290 | func ParseModuleConfig(ctx android.PathContext, data []byte) (*ModuleConfig, error) { |
Jeongik Cha | c624667 | 2021-04-08 00:00:19 +0900 | [diff] [blame] | 291 | config := moduleJSONConfig{} |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 292 | |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 293 | err := json.Unmarshal(data, &config) |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 294 | if err != nil { |
| 295 | return config.ModuleConfig, err |
| 296 | } |
| 297 | |
| 298 | // Construct paths that require a PathContext. |
| 299 | config.ModuleConfig.BuildPath = constructPath(ctx, config.BuildPath).(android.OutputPath) |
| 300 | config.ModuleConfig.DexPath = constructPath(ctx, config.DexPath) |
Jeongik Cha | 33a3a81 | 2021-04-15 09:12:49 +0900 | [diff] [blame] | 301 | config.ModuleConfig.ManifestPath = android.OptionalPathForPath(constructPath(ctx, config.ManifestPath)) |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 302 | config.ModuleConfig.ProfileClassListing = android.OptionalPathForPath(constructPath(ctx, config.ProfileClassListing)) |
Ulya Trafimovich | 8c35fcf | 2021-02-17 16:23:28 +0000 | [diff] [blame] | 303 | config.ModuleConfig.EnforceUsesLibrariesStatusFile = constructPath(ctx, config.EnforceUsesLibrariesStatusFile) |
Ulya Trafimovich | 8cbc5d2 | 2020-11-03 15:15:46 +0000 | [diff] [blame] | 304 | config.ModuleConfig.ClassLoaderContexts = fromJsonClassLoaderContext(ctx, config.ClassLoaderContexts) |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 305 | config.ModuleConfig.PreoptBootClassPathDexFiles = constructPaths(ctx, config.PreoptBootClassPathDexFiles) |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 306 | |
Dan Willemsen | 0f41678 | 2019-06-13 21:44:53 +0000 | [diff] [blame] | 307 | // This needs to exist, but dependencies are already handled in Make, so we don't need to pass them through JSON. |
Jeongik Cha | b19b58a | 2021-04-26 22:57:27 +0900 | [diff] [blame] | 308 | config.ModuleConfig.DexPreoptImagesDeps = make([]android.OutputPaths, len(config.ModuleConfig.Archs)) |
Dan Willemsen | 0f41678 | 2019-06-13 21:44:53 +0000 | [diff] [blame] | 309 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 310 | return config.ModuleConfig, nil |
| 311 | } |
| 312 | |
Jeongik Cha | c624667 | 2021-04-08 00:00:19 +0900 | [diff] [blame] | 313 | func pathsListToStringLists(pathsList []android.OutputPaths) [][]string { |
| 314 | ret := make([][]string, 0, len(pathsList)) |
| 315 | for _, paths := range pathsList { |
| 316 | ret = append(ret, paths.Strings()) |
| 317 | } |
| 318 | return ret |
| 319 | } |
| 320 | |
| 321 | func moduleConfigToJSON(config *ModuleConfig) ([]byte, error) { |
| 322 | return json.MarshalIndent(&moduleJSONConfig{ |
| 323 | BuildPath: config.BuildPath.String(), |
| 324 | DexPath: config.DexPath.String(), |
| 325 | ManifestPath: config.ManifestPath.String(), |
| 326 | ProfileClassListing: config.ProfileClassListing.String(), |
| 327 | ProfileBootListing: config.ProfileBootListing.String(), |
| 328 | EnforceUsesLibrariesStatusFile: config.EnforceUsesLibrariesStatusFile.String(), |
| 329 | ClassLoaderContexts: toJsonClassLoaderContext(config.ClassLoaderContexts), |
Jeongik Cha | c624667 | 2021-04-08 00:00:19 +0900 | [diff] [blame] | 330 | DexPreoptImagesDeps: pathsListToStringLists(config.DexPreoptImagesDeps), |
| 331 | PreoptBootClassPathDexFiles: config.PreoptBootClassPathDexFiles.Strings(), |
| 332 | ModuleConfig: config, |
| 333 | }, "", " ") |
| 334 | } |
| 335 | |
| 336 | // WriteModuleConfig serializes a ModuleConfig into a per-module dexpreopt.config JSON file. |
| 337 | // These config files are used for post-processing. |
| 338 | func WriteModuleConfig(ctx android.ModuleContext, config *ModuleConfig, path android.WritablePath) { |
Ulya Trafimovich | 76b0852 | 2021-01-14 17:52:43 +0000 | [diff] [blame] | 339 | if path == nil { |
| 340 | return |
| 341 | } |
| 342 | |
Jeongik Cha | c624667 | 2021-04-08 00:00:19 +0900 | [diff] [blame] | 343 | data, err := moduleConfigToJSON(config) |
Ulya Trafimovich | 76b0852 | 2021-01-14 17:52:43 +0000 | [diff] [blame] | 344 | if err != nil { |
| 345 | ctx.ModuleErrorf("failed to JSON marshal module dexpreopt.config: %v", err) |
| 346 | return |
| 347 | } |
| 348 | |
| 349 | android.WriteFileRule(ctx, path, string(data)) |
| 350 | } |
| 351 | |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 352 | // dex2oatModuleName returns the name of the module to use for the dex2oat host |
| 353 | // tool. It should be a binary module with public visibility that is compiled |
| 354 | // and installed for host. |
| 355 | func dex2oatModuleName(config android.Config) string { |
| 356 | // Default to the debug variant of dex2oat to help find bugs. |
| 357 | // Set USE_DEX2OAT_DEBUG to false for only building non-debug versions. |
| 358 | if config.Getenv("USE_DEX2OAT_DEBUG") == "false" { |
| 359 | return "dex2oat" |
| 360 | } else { |
| 361 | return "dex2oatd" |
| 362 | } |
| 363 | } |
| 364 | |
Paul Duffin | b506c9d | 2021-03-24 14:34:40 +0000 | [diff] [blame] | 365 | type dex2oatDependencyTag struct { |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 366 | blueprint.BaseDependencyTag |
Paul Duffin | b506c9d | 2021-03-24 14:34:40 +0000 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | func (d dex2oatDependencyTag) ExcludeFromVisibilityEnforcement() { |
| 370 | } |
| 371 | |
| 372 | func (d dex2oatDependencyTag) ExcludeFromApexContents() { |
| 373 | } |
| 374 | |
| 375 | // Dex2oatDepTag represents the dependency onto the dex2oatd module. It is added to any module that |
| 376 | // needs dexpreopting and so it makes no sense for it to be checked for visibility or included in |
| 377 | // the apex. |
| 378 | var Dex2oatDepTag = dex2oatDependencyTag{} |
| 379 | |
| 380 | var _ android.ExcludeFromVisibilityEnforcementTag = Dex2oatDepTag |
| 381 | var _ android.ExcludeFromApexContentsTag = Dex2oatDepTag |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 382 | |
Martin Stjernholm | 6d41527 | 2020-01-31 17:10:36 +0000 | [diff] [blame] | 383 | // RegisterToolDeps adds the necessary dependencies to binary modules for tools |
| 384 | // that are required later when Get(Cached)GlobalSoongConfig is called. It |
| 385 | // should be called from a mutator that's registered with |
| 386 | // android.RegistrationContext.FinalDepsMutators. |
| 387 | func RegisterToolDeps(ctx android.BottomUpMutatorContext) { |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 388 | dex2oatBin := dex2oatModuleName(ctx.Config()) |
| 389 | v := ctx.Config().BuildOSTarget.Variations() |
Ulya Trafimovich | a4a1c4e | 2021-01-15 18:40:04 +0000 | [diff] [blame] | 390 | ctx.AddFarVariationDependencies(v, Dex2oatDepTag, dex2oatBin) |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | func dex2oatPathFromDep(ctx android.ModuleContext) android.Path { |
| 394 | dex2oatBin := dex2oatModuleName(ctx.Config()) |
| 395 | |
Martin Stjernholm | c004862 | 2020-08-18 17:37:41 +0100 | [diff] [blame] | 396 | // Find the right dex2oat module, trying to follow PrebuiltDepTag from source |
| 397 | // to prebuilt if there is one. We wouldn't have to do this if the |
| 398 | // prebuilt_postdeps mutator that replaces source deps with prebuilt deps was |
| 399 | // run after RegisterToolDeps above, but changing that leads to ordering |
| 400 | // problems between mutators (RegisterToolDeps needs to run late to act on |
| 401 | // final variants, while prebuilt_postdeps needs to run before many of the |
| 402 | // PostDeps mutators, like the APEX mutators). Hence we need to dig out the |
| 403 | // prebuilt explicitly here instead. |
| 404 | var dex2oatModule android.Module |
| 405 | ctx.WalkDeps(func(child, parent android.Module) bool { |
Ulya Trafimovich | a4a1c4e | 2021-01-15 18:40:04 +0000 | [diff] [blame] | 406 | if parent == ctx.Module() && ctx.OtherModuleDependencyTag(child) == Dex2oatDepTag { |
Martin Stjernholm | c004862 | 2020-08-18 17:37:41 +0100 | [diff] [blame] | 407 | // Found the source module, or prebuilt module that has replaced the source. |
| 408 | dex2oatModule = child |
Paul Duffin | f7c99f5 | 2021-04-28 10:41:21 +0100 | [diff] [blame] | 409 | if android.IsModulePrebuilt(child) { |
Martin Stjernholm | c004862 | 2020-08-18 17:37:41 +0100 | [diff] [blame] | 410 | return false // If it's the prebuilt we're done. |
| 411 | } else { |
| 412 | return true // Recurse to check if the source has a prebuilt dependency. |
| 413 | } |
| 414 | } |
| 415 | if parent == dex2oatModule && ctx.OtherModuleDependencyTag(child) == android.PrebuiltDepTag { |
Paul Duffin | f7c99f5 | 2021-04-28 10:41:21 +0100 | [diff] [blame] | 416 | if p := android.GetEmbeddedPrebuilt(child); p != nil && p.UsePrebuilt() { |
Martin Stjernholm | c004862 | 2020-08-18 17:37:41 +0100 | [diff] [blame] | 417 | dex2oatModule = child // Found a prebuilt that should be used. |
| 418 | } |
| 419 | } |
| 420 | return false |
| 421 | }) |
| 422 | |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 423 | if dex2oatModule == nil { |
| 424 | // If this happens there's probably a missing call to AddToolDeps in DepsMutator. |
| 425 | panic(fmt.Sprintf("Failed to lookup %s dependency", dex2oatBin)) |
| 426 | } |
| 427 | |
| 428 | dex2oatPath := dex2oatModule.(android.HostToolProvider).HostToolPath() |
| 429 | if !dex2oatPath.Valid() { |
| 430 | panic(fmt.Sprintf("Failed to find host tool path in %s", dex2oatModule)) |
| 431 | } |
| 432 | |
| 433 | return dex2oatPath.Path() |
| 434 | } |
| 435 | |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 436 | // createGlobalSoongConfig creates a GlobalSoongConfig from the current context. |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 437 | // Should not be used in dexpreopt_gen. |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 438 | func createGlobalSoongConfig(ctx android.ModuleContext) *GlobalSoongConfig { |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 439 | return &GlobalSoongConfig{ |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 440 | Profman: ctx.Config().HostToolPath(ctx, "profman"), |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 441 | Dex2oat: dex2oatPathFromDep(ctx), |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 442 | Aapt: ctx.Config().HostToolPath(ctx, "aapt"), |
| 443 | SoongZip: ctx.Config().HostToolPath(ctx, "soong_zip"), |
| 444 | Zip2zip: ctx.Config().HostToolPath(ctx, "zip2zip"), |
| 445 | ManifestCheck: ctx.Config().HostToolPath(ctx, "manifest_check"), |
Ulya Trafimovich | 5f364b6 | 2020-06-30 12:39:01 +0100 | [diff] [blame] | 446 | ConstructContext: ctx.Config().HostToolPath(ctx, "construct_context"), |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 447 | } |
| 448 | } |
| 449 | |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 450 | // The main reason for this Once cache for GlobalSoongConfig is to make the |
| 451 | // dex2oat path available to singletons. In ordinary modules we get it through a |
Ulya Trafimovich | a4a1c4e | 2021-01-15 18:40:04 +0000 | [diff] [blame] | 452 | // Dex2oatDepTag dependency, but in singletons there's no simple way to do the |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 453 | // same thing and ensure the right variant is selected, hence this cache to make |
| 454 | // the resolved path available to singletons. This means we depend on there |
Ulya Trafimovich | a4a1c4e | 2021-01-15 18:40:04 +0000 | [diff] [blame] | 455 | // being at least one ordinary module with a Dex2oatDepTag dependency. |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 456 | // |
| 457 | // TODO(b/147613152): Implement a way to deal with dependencies from singletons, |
Paul Duffin | 9f04524 | 2021-01-21 15:05:11 +0000 | [diff] [blame] | 458 | // and then possibly remove this cache altogether. |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 459 | var globalSoongConfigOnceKey = android.NewOnceKey("DexpreoptGlobalSoongConfig") |
| 460 | |
| 461 | // GetGlobalSoongConfig creates a GlobalSoongConfig the first time it's called, |
| 462 | // and later returns the same cached instance. |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 463 | func GetGlobalSoongConfig(ctx android.ModuleContext) *GlobalSoongConfig { |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 464 | globalSoong := ctx.Config().Once(globalSoongConfigOnceKey, func() interface{} { |
| 465 | return createGlobalSoongConfig(ctx) |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 466 | }).(*GlobalSoongConfig) |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 467 | |
| 468 | // Always resolve the tool path from the dependency, to ensure that every |
| 469 | // module has the dependency added properly. |
| 470 | myDex2oat := dex2oatPathFromDep(ctx) |
| 471 | if myDex2oat != globalSoong.Dex2oat { |
| 472 | panic(fmt.Sprintf("Inconsistent dex2oat path in cached config: expected %s, got %s", globalSoong.Dex2oat, myDex2oat)) |
| 473 | } |
| 474 | |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 475 | return globalSoong |
| 476 | } |
| 477 | |
| 478 | // GetCachedGlobalSoongConfig returns a cached GlobalSoongConfig created by an |
| 479 | // earlier GetGlobalSoongConfig call. This function works with any context |
| 480 | // 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] | 481 | // GlobalSoongConfig with the proper paths (which requires a full |
| 482 | // ModuleContext). If there has been no prior call to GetGlobalSoongConfig, nil |
| 483 | // is returned. |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 484 | func GetCachedGlobalSoongConfig(ctx android.PathContext) *GlobalSoongConfig { |
Martin Stjernholm | 6d41527 | 2020-01-31 17:10:36 +0000 | [diff] [blame] | 485 | return ctx.Config().Once(globalSoongConfigOnceKey, func() interface{} { |
| 486 | return (*GlobalSoongConfig)(nil) |
| 487 | }).(*GlobalSoongConfig) |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 488 | } |
| 489 | |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 490 | type globalJsonSoongConfig struct { |
| 491 | Profman string |
| 492 | Dex2oat string |
| 493 | Aapt string |
| 494 | SoongZip string |
| 495 | Zip2zip string |
| 496 | ManifestCheck string |
| 497 | ConstructContext string |
| 498 | } |
| 499 | |
Martin Stjernholm | 40f9f3c | 2020-01-20 18:12:23 +0000 | [diff] [blame] | 500 | // ParseGlobalSoongConfig parses the given data assumed to be read from the |
| 501 | // global dexpreopt_soong.config file into a GlobalSoongConfig struct. It is |
| 502 | // only used in dexpreopt_gen. |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 503 | func ParseGlobalSoongConfig(ctx android.PathContext, data []byte) (*GlobalSoongConfig, error) { |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 504 | var jc globalJsonSoongConfig |
| 505 | |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 506 | err := json.Unmarshal(data, &jc) |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 507 | if err != nil { |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 508 | return &GlobalSoongConfig{}, err |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 509 | } |
| 510 | |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 511 | config := &GlobalSoongConfig{ |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 512 | Profman: constructPath(ctx, jc.Profman), |
| 513 | Dex2oat: constructPath(ctx, jc.Dex2oat), |
| 514 | Aapt: constructPath(ctx, jc.Aapt), |
| 515 | SoongZip: constructPath(ctx, jc.SoongZip), |
| 516 | Zip2zip: constructPath(ctx, jc.Zip2zip), |
| 517 | ManifestCheck: constructPath(ctx, jc.ManifestCheck), |
| 518 | ConstructContext: constructPath(ctx, jc.ConstructContext), |
| 519 | } |
| 520 | |
| 521 | return config, nil |
| 522 | } |
| 523 | |
Paul Duffin | 7d1d083 | 2021-04-23 11:39:41 +0100 | [diff] [blame] | 524 | // checkBootJarsConfigConsistency checks the consistency of BootJars and UpdatableBootJars fields in |
| 525 | // DexpreoptGlobalConfig and Config.productVariables. |
| 526 | func checkBootJarsConfigConsistency(ctx android.SingletonContext, dexpreoptConfig *GlobalConfig, config android.Config) { |
| 527 | compareBootJars := func(property string, dexpreoptJars, variableJars android.ConfiguredJarList) { |
| 528 | dexpreoptPairs := dexpreoptJars.CopyOfApexJarPairs() |
| 529 | variablePairs := variableJars.CopyOfApexJarPairs() |
| 530 | if !reflect.DeepEqual(dexpreoptPairs, variablePairs) { |
| 531 | ctx.Errorf("Inconsistent configuration of %[1]s\n"+ |
| 532 | " dexpreopt.GlobalConfig.%[1]s = %[2]s\n"+ |
| 533 | " productVariables.%[1]s = %[3]s", |
| 534 | property, dexpreoptPairs, variablePairs) |
| 535 | } |
| 536 | } |
| 537 | |
| 538 | compareBootJars("BootJars", dexpreoptConfig.BootJars, config.NonUpdatableBootJars()) |
| 539 | compareBootJars("UpdatableBootJars", dexpreoptConfig.UpdatableBootJars, config.UpdatableBootJars()) |
| 540 | } |
| 541 | |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 542 | func (s *globalSoongConfigSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
Paul Duffin | 7d1d083 | 2021-04-23 11:39:41 +0100 | [diff] [blame] | 543 | checkBootJarsConfigConsistency(ctx, GetGlobalConfig(ctx), ctx.Config()) |
| 544 | |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 545 | if GetGlobalConfig(ctx).DisablePreopt { |
| 546 | return |
| 547 | } |
| 548 | |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 549 | config := GetCachedGlobalSoongConfig(ctx) |
Martin Stjernholm | 6d41527 | 2020-01-31 17:10:36 +0000 | [diff] [blame] | 550 | if config == nil { |
| 551 | // No module has enabled dexpreopting, so we assume there will be no calls |
| 552 | // to dexpreopt_gen. |
| 553 | return |
| 554 | } |
| 555 | |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 556 | jc := globalJsonSoongConfig{ |
| 557 | Profman: config.Profman.String(), |
| 558 | Dex2oat: config.Dex2oat.String(), |
| 559 | Aapt: config.Aapt.String(), |
| 560 | SoongZip: config.SoongZip.String(), |
| 561 | Zip2zip: config.Zip2zip.String(), |
| 562 | ManifestCheck: config.ManifestCheck.String(), |
| 563 | ConstructContext: config.ConstructContext.String(), |
| 564 | } |
| 565 | |
| 566 | data, err := json.Marshal(jc) |
| 567 | if err != nil { |
| 568 | ctx.Errorf("failed to JSON marshal GlobalSoongConfig: %v", err) |
| 569 | return |
| 570 | } |
| 571 | |
Colin Cross | cf371cc | 2020-11-13 11:48:42 -0800 | [diff] [blame] | 572 | android.WriteFileRule(ctx, android.PathForOutput(ctx, "dexpreopt_soong.config"), string(data)) |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | func (s *globalSoongConfigSingleton) MakeVars(ctx android.MakeVarsContext) { |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 576 | if GetGlobalConfig(ctx).DisablePreopt { |
| 577 | return |
| 578 | } |
| 579 | |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 580 | config := GetCachedGlobalSoongConfig(ctx) |
Martin Stjernholm | 6d41527 | 2020-01-31 17:10:36 +0000 | [diff] [blame] | 581 | if config == nil { |
| 582 | return |
| 583 | } |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 584 | |
| 585 | ctx.Strict("DEX2OAT", config.Dex2oat.String()) |
| 586 | ctx.Strict("DEXPREOPT_GEN_DEPS", strings.Join([]string{ |
| 587 | config.Profman.String(), |
| 588 | config.Dex2oat.String(), |
| 589 | config.Aapt.String(), |
| 590 | config.SoongZip.String(), |
| 591 | config.Zip2zip.String(), |
| 592 | config.ManifestCheck.String(), |
| 593 | config.ConstructContext.String(), |
| 594 | }, " ")) |
| 595 | } |
| 596 | |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 597 | func GlobalConfigForTests(ctx android.PathContext) *GlobalConfig { |
| 598 | return &GlobalConfig{ |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 599 | DisablePreopt: false, |
| 600 | DisablePreoptModules: nil, |
| 601 | OnlyPreoptBootImageAndSystemServer: false, |
| 602 | HasSystemOther: false, |
| 603 | PatternsOnSystemOther: nil, |
| 604 | DisableGenerateProfile: false, |
| 605 | ProfileDir: "", |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 606 | BootJars: android.EmptyConfiguredJarList(), |
| 607 | UpdatableBootJars: android.EmptyConfiguredJarList(), |
| 608 | ArtApexJars: android.EmptyConfiguredJarList(), |
satayev | 9a6f87e | 2021-05-04 16:14:48 +0100 | [diff] [blame] | 609 | SystemServerJars: android.EmptyConfiguredJarList(), |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 610 | SystemServerApps: nil, |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 611 | UpdatableSystemServerJars: android.EmptyConfiguredJarList(), |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 612 | SpeedApps: nil, |
| 613 | PreoptFlags: nil, |
| 614 | DefaultCompilerFilter: "", |
| 615 | SystemServerCompilerFilter: "", |
| 616 | GenerateDMFiles: false, |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 617 | NoDebugInfo: false, |
Mathieu Chartier | 3f7ddbb | 2019-04-29 09:33:50 -0700 | [diff] [blame] | 618 | DontResolveStartupStrings: false, |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 619 | AlwaysSystemServerDebugInfo: false, |
| 620 | NeverSystemServerDebugInfo: false, |
| 621 | AlwaysOtherDebugInfo: false, |
| 622 | NeverOtherDebugInfo: false, |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 623 | IsEng: false, |
| 624 | SanitizeLite: false, |
| 625 | DefaultAppImages: false, |
| 626 | Dex2oatXmx: "", |
| 627 | Dex2oatXms: "", |
| 628 | EmptyDirectory: "empty_dir", |
| 629 | CpuVariant: nil, |
| 630 | InstructionSetFeatures: nil, |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 631 | BootImageProfiles: nil, |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 632 | BootFlags: "", |
| 633 | Dex2oatImageXmx: "", |
| 634 | Dex2oatImageXms: "", |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 635 | } |
| 636 | } |
| 637 | |
Paul Duffin | 9f04524 | 2021-01-21 15:05:11 +0000 | [diff] [blame] | 638 | func globalSoongConfigForTests() *GlobalSoongConfig { |
| 639 | return &GlobalSoongConfig{ |
| 640 | Profman: android.PathForTesting("profman"), |
| 641 | Dex2oat: android.PathForTesting("dex2oat"), |
| 642 | Aapt: android.PathForTesting("aapt"), |
| 643 | SoongZip: android.PathForTesting("soong_zip"), |
| 644 | Zip2zip: android.PathForTesting("zip2zip"), |
| 645 | ManifestCheck: android.PathForTesting("manifest_check"), |
| 646 | ConstructContext: android.PathForTesting("construct_context"), |
| 647 | } |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 648 | } |