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