blob: 6a4fd4a05b03b95524888388b2c1f9e746c0d5d1 [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
35 BootJars []string // jars that form the boot image
36 SystemServerJars []string // jars that form the system server
37 SystemServerApps []string // apps that are loaded into system server
38 SpeedApps []string // apps that should be speed optimized
39
40 PreoptFlags []string // global dex2oat flags that should be used if no module-specific dex2oat flags are specified
41
42 DefaultCompilerFilter string // default compiler filter to pass to dex2oat, overridden by --compiler-filter= in module-specific dex2oat flags
43 SystemServerCompilerFilter string // default compiler filter to pass to dex2oat for system server jars
44
45 GenerateDMFiles bool // generate Dex Metadata files
46
47 NoDebugInfo bool // don't generate debug info by default
48 AlwaysSystemServerDebugInfo bool // always generate mini debug info for system server modules (overrides NoDebugInfo=true)
49 NeverSystemServerDebugInfo bool // never generate mini debug info for system server modules (overrides NoDebugInfo=false)
50 AlwaysOtherDebugInfo bool // always generate mini debug info for non-system server modules (overrides NoDebugInfo=true)
51 NeverOtherDebugInfo bool // never generate mini debug info for non-system server modules (overrides NoDebugInfo=true)
52
53 MissingUsesLibraries []string // libraries that may be listed in OptionalUsesLibraries but will not be installed by the product
54
55 IsEng bool // build is a eng variant
56 SanitizeLite bool // build is the second phase of a SANITIZE_LITE build
57
58 DefaultAppImages bool // build app images (TODO: .art files?) by default
59
60 Dex2oatXmx string // max heap size
61 Dex2oatXms string // initial heap size
62
63 EmptyDirectory string // path to an empty directory
64
65 DefaultDexPreoptImageLocation map[string]string // default boot image location for each architecture
66 CpuVariant map[string]string // cpu variant for each architecture
67 InstructionSetFeatures map[string]string // instruction set for each architecture
68
69 Tools Tools // paths to tools possibly used by the generated commands
70}
71
72// Tools contains paths to tools possibly used by the generated commands. If you add a new tool here you MUST add it
73// to the order-only dependency list in DEXPREOPT_GEN_DEPS.
74type Tools struct {
75 Profman string
76 Dex2oat string
77 Aapt string
78 SoongZip string
79 Zip2zip string
80
81 VerifyUsesLibraries string
82 ConstructContext string
83}
84
85type ModuleConfig struct {
86 Name string
87 DexLocation string // dex location on device
88 BuildPath string
89 DexPath string
90 PreferIntegrity bool
91 UncompressedDex bool
92 HasApkLibraries bool
93 PreoptFlags []string
94
95 ProfileClassListing string
96 ProfileIsTextListing bool
97
98 EnforceUsesLibraries bool
99 OptionalUsesLibraries []string
100 UsesLibraries []string
101 LibraryPaths map[string]string
102
103 Archs []string
104 DexPreoptImageLocation string
105
106 PreoptExtractedApk bool // Overrides OnlyPreoptModules
107
108 NoCreateAppImage bool
109 ForceCreateAppImage bool
110
111 PresignedPrebuilt bool
112
113 StripInputPath string
114 StripOutputPath string
115}
116
117func LoadGlobalConfig(path string) (GlobalConfig, error) {
118 config := GlobalConfig{}
119 err := loadConfig(path, &config)
120 return config, err
121}
122
123func LoadModuleConfig(path string) (ModuleConfig, error) {
124 config := ModuleConfig{}
125 err := loadConfig(path, &config)
126 return config, err
127}
128
129func loadConfig(path string, config interface{}) error {
130 data, err := ioutil.ReadFile(path)
131 if err != nil {
132 return err
133 }
134
135 err = json.Unmarshal(data, config)
136 if err != nil {
137 return err
138 }
139
140 return nil
141}