blob: 13a14f4f22fe84af6468eda79ac1dba87185d948 [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"
20)
21
22// GlobalConfig stores the configuration for dex preopting set by the product
23type GlobalConfig struct {
24 DefaultNoStripping bool // don't strip dex files by default
25
26 DisablePreoptModules []string // modules with preopt disabled by product-specific config
27
28 OnlyPreoptBootImageAndSystemServer bool // only preopt jars in the boot image or system server
29
30 HasSystemOther bool // store odex files that match PatternsOnSystemOther on the system_other partition
31 PatternsOnSystemOther []string // patterns (using '%' to denote a prefix match) to put odex on the system_other partition
32
33 DisableGenerateProfile bool // don't generate profiles
34
Vladimir Markod2ee5322018-12-19 17:57:57 +000035 PreoptBootClassPathDexFiles []string // file paths of boot class path files
36 PreoptBootClassPathDexLocations []string // virtual locations of boot class path files
37
38 BootJars []string // modules for jars that form the boot class path
Colin Cross43f08db2018-11-12 10:13:39 -080039 SystemServerJars []string // jars that form the system server
40 SystemServerApps []string // apps that are loaded into system server
41 SpeedApps []string // apps that should be speed optimized
42
43 PreoptFlags []string // global dex2oat flags that should be used if no module-specific dex2oat flags are specified
44
45 DefaultCompilerFilter string // default compiler filter to pass to dex2oat, overridden by --compiler-filter= in module-specific dex2oat flags
46 SystemServerCompilerFilter string // default compiler filter to pass to dex2oat for system server jars
47
48 GenerateDMFiles bool // generate Dex Metadata files
49
50 NoDebugInfo bool // don't generate debug info by default
51 AlwaysSystemServerDebugInfo bool // always generate mini debug info for system server modules (overrides NoDebugInfo=true)
52 NeverSystemServerDebugInfo bool // never generate mini debug info for system server modules (overrides NoDebugInfo=false)
53 AlwaysOtherDebugInfo bool // always generate mini debug info for non-system server modules (overrides NoDebugInfo=true)
54 NeverOtherDebugInfo bool // never generate mini debug info for non-system server modules (overrides NoDebugInfo=true)
55
56 MissingUsesLibraries []string // libraries that may be listed in OptionalUsesLibraries but will not be installed by the product
57
58 IsEng bool // build is a eng variant
59 SanitizeLite bool // build is the second phase of a SANITIZE_LITE build
60
61 DefaultAppImages bool // build app images (TODO: .art files?) by default
62
63 Dex2oatXmx string // max heap size
64 Dex2oatXms string // initial heap size
65
66 EmptyDirectory string // path to an empty directory
67
68 DefaultDexPreoptImageLocation map[string]string // default boot image location for each architecture
69 CpuVariant map[string]string // cpu variant for each architecture
70 InstructionSetFeatures map[string]string // instruction set for each architecture
71
72 Tools Tools // paths to tools possibly used by the generated commands
73}
74
75// Tools contains paths to tools possibly used by the generated commands. If you add a new tool here you MUST add it
76// to the order-only dependency list in DEXPREOPT_GEN_DEPS.
77type Tools struct {
78 Profman string
79 Dex2oat string
80 Aapt string
81 SoongZip string
82 Zip2zip string
83
84 VerifyUsesLibraries string
85 ConstructContext string
86}
87
88type ModuleConfig struct {
Victor Hsieha2c16c12019-01-02 14:50:56 -080089 Name string
90 DexLocation string // dex location on device
91 BuildPath string
92 DexPath string
93 PreferCodeIntegrity bool
94 UncompressedDex bool
95 HasApkLibraries bool
96 PreoptFlags []string
Colin Cross43f08db2018-11-12 10:13:39 -080097
98 ProfileClassListing string
99 ProfileIsTextListing bool
100
101 EnforceUsesLibraries bool
102 OptionalUsesLibraries []string
103 UsesLibraries []string
104 LibraryPaths map[string]string
105
106 Archs []string
107 DexPreoptImageLocation string
108
109 PreoptExtractedApk bool // Overrides OnlyPreoptModules
110
111 NoCreateAppImage bool
112 ForceCreateAppImage bool
113
114 PresignedPrebuilt bool
115
116 StripInputPath string
117 StripOutputPath string
118}
119
120func LoadGlobalConfig(path string) (GlobalConfig, error) {
121 config := GlobalConfig{}
122 err := loadConfig(path, &config)
123 return config, err
124}
125
126func LoadModuleConfig(path string) (ModuleConfig, error) {
127 config := ModuleConfig{}
128 err := loadConfig(path, &config)
129 return config, err
130}
131
132func loadConfig(path string, config interface{}) error {
133 data, err := ioutil.ReadFile(path)
134 if err != nil {
135 return err
136 }
137
138 err = json.Unmarshal(data, config)
139 if err != nil {
140 return err
141 }
142
143 return nil
144}