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