blob: 8fef010980e878e1dc8c157404c0c58f34d5d794 [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
51 GenerateDMFiles bool // generate Dex Metadata files
52
53 NoDebugInfo bool // don't generate debug info by default
54 AlwaysSystemServerDebugInfo bool // always generate mini debug info for system server modules (overrides NoDebugInfo=true)
55 NeverSystemServerDebugInfo bool // never generate mini debug info for system server modules (overrides NoDebugInfo=false)
56 AlwaysOtherDebugInfo bool // always generate mini debug info for non-system server modules (overrides NoDebugInfo=true)
57 NeverOtherDebugInfo bool // never generate mini debug info for non-system server modules (overrides NoDebugInfo=true)
58
59 MissingUsesLibraries []string // libraries that may be listed in OptionalUsesLibraries but will not be installed by the product
60
61 IsEng bool // build is a eng variant
62 SanitizeLite bool // build is the second phase of a SANITIZE_LITE build
63
64 DefaultAppImages bool // build app images (TODO: .art files?) by default
65
66 Dex2oatXmx string // max heap size
67 Dex2oatXms string // initial heap size
68
69 EmptyDirectory string // path to an empty directory
70
Colin Cross74ba9622019-02-11 15:11:14 -080071 DefaultDexPreoptImage map[android.ArchType]string // default boot image location for each architecture
72 CpuVariant map[android.ArchType]string // cpu variant for each architecture
73 InstructionSetFeatures map[android.ArchType]string // instruction set for each architecture
Colin Cross43f08db2018-11-12 10:13:39 -080074
75 Tools Tools // paths to tools possibly used by the generated commands
76}
77
78// Tools contains paths to tools possibly used by the generated commands. If you add a new tool here you MUST add it
79// to the order-only dependency list in DEXPREOPT_GEN_DEPS.
80type Tools struct {
81 Profman string
82 Dex2oat string
83 Aapt string
84 SoongZip string
85 Zip2zip string
86
87 VerifyUsesLibraries string
88 ConstructContext string
89}
90
91type ModuleConfig struct {
Victor Hsiehd181c8b2019-01-29 13:00:33 -080092 Name string
93 DexLocation string // dex location on device
94 BuildPath string
95 DexPath string
Victor Hsiehd181c8b2019-01-29 13:00:33 -080096 UncompressedDex bool
97 HasApkLibraries bool
98 PreoptFlags []string
Colin Cross43f08db2018-11-12 10:13:39 -080099
100 ProfileClassListing string
101 ProfileIsTextListing bool
102
103 EnforceUsesLibraries bool
104 OptionalUsesLibraries []string
105 UsesLibraries []string
106 LibraryPaths map[string]string
107
Colin Cross74ba9622019-02-11 15:11:14 -0800108 Archs []android.ArchType
Colin Crossc7e40aa2019-02-08 21:37:00 -0800109 DexPreoptImages []string
Colin Cross43f08db2018-11-12 10:13:39 -0800110
111 PreoptExtractedApk bool // Overrides OnlyPreoptModules
112
113 NoCreateAppImage bool
114 ForceCreateAppImage bool
115
116 PresignedPrebuilt bool
117
Colin Cross8c6d2502019-01-09 21:09:14 -0800118 NoStripping bool
Colin Cross43f08db2018-11-12 10:13:39 -0800119 StripInputPath string
120 StripOutputPath string
121}
122
123func LoadGlobalConfig(path string) (GlobalConfig, error) {
124 config := GlobalConfig{}
125 err := loadConfig(path, &config)
126 return config, err
127}
128
129func LoadModuleConfig(path string) (ModuleConfig, error) {
130 config := ModuleConfig{}
131 err := loadConfig(path, &config)
132 return config, err
133}
134
135func loadConfig(path string, config interface{}) error {
136 data, err := ioutil.ReadFile(path)
137 if err != nil {
138 return err
139 }
140
141 err = json.Unmarshal(data, config)
142 if err != nil {
143 return err
144 }
145
146 return nil
147}