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