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 | |
| 406 | dex2oatModule := ctx.GetDirectDepWithTag(dex2oatBin, dex2oatDepTag) |
| 407 | if dex2oatModule == nil { |
| 408 | // If this happens there's probably a missing call to AddToolDeps in DepsMutator. |
| 409 | panic(fmt.Sprintf("Failed to lookup %s dependency", dex2oatBin)) |
| 410 | } |
| 411 | |
| 412 | dex2oatPath := dex2oatModule.(android.HostToolProvider).HostToolPath() |
| 413 | if !dex2oatPath.Valid() { |
| 414 | panic(fmt.Sprintf("Failed to find host tool path in %s", dex2oatModule)) |
| 415 | } |
| 416 | |
| 417 | return dex2oatPath.Path() |
| 418 | } |
| 419 | |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 420 | // createGlobalSoongConfig creates a GlobalSoongConfig from the current context. |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 421 | // Should not be used in dexpreopt_gen. |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 422 | func createGlobalSoongConfig(ctx android.ModuleContext) *GlobalSoongConfig { |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 423 | if ctx.Config().TestProductVariables != nil { |
| 424 | // If we're called in a test there'll be a confusing error from the path |
| 425 | // functions below that gets reported without a stack trace, so let's panic |
| 426 | // properly with a more helpful message. |
| 427 | panic("This should not be called from tests. Please call GlobalSoongConfigForTests somewhere in the test setup.") |
| 428 | } |
| 429 | |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 430 | return &GlobalSoongConfig{ |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 431 | Profman: ctx.Config().HostToolPath(ctx, "profman"), |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 432 | Dex2oat: dex2oatPathFromDep(ctx), |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 433 | Aapt: ctx.Config().HostToolPath(ctx, "aapt"), |
| 434 | SoongZip: ctx.Config().HostToolPath(ctx, "soong_zip"), |
| 435 | Zip2zip: ctx.Config().HostToolPath(ctx, "zip2zip"), |
| 436 | ManifestCheck: ctx.Config().HostToolPath(ctx, "manifest_check"), |
Ulya Trafimovich | 5f364b6 | 2020-06-30 12:39:01 +0100 | [diff] [blame] | 437 | ConstructContext: ctx.Config().HostToolPath(ctx, "construct_context"), |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 438 | } |
| 439 | } |
| 440 | |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 441 | // The main reason for this Once cache for GlobalSoongConfig is to make the |
| 442 | // dex2oat path available to singletons. In ordinary modules we get it through a |
| 443 | // dex2oatDepTag dependency, but in singletons there's no simple way to do the |
| 444 | // same thing and ensure the right variant is selected, hence this cache to make |
| 445 | // the resolved path available to singletons. This means we depend on there |
| 446 | // being at least one ordinary module with a dex2oatDepTag dependency. |
| 447 | // |
| 448 | // TODO(b/147613152): Implement a way to deal with dependencies from singletons, |
| 449 | // and then possibly remove this cache altogether (but the use in |
| 450 | // GlobalSoongConfigForTests also needs to be rethought). |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 451 | var globalSoongConfigOnceKey = android.NewOnceKey("DexpreoptGlobalSoongConfig") |
| 452 | |
| 453 | // GetGlobalSoongConfig creates a GlobalSoongConfig the first time it's called, |
| 454 | // and later returns the same cached instance. |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 455 | func GetGlobalSoongConfig(ctx android.ModuleContext) *GlobalSoongConfig { |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 456 | globalSoong := ctx.Config().Once(globalSoongConfigOnceKey, func() interface{} { |
| 457 | return createGlobalSoongConfig(ctx) |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 458 | }).(*GlobalSoongConfig) |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 459 | |
| 460 | // Always resolve the tool path from the dependency, to ensure that every |
| 461 | // module has the dependency added properly. |
| 462 | myDex2oat := dex2oatPathFromDep(ctx) |
| 463 | if myDex2oat != globalSoong.Dex2oat { |
| 464 | panic(fmt.Sprintf("Inconsistent dex2oat path in cached config: expected %s, got %s", globalSoong.Dex2oat, myDex2oat)) |
| 465 | } |
| 466 | |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 467 | return globalSoong |
| 468 | } |
| 469 | |
| 470 | // GetCachedGlobalSoongConfig returns a cached GlobalSoongConfig created by an |
| 471 | // earlier GetGlobalSoongConfig call. This function works with any context |
| 472 | // 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] | 473 | // GlobalSoongConfig with the proper paths (which requires a full |
| 474 | // ModuleContext). If there has been no prior call to GetGlobalSoongConfig, nil |
| 475 | // is returned. |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 476 | func GetCachedGlobalSoongConfig(ctx android.PathContext) *GlobalSoongConfig { |
Martin Stjernholm | 6d41527 | 2020-01-31 17:10:36 +0000 | [diff] [blame] | 477 | return ctx.Config().Once(globalSoongConfigOnceKey, func() interface{} { |
| 478 | return (*GlobalSoongConfig)(nil) |
| 479 | }).(*GlobalSoongConfig) |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 480 | } |
| 481 | |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 482 | type globalJsonSoongConfig struct { |
| 483 | Profman string |
| 484 | Dex2oat string |
| 485 | Aapt string |
| 486 | SoongZip string |
| 487 | Zip2zip string |
| 488 | ManifestCheck string |
| 489 | ConstructContext string |
| 490 | } |
| 491 | |
Martin Stjernholm | 40f9f3c | 2020-01-20 18:12:23 +0000 | [diff] [blame] | 492 | // ParseGlobalSoongConfig parses the given data assumed to be read from the |
| 493 | // global dexpreopt_soong.config file into a GlobalSoongConfig struct. It is |
| 494 | // only used in dexpreopt_gen. |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 495 | func ParseGlobalSoongConfig(ctx android.PathContext, data []byte) (*GlobalSoongConfig, error) { |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 496 | var jc globalJsonSoongConfig |
| 497 | |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 498 | err := json.Unmarshal(data, &jc) |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 499 | if err != nil { |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 500 | return &GlobalSoongConfig{}, err |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 501 | } |
| 502 | |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 503 | config := &GlobalSoongConfig{ |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 504 | Profman: constructPath(ctx, jc.Profman), |
| 505 | Dex2oat: constructPath(ctx, jc.Dex2oat), |
| 506 | Aapt: constructPath(ctx, jc.Aapt), |
| 507 | SoongZip: constructPath(ctx, jc.SoongZip), |
| 508 | Zip2zip: constructPath(ctx, jc.Zip2zip), |
| 509 | ManifestCheck: constructPath(ctx, jc.ManifestCheck), |
| 510 | ConstructContext: constructPath(ctx, jc.ConstructContext), |
| 511 | } |
| 512 | |
| 513 | return config, nil |
| 514 | } |
| 515 | |
| 516 | func (s *globalSoongConfigSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 517 | if GetGlobalConfig(ctx).DisablePreopt { |
| 518 | return |
| 519 | } |
| 520 | |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 521 | config := GetCachedGlobalSoongConfig(ctx) |
Martin Stjernholm | 6d41527 | 2020-01-31 17:10:36 +0000 | [diff] [blame] | 522 | if config == nil { |
| 523 | // No module has enabled dexpreopting, so we assume there will be no calls |
| 524 | // to dexpreopt_gen. |
| 525 | return |
| 526 | } |
| 527 | |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 528 | jc := globalJsonSoongConfig{ |
| 529 | Profman: config.Profman.String(), |
| 530 | Dex2oat: config.Dex2oat.String(), |
| 531 | Aapt: config.Aapt.String(), |
| 532 | SoongZip: config.SoongZip.String(), |
| 533 | Zip2zip: config.Zip2zip.String(), |
| 534 | ManifestCheck: config.ManifestCheck.String(), |
| 535 | ConstructContext: config.ConstructContext.String(), |
| 536 | } |
| 537 | |
| 538 | data, err := json.Marshal(jc) |
| 539 | if err != nil { |
| 540 | ctx.Errorf("failed to JSON marshal GlobalSoongConfig: %v", err) |
| 541 | return |
| 542 | } |
| 543 | |
| 544 | ctx.Build(pctx, android.BuildParams{ |
| 545 | Rule: android.WriteFile, |
| 546 | Output: android.PathForOutput(ctx, "dexpreopt_soong.config"), |
| 547 | Args: map[string]string{ |
| 548 | "content": string(data), |
| 549 | }, |
| 550 | }) |
| 551 | } |
| 552 | |
| 553 | func (s *globalSoongConfigSingleton) MakeVars(ctx android.MakeVarsContext) { |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 554 | if GetGlobalConfig(ctx).DisablePreopt { |
| 555 | return |
| 556 | } |
| 557 | |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 558 | config := GetCachedGlobalSoongConfig(ctx) |
Martin Stjernholm | 6d41527 | 2020-01-31 17:10:36 +0000 | [diff] [blame] | 559 | if config == nil { |
| 560 | return |
| 561 | } |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 562 | |
| 563 | ctx.Strict("DEX2OAT", config.Dex2oat.String()) |
| 564 | ctx.Strict("DEXPREOPT_GEN_DEPS", strings.Join([]string{ |
| 565 | config.Profman.String(), |
| 566 | config.Dex2oat.String(), |
| 567 | config.Aapt.String(), |
| 568 | config.SoongZip.String(), |
| 569 | config.Zip2zip.String(), |
| 570 | config.ManifestCheck.String(), |
| 571 | config.ConstructContext.String(), |
| 572 | }, " ")) |
| 573 | } |
| 574 | |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 575 | func GlobalConfigForTests(ctx android.PathContext) *GlobalConfig { |
| 576 | return &GlobalConfig{ |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 577 | DisablePreopt: false, |
| 578 | DisablePreoptModules: nil, |
| 579 | OnlyPreoptBootImageAndSystemServer: false, |
| 580 | HasSystemOther: false, |
| 581 | PatternsOnSystemOther: nil, |
| 582 | DisableGenerateProfile: false, |
| 583 | ProfileDir: "", |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 584 | BootJars: android.EmptyConfiguredJarList(), |
| 585 | UpdatableBootJars: android.EmptyConfiguredJarList(), |
| 586 | ArtApexJars: android.EmptyConfiguredJarList(), |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 587 | SystemServerJars: nil, |
| 588 | SystemServerApps: nil, |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 589 | UpdatableSystemServerJars: android.EmptyConfiguredJarList(), |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 590 | SpeedApps: nil, |
| 591 | PreoptFlags: nil, |
| 592 | DefaultCompilerFilter: "", |
| 593 | SystemServerCompilerFilter: "", |
| 594 | GenerateDMFiles: false, |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 595 | NoDebugInfo: false, |
Mathieu Chartier | 3f7ddbb | 2019-04-29 09:33:50 -0700 | [diff] [blame] | 596 | DontResolveStartupStrings: false, |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 597 | AlwaysSystemServerDebugInfo: false, |
| 598 | NeverSystemServerDebugInfo: false, |
| 599 | AlwaysOtherDebugInfo: false, |
| 600 | NeverOtherDebugInfo: false, |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 601 | IsEng: false, |
| 602 | SanitizeLite: false, |
| 603 | DefaultAppImages: false, |
| 604 | Dex2oatXmx: "", |
| 605 | Dex2oatXms: "", |
| 606 | EmptyDirectory: "empty_dir", |
| 607 | CpuVariant: nil, |
| 608 | InstructionSetFeatures: nil, |
| 609 | DirtyImageObjects: android.OptionalPath{}, |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 610 | BootImageProfiles: nil, |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 611 | BootFlags: "", |
| 612 | Dex2oatImageXmx: "", |
| 613 | Dex2oatImageXms: "", |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 614 | } |
| 615 | } |
| 616 | |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 617 | func GlobalSoongConfigForTests(config android.Config) *GlobalSoongConfig { |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 618 | // Install the test GlobalSoongConfig in the Once cache so that later calls to |
| 619 | // Get(Cached)GlobalSoongConfig returns it without trying to create a real one. |
| 620 | return config.Once(globalSoongConfigOnceKey, func() interface{} { |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 621 | return &GlobalSoongConfig{ |
Colin Cross | 38b9685 | 2019-05-22 10:21:09 -0700 | [diff] [blame] | 622 | Profman: android.PathForTesting("profman"), |
| 623 | Dex2oat: android.PathForTesting("dex2oat"), |
| 624 | Aapt: android.PathForTesting("aapt"), |
| 625 | SoongZip: android.PathForTesting("soong_zip"), |
| 626 | Zip2zip: android.PathForTesting("zip2zip"), |
| 627 | ManifestCheck: android.PathForTesting("manifest_check"), |
Ulya Trafimovich | 5f364b6 | 2020-06-30 12:39:01 +0100 | [diff] [blame] | 628 | ConstructContext: android.PathForTesting("construct_context"), |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 629 | } |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 630 | }).(*GlobalSoongConfig) |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 631 | } |