blob: c7f063878e27e43fd88b9b62a95dbfc7d522d7f5 [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
Vladimir Markod2ee5322018-12-19 17:57:57 +000037 PreoptBootClassPathDexFiles []string // file paths of boot class path files
38 PreoptBootClassPathDexLocations []string // virtual locations of boot class path files
39
40 BootJars []string // modules for jars that form the boot class path
Vladimir Markoe8b00d62018-12-21 15:54:16 +000041 PreoptBootJars []string // modules for jars that form the boot image
Colin Cross43f08db2018-11-12 10:13:39 -080042 SystemServerJars []string // jars that form the system server
43 SystemServerApps []string // apps that are loaded into system server
44 SpeedApps []string // apps that should be speed optimized
45
46 PreoptFlags []string // global dex2oat flags that should be used if no module-specific dex2oat flags are specified
47
48 DefaultCompilerFilter string // default compiler filter to pass to dex2oat, overridden by --compiler-filter= in module-specific dex2oat flags
49 SystemServerCompilerFilter string // default compiler filter to pass to dex2oat for system server jars
50
Nicolas Geoffrayfa6e9ec2019-02-12 13:12:16 +000051 GenerateDMFiles bool // generate Dex Metadata files
52 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 -080053
54 NoDebugInfo bool // don't generate debug info by default
55 AlwaysSystemServerDebugInfo bool // always generate mini debug info for system server modules (overrides NoDebugInfo=true)
56 NeverSystemServerDebugInfo bool // never generate mini debug info for system server modules (overrides NoDebugInfo=false)
57 AlwaysOtherDebugInfo bool // always generate mini debug info for non-system server modules (overrides NoDebugInfo=true)
58 NeverOtherDebugInfo bool // never generate mini debug info for non-system server modules (overrides NoDebugInfo=true)
59
60 MissingUsesLibraries []string // libraries that may be listed in OptionalUsesLibraries but will not be installed by the product
61
62 IsEng bool // build is a eng variant
63 SanitizeLite bool // build is the second phase of a SANITIZE_LITE build
64
65 DefaultAppImages bool // build app images (TODO: .art files?) by default
66
67 Dex2oatXmx string // max heap size
68 Dex2oatXms string // initial heap size
69
70 EmptyDirectory string // path to an empty directory
71
Colin Cross74ba9622019-02-11 15:11:14 -080072 DefaultDexPreoptImage map[android.ArchType]string // default boot image location for each architecture
73 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
76 Tools Tools // paths to tools possibly used by the generated commands
77}
78
79// Tools contains paths to tools possibly used by the generated commands. If you add a new tool here you MUST add it
80// to the order-only dependency list in DEXPREOPT_GEN_DEPS.
81type Tools struct {
82 Profman string
83 Dex2oat string
84 Aapt string
85 SoongZip string
86 Zip2zip string
87
88 VerifyUsesLibraries string
89 ConstructContext string
90}
91
92type ModuleConfig struct {
Victor Hsiehd181c8b2019-01-29 13:00:33 -080093 Name string
94 DexLocation string // dex location on device
95 BuildPath string
96 DexPath string
Victor Hsiehd181c8b2019-01-29 13:00:33 -080097 UncompressedDex bool
98 HasApkLibraries bool
99 PreoptFlags []string
Colin Cross43f08db2018-11-12 10:13:39 -0800100
101 ProfileClassListing string
102 ProfileIsTextListing bool
103
104 EnforceUsesLibraries bool
105 OptionalUsesLibraries []string
106 UsesLibraries []string
107 LibraryPaths map[string]string
108
Colin Cross74ba9622019-02-11 15:11:14 -0800109 Archs []android.ArchType
Colin Crossc7e40aa2019-02-08 21:37:00 -0800110 DexPreoptImages []string
Colin Cross43f08db2018-11-12 10:13:39 -0800111
112 PreoptExtractedApk bool // Overrides OnlyPreoptModules
113
114 NoCreateAppImage bool
115 ForceCreateAppImage bool
116
117 PresignedPrebuilt bool
118
Colin Cross8c6d2502019-01-09 21:09:14 -0800119 NoStripping bool
Colin Cross43f08db2018-11-12 10:13:39 -0800120 StripInputPath string
121 StripOutputPath string
122}
123
124func LoadGlobalConfig(path string) (GlobalConfig, error) {
125 config := GlobalConfig{}
126 err := loadConfig(path, &config)
127 return config, err
128}
129
130func LoadModuleConfig(path string) (ModuleConfig, error) {
131 config := ModuleConfig{}
132 err := loadConfig(path, &config)
133 return config, err
134}
135
136func loadConfig(path string, config interface{}) error {
137 data, err := ioutil.ReadFile(path)
138 if err != nil {
139 return err
140 }
141
142 err = json.Unmarshal(data, config)
143 if err != nil {
144 return err
145 }
146
147 return nil
148}