blob: e3804e57fbca4fe573a66374484195d5a9f9dde0 [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"
Martin Stjernholmd90676f2020-01-11 00:37:30 +000019 "fmt"
Paul Duffin7d1d0832021-04-23 11:39:41 +010020 "reflect"
Colin Cross69f59a32019-02-15 10:39:37 -080021 "strings"
Colin Cross74ba9622019-02-11 15:11:14 -080022
Martin Stjernholmd90676f2020-01-11 00:37:30 +000023 "github.com/google/blueprint"
24
Colin Cross74ba9622019-02-11 15:11:14 -080025 "android/soong/android"
Colin Cross43f08db2018-11-12 10:13:39 -080026)
27
Martin Stjernholmc52aaf12020-01-06 23:11:37 +000028// GlobalConfig stores the configuration for dex preopting. The fields are set
Martin Stjernholm75a48d82020-01-10 20:32:59 +000029// from product variables via dex_preopt_config.mk.
Colin Cross43f08db2018-11-12 10:13:39 -080030type GlobalConfig struct {
Ulya Trafimovicha4a1c4e2021-01-15 18:40:04 +000031 DisablePreopt bool // disable preopt for all modules (excluding boot images)
32 DisablePreoptBootImages bool // disable prepot for boot images
33 DisablePreoptModules []string // modules with preopt disabled by product-specific config
Colin Cross43f08db2018-11-12 10:13:39 -080034
Jiakai Zhang23984422023-11-09 16:47:04 +000035 OnlyPreoptArtBootImage bool // only preopt jars in the ART boot image
Colin Cross43f08db2018-11-12 10:13:39 -080036
Ulya Trafimovich9023b022021-03-22 16:02:28 +000037 PreoptWithUpdatableBcp bool // If updatable boot jars are included in dexpreopt or not.
38
Colin Cross43f08db2018-11-12 10:13:39 -080039 HasSystemOther bool // store odex files that match PatternsOnSystemOther on the system_other partition
40 PatternsOnSystemOther []string // patterns (using '%' to denote a prefix match) to put odex on the system_other partition
41
Colin Cross69f59a32019-02-15 10:39:37 -080042 DisableGenerateProfile bool // don't generate profiles
43 ProfileDir string // directory to find profiles in
Colin Cross43f08db2018-11-12 10:13:39 -080044
satayevd604b212021-07-21 14:23:52 +010045 BootJars android.ConfiguredJarList // modules for jars that form the boot class path
46 ApexBootJars android.ConfiguredJarList // jars within apex that form the boot class path
Vladimir Markod2ee5322018-12-19 17:57:57 +000047
Jiakai Zhang556bdf82023-07-12 16:51:57 +010048 ArtApexJars android.ConfiguredJarList // modules for jars that are in the ART APEX
49 TestOnlyArtBootImageJars android.ConfiguredJarList // modules for jars to be included in the ART boot image for testing
Colin Cross800fe132019-02-11 14:21:24 -080050
Jiakai Zhangcee9e192021-10-29 19:46:45 +000051 SystemServerJars android.ConfiguredJarList // system_server classpath jars on the platform
52 SystemServerApps []string // apps that are loaded into system server
53 ApexSystemServerJars android.ConfiguredJarList // system_server classpath jars delivered via apex
54 StandaloneSystemServerJars android.ConfiguredJarList // jars on the platform that system_server loads dynamically using separate classloaders
55 ApexStandaloneSystemServerJars android.ConfiguredJarList // jars delivered via apex that system_server loads dynamically using separate classloaders
56 SpeedApps []string // apps that should be speed optimized
Colin Cross43f08db2018-11-12 10:13:39 -080057
Ulya Trafimovichcd3203f2020-03-27 11:30:00 +000058 BrokenSuboptimalOrderOfSystemServerJars bool // if true, sub-optimal order does not cause a build error
59
Colin Cross43f08db2018-11-12 10:13:39 -080060 PreoptFlags []string // global dex2oat flags that should be used if no module-specific dex2oat flags are specified
61
62 DefaultCompilerFilter string // default compiler filter to pass to dex2oat, overridden by --compiler-filter= in module-specific dex2oat flags
63 SystemServerCompilerFilter string // default compiler filter to pass to dex2oat for system server jars
64
Nicolas Geoffrayc1bf7242019-10-18 14:51:38 +010065 GenerateDMFiles bool // generate Dex Metadata files
Colin Cross43f08db2018-11-12 10:13:39 -080066
67 NoDebugInfo bool // don't generate debug info by default
Mathieu Chartier3f7ddbb2019-04-29 09:33:50 -070068 DontResolveStartupStrings bool // don't resolve string literals loaded during application startup.
Colin Cross43f08db2018-11-12 10:13:39 -080069 AlwaysSystemServerDebugInfo bool // always generate mini debug info for system server modules (overrides NoDebugInfo=true)
70 NeverSystemServerDebugInfo bool // never generate mini debug info for system server modules (overrides NoDebugInfo=false)
71 AlwaysOtherDebugInfo bool // always generate mini debug info for non-system server modules (overrides NoDebugInfo=true)
72 NeverOtherDebugInfo bool // never generate mini debug info for non-system server modules (overrides NoDebugInfo=true)
73
Colin Cross43f08db2018-11-12 10:13:39 -080074 IsEng bool // build is a eng variant
75 SanitizeLite bool // build is the second phase of a SANITIZE_LITE build
76
77 DefaultAppImages bool // build app images (TODO: .art files?) by default
78
Colin Cross800fe132019-02-11 14:21:24 -080079 Dex2oatXmx string // max heap size for dex2oat
80 Dex2oatXms string // initial heap size for dex2oat
Colin Cross43f08db2018-11-12 10:13:39 -080081
82 EmptyDirectory string // path to an empty directory
83
Colin Cross74ba9622019-02-11 15:11:14 -080084 CpuVariant map[android.ArchType]string // cpu variant for each architecture
85 InstructionSetFeatures map[android.ArchType]string // instruction set for each architecture
Colin Cross43f08db2018-11-12 10:13:39 -080086
Nicolas Geoffray1086e602021-01-20 14:30:40 +000087 BootImageProfiles android.Paths // path to a boot-image-profile.txt file
88 BootFlags string // extra flags to pass to dex2oat for the boot image
89 Dex2oatImageXmx string // max heap size for dex2oat for the boot image
90 Dex2oatImageXms string // initial heap size for dex2oat for the boot image
Ulya Trafimovich8c35fcf2021-02-17 16:23:28 +000091
Ulya Trafimovich4a13acb2021-03-02 12:25:02 +000092 // If true, downgrade the compiler filter of dexpreopt to "verify" when verify_uses_libraries
Ulya Trafimovich8c35fcf2021-02-17 16:23:28 +000093 // check fails, instead of failing the build. This will disable any AOT-compilation.
94 //
95 // The intended use case for this flag is to have a smoother migration path for the Java
96 // modules that need to add <uses-library> information in their build files. The flag allows to
97 // quickly silence build errors. This flag should be used with caution and only as a temporary
98 // measure, as it masks real errors and affects performance.
99 RelaxUsesLibraryCheck bool
Jiakai Zhang616be062022-11-16 11:50:59 +0000100
Jiakai Zhang7d292222024-01-18 17:27:42 +0000101 // "true" to force preopt with CMC GC (a.k.a., UFFD GC); "false" to force preopt with CC GC;
102 // "default" to determine the GC type based on the kernel version file.
103 EnableUffdGc string
Colin Cross43f08db2018-11-12 10:13:39 -0800104}
105
Jiakai Zhang389a6472021-12-14 18:54:06 +0000106var allPlatformSystemServerJarsKey = android.NewOnceKey("allPlatformSystemServerJars")
107
108// Returns all jars on the platform that system_server loads, including those on classpath and those
109// loaded dynamically.
110func (g *GlobalConfig) AllPlatformSystemServerJars(ctx android.PathContext) *android.ConfiguredJarList {
111 return ctx.Config().Once(allPlatformSystemServerJarsKey, func() interface{} {
112 res := g.SystemServerJars.AppendList(&g.StandaloneSystemServerJars)
113 return &res
114 }).(*android.ConfiguredJarList)
115}
116
117var allApexSystemServerJarsKey = android.NewOnceKey("allApexSystemServerJars")
118
119// Returns all jars delivered via apex that system_server loads, including those on classpath and
120// those loaded dynamically.
121func (g *GlobalConfig) AllApexSystemServerJars(ctx android.PathContext) *android.ConfiguredJarList {
122 return ctx.Config().Once(allApexSystemServerJarsKey, func() interface{} {
123 res := g.ApexSystemServerJars.AppendList(&g.ApexStandaloneSystemServerJars)
124 return &res
125 }).(*android.ConfiguredJarList)
126}
127
128var allSystemServerClasspathJarsKey = android.NewOnceKey("allSystemServerClasspathJars")
129
130// Returns all system_server classpath jars.
131func (g *GlobalConfig) AllSystemServerClasspathJars(ctx android.PathContext) *android.ConfiguredJarList {
132 return ctx.Config().Once(allSystemServerClasspathJarsKey, func() interface{} {
133 res := g.SystemServerJars.AppendList(&g.ApexSystemServerJars)
134 return &res
135 }).(*android.ConfiguredJarList)
136}
137
138var allSystemServerJarsKey = android.NewOnceKey("allSystemServerJars")
139
140// Returns all jars that system_server loads.
141func (g *GlobalConfig) AllSystemServerJars(ctx android.PathContext) *android.ConfiguredJarList {
142 return ctx.Config().Once(allSystemServerJarsKey, func() interface{} {
143 res := g.AllPlatformSystemServerJars(ctx).AppendList(g.AllApexSystemServerJars(ctx))
144 return &res
145 }).(*android.ConfiguredJarList)
146}
147
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000148// GlobalSoongConfig contains the global config that is generated from Soong,
149// stored in dexpreopt_soong.config.
150type GlobalSoongConfig struct {
151 // Paths to tools possibly used by the generated commands.
152 Profman android.Path
153 Dex2oat android.Path
154 Aapt android.Path
155 SoongZip android.Path
156 Zip2zip android.Path
157 ManifestCheck android.Path
Colin Cross38b96852019-05-22 10:21:09 -0700158 ConstructContext android.Path
Jiakai Zhang7d292222024-01-18 17:27:42 +0000159 UffdGcFlag android.WritablePath
Colin Cross43f08db2018-11-12 10:13:39 -0800160}
161
162type ModuleConfig struct {
Victor Hsiehd181c8b2019-01-29 13:00:33 -0800163 Name string
164 DexLocation string // dex location on device
Colin Cross69f59a32019-02-15 10:39:37 -0800165 BuildPath android.OutputPath
166 DexPath android.Path
Jeongik Cha33a3a812021-04-15 09:12:49 +0900167 ManifestPath android.OptionalPath
Victor Hsiehd181c8b2019-01-29 13:00:33 -0800168 UncompressedDex bool
169 HasApkLibraries bool
170 PreoptFlags []string
Colin Cross43f08db2018-11-12 10:13:39 -0800171
Colin Cross69f59a32019-02-15 10:39:37 -0800172 ProfileClassListing android.OptionalPath
Colin Cross43f08db2018-11-12 10:13:39 -0800173 ProfileIsTextListing bool
Nicolas Geoffraye7102422019-07-24 13:19:29 +0100174 ProfileBootListing android.OptionalPath
Colin Cross43f08db2018-11-12 10:13:39 -0800175
Ulya Trafimovich8c35fcf2021-02-17 16:23:28 +0000176 EnforceUsesLibraries bool // turn on build-time verify_uses_libraries check
177 EnforceUsesLibrariesStatusFile android.Path // a file with verify_uses_libraries errors (if any)
178 ProvidesUsesLibrary string // library name (usually the same as module name)
179 ClassLoaderContexts ClassLoaderContextMap
Colin Cross43f08db2018-11-12 10:13:39 -0800180
Jeongik Cha4dda75e2021-04-27 23:56:44 +0900181 Archs []android.ArchType
182 DexPreoptImagesDeps []android.OutputPaths
183
184 DexPreoptImageLocationsOnHost []string // boot image location on host (file path without the arch subdirectory)
185 DexPreoptImageLocationsOnDevice []string // boot image location on device (file path without the arch subdirectory)
Colin Cross43f08db2018-11-12 10:13:39 -0800186
Colin Cross69f59a32019-02-15 10:39:37 -0800187 PreoptBootClassPathDexFiles android.Paths // file paths of boot class path files
188 PreoptBootClassPathDexLocations []string // virtual locations of boot class path files
Colin Cross800fe132019-02-11 14:21:24 -0800189
Colin Cross43f08db2018-11-12 10:13:39 -0800190 NoCreateAppImage bool
191 ForceCreateAppImage bool
192
193 PresignedPrebuilt bool
Spandan Das950deca2024-10-01 18:35:23 +0000194
195 // ApexPartition is the partition in which the dexpreopt files of apex system server jars (if any) are installed.
196 // This is a noop unless the module is apex system server jar.
197 ApexPartition string
Colin Cross43f08db2018-11-12 10:13:39 -0800198}
199
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000200type globalSoongConfigSingleton struct{}
201
202var pctx = android.NewPackageContext("android/soong/dexpreopt")
203
204func init() {
205 pctx.Import("android/soong/android")
LaMont Jones0c10e4d2023-05-16 00:58:37 +0000206 android.RegisterParallelSingletonType("dexpreopt-soong-config", func() android.Singleton {
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000207 return &globalSoongConfigSingleton{}
208 })
209}
210
Colin Cross69f59a32019-02-15 10:39:37 -0800211func constructPath(ctx android.PathContext, path string) android.Path {
Lukacs T. Berki9f6c24a2021-08-26 15:07:24 +0200212 buildDirPrefix := ctx.Config().SoongOutDir() + "/"
Colin Cross69f59a32019-02-15 10:39:37 -0800213 if path == "" {
214 return nil
215 } else if strings.HasPrefix(path, buildDirPrefix) {
216 return android.PathForOutput(ctx, strings.TrimPrefix(path, buildDirPrefix))
217 } else {
218 return android.PathForSource(ctx, path)
219 }
Colin Cross43f08db2018-11-12 10:13:39 -0800220}
221
Colin Cross69f59a32019-02-15 10:39:37 -0800222func constructPaths(ctx android.PathContext, paths []string) android.Paths {
223 var ret android.Paths
224 for _, path := range paths {
225 ret = append(ret, constructPath(ctx, path))
226 }
227 return ret
Colin Cross43f08db2018-11-12 10:13:39 -0800228}
229
Colin Cross69f59a32019-02-15 10:39:37 -0800230func constructWritablePath(ctx android.PathContext, path string) android.WritablePath {
231 if path == "" {
232 return nil
233 }
234 return constructPath(ctx, path).(android.WritablePath)
235}
236
Martin Stjernholm40f9f3c2020-01-20 18:12:23 +0000237// ParseGlobalConfig parses the given data assumed to be read from the global
238// dexpreopt.config file into a GlobalConfig struct.
Martin Stjernholm8d80cee2020-01-31 17:44:54 +0000239func ParseGlobalConfig(ctx android.PathContext, data []byte) (*GlobalConfig, error) {
Colin Cross69f59a32019-02-15 10:39:37 -0800240 type GlobalJSONConfig struct {
Martin Stjernholm8d80cee2020-01-31 17:44:54 +0000241 *GlobalConfig
Colin Cross69f59a32019-02-15 10:39:37 -0800242
243 // Copies of entries in GlobalConfig that are not constructable without extra parameters. They will be
244 // used to construct the real value manually below.
Paul Duffin7ccacae2020-10-23 21:14:20 +0100245 BootImageProfiles []string
Colin Cross69f59a32019-02-15 10:39:37 -0800246 }
247
248 config := GlobalJSONConfig{}
Colin Cross988414c2020-01-11 01:11:46 +0000249 err := json.Unmarshal(data, &config)
Colin Cross69f59a32019-02-15 10:39:37 -0800250 if err != nil {
Colin Cross988414c2020-01-11 01:11:46 +0000251 return config.GlobalConfig, err
Colin Cross69f59a32019-02-15 10:39:37 -0800252 }
253
254 // Construct paths that require a PathContext.
Colin Cross69f59a32019-02-15 10:39:37 -0800255 config.GlobalConfig.BootImageProfiles = constructPaths(ctx, config.BootImageProfiles)
256
Colin Cross988414c2020-01-11 01:11:46 +0000257 return config.GlobalConfig, nil
Colin Cross69f59a32019-02-15 10:39:37 -0800258}
259
Martin Stjernholm40f9f3c2020-01-20 18:12:23 +0000260type globalConfigAndRaw struct {
Colin Cross7134e282021-12-01 12:16:55 -0800261 global *GlobalConfig
262 data []byte
263 pathErrors []error
Martin Stjernholm40f9f3c2020-01-20 18:12:23 +0000264}
265
266// GetGlobalConfig returns the global dexpreopt.config that's created in the
267// make config phase. It is loaded once the first time it is called for any
268// ctx.Config(), and returns the same data for all future calls with the same
269// ctx.Config(). A value can be inserted for tests using
270// setDexpreoptTestGlobalConfig.
Martin Stjernholm8d80cee2020-01-31 17:44:54 +0000271func GetGlobalConfig(ctx android.PathContext) *GlobalConfig {
Martin Stjernholm40f9f3c2020-01-20 18:12:23 +0000272 return getGlobalConfigRaw(ctx).global
273}
274
275// GetGlobalConfigRawData is the same as GetGlobalConfig, except that it returns
276// the literal content of dexpreopt.config.
277func GetGlobalConfigRawData(ctx android.PathContext) []byte {
278 return getGlobalConfigRaw(ctx).data
279}
280
281var globalConfigOnceKey = android.NewOnceKey("DexpreoptGlobalConfig")
282var testGlobalConfigOnceKey = android.NewOnceKey("TestDexpreoptGlobalConfig")
283
Colin Cross7134e282021-12-01 12:16:55 -0800284type pathContextErrorCollector struct {
285 android.PathContext
286 errors []error
287}
288
289func (p *pathContextErrorCollector) Errorf(format string, args ...interface{}) {
290 p.errors = append(p.errors, fmt.Errorf(format, args...))
291}
292
Martin Stjernholm40f9f3c2020-01-20 18:12:23 +0000293func getGlobalConfigRaw(ctx android.PathContext) globalConfigAndRaw {
Colin Cross7134e282021-12-01 12:16:55 -0800294 config := ctx.Config().Once(globalConfigOnceKey, func() interface{} {
Martin Stjernholm40f9f3c2020-01-20 18:12:23 +0000295 if data, err := ctx.Config().DexpreoptGlobalConfig(ctx); err != nil {
296 panic(err)
297 } else if data != nil {
Colin Cross7134e282021-12-01 12:16:55 -0800298 pathErrorCollectorCtx := &pathContextErrorCollector{PathContext: ctx}
299 globalConfig, err := ParseGlobalConfig(pathErrorCollectorCtx, data)
Martin Stjernholm40f9f3c2020-01-20 18:12:23 +0000300 if err != nil {
301 panic(err)
302 }
Colin Cross7134e282021-12-01 12:16:55 -0800303 return globalConfigAndRaw{globalConfig, data, pathErrorCollectorCtx.errors}
Martin Stjernholm40f9f3c2020-01-20 18:12:23 +0000304 }
305
306 // No global config filename set, see if there is a test config set
307 return ctx.Config().Once(testGlobalConfigOnceKey, func() interface{} {
308 // Nope, return a config with preopting disabled
Martin Stjernholm8d80cee2020-01-31 17:44:54 +0000309 return globalConfigAndRaw{&GlobalConfig{
Ulya Trafimovicha4a1c4e2021-01-15 18:40:04 +0000310 DisablePreopt: true,
311 DisablePreoptBootImages: true,
312 DisableGenerateProfile: true,
Colin Cross7134e282021-12-01 12:16:55 -0800313 }, nil, nil}
Martin Stjernholm40f9f3c2020-01-20 18:12:23 +0000314 })
315 }).(globalConfigAndRaw)
Colin Cross7134e282021-12-01 12:16:55 -0800316
317 // Avoid non-deterministic errors by reporting cached path errors on all callers.
318 for _, err := range config.pathErrors {
319 if ctx.Config().AllowMissingDependencies() {
320 // When AllowMissingDependencies it set, report errors through AddMissingDependencies.
321 // If AddMissingDependencies doesn't exist on the current context (for example when
322 // called with a SingletonContext), just swallow the errors since there is no way to
323 // report them.
324 if missingDepsCtx, ok := ctx.(interface {
325 AddMissingDependencies(missingDeps []string)
326 }); ok {
327 missingDepsCtx.AddMissingDependencies([]string{err.Error()})
328 }
329 } else {
Colin Crossc85750b2022-04-21 12:50:51 -0700330 android.ReportPathErrorf(ctx, "%s", err)
Colin Cross7134e282021-12-01 12:16:55 -0800331 }
332 }
333
334 return config
Martin Stjernholm40f9f3c2020-01-20 18:12:23 +0000335}
336
337// SetTestGlobalConfig sets a GlobalConfig that future calls to GetGlobalConfig
338// will return. It must be called before the first call to GetGlobalConfig for
339// the config.
Martin Stjernholm8d80cee2020-01-31 17:44:54 +0000340func SetTestGlobalConfig(config android.Config, globalConfig *GlobalConfig) {
Colin Cross7134e282021-12-01 12:16:55 -0800341 config.Once(testGlobalConfigOnceKey, func() interface{} { return globalConfigAndRaw{globalConfig, nil, nil} })
Martin Stjernholm40f9f3c2020-01-20 18:12:23 +0000342}
343
Jeongik Chac6246672021-04-08 00:00:19 +0900344// This struct is required to convert ModuleConfig from/to JSON.
345// The types of fields in ModuleConfig are not convertible,
346// so moduleJSONConfig has those fields as a convertible type.
347type moduleJSONConfig struct {
348 *ModuleConfig
349
350 BuildPath string
351 DexPath string
352 ManifestPath string
353
354 ProfileClassListing string
355 ProfileBootListing string
356
357 EnforceUsesLibrariesStatusFile string
358 ClassLoaderContexts jsonClassLoaderContextMap
359
Jeongik Chac6246672021-04-08 00:00:19 +0900360 DexPreoptImagesDeps [][]string
361
362 PreoptBootClassPathDexFiles []string
363}
364
Martin Stjernholm40f9f3c2020-01-20 18:12:23 +0000365// ParseModuleConfig parses a per-module dexpreopt.config file into a
366// ModuleConfig struct. It is not used in Soong, which receives a ModuleConfig
367// struct directly from java/dexpreopt.go. It is used in dexpreopt_gen called
368// from Make to read the module dexpreopt.config written in the Make config
369// stage.
Martin Stjernholm8d80cee2020-01-31 17:44:54 +0000370func ParseModuleConfig(ctx android.PathContext, data []byte) (*ModuleConfig, error) {
Jeongik Chac6246672021-04-08 00:00:19 +0900371 config := moduleJSONConfig{}
Colin Cross69f59a32019-02-15 10:39:37 -0800372
Colin Cross988414c2020-01-11 01:11:46 +0000373 err := json.Unmarshal(data, &config)
Colin Cross69f59a32019-02-15 10:39:37 -0800374 if err != nil {
375 return config.ModuleConfig, err
376 }
377
378 // Construct paths that require a PathContext.
379 config.ModuleConfig.BuildPath = constructPath(ctx, config.BuildPath).(android.OutputPath)
380 config.ModuleConfig.DexPath = constructPath(ctx, config.DexPath)
Jeongik Cha33a3a812021-04-15 09:12:49 +0900381 config.ModuleConfig.ManifestPath = android.OptionalPathForPath(constructPath(ctx, config.ManifestPath))
Colin Cross69f59a32019-02-15 10:39:37 -0800382 config.ModuleConfig.ProfileClassListing = android.OptionalPathForPath(constructPath(ctx, config.ProfileClassListing))
Ulya Trafimovich8c35fcf2021-02-17 16:23:28 +0000383 config.ModuleConfig.EnforceUsesLibrariesStatusFile = constructPath(ctx, config.EnforceUsesLibrariesStatusFile)
Ulya Trafimovich8cbc5d22020-11-03 15:15:46 +0000384 config.ModuleConfig.ClassLoaderContexts = fromJsonClassLoaderContext(ctx, config.ClassLoaderContexts)
Colin Cross69f59a32019-02-15 10:39:37 -0800385 config.ModuleConfig.PreoptBootClassPathDexFiles = constructPaths(ctx, config.PreoptBootClassPathDexFiles)
Colin Cross69f59a32019-02-15 10:39:37 -0800386
Dan Willemsen0f416782019-06-13 21:44:53 +0000387 // This needs to exist, but dependencies are already handled in Make, so we don't need to pass them through JSON.
Jeongik Chab19b58a2021-04-26 22:57:27 +0900388 config.ModuleConfig.DexPreoptImagesDeps = make([]android.OutputPaths, len(config.ModuleConfig.Archs))
Dan Willemsen0f416782019-06-13 21:44:53 +0000389
Colin Cross69f59a32019-02-15 10:39:37 -0800390 return config.ModuleConfig, nil
391}
392
Jeongik Chac6246672021-04-08 00:00:19 +0900393func pathsListToStringLists(pathsList []android.OutputPaths) [][]string {
394 ret := make([][]string, 0, len(pathsList))
395 for _, paths := range pathsList {
396 ret = append(ret, paths.Strings())
397 }
398 return ret
399}
400
401func moduleConfigToJSON(config *ModuleConfig) ([]byte, error) {
402 return json.MarshalIndent(&moduleJSONConfig{
403 BuildPath: config.BuildPath.String(),
404 DexPath: config.DexPath.String(),
405 ManifestPath: config.ManifestPath.String(),
406 ProfileClassListing: config.ProfileClassListing.String(),
407 ProfileBootListing: config.ProfileBootListing.String(),
408 EnforceUsesLibrariesStatusFile: config.EnforceUsesLibrariesStatusFile.String(),
409 ClassLoaderContexts: toJsonClassLoaderContext(config.ClassLoaderContexts),
Jeongik Chac6246672021-04-08 00:00:19 +0900410 DexPreoptImagesDeps: pathsListToStringLists(config.DexPreoptImagesDeps),
411 PreoptBootClassPathDexFiles: config.PreoptBootClassPathDexFiles.Strings(),
412 ModuleConfig: config,
413 }, "", " ")
414}
415
416// WriteModuleConfig serializes a ModuleConfig into a per-module dexpreopt.config JSON file.
417// These config files are used for post-processing.
418func WriteModuleConfig(ctx android.ModuleContext, config *ModuleConfig, path android.WritablePath) {
Ulya Trafimovich76b08522021-01-14 17:52:43 +0000419 if path == nil {
420 return
421 }
422
Jeongik Chac6246672021-04-08 00:00:19 +0900423 data, err := moduleConfigToJSON(config)
Ulya Trafimovich76b08522021-01-14 17:52:43 +0000424 if err != nil {
425 ctx.ModuleErrorf("failed to JSON marshal module dexpreopt.config: %v", err)
426 return
427 }
428
429 android.WriteFileRule(ctx, path, string(data))
430}
431
Martin Stjernholmd90676f2020-01-11 00:37:30 +0000432// dex2oatModuleName returns the name of the module to use for the dex2oat host
433// tool. It should be a binary module with public visibility that is compiled
434// and installed for host.
435func dex2oatModuleName(config android.Config) string {
436 // Default to the debug variant of dex2oat to help find bugs.
437 // Set USE_DEX2OAT_DEBUG to false for only building non-debug versions.
438 if config.Getenv("USE_DEX2OAT_DEBUG") == "false" {
439 return "dex2oat"
440 } else {
441 return "dex2oatd"
442 }
443}
444
Paul Duffinb506c9d2021-03-24 14:34:40 +0000445type dex2oatDependencyTag struct {
Martin Stjernholmd90676f2020-01-11 00:37:30 +0000446 blueprint.BaseDependencyTag
Colin Crossce564252022-01-12 11:13:32 -0800447 android.LicenseAnnotationToolchainDependencyTag
Paul Duffinb506c9d2021-03-24 14:34:40 +0000448}
449
450func (d dex2oatDependencyTag) ExcludeFromVisibilityEnforcement() {
451}
452
453func (d dex2oatDependencyTag) ExcludeFromApexContents() {
454}
455
Martin Stjernholm0e4cceb2021-05-13 02:38:35 +0100456func (d dex2oatDependencyTag) AllowDisabledModuleDependency(target android.Module) bool {
457 // RegisterToolDeps may run after the prebuilt mutators and hence register a
458 // dependency on the source module even when the prebuilt is to be used.
459 // dex2oatPathFromDep takes that into account when it retrieves the path to
460 // the binary, but we also need to disable the check for dependencies on
461 // disabled modules.
462 return target.IsReplacedByPrebuilt()
463}
464
Yu Liud2a95952024-10-10 00:15:26 +0000465func (d dex2oatDependencyTag) AllowDisabledModuleDependencyProxy(
466 ctx android.OtherModuleProviderContext, target android.ModuleProxy) bool {
467 return android.OtherModuleProviderOrDefault(
Yu Liub5275322024-11-13 18:40:43 +0000468 ctx, target, android.CommonModuleInfoKey).ReplacedByPrebuilt
Yu Liud2a95952024-10-10 00:15:26 +0000469}
470
Paul Duffinb506c9d2021-03-24 14:34:40 +0000471// Dex2oatDepTag represents the dependency onto the dex2oatd module. It is added to any module that
472// needs dexpreopting and so it makes no sense for it to be checked for visibility or included in
473// the apex.
474var Dex2oatDepTag = dex2oatDependencyTag{}
475
476var _ android.ExcludeFromVisibilityEnforcementTag = Dex2oatDepTag
477var _ android.ExcludeFromApexContentsTag = Dex2oatDepTag
Martin Stjernholm0e4cceb2021-05-13 02:38:35 +0100478var _ android.AllowDisabledModuleDependency = Dex2oatDepTag
Martin Stjernholmd90676f2020-01-11 00:37:30 +0000479
Martin Stjernholm6d415272020-01-31 17:10:36 +0000480// RegisterToolDeps adds the necessary dependencies to binary modules for tools
481// that are required later when Get(Cached)GlobalSoongConfig is called. It
482// should be called from a mutator that's registered with
483// android.RegistrationContext.FinalDepsMutators.
484func RegisterToolDeps(ctx android.BottomUpMutatorContext) {
Martin Stjernholmd90676f2020-01-11 00:37:30 +0000485 dex2oatBin := dex2oatModuleName(ctx.Config())
486 v := ctx.Config().BuildOSTarget.Variations()
Ulya Trafimovicha4a1c4e2021-01-15 18:40:04 +0000487 ctx.AddFarVariationDependencies(v, Dex2oatDepTag, dex2oatBin)
Martin Stjernholmd90676f2020-01-11 00:37:30 +0000488}
489
Jiakai Zhangbc698cd2023-05-08 16:28:38 +0000490func IsDex2oatNeeded(ctx android.PathContext) bool {
491 global := GetGlobalConfig(ctx)
492 return !global.DisablePreopt || !global.DisablePreoptBootImages
493}
494
Martin Stjernholmd90676f2020-01-11 00:37:30 +0000495func dex2oatPathFromDep(ctx android.ModuleContext) android.Path {
Jiakai Zhangbc698cd2023-05-08 16:28:38 +0000496 if !IsDex2oatNeeded(ctx) {
497 return nil
498 }
499
Martin Stjernholmd90676f2020-01-11 00:37:30 +0000500 dex2oatBin := dex2oatModuleName(ctx.Config())
501
Martin Stjernholmc0048622020-08-18 17:37:41 +0100502 // Find the right dex2oat module, trying to follow PrebuiltDepTag from source
503 // to prebuilt if there is one. We wouldn't have to do this if the
504 // prebuilt_postdeps mutator that replaces source deps with prebuilt deps was
505 // run after RegisterToolDeps above, but changing that leads to ordering
506 // problems between mutators (RegisterToolDeps needs to run late to act on
507 // final variants, while prebuilt_postdeps needs to run before many of the
508 // PostDeps mutators, like the APEX mutators). Hence we need to dig out the
509 // prebuilt explicitly here instead.
510 var dex2oatModule android.Module
511 ctx.WalkDeps(func(child, parent android.Module) bool {
Ulya Trafimovicha4a1c4e2021-01-15 18:40:04 +0000512 if parent == ctx.Module() && ctx.OtherModuleDependencyTag(child) == Dex2oatDepTag {
Martin Stjernholmc0048622020-08-18 17:37:41 +0100513 // Found the source module, or prebuilt module that has replaced the source.
514 dex2oatModule = child
Paul Duffinf7c99f52021-04-28 10:41:21 +0100515 if android.IsModulePrebuilt(child) {
Martin Stjernholmc0048622020-08-18 17:37:41 +0100516 return false // If it's the prebuilt we're done.
517 } else {
518 return true // Recurse to check if the source has a prebuilt dependency.
519 }
520 }
521 if parent == dex2oatModule && ctx.OtherModuleDependencyTag(child) == android.PrebuiltDepTag {
Paul Duffinf7c99f52021-04-28 10:41:21 +0100522 if p := android.GetEmbeddedPrebuilt(child); p != nil && p.UsePrebuilt() {
Martin Stjernholmc0048622020-08-18 17:37:41 +0100523 dex2oatModule = child // Found a prebuilt that should be used.
524 }
525 }
526 return false
527 })
528
Martin Stjernholmd90676f2020-01-11 00:37:30 +0000529 if dex2oatModule == nil {
530 // If this happens there's probably a missing call to AddToolDeps in DepsMutator.
531 panic(fmt.Sprintf("Failed to lookup %s dependency", dex2oatBin))
532 }
533
534 dex2oatPath := dex2oatModule.(android.HostToolProvider).HostToolPath()
535 if !dex2oatPath.Valid() {
536 panic(fmt.Sprintf("Failed to find host tool path in %s", dex2oatModule))
537 }
538
539 return dex2oatPath.Path()
540}
541
Martin Stjernholm75a48d82020-01-10 20:32:59 +0000542// createGlobalSoongConfig creates a GlobalSoongConfig from the current context.
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000543// Should not be used in dexpreopt_gen.
Martin Stjernholm8d80cee2020-01-31 17:44:54 +0000544func createGlobalSoongConfig(ctx android.ModuleContext) *GlobalSoongConfig {
Martin Stjernholm8d80cee2020-01-31 17:44:54 +0000545 return &GlobalSoongConfig{
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000546 Profman: ctx.Config().HostToolPath(ctx, "profman"),
Martin Stjernholmd90676f2020-01-11 00:37:30 +0000547 Dex2oat: dex2oatPathFromDep(ctx),
Saeid Farivar Asanjanfd27c7c2022-08-08 20:21:26 +0000548 Aapt: ctx.Config().HostToolPath(ctx, "aapt2"),
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000549 SoongZip: ctx.Config().HostToolPath(ctx, "soong_zip"),
550 Zip2zip: ctx.Config().HostToolPath(ctx, "zip2zip"),
551 ManifestCheck: ctx.Config().HostToolPath(ctx, "manifest_check"),
Ulya Trafimovich5f364b62020-06-30 12:39:01 +0100552 ConstructContext: ctx.Config().HostToolPath(ctx, "construct_context"),
Jiakai Zhang7d292222024-01-18 17:27:42 +0000553 UffdGcFlag: getUffdGcFlagPath(ctx),
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000554 }
555}
556
Martin Stjernholmd90676f2020-01-11 00:37:30 +0000557// The main reason for this Once cache for GlobalSoongConfig is to make the
558// dex2oat path available to singletons. In ordinary modules we get it through a
Ulya Trafimovicha4a1c4e2021-01-15 18:40:04 +0000559// Dex2oatDepTag dependency, but in singletons there's no simple way to do the
Martin Stjernholmd90676f2020-01-11 00:37:30 +0000560// same thing and ensure the right variant is selected, hence this cache to make
561// the resolved path available to singletons. This means we depend on there
Ulya Trafimovicha4a1c4e2021-01-15 18:40:04 +0000562// being at least one ordinary module with a Dex2oatDepTag dependency.
Martin Stjernholmd90676f2020-01-11 00:37:30 +0000563//
564// TODO(b/147613152): Implement a way to deal with dependencies from singletons,
Paul Duffin9f045242021-01-21 15:05:11 +0000565// and then possibly remove this cache altogether.
Martin Stjernholm75a48d82020-01-10 20:32:59 +0000566var globalSoongConfigOnceKey = android.NewOnceKey("DexpreoptGlobalSoongConfig")
567
568// GetGlobalSoongConfig creates a GlobalSoongConfig the first time it's called,
569// and later returns the same cached instance.
Martin Stjernholm8d80cee2020-01-31 17:44:54 +0000570func GetGlobalSoongConfig(ctx android.ModuleContext) *GlobalSoongConfig {
Martin Stjernholm75a48d82020-01-10 20:32:59 +0000571 globalSoong := ctx.Config().Once(globalSoongConfigOnceKey, func() interface{} {
572 return createGlobalSoongConfig(ctx)
Martin Stjernholm8d80cee2020-01-31 17:44:54 +0000573 }).(*GlobalSoongConfig)
Martin Stjernholmd90676f2020-01-11 00:37:30 +0000574
575 // Always resolve the tool path from the dependency, to ensure that every
576 // module has the dependency added properly.
577 myDex2oat := dex2oatPathFromDep(ctx)
578 if myDex2oat != globalSoong.Dex2oat {
579 panic(fmt.Sprintf("Inconsistent dex2oat path in cached config: expected %s, got %s", globalSoong.Dex2oat, myDex2oat))
580 }
581
Martin Stjernholm75a48d82020-01-10 20:32:59 +0000582 return globalSoong
583}
584
585// GetCachedGlobalSoongConfig returns a cached GlobalSoongConfig created by an
586// earlier GetGlobalSoongConfig call. This function works with any context
587// compatible with a basic PathContext, since it doesn't try to create a
Martin Stjernholm6d415272020-01-31 17:10:36 +0000588// GlobalSoongConfig with the proper paths (which requires a full
589// ModuleContext). If there has been no prior call to GetGlobalSoongConfig, nil
590// is returned.
Martin Stjernholm8d80cee2020-01-31 17:44:54 +0000591func GetCachedGlobalSoongConfig(ctx android.PathContext) *GlobalSoongConfig {
Martin Stjernholm6d415272020-01-31 17:10:36 +0000592 return ctx.Config().Once(globalSoongConfigOnceKey, func() interface{} {
593 return (*GlobalSoongConfig)(nil)
594 }).(*GlobalSoongConfig)
Martin Stjernholm75a48d82020-01-10 20:32:59 +0000595}
596
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000597type globalJsonSoongConfig struct {
598 Profman string
599 Dex2oat string
600 Aapt string
601 SoongZip string
602 Zip2zip string
603 ManifestCheck string
604 ConstructContext string
Jiakai Zhang7d292222024-01-18 17:27:42 +0000605 UffdGcFlag string
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000606}
607
Martin Stjernholm40f9f3c2020-01-20 18:12:23 +0000608// ParseGlobalSoongConfig parses the given data assumed to be read from the
609// global dexpreopt_soong.config file into a GlobalSoongConfig struct. It is
610// only used in dexpreopt_gen.
Martin Stjernholm8d80cee2020-01-31 17:44:54 +0000611func ParseGlobalSoongConfig(ctx android.PathContext, data []byte) (*GlobalSoongConfig, error) {
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000612 var jc globalJsonSoongConfig
613
Colin Cross988414c2020-01-11 01:11:46 +0000614 err := json.Unmarshal(data, &jc)
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000615 if err != nil {
Martin Stjernholm8d80cee2020-01-31 17:44:54 +0000616 return &GlobalSoongConfig{}, err
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000617 }
618
Martin Stjernholm8d80cee2020-01-31 17:44:54 +0000619 config := &GlobalSoongConfig{
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000620 Profman: constructPath(ctx, jc.Profman),
621 Dex2oat: constructPath(ctx, jc.Dex2oat),
622 Aapt: constructPath(ctx, jc.Aapt),
623 SoongZip: constructPath(ctx, jc.SoongZip),
624 Zip2zip: constructPath(ctx, jc.Zip2zip),
625 ManifestCheck: constructPath(ctx, jc.ManifestCheck),
626 ConstructContext: constructPath(ctx, jc.ConstructContext),
Jiakai Zhang7d292222024-01-18 17:27:42 +0000627 UffdGcFlag: constructWritablePath(ctx, jc.UffdGcFlag),
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000628 }
629
630 return config, nil
631}
632
satayevd604b212021-07-21 14:23:52 +0100633// checkBootJarsConfigConsistency checks the consistency of BootJars and ApexBootJars fields in
Paul Duffin7d1d0832021-04-23 11:39:41 +0100634// DexpreoptGlobalConfig and Config.productVariables.
635func checkBootJarsConfigConsistency(ctx android.SingletonContext, dexpreoptConfig *GlobalConfig, config android.Config) {
636 compareBootJars := func(property string, dexpreoptJars, variableJars android.ConfiguredJarList) {
637 dexpreoptPairs := dexpreoptJars.CopyOfApexJarPairs()
638 variablePairs := variableJars.CopyOfApexJarPairs()
639 if !reflect.DeepEqual(dexpreoptPairs, variablePairs) {
640 ctx.Errorf("Inconsistent configuration of %[1]s\n"+
641 " dexpreopt.GlobalConfig.%[1]s = %[2]s\n"+
642 " productVariables.%[1]s = %[3]s",
643 property, dexpreoptPairs, variablePairs)
644 }
645 }
646
satayevd604b212021-07-21 14:23:52 +0100647 compareBootJars("BootJars", dexpreoptConfig.BootJars, config.NonApexBootJars())
648 compareBootJars("ApexBootJars", dexpreoptConfig.ApexBootJars, config.ApexBootJars())
Paul Duffin7d1d0832021-04-23 11:39:41 +0100649}
650
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000651func (s *globalSoongConfigSingleton) GenerateBuildActions(ctx android.SingletonContext) {
Jiakai Zhang7d292222024-01-18 17:27:42 +0000652 global := GetGlobalConfig(ctx)
653 checkBootJarsConfigConsistency(ctx, global, ctx.Config())
Paul Duffin7d1d0832021-04-23 11:39:41 +0100654
Jiakai Zhang7d292222024-01-18 17:27:42 +0000655 if global.DisablePreopt {
Martin Stjernholmd90676f2020-01-11 00:37:30 +0000656 return
657 }
658
Jiakai Zhang7d292222024-01-18 17:27:42 +0000659 buildUffdGcFlag(ctx, global)
660
Martin Stjernholm75a48d82020-01-10 20:32:59 +0000661 config := GetCachedGlobalSoongConfig(ctx)
Martin Stjernholm6d415272020-01-31 17:10:36 +0000662 if config == nil {
663 // No module has enabled dexpreopting, so we assume there will be no calls
664 // to dexpreopt_gen.
665 return
666 }
667
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000668 jc := globalJsonSoongConfig{
669 Profman: config.Profman.String(),
670 Dex2oat: config.Dex2oat.String(),
671 Aapt: config.Aapt.String(),
672 SoongZip: config.SoongZip.String(),
673 Zip2zip: config.Zip2zip.String(),
674 ManifestCheck: config.ManifestCheck.String(),
675 ConstructContext: config.ConstructContext.String(),
Jiakai Zhang7d292222024-01-18 17:27:42 +0000676 UffdGcFlag: config.UffdGcFlag.String(),
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000677 }
678
679 data, err := json.Marshal(jc)
680 if err != nil {
681 ctx.Errorf("failed to JSON marshal GlobalSoongConfig: %v", err)
682 return
683 }
684
Colin Crosscf371cc2020-11-13 11:48:42 -0800685 android.WriteFileRule(ctx, android.PathForOutput(ctx, "dexpreopt_soong.config"), string(data))
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000686}
687
688func (s *globalSoongConfigSingleton) MakeVars(ctx android.MakeVarsContext) {
Martin Stjernholmd90676f2020-01-11 00:37:30 +0000689 if GetGlobalConfig(ctx).DisablePreopt {
690 return
691 }
692
Martin Stjernholm75a48d82020-01-10 20:32:59 +0000693 config := GetCachedGlobalSoongConfig(ctx)
Martin Stjernholm6d415272020-01-31 17:10:36 +0000694 if config == nil {
695 return
696 }
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000697
698 ctx.Strict("DEX2OAT", config.Dex2oat.String())
699 ctx.Strict("DEXPREOPT_GEN_DEPS", strings.Join([]string{
700 config.Profman.String(),
701 config.Dex2oat.String(),
702 config.Aapt.String(),
703 config.SoongZip.String(),
704 config.Zip2zip.String(),
705 config.ManifestCheck.String(),
706 config.ConstructContext.String(),
Jiakai Zhang7d292222024-01-18 17:27:42 +0000707 config.UffdGcFlag.String(),
Martin Stjernholmc52aaf12020-01-06 23:11:37 +0000708 }, " "))
709}
710
Jiakai Zhang7d292222024-01-18 17:27:42 +0000711func buildUffdGcFlag(ctx android.BuilderContext, global *GlobalConfig) {
712 uffdGcFlag := getUffdGcFlagPath(ctx)
713
714 if global.EnableUffdGc == "true" {
715 android.WriteFileRuleVerbatim(ctx, uffdGcFlag, "--runtime-arg -Xgc:CMC")
716 } else if global.EnableUffdGc == "false" {
717 android.WriteFileRuleVerbatim(ctx, uffdGcFlag, "")
718 } else if global.EnableUffdGc == "default" {
719 // Generated by `build/make/core/Makefile`.
720 kernelVersionFile := android.PathForOutput(ctx, "dexpreopt/kernel_version_for_uffd_gc.txt")
721 // Determine the UFFD GC flag by the kernel version file.
722 rule := android.NewRuleBuilder(pctx, ctx)
723 rule.Command().
724 Tool(ctx.Config().HostToolPath(ctx, "construct_uffd_gc_flag")).
725 Input(kernelVersionFile).
726 Output(uffdGcFlag)
727 rule.Restat().Build("dexpreopt_uffd_gc_flag", "dexpreopt_uffd_gc_flag")
728 } else {
729 panic(fmt.Sprintf("Unknown value of PRODUCT_ENABLE_UFFD_GC: %s", global.EnableUffdGc))
730 }
731}
732
Martin Stjernholm8d80cee2020-01-31 17:44:54 +0000733func GlobalConfigForTests(ctx android.PathContext) *GlobalConfig {
734 return &GlobalConfig{
Jiakai Zhang23984422023-11-09 16:47:04 +0000735 DisablePreopt: false,
736 DisablePreoptModules: nil,
737 OnlyPreoptArtBootImage: false,
738 HasSystemOther: false,
739 PatternsOnSystemOther: nil,
740 DisableGenerateProfile: false,
741 ProfileDir: "",
742 BootJars: android.EmptyConfiguredJarList(),
743 ApexBootJars: android.EmptyConfiguredJarList(),
744 ArtApexJars: android.EmptyConfiguredJarList(),
745 TestOnlyArtBootImageJars: android.EmptyConfiguredJarList(),
746 SystemServerJars: android.EmptyConfiguredJarList(),
747 SystemServerApps: nil,
748 ApexSystemServerJars: android.EmptyConfiguredJarList(),
749 StandaloneSystemServerJars: android.EmptyConfiguredJarList(),
750 ApexStandaloneSystemServerJars: android.EmptyConfiguredJarList(),
751 SpeedApps: nil,
752 PreoptFlags: nil,
753 DefaultCompilerFilter: "",
754 SystemServerCompilerFilter: "",
755 GenerateDMFiles: false,
756 NoDebugInfo: false,
757 DontResolveStartupStrings: false,
758 AlwaysSystemServerDebugInfo: false,
759 NeverSystemServerDebugInfo: false,
760 AlwaysOtherDebugInfo: false,
761 NeverOtherDebugInfo: false,
762 IsEng: false,
763 SanitizeLite: false,
764 DefaultAppImages: false,
765 Dex2oatXmx: "",
766 Dex2oatXms: "",
767 EmptyDirectory: "empty_dir",
768 CpuVariant: nil,
769 InstructionSetFeatures: nil,
770 BootImageProfiles: nil,
771 BootFlags: "",
772 Dex2oatImageXmx: "",
773 Dex2oatImageXms: "",
Martin Stjernholm75a48d82020-01-10 20:32:59 +0000774 }
775}
776
Jiakai Zhang7d292222024-01-18 17:27:42 +0000777func globalSoongConfigForTests(ctx android.BuilderContext) *GlobalSoongConfig {
Paul Duffin9f045242021-01-21 15:05:11 +0000778 return &GlobalSoongConfig{
779 Profman: android.PathForTesting("profman"),
780 Dex2oat: android.PathForTesting("dex2oat"),
Saeid Farivar Asanjanfd27c7c2022-08-08 20:21:26 +0000781 Aapt: android.PathForTesting("aapt2"),
Paul Duffin9f045242021-01-21 15:05:11 +0000782 SoongZip: android.PathForTesting("soong_zip"),
783 Zip2zip: android.PathForTesting("zip2zip"),
784 ManifestCheck: android.PathForTesting("manifest_check"),
785 ConstructContext: android.PathForTesting("construct_context"),
Jiakai Zhang7d292222024-01-18 17:27:42 +0000786 UffdGcFlag: android.PathForOutput(ctx, "dexpreopt_test", "uffd_gc_flag.txt"),
Paul Duffin9f045242021-01-21 15:05:11 +0000787 }
Colin Cross69f59a32019-02-15 10:39:37 -0800788}
Jiakai Zhang7d292222024-01-18 17:27:42 +0000789
790func GetDexpreoptDirName(ctx android.PathContext) string {
791 prefix := "dexpreopt_"
792 targets := ctx.Config().Targets[android.Android]
793 if len(targets) > 0 {
794 return prefix + targets[0].Arch.ArchType.String()
795 }
796 return prefix + "unknown_target"
797}
798
799func getUffdGcFlagPath(ctx android.PathContext) android.WritablePath {
800 return android.PathForOutput(ctx, "dexpreopt/uffd_gc_flag.txt")
801}