blob: 0eb162dce3fad24d99ac59c573ad979cf3a83c1c [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"
19 "io/ioutil"
Colin Cross74ba9622019-02-11 15:11:14 -080020
21 "android/soong/android"
Colin Cross43f08db2018-11-12 10:13:39 -080022)
23
24// GlobalConfig stores the configuration for dex preopting set by the product
25type GlobalConfig struct {
26 DefaultNoStripping bool // don't strip dex files by default
27
28 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
32 HasSystemOther bool // store odex files that match PatternsOnSystemOther on the system_other partition
33 PatternsOnSystemOther []string // patterns (using '%' to denote a prefix match) to put odex on the system_other partition
34
35 DisableGenerateProfile bool // don't generate profiles
36
Colin Cross800fe132019-02-11 14:21:24 -080037 BootJars []string // modules for jars that form the boot class path
Vladimir Markod2ee5322018-12-19 17:57:57 +000038
Colin Cross800fe132019-02-11 14:21:24 -080039 TargetCoreJars []string // modules for jars that are in the runtime apex
40 ProductUpdatableBootModules []string
41 ProductUpdatableBootLocations []string
42
Colin Cross43f08db2018-11-12 10:13:39 -080043 SystemServerJars []string // jars that form the system server
44 SystemServerApps []string // apps that are loaded into system server
45 SpeedApps []string // apps that should be speed optimized
46
47 PreoptFlags []string // global dex2oat flags that should be used if no module-specific dex2oat flags are specified
48
49 DefaultCompilerFilter string // default compiler filter to pass to dex2oat, overridden by --compiler-filter= in module-specific dex2oat flags
50 SystemServerCompilerFilter string // default compiler filter to pass to dex2oat for system server jars
51
Nicolas Geoffrayfa6e9ec2019-02-12 13:12:16 +000052 GenerateDMFiles bool // generate Dex Metadata files
53 NeverAllowStripping bool // whether stripping should not be done - used as build time check to make sure dex files are always available
Colin Cross43f08db2018-11-12 10:13:39 -080054
55 NoDebugInfo bool // don't generate debug info by default
56 AlwaysSystemServerDebugInfo bool // always generate mini debug info for system server modules (overrides NoDebugInfo=true)
57 NeverSystemServerDebugInfo bool // never generate mini debug info for system server modules (overrides NoDebugInfo=false)
58 AlwaysOtherDebugInfo bool // always generate mini debug info for non-system server modules (overrides NoDebugInfo=true)
59 NeverOtherDebugInfo bool // never generate mini debug info for non-system server modules (overrides NoDebugInfo=true)
60
61 MissingUsesLibraries []string // libraries that may be listed in OptionalUsesLibraries but will not be installed by the product
62
63 IsEng bool // build is a eng variant
64 SanitizeLite bool // build is the second phase of a SANITIZE_LITE build
65
66 DefaultAppImages bool // build app images (TODO: .art files?) by default
67
Colin Cross800fe132019-02-11 14:21:24 -080068 Dex2oatXmx string // max heap size for dex2oat
69 Dex2oatXms string // initial heap size for dex2oat
Colin Cross43f08db2018-11-12 10:13:39 -080070
71 EmptyDirectory string // path to an empty directory
72
Colin Cross74ba9622019-02-11 15:11:14 -080073 CpuVariant map[android.ArchType]string // cpu variant for each architecture
74 InstructionSetFeatures map[android.ArchType]string // instruction set for each architecture
Colin Cross43f08db2018-11-12 10:13:39 -080075
Colin Cross800fe132019-02-11 14:21:24 -080076 // Only used for boot image
77 DirtyImageObjects string // path to a dirty-image-objects file
78 PreloadedClasses string // path to a preloaded-classes file
79 BootImageProfiles []string // 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
83
Colin Cross43f08db2018-11-12 10:13:39 -080084 Tools Tools // paths to tools possibly used by the generated commands
85}
86
87// Tools contains paths to tools possibly used by the generated commands. If you add a new tool here you MUST add it
88// to the order-only dependency list in DEXPREOPT_GEN_DEPS.
89type Tools struct {
90 Profman string
91 Dex2oat string
92 Aapt string
93 SoongZip string
94 Zip2zip string
95
96 VerifyUsesLibraries string
97 ConstructContext string
98}
99
100type ModuleConfig struct {
Victor Hsiehd181c8b2019-01-29 13:00:33 -0800101 Name string
102 DexLocation string // dex location on device
103 BuildPath string
104 DexPath string
Victor Hsiehd181c8b2019-01-29 13:00:33 -0800105 UncompressedDex bool
106 HasApkLibraries bool
107 PreoptFlags []string
Colin Cross43f08db2018-11-12 10:13:39 -0800108
109 ProfileClassListing string
110 ProfileIsTextListing bool
111
112 EnforceUsesLibraries bool
113 OptionalUsesLibraries []string
114 UsesLibraries []string
115 LibraryPaths map[string]string
116
Colin Cross74ba9622019-02-11 15:11:14 -0800117 Archs []android.ArchType
Colin Crossc7e40aa2019-02-08 21:37:00 -0800118 DexPreoptImages []string
Colin Cross43f08db2018-11-12 10:13:39 -0800119
Colin Cross800fe132019-02-11 14:21:24 -0800120 PreoptBootClassPathDexFiles []string // file paths of boot class path files
121 PreoptBootClassPathDexLocations []string // virtual locations of boot class path files
122
Colin Cross43f08db2018-11-12 10:13:39 -0800123 PreoptExtractedApk bool // Overrides OnlyPreoptModules
124
125 NoCreateAppImage bool
126 ForceCreateAppImage bool
127
128 PresignedPrebuilt bool
129
Colin Cross8c6d2502019-01-09 21:09:14 -0800130 NoStripping bool
Colin Cross43f08db2018-11-12 10:13:39 -0800131 StripInputPath string
132 StripOutputPath string
133}
134
135func LoadGlobalConfig(path string) (GlobalConfig, error) {
136 config := GlobalConfig{}
137 err := loadConfig(path, &config)
138 return config, err
139}
140
141func LoadModuleConfig(path string) (ModuleConfig, error) {
142 config := ModuleConfig{}
143 err := loadConfig(path, &config)
144 return config, err
145}
146
147func loadConfig(path string, config interface{}) error {
148 data, err := ioutil.ReadFile(path)
149 if err != nil {
150 return err
151 }
152
153 err = json.Unmarshal(data, config)
154 if err != nil {
155 return err
156 }
157
158 return nil
159}