blob: 2ba6bb484bb75ca50d10eda7c37f983f8742633a [file] [log] [blame]
Colin Cross43f08db2018-11-12 10:13:39 -08001// 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
15package dexpreopt
16
17import (
18 "encoding/json"
Colin Cross69f59a32019-02-15 10:39:37 -080019 "strings"
Colin Cross74ba9622019-02-11 15:11:14 -080020
21 "android/soong/android"
Colin Cross43f08db2018-11-12 10:13:39 -080022)
23
Martin Stjernholmc52aaf12020-01-06 23:11:37 +000024// GlobalConfig stores the configuration for dex preopting. The fields are set
Martin Stjernholm75a48d82020-01-10 20:32:59 +000025// from product variables via dex_preopt_config.mk.
Colin Cross43f08db2018-11-12 10:13:39 -080026type GlobalConfig struct {
Colin Cross69f59a32019-02-15 10:39:37 -080027 DisablePreopt bool // disable preopt for all modules
Colin Cross43f08db2018-11-12 10:13:39 -080028 DisablePreoptModules []string // modules with preopt disabled by product-specific config
29
30 OnlyPreoptBootImageAndSystemServer bool // only preopt jars in the boot image or system server
31
Vladimir Marko40139d62020-02-06 15:14:29 +000032 UseArtImage bool // use the art image (use other boot class path dex files without image)
33
Colin Cross43f08db2018-11-12 10:13:39 -080034 HasSystemOther bool // store odex files that match PatternsOnSystemOther on the system_other partition
35 PatternsOnSystemOther []string // patterns (using '%' to denote a prefix match) to put odex on the system_other partition
36
Colin Cross69f59a32019-02-15 10:39:37 -080037 DisableGenerateProfile bool // don't generate profiles
38 ProfileDir string // directory to find profiles in
Colin Cross43f08db2018-11-12 10:13:39 -080039
Roshan Piusccc26ef2019-11-27 09:37:46 -080040 BootJars []string // modules for jars that form the boot class path
41 UpdatableBootJars []string // jars within apex that form the boot class path
Vladimir Markod2ee5322018-12-19 17:57:57 +000042
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +000043 ArtApexJars []string // modules for jars that are in the ART APEX
Colin Cross800fe132019-02-11 14:21:24 -080044
Roshan Pius9b51a402019-11-21 12:36:53 -080045 SystemServerJars []string // jars that form the system server
46 SystemServerApps []string // apps that are loaded into system server
47 UpdatableSystemServerJars []string // jars within apex that are loaded into system server
48 SpeedApps []string // apps that should be speed optimized
Colin Cross43f08db2018-11-12 10:13:39 -080049
50 PreoptFlags []string // global dex2oat flags that should be used if no module-specific dex2oat flags are specified
51
52 DefaultCompilerFilter string // default compiler filter to pass to dex2oat, overridden by --compiler-filter= in module-specific dex2oat flags
53 SystemServerCompilerFilter string // default compiler filter to pass to dex2oat for system server jars
54
Nicolas Geoffrayc1bf7242019-10-18 14:51:38 +010055 GenerateDMFiles bool // generate Dex Metadata files
Colin Cross43f08db2018-11-12 10:13:39 -080056
57 NoDebugInfo bool // don't generate debug info by default
Mathieu Chartier3f7ddbb2019-04-29 09:33:50 -070058 DontResolveStartupStrings bool // don't resolve string literals loaded during application startup.
Colin Cross43f08db2018-11-12 10:13:39 -080059 AlwaysSystemServerDebugInfo bool // always generate mini debug info for system server modules (overrides NoDebugInfo=true)
60 NeverSystemServerDebugInfo bool // never generate mini debug info for system server modules (overrides NoDebugInfo=false)
61 AlwaysOtherDebugInfo bool // always generate mini debug info for non-system server modules (overrides NoDebugInfo=true)
62 NeverOtherDebugInfo bool // never generate mini debug info for non-system server modules (overrides NoDebugInfo=true)
63
Colin Cross43f08db2018-11-12 10:13:39 -080064 IsEng bool // build is a eng variant
65 SanitizeLite bool // build is the second phase of a SANITIZE_LITE build
66
67 DefaultAppImages bool // build app images (TODO: .art files?) by default
68
Colin Cross800fe132019-02-11 14:21:24 -080069 Dex2oatXmx string // max heap size for dex2oat
70 Dex2oatXms string // initial heap size for dex2oat
Colin Cross43f08db2018-11-12 10:13:39 -080071
72 EmptyDirectory string // path to an empty directory
73
Colin Cross74ba9622019-02-11 15:11:14 -080074 CpuVariant map[android.ArchType]string // cpu variant for each architecture
75 InstructionSetFeatures map[android.ArchType]string // instruction set for each architecture
Colin Cross43f08db2018-11-12 10:13:39 -080076
Colin Cross800fe132019-02-11 14:21:24 -080077 // Only used for boot image
Mathieu Chartier6adeee12019-06-26 10:01:36 -070078 DirtyImageObjects android.OptionalPath // path to a dirty-image-objects file
79 BootImageProfiles android.Paths // path to a boot-image-profile.txt file
80 BootFlags string // extra flags to pass to dex2oat for the boot image
81 Dex2oatImageXmx string // max heap size for dex2oat for the boot image
82 Dex2oatImageXms string // initial heap size for dex2oat for the boot image
Colin Cross43f08db2018-11-12 10:13:39 -080083}
84
Martin Stjernholmc52aaf12020-01-06 23:11:37 +000085// GlobalSoongConfig contains the global config that is generated from Soong,
86// stored in dexpreopt_soong.config.
87type GlobalSoongConfig struct {
88 // Paths to tools possibly used by the generated commands.
89 Profman android.Path
90 Dex2oat android.Path
91 Aapt android.Path
92 SoongZip android.Path
93 Zip2zip android.Path
94 ManifestCheck android.Path
Colin Cross38b96852019-05-22 10:21:09 -070095 ConstructContext android.Path
Colin Cross43f08db2018-11-12 10:13:39 -080096}
97
98type ModuleConfig struct {
Victor Hsiehd181c8b2019-01-29 13:00:33 -080099 Name string
100 DexLocation string // dex location on device
Colin Cross69f59a32019-02-15 10:39:37 -0800101 BuildPath android.OutputPath
102 DexPath android.Path
Colin Cross38b96852019-05-22 10:21:09 -0700103 ManifestPath android.Path
Victor Hsiehd181c8b2019-01-29 13:00:33 -0800104 UncompressedDex bool
105 HasApkLibraries bool
106 PreoptFlags []string
Colin Cross43f08db2018-11-12 10:13:39 -0800107
Colin Cross69f59a32019-02-15 10:39:37 -0800108 ProfileClassListing android.OptionalPath
Colin Cross43f08db2018-11-12 10:13:39 -0800109 ProfileIsTextListing bool
Nicolas Geoffraye7102422019-07-24 13:19:29 +0100110 ProfileBootListing android.OptionalPath
Colin Cross43f08db2018-11-12 10:13:39 -0800111
Colin Cross50ddcc42019-05-16 12:28:22 -0700112 EnforceUsesLibraries bool
113 PresentOptionalUsesLibraries []string
114 UsesLibraries []string
115 LibraryPaths map[string]android.Path
Colin Cross43f08db2018-11-12 10:13:39 -0800116
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +0000117 Archs []android.ArchType
118 DexPreoptImages []android.Path
119 DexPreoptImagesDeps []android.OutputPaths
120 DexPreoptImageLocations []string
Colin Cross43f08db2018-11-12 10:13:39 -0800121
Colin Cross69f59a32019-02-15 10:39:37 -0800122 PreoptBootClassPathDexFiles android.Paths // file paths of boot class path files
123 PreoptBootClassPathDexLocations []string // virtual locations of boot class path files
Colin Cross800fe132019-02-11 14:21:24 -0800124
Colin Cross43f08db2018-11-12 10:13:39 -0800125 PreoptExtractedApk bool // Overrides OnlyPreoptModules
126
127 NoCreateAppImage bool
128 ForceCreateAppImage bool
129
130 PresignedPrebuilt bool
Colin Cross43f08db2018-11-12 10:13:39 -0800131}
132
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000133type globalSoongConfigSingleton struct{}
134
135var pctx = android.NewPackageContext("android/soong/dexpreopt")
136
137func init() {
138 pctx.Import("android/soong/android")
139 android.RegisterSingletonType("dexpreopt-soong-config", func() android.Singleton {
140 return &globalSoongConfigSingleton{}
141 })
142}
143
Colin Cross69f59a32019-02-15 10:39:37 -0800144func constructPath(ctx android.PathContext, path string) android.Path {
145 buildDirPrefix := ctx.Config().BuildDir() + "/"
146 if path == "" {
147 return nil
148 } else if strings.HasPrefix(path, buildDirPrefix) {
149 return android.PathForOutput(ctx, strings.TrimPrefix(path, buildDirPrefix))
150 } else {
151 return android.PathForSource(ctx, path)
152 }
Colin Cross43f08db2018-11-12 10:13:39 -0800153}
154
Colin Cross69f59a32019-02-15 10:39:37 -0800155func constructPaths(ctx android.PathContext, paths []string) android.Paths {
156 var ret android.Paths
157 for _, path := range paths {
158 ret = append(ret, constructPath(ctx, path))
159 }
160 return ret
Colin Cross43f08db2018-11-12 10:13:39 -0800161}
162
Colin Cross69f59a32019-02-15 10:39:37 -0800163func constructPathMap(ctx android.PathContext, paths map[string]string) map[string]android.Path {
164 ret := map[string]android.Path{}
165 for key, path := range paths {
166 ret[key] = constructPath(ctx, path)
167 }
168 return ret
169}
170
171func constructWritablePath(ctx android.PathContext, path string) android.WritablePath {
172 if path == "" {
173 return nil
174 }
175 return constructPath(ctx, path).(android.WritablePath)
176}
177
Hans Boehm453bf092020-01-25 01:44:30 +0000178// LoadGlobalConfig reads the global dexpreopt.config file into a GlobalConfig
Martin Stjernholm75a48d82020-01-10 20:32:59 +0000179// struct. LoadGlobalConfig is used directly in Soong and in dexpreopt_gen
180// called from Make to read the $OUT/dexpreopt.config written by Make.
181func LoadGlobalConfig(ctx android.PathContext, data []byte) (GlobalConfig, error) {
Colin Cross69f59a32019-02-15 10:39:37 -0800182 type GlobalJSONConfig struct {
183 GlobalConfig
184
185 // Copies of entries in GlobalConfig that are not constructable without extra parameters. They will be
186 // used to construct the real value manually below.
187 DirtyImageObjects string
Colin Cross69f59a32019-02-15 10:39:37 -0800188 BootImageProfiles []string
Colin Cross69f59a32019-02-15 10:39:37 -0800189 }
190
191 config := GlobalJSONConfig{}
Colin Cross988414c2020-01-11 01:11:46 +0000192 err := json.Unmarshal(data, &config)
Colin Cross69f59a32019-02-15 10:39:37 -0800193 if err != nil {
Colin Cross988414c2020-01-11 01:11:46 +0000194 return config.GlobalConfig, err
Colin Cross69f59a32019-02-15 10:39:37 -0800195 }
196
197 // Construct paths that require a PathContext.
198 config.GlobalConfig.DirtyImageObjects = android.OptionalPathForPath(constructPath(ctx, config.DirtyImageObjects))
Colin Cross69f59a32019-02-15 10:39:37 -0800199 config.GlobalConfig.BootImageProfiles = constructPaths(ctx, config.BootImageProfiles)
200
Colin Cross988414c2020-01-11 01:11:46 +0000201 return config.GlobalConfig, nil
Colin Cross69f59a32019-02-15 10:39:37 -0800202}
203
Hans Boehm453bf092020-01-25 01:44:30 +0000204// LoadModuleConfig reads a per-module dexpreopt.config file into a ModuleConfig struct. It is not used in Soong, which
205// receives a ModuleConfig struct directly from java/dexpreopt.go. It is used in dexpreopt_gen called from oMake to
206// read the module dexpreopt.config written by Make.
207func LoadModuleConfig(ctx android.PathContext, data []byte) (ModuleConfig, error) {
Colin Cross69f59a32019-02-15 10:39:37 -0800208 type ModuleJSONConfig struct {
209 ModuleConfig
210
211 // Copies of entries in ModuleConfig that are not constructable without extra parameters. They will be
212 // used to construct the real value manually below.
213 BuildPath string
214 DexPath string
Colin Cross38b96852019-05-22 10:21:09 -0700215 ManifestPath string
Colin Cross69f59a32019-02-15 10:39:37 -0800216 ProfileClassListing string
217 LibraryPaths map[string]string
218 DexPreoptImages []string
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +0000219 DexPreoptImageLocations []string
Colin Cross69f59a32019-02-15 10:39:37 -0800220 PreoptBootClassPathDexFiles []string
Colin Cross69f59a32019-02-15 10:39:37 -0800221 }
222
223 config := ModuleJSONConfig{}
224
Colin Cross988414c2020-01-11 01:11:46 +0000225 err := json.Unmarshal(data, &config)
Colin Cross69f59a32019-02-15 10:39:37 -0800226 if err != nil {
227 return config.ModuleConfig, err
228 }
229
230 // Construct paths that require a PathContext.
231 config.ModuleConfig.BuildPath = constructPath(ctx, config.BuildPath).(android.OutputPath)
232 config.ModuleConfig.DexPath = constructPath(ctx, config.DexPath)
Colin Cross38b96852019-05-22 10:21:09 -0700233 config.ModuleConfig.ManifestPath = constructPath(ctx, config.ManifestPath)
Colin Cross69f59a32019-02-15 10:39:37 -0800234 config.ModuleConfig.ProfileClassListing = android.OptionalPathForPath(constructPath(ctx, config.ProfileClassListing))
235 config.ModuleConfig.LibraryPaths = constructPathMap(ctx, config.LibraryPaths)
236 config.ModuleConfig.DexPreoptImages = constructPaths(ctx, config.DexPreoptImages)
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +0000237 config.ModuleConfig.DexPreoptImageLocations = config.DexPreoptImageLocations
Colin Cross69f59a32019-02-15 10:39:37 -0800238 config.ModuleConfig.PreoptBootClassPathDexFiles = constructPaths(ctx, config.PreoptBootClassPathDexFiles)
Colin Cross69f59a32019-02-15 10:39:37 -0800239
Dan Willemsen0f416782019-06-13 21:44:53 +0000240 // This needs to exist, but dependencies are already handled in Make, so we don't need to pass them through JSON.
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +0000241 config.ModuleConfig.DexPreoptImagesDeps = make([]android.OutputPaths, len(config.ModuleConfig.DexPreoptImages))
Dan Willemsen0f416782019-06-13 21:44:53 +0000242
Colin Cross69f59a32019-02-15 10:39:37 -0800243 return config.ModuleConfig, nil
244}
245
Martin Stjernholm75a48d82020-01-10 20:32:59 +0000246// createGlobalSoongConfig creates a GlobalSoongConfig from the current context.
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000247// Should not be used in dexpreopt_gen.
Martin Stjernholm75a48d82020-01-10 20:32:59 +0000248func createGlobalSoongConfig(ctx android.ModuleContext) GlobalSoongConfig {
249 if ctx.Config().TestProductVariables != nil {
250 // If we're called in a test there'll be a confusing error from the path
251 // functions below that gets reported without a stack trace, so let's panic
252 // properly with a more helpful message.
253 panic("This should not be called from tests. Please call GlobalSoongConfigForTests somewhere in the test setup.")
254 }
255
Hans Boehm7b2e6f32020-01-25 01:44:30 +0000256 // Default to debug version to help find bugs.
257 // Set USE_DEX2OAT_DEBUG to false for only building non-debug versions.
258 var dex2oatBinary string
259 if ctx.Config().Getenv("USE_DEX2OAT_DEBUG") == "false" {
260 dex2oatBinary = "dex2oat"
261 } else {
262 dex2oatBinary = "dex2oatd"
263 }
264
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000265 return GlobalSoongConfig{
266 Profman: ctx.Config().HostToolPath(ctx, "profman"),
Hans Boehm7b2e6f32020-01-25 01:44:30 +0000267 Dex2oat: ctx.Config().HostToolPath(ctx, dex2oatBinary),
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000268 Aapt: ctx.Config().HostToolPath(ctx, "aapt"),
269 SoongZip: ctx.Config().HostToolPath(ctx, "soong_zip"),
270 Zip2zip: ctx.Config().HostToolPath(ctx, "zip2zip"),
271 ManifestCheck: ctx.Config().HostToolPath(ctx, "manifest_check"),
272 ConstructContext: android.PathForSource(ctx, "build/make/core/construct_context.sh"),
273 }
274}
275
Martin Stjernholm75a48d82020-01-10 20:32:59 +0000276var globalSoongConfigOnceKey = android.NewOnceKey("DexpreoptGlobalSoongConfig")
277
278// GetGlobalSoongConfig creates a GlobalSoongConfig the first time it's called,
279// and later returns the same cached instance.
280func GetGlobalSoongConfig(ctx android.ModuleContext) GlobalSoongConfig {
281 globalSoong := ctx.Config().Once(globalSoongConfigOnceKey, func() interface{} {
282 return createGlobalSoongConfig(ctx)
283 }).(GlobalSoongConfig)
284 return globalSoong
285}
286
287// GetCachedGlobalSoongConfig returns a cached GlobalSoongConfig created by an
288// earlier GetGlobalSoongConfig call. This function works with any context
289// compatible with a basic PathContext, since it doesn't try to create a
290// GlobalSoongConfig (which requires a full ModuleContext). It will panic if
291// called before the first GetGlobalSoongConfig call.
292func GetCachedGlobalSoongConfig(ctx android.PathContext) GlobalSoongConfig {
293 return ctx.Config().Get(globalSoongConfigOnceKey).(GlobalSoongConfig)
294}
295
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000296type globalJsonSoongConfig struct {
297 Profman string
298 Dex2oat string
299 Aapt string
300 SoongZip string
301 Zip2zip string
302 ManifestCheck string
303 ConstructContext string
304}
305
Hans Boehm453bf092020-01-25 01:44:30 +0000306// LoadGlobalSoongConfig reads the dexpreopt_soong.config file into a
307// GlobalSoongConfig struct. It is only used in dexpreopt_gen.
308func LoadGlobalSoongConfig(ctx android.PathContext, data []byte) (GlobalSoongConfig, error) {
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000309 var jc globalJsonSoongConfig
310
Colin Cross988414c2020-01-11 01:11:46 +0000311 err := json.Unmarshal(data, &jc)
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000312 if err != nil {
313 return GlobalSoongConfig{}, err
314 }
315
316 config := GlobalSoongConfig{
317 Profman: constructPath(ctx, jc.Profman),
318 Dex2oat: constructPath(ctx, jc.Dex2oat),
319 Aapt: constructPath(ctx, jc.Aapt),
320 SoongZip: constructPath(ctx, jc.SoongZip),
321 Zip2zip: constructPath(ctx, jc.Zip2zip),
322 ManifestCheck: constructPath(ctx, jc.ManifestCheck),
323 ConstructContext: constructPath(ctx, jc.ConstructContext),
324 }
325
326 return config, nil
327}
328
329func (s *globalSoongConfigSingleton) GenerateBuildActions(ctx android.SingletonContext) {
Martin Stjernholm75a48d82020-01-10 20:32:59 +0000330 config := GetCachedGlobalSoongConfig(ctx)
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000331 jc := globalJsonSoongConfig{
332 Profman: config.Profman.String(),
333 Dex2oat: config.Dex2oat.String(),
334 Aapt: config.Aapt.String(),
335 SoongZip: config.SoongZip.String(),
336 Zip2zip: config.Zip2zip.String(),
337 ManifestCheck: config.ManifestCheck.String(),
338 ConstructContext: config.ConstructContext.String(),
339 }
340
341 data, err := json.Marshal(jc)
342 if err != nil {
343 ctx.Errorf("failed to JSON marshal GlobalSoongConfig: %v", err)
344 return
345 }
346
347 ctx.Build(pctx, android.BuildParams{
348 Rule: android.WriteFile,
349 Output: android.PathForOutput(ctx, "dexpreopt_soong.config"),
350 Args: map[string]string{
351 "content": string(data),
352 },
353 })
354}
355
356func (s *globalSoongConfigSingleton) MakeVars(ctx android.MakeVarsContext) {
Martin Stjernholm75a48d82020-01-10 20:32:59 +0000357 config := GetCachedGlobalSoongConfig(ctx)
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000358
359 ctx.Strict("DEX2OAT", config.Dex2oat.String())
360 ctx.Strict("DEXPREOPT_GEN_DEPS", strings.Join([]string{
361 config.Profman.String(),
362 config.Dex2oat.String(),
363 config.Aapt.String(),
364 config.SoongZip.String(),
365 config.Zip2zip.String(),
366 config.ManifestCheck.String(),
367 config.ConstructContext.String(),
368 }, " "))
369}
370
Colin Cross69f59a32019-02-15 10:39:37 -0800371func GlobalConfigForTests(ctx android.PathContext) GlobalConfig {
372 return GlobalConfig{
Colin Cross69f59a32019-02-15 10:39:37 -0800373 DisablePreopt: false,
374 DisablePreoptModules: nil,
375 OnlyPreoptBootImageAndSystemServer: false,
376 HasSystemOther: false,
377 PatternsOnSystemOther: nil,
378 DisableGenerateProfile: false,
379 ProfileDir: "",
380 BootJars: nil,
Roshan Piusccc26ef2019-11-27 09:37:46 -0800381 UpdatableBootJars: nil,
Martin Stjernholmcc4b0ad2019-07-05 22:38:25 +0100382 ArtApexJars: nil,
Colin Cross69f59a32019-02-15 10:39:37 -0800383 SystemServerJars: nil,
384 SystemServerApps: nil,
Roshan Pius9b51a402019-11-21 12:36:53 -0800385 UpdatableSystemServerJars: nil,
Colin Cross69f59a32019-02-15 10:39:37 -0800386 SpeedApps: nil,
387 PreoptFlags: nil,
388 DefaultCompilerFilter: "",
389 SystemServerCompilerFilter: "",
390 GenerateDMFiles: false,
Colin Cross69f59a32019-02-15 10:39:37 -0800391 NoDebugInfo: false,
Mathieu Chartier3f7ddbb2019-04-29 09:33:50 -0700392 DontResolveStartupStrings: false,
Colin Cross69f59a32019-02-15 10:39:37 -0800393 AlwaysSystemServerDebugInfo: false,
394 NeverSystemServerDebugInfo: false,
395 AlwaysOtherDebugInfo: false,
396 NeverOtherDebugInfo: false,
Colin Cross69f59a32019-02-15 10:39:37 -0800397 IsEng: false,
398 SanitizeLite: false,
399 DefaultAppImages: false,
400 Dex2oatXmx: "",
401 Dex2oatXms: "",
402 EmptyDirectory: "empty_dir",
403 CpuVariant: nil,
404 InstructionSetFeatures: nil,
405 DirtyImageObjects: android.OptionalPath{},
Colin Cross69f59a32019-02-15 10:39:37 -0800406 BootImageProfiles: nil,
Colin Cross69f59a32019-02-15 10:39:37 -0800407 BootFlags: "",
408 Dex2oatImageXmx: "",
409 Dex2oatImageXms: "",
Martin Stjernholm75a48d82020-01-10 20:32:59 +0000410 }
411}
412
413func GlobalSoongConfigForTests(config android.Config) GlobalSoongConfig {
414 // Install the test GlobalSoongConfig in the Once cache so that later calls to
415 // Get(Cached)GlobalSoongConfig returns it without trying to create a real one.
416 return config.Once(globalSoongConfigOnceKey, func() interface{} {
417 return GlobalSoongConfig{
Colin Cross38b96852019-05-22 10:21:09 -0700418 Profman: android.PathForTesting("profman"),
419 Dex2oat: android.PathForTesting("dex2oat"),
420 Aapt: android.PathForTesting("aapt"),
421 SoongZip: android.PathForTesting("soong_zip"),
422 Zip2zip: android.PathForTesting("zip2zip"),
423 ManifestCheck: android.PathForTesting("manifest_check"),
424 ConstructContext: android.PathForTesting("construct_context.sh"),
Martin Stjernholm75a48d82020-01-10 20:32:59 +0000425 }
426 }).(GlobalSoongConfig)
Colin Cross69f59a32019-02-15 10:39:37 -0800427}