blob: cd74ec8470c67b135a5db71649c1d7ec18b1366a [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 Stjernholmbe9d0d22020-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
Nicolas Geoffray72892f12019-02-22 15:34:40 +000032 GenerateApexImage bool // generate an extra boot image only containing jars from the runtime apex
Nicolas Geoffray25c0e032019-04-04 18:45:20 +010033 UseApexImage bool // use the apex image by default
Nicolas Geoffray72892f12019-02-22 15:34:40 +000034
Colin Cross43f08db2018-11-12 10:13:39 -080035 HasSystemOther bool // store odex files that match PatternsOnSystemOther on the system_other partition
36 PatternsOnSystemOther []string // patterns (using '%' to denote a prefix match) to put odex on the system_other partition
37
Colin Cross69f59a32019-02-15 10:39:37 -080038 DisableGenerateProfile bool // don't generate profiles
39 ProfileDir string // directory to find profiles in
Colin Cross43f08db2018-11-12 10:13:39 -080040
Roshan Piusccc26ef2019-11-27 09:37:46 -080041 BootJars []string // modules for jars that form the boot class path
42 UpdatableBootJars []string // jars within apex that form the boot class path
Vladimir Markod2ee5322018-12-19 17:57:57 +000043
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +000044 ArtApexJars []string // modules for jars that are in the ART APEX
Colin Cross800fe132019-02-11 14:21:24 -080045
Roshan Pius9b51a402019-11-21 12:36:53 -080046 SystemServerJars []string // jars that form the system server
47 SystemServerApps []string // apps that are loaded into system server
48 UpdatableSystemServerJars []string // jars within apex that are loaded into system server
49 SpeedApps []string // apps that should be speed optimized
Colin Cross43f08db2018-11-12 10:13:39 -080050
51 PreoptFlags []string // global dex2oat flags that should be used if no module-specific dex2oat flags are specified
52
53 DefaultCompilerFilter string // default compiler filter to pass to dex2oat, overridden by --compiler-filter= in module-specific dex2oat flags
54 SystemServerCompilerFilter string // default compiler filter to pass to dex2oat for system server jars
55
Nicolas Geoffrayc1bf7242019-10-18 14:51:38 +010056 GenerateDMFiles bool // generate Dex Metadata files
Colin Cross43f08db2018-11-12 10:13:39 -080057
58 NoDebugInfo bool // don't generate debug info by default
Mathieu Chartier3f7ddbb2019-04-29 09:33:50 -070059 DontResolveStartupStrings bool // don't resolve string literals loaded during application startup.
Colin Cross43f08db2018-11-12 10:13:39 -080060 AlwaysSystemServerDebugInfo bool // always generate mini debug info for system server modules (overrides NoDebugInfo=true)
61 NeverSystemServerDebugInfo bool // never generate mini debug info for system server modules (overrides NoDebugInfo=false)
62 AlwaysOtherDebugInfo bool // always generate mini debug info for non-system server modules (overrides NoDebugInfo=true)
63 NeverOtherDebugInfo bool // never generate mini debug info for non-system server modules (overrides NoDebugInfo=true)
64
Colin Cross43f08db2018-11-12 10:13:39 -080065 IsEng bool // build is a eng variant
66 SanitizeLite bool // build is the second phase of a SANITIZE_LITE build
67
68 DefaultAppImages bool // build app images (TODO: .art files?) by default
69
Colin Cross800fe132019-02-11 14:21:24 -080070 Dex2oatXmx string // max heap size for dex2oat
71 Dex2oatXms string // initial heap size for dex2oat
Colin Cross43f08db2018-11-12 10:13:39 -080072
73 EmptyDirectory string // path to an empty directory
74
Colin Cross74ba9622019-02-11 15:11:14 -080075 CpuVariant map[android.ArchType]string // cpu variant for each architecture
76 InstructionSetFeatures map[android.ArchType]string // instruction set for each architecture
Colin Cross43f08db2018-11-12 10:13:39 -080077
Colin Cross800fe132019-02-11 14:21:24 -080078 // Only used for boot image
Mathieu Chartier6adeee12019-06-26 10:01:36 -070079 DirtyImageObjects android.OptionalPath // path to a dirty-image-objects file
80 BootImageProfiles android.Paths // path to a boot-image-profile.txt file
81 BootFlags string // extra flags to pass to dex2oat for the boot image
82 Dex2oatImageXmx string // max heap size for dex2oat for the boot image
83 Dex2oatImageXms string // initial heap size for dex2oat for the boot image
Colin Cross43f08db2018-11-12 10:13:39 -080084}
85
Martin Stjernholmc52aaf12020-01-06 23:11:37 +000086// GlobalSoongConfig contains the global config that is generated from Soong,
87// stored in dexpreopt_soong.config.
88type GlobalSoongConfig struct {
89 // Paths to tools possibly used by the generated commands.
90 Profman android.Path
91 Dex2oat android.Path
92 Aapt android.Path
93 SoongZip android.Path
94 Zip2zip android.Path
95 ManifestCheck android.Path
Colin Cross38b96852019-05-22 10:21:09 -070096 ConstructContext android.Path
Colin Cross43f08db2018-11-12 10:13:39 -080097}
98
99type ModuleConfig struct {
Victor Hsiehd181c8b2019-01-29 13:00:33 -0800100 Name string
101 DexLocation string // dex location on device
Colin Cross69f59a32019-02-15 10:39:37 -0800102 BuildPath android.OutputPath
103 DexPath android.Path
Colin Cross38b96852019-05-22 10:21:09 -0700104 ManifestPath android.Path
Victor Hsiehd181c8b2019-01-29 13:00:33 -0800105 UncompressedDex bool
106 HasApkLibraries bool
107 PreoptFlags []string
Colin Cross43f08db2018-11-12 10:13:39 -0800108
Colin Cross69f59a32019-02-15 10:39:37 -0800109 ProfileClassListing android.OptionalPath
Colin Cross43f08db2018-11-12 10:13:39 -0800110 ProfileIsTextListing bool
Nicolas Geoffraye7102422019-07-24 13:19:29 +0100111 ProfileBootListing android.OptionalPath
Colin Cross43f08db2018-11-12 10:13:39 -0800112
Colin Cross50ddcc42019-05-16 12:28:22 -0700113 EnforceUsesLibraries bool
114 PresentOptionalUsesLibraries []string
115 UsesLibraries []string
116 LibraryPaths map[string]android.Path
Colin Cross43f08db2018-11-12 10:13:39 -0800117
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +0000118 Archs []android.ArchType
119 DexPreoptImages []android.Path
120 DexPreoptImagesDeps []android.OutputPaths
121 DexPreoptImageLocations []string
Colin Cross43f08db2018-11-12 10:13:39 -0800122
Colin Cross69f59a32019-02-15 10:39:37 -0800123 PreoptBootClassPathDexFiles android.Paths // file paths of boot class path files
124 PreoptBootClassPathDexLocations []string // virtual locations of boot class path files
Colin Cross800fe132019-02-11 14:21:24 -0800125
Colin Cross43f08db2018-11-12 10:13:39 -0800126 PreoptExtractedApk bool // Overrides OnlyPreoptModules
127
128 NoCreateAppImage bool
129 ForceCreateAppImage bool
130
131 PresignedPrebuilt bool
Colin Cross43f08db2018-11-12 10:13:39 -0800132}
133
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000134type globalSoongConfigSingleton struct{}
135
136var pctx = android.NewPackageContext("android/soong/dexpreopt")
137
138func init() {
139 pctx.Import("android/soong/android")
140 android.RegisterSingletonType("dexpreopt-soong-config", func() android.Singleton {
141 return &globalSoongConfigSingleton{}
142 })
143}
144
Colin Cross69f59a32019-02-15 10:39:37 -0800145func constructPath(ctx android.PathContext, path string) android.Path {
146 buildDirPrefix := ctx.Config().BuildDir() + "/"
147 if path == "" {
148 return nil
149 } else if strings.HasPrefix(path, buildDirPrefix) {
150 return android.PathForOutput(ctx, strings.TrimPrefix(path, buildDirPrefix))
151 } else {
152 return android.PathForSource(ctx, path)
153 }
Colin Cross43f08db2018-11-12 10:13:39 -0800154}
155
Colin Cross69f59a32019-02-15 10:39:37 -0800156func constructPaths(ctx android.PathContext, paths []string) android.Paths {
157 var ret android.Paths
158 for _, path := range paths {
159 ret = append(ret, constructPath(ctx, path))
160 }
161 return ret
Colin Cross43f08db2018-11-12 10:13:39 -0800162}
163
Colin Cross69f59a32019-02-15 10:39:37 -0800164func constructPathMap(ctx android.PathContext, paths map[string]string) map[string]android.Path {
165 ret := map[string]android.Path{}
166 for key, path := range paths {
167 ret[key] = constructPath(ctx, path)
168 }
169 return ret
170}
171
172func constructWritablePath(ctx android.PathContext, path string) android.WritablePath {
173 if path == "" {
174 return nil
175 }
176 return constructPath(ctx, path).(android.WritablePath)
177}
178
Martin Stjernholmdae8a802020-01-20 18:12:23 +0000179// ParseGlobalConfig parses the given data assumed to be read from the global
180// dexpreopt.config file into a GlobalConfig struct.
181func ParseGlobalConfig(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
Martin Stjernholmdae8a802020-01-20 18:12:23 +0000204type globalConfigAndRaw struct {
205 global GlobalConfig
206 data []byte
207}
208
209// GetGlobalConfig returns the global dexpreopt.config that's created in the
210// make config phase. It is loaded once the first time it is called for any
211// ctx.Config(), and returns the same data for all future calls with the same
212// ctx.Config(). A value can be inserted for tests using
213// setDexpreoptTestGlobalConfig.
214func GetGlobalConfig(ctx android.PathContext) GlobalConfig {
215 return getGlobalConfigRaw(ctx).global
216}
217
218// GetGlobalConfigRawData is the same as GetGlobalConfig, except that it returns
219// the literal content of dexpreopt.config.
220func GetGlobalConfigRawData(ctx android.PathContext) []byte {
221 return getGlobalConfigRaw(ctx).data
222}
223
224var globalConfigOnceKey = android.NewOnceKey("DexpreoptGlobalConfig")
225var testGlobalConfigOnceKey = android.NewOnceKey("TestDexpreoptGlobalConfig")
226
227func getGlobalConfigRaw(ctx android.PathContext) globalConfigAndRaw {
228 return ctx.Config().Once(globalConfigOnceKey, func() interface{} {
229 if data, err := ctx.Config().DexpreoptGlobalConfig(ctx); err != nil {
230 panic(err)
231 } else if data != nil {
232 globalConfig, err := ParseGlobalConfig(ctx, data)
233 if err != nil {
234 panic(err)
235 }
236 return globalConfigAndRaw{globalConfig, data}
237 }
238
239 // No global config filename set, see if there is a test config set
240 return ctx.Config().Once(testGlobalConfigOnceKey, func() interface{} {
241 // Nope, return a config with preopting disabled
242 return globalConfigAndRaw{GlobalConfig{
243 DisablePreopt: true,
244 DisableGenerateProfile: true,
245 }, nil}
246 })
247 }).(globalConfigAndRaw)
248}
249
250// SetTestGlobalConfig sets a GlobalConfig that future calls to GetGlobalConfig
251// will return. It must be called before the first call to GetGlobalConfig for
252// the config.
253func SetTestGlobalConfig(config android.Config, globalConfig GlobalConfig) {
254 config.Once(testGlobalConfigOnceKey, func() interface{} { return globalConfigAndRaw{globalConfig, nil} })
255}
256
257// ParseModuleConfig parses a per-module dexpreopt.config file into a
258// ModuleConfig struct. It is not used in Soong, which receives a ModuleConfig
259// struct directly from java/dexpreopt.go. It is used in dexpreopt_gen called
260// from Make to read the module dexpreopt.config written in the Make config
261// stage.
262func ParseModuleConfig(ctx android.PathContext, data []byte) (ModuleConfig, error) {
Colin Cross69f59a32019-02-15 10:39:37 -0800263 type ModuleJSONConfig struct {
264 ModuleConfig
265
266 // Copies of entries in ModuleConfig that are not constructable without extra parameters. They will be
267 // used to construct the real value manually below.
268 BuildPath string
269 DexPath string
Colin Cross38b96852019-05-22 10:21:09 -0700270 ManifestPath string
Colin Cross69f59a32019-02-15 10:39:37 -0800271 ProfileClassListing string
272 LibraryPaths map[string]string
273 DexPreoptImages []string
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +0000274 DexPreoptImageLocations []string
Colin Cross69f59a32019-02-15 10:39:37 -0800275 PreoptBootClassPathDexFiles []string
Colin Cross69f59a32019-02-15 10:39:37 -0800276 }
277
278 config := ModuleJSONConfig{}
279
Colin Cross988414c2020-01-11 01:11:46 +0000280 err := json.Unmarshal(data, &config)
Colin Cross69f59a32019-02-15 10:39:37 -0800281 if err != nil {
282 return config.ModuleConfig, err
283 }
284
285 // Construct paths that require a PathContext.
286 config.ModuleConfig.BuildPath = constructPath(ctx, config.BuildPath).(android.OutputPath)
287 config.ModuleConfig.DexPath = constructPath(ctx, config.DexPath)
Colin Cross38b96852019-05-22 10:21:09 -0700288 config.ModuleConfig.ManifestPath = constructPath(ctx, config.ManifestPath)
Colin Cross69f59a32019-02-15 10:39:37 -0800289 config.ModuleConfig.ProfileClassListing = android.OptionalPathForPath(constructPath(ctx, config.ProfileClassListing))
290 config.ModuleConfig.LibraryPaths = constructPathMap(ctx, config.LibraryPaths)
291 config.ModuleConfig.DexPreoptImages = constructPaths(ctx, config.DexPreoptImages)
Ulya Trafimovich4d2eeed2019-11-08 10:54:21 +0000292 config.ModuleConfig.DexPreoptImageLocations = config.DexPreoptImageLocations
Colin Cross69f59a32019-02-15 10:39:37 -0800293 config.ModuleConfig.PreoptBootClassPathDexFiles = constructPaths(ctx, config.PreoptBootClassPathDexFiles)
Colin Cross69f59a32019-02-15 10:39:37 -0800294
Dan Willemsen0f416782019-06-13 21:44:53 +0000295 // 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 +0000296 config.ModuleConfig.DexPreoptImagesDeps = make([]android.OutputPaths, len(config.ModuleConfig.DexPreoptImages))
Dan Willemsen0f416782019-06-13 21:44:53 +0000297
Colin Cross69f59a32019-02-15 10:39:37 -0800298 return config.ModuleConfig, nil
299}
300
Martin Stjernholmbe9d0d22020-01-10 20:32:59 +0000301// createGlobalSoongConfig creates a GlobalSoongConfig from the current context.
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000302// Should not be used in dexpreopt_gen.
Martin Stjernholmbe9d0d22020-01-10 20:32:59 +0000303func createGlobalSoongConfig(ctx android.ModuleContext) GlobalSoongConfig {
304 if ctx.Config().TestProductVariables != nil {
305 // If we're called in a test there'll be a confusing error from the path
306 // functions below that gets reported without a stack trace, so let's panic
307 // properly with a more helpful message.
308 panic("This should not be called from tests. Please call GlobalSoongConfigForTests somewhere in the test setup.")
309 }
310
Hans Boehm7b2e6f32020-01-25 01:44:30 +0000311 // Default to debug version to help find bugs.
312 // Set USE_DEX2OAT_DEBUG to false for only building non-debug versions.
313 var dex2oatBinary string
314 if ctx.Config().Getenv("USE_DEX2OAT_DEBUG") == "false" {
315 dex2oatBinary = "dex2oat"
316 } else {
317 dex2oatBinary = "dex2oatd"
318 }
319
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000320 return GlobalSoongConfig{
321 Profman: ctx.Config().HostToolPath(ctx, "profman"),
Hans Boehm7b2e6f32020-01-25 01:44:30 +0000322 Dex2oat: ctx.Config().HostToolPath(ctx, dex2oatBinary),
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000323 Aapt: ctx.Config().HostToolPath(ctx, "aapt"),
324 SoongZip: ctx.Config().HostToolPath(ctx, "soong_zip"),
325 Zip2zip: ctx.Config().HostToolPath(ctx, "zip2zip"),
326 ManifestCheck: ctx.Config().HostToolPath(ctx, "manifest_check"),
327 ConstructContext: android.PathForSource(ctx, "build/make/core/construct_context.sh"),
328 }
329}
330
Martin Stjernholmbe9d0d22020-01-10 20:32:59 +0000331var globalSoongConfigOnceKey = android.NewOnceKey("DexpreoptGlobalSoongConfig")
332
333// GetGlobalSoongConfig creates a GlobalSoongConfig the first time it's called,
334// and later returns the same cached instance.
335func GetGlobalSoongConfig(ctx android.ModuleContext) GlobalSoongConfig {
336 globalSoong := ctx.Config().Once(globalSoongConfigOnceKey, func() interface{} {
337 return createGlobalSoongConfig(ctx)
338 }).(GlobalSoongConfig)
339 return globalSoong
340}
341
342// GetCachedGlobalSoongConfig returns a cached GlobalSoongConfig created by an
343// earlier GetGlobalSoongConfig call. This function works with any context
344// compatible with a basic PathContext, since it doesn't try to create a
345// GlobalSoongConfig (which requires a full ModuleContext). It will panic if
346// called before the first GetGlobalSoongConfig call.
347func GetCachedGlobalSoongConfig(ctx android.PathContext) GlobalSoongConfig {
348 return ctx.Config().Get(globalSoongConfigOnceKey).(GlobalSoongConfig)
349}
350
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000351type globalJsonSoongConfig struct {
352 Profman string
353 Dex2oat string
354 Aapt string
355 SoongZip string
356 Zip2zip string
357 ManifestCheck string
358 ConstructContext string
359}
360
Martin Stjernholmdae8a802020-01-20 18:12:23 +0000361// ParseGlobalSoongConfig parses the given data assumed to be read from the
362// global dexpreopt_soong.config file into a GlobalSoongConfig struct. It is
363// only used in dexpreopt_gen.
364func ParseGlobalSoongConfig(ctx android.PathContext, data []byte) (GlobalSoongConfig, error) {
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000365 var jc globalJsonSoongConfig
366
Colin Cross988414c2020-01-11 01:11:46 +0000367 err := json.Unmarshal(data, &jc)
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000368 if err != nil {
369 return GlobalSoongConfig{}, err
370 }
371
372 config := GlobalSoongConfig{
373 Profman: constructPath(ctx, jc.Profman),
374 Dex2oat: constructPath(ctx, jc.Dex2oat),
375 Aapt: constructPath(ctx, jc.Aapt),
376 SoongZip: constructPath(ctx, jc.SoongZip),
377 Zip2zip: constructPath(ctx, jc.Zip2zip),
378 ManifestCheck: constructPath(ctx, jc.ManifestCheck),
379 ConstructContext: constructPath(ctx, jc.ConstructContext),
380 }
381
382 return config, nil
383}
384
385func (s *globalSoongConfigSingleton) GenerateBuildActions(ctx android.SingletonContext) {
Martin Stjernholmbe9d0d22020-01-10 20:32:59 +0000386 config := GetCachedGlobalSoongConfig(ctx)
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000387 jc := globalJsonSoongConfig{
388 Profman: config.Profman.String(),
389 Dex2oat: config.Dex2oat.String(),
390 Aapt: config.Aapt.String(),
391 SoongZip: config.SoongZip.String(),
392 Zip2zip: config.Zip2zip.String(),
393 ManifestCheck: config.ManifestCheck.String(),
394 ConstructContext: config.ConstructContext.String(),
395 }
396
397 data, err := json.Marshal(jc)
398 if err != nil {
399 ctx.Errorf("failed to JSON marshal GlobalSoongConfig: %v", err)
400 return
401 }
402
403 ctx.Build(pctx, android.BuildParams{
404 Rule: android.WriteFile,
405 Output: android.PathForOutput(ctx, "dexpreopt_soong.config"),
406 Args: map[string]string{
407 "content": string(data),
408 },
409 })
410}
411
412func (s *globalSoongConfigSingleton) MakeVars(ctx android.MakeVarsContext) {
Martin Stjernholmbe9d0d22020-01-10 20:32:59 +0000413 config := GetCachedGlobalSoongConfig(ctx)
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000414
415 ctx.Strict("DEX2OAT", config.Dex2oat.String())
416 ctx.Strict("DEXPREOPT_GEN_DEPS", strings.Join([]string{
417 config.Profman.String(),
418 config.Dex2oat.String(),
419 config.Aapt.String(),
420 config.SoongZip.String(),
421 config.Zip2zip.String(),
422 config.ManifestCheck.String(),
423 config.ConstructContext.String(),
424 }, " "))
425}
426
Colin Cross69f59a32019-02-15 10:39:37 -0800427func GlobalConfigForTests(ctx android.PathContext) GlobalConfig {
428 return GlobalConfig{
Colin Cross69f59a32019-02-15 10:39:37 -0800429 DisablePreopt: false,
430 DisablePreoptModules: nil,
431 OnlyPreoptBootImageAndSystemServer: false,
432 HasSystemOther: false,
433 PatternsOnSystemOther: nil,
434 DisableGenerateProfile: false,
435 ProfileDir: "",
436 BootJars: nil,
Roshan Piusccc26ef2019-11-27 09:37:46 -0800437 UpdatableBootJars: nil,
Martin Stjernholmcc4b0ad2019-07-05 22:38:25 +0100438 ArtApexJars: nil,
Colin Cross69f59a32019-02-15 10:39:37 -0800439 SystemServerJars: nil,
440 SystemServerApps: nil,
Roshan Pius9b51a402019-11-21 12:36:53 -0800441 UpdatableSystemServerJars: nil,
Colin Cross69f59a32019-02-15 10:39:37 -0800442 SpeedApps: nil,
443 PreoptFlags: nil,
444 DefaultCompilerFilter: "",
445 SystemServerCompilerFilter: "",
446 GenerateDMFiles: false,
Colin Cross69f59a32019-02-15 10:39:37 -0800447 NoDebugInfo: false,
Mathieu Chartier3f7ddbb2019-04-29 09:33:50 -0700448 DontResolveStartupStrings: false,
Colin Cross69f59a32019-02-15 10:39:37 -0800449 AlwaysSystemServerDebugInfo: false,
450 NeverSystemServerDebugInfo: false,
451 AlwaysOtherDebugInfo: false,
452 NeverOtherDebugInfo: false,
Colin Cross69f59a32019-02-15 10:39:37 -0800453 IsEng: false,
454 SanitizeLite: false,
455 DefaultAppImages: false,
456 Dex2oatXmx: "",
457 Dex2oatXms: "",
458 EmptyDirectory: "empty_dir",
459 CpuVariant: nil,
460 InstructionSetFeatures: nil,
461 DirtyImageObjects: android.OptionalPath{},
Colin Cross69f59a32019-02-15 10:39:37 -0800462 BootImageProfiles: nil,
Colin Cross69f59a32019-02-15 10:39:37 -0800463 BootFlags: "",
464 Dex2oatImageXmx: "",
465 Dex2oatImageXms: "",
Martin Stjernholmbe9d0d22020-01-10 20:32:59 +0000466 }
467}
468
469func GlobalSoongConfigForTests(config android.Config) GlobalSoongConfig {
470 // Install the test GlobalSoongConfig in the Once cache so that later calls to
471 // Get(Cached)GlobalSoongConfig returns it without trying to create a real one.
472 return config.Once(globalSoongConfigOnceKey, func() interface{} {
473 return GlobalSoongConfig{
Colin Cross38b96852019-05-22 10:21:09 -0700474 Profman: android.PathForTesting("profman"),
475 Dex2oat: android.PathForTesting("dex2oat"),
476 Aapt: android.PathForTesting("aapt"),
477 SoongZip: android.PathForTesting("soong_zip"),
478 Zip2zip: android.PathForTesting("zip2zip"),
479 ManifestCheck: android.PathForTesting("manifest_check"),
480 ConstructContext: android.PathForTesting("construct_context.sh"),
Martin Stjernholmbe9d0d22020-01-10 20:32:59 +0000481 }
482 }).(GlobalSoongConfig)
Colin Cross69f59a32019-02-15 10:39:37 -0800483}