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 | |
Vladimir Marko | d2ee532 | 2018-12-19 17:57:57 +0000 | [diff] [blame] | 37 | 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 Marko | e8b00d6 | 2018-12-21 15:54:16 +0000 | [diff] [blame] | 41 | PreoptBootJars []string // modules for jars that form the boot image |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 42 | 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 Geoffray | fa6e9ec | 2019-02-12 13:12:16 +0000 | [diff] [blame] | 51 | 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 Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 53 | |
| 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 Cross | 74ba962 | 2019-02-11 15:11:14 -0800 | [diff] [blame] | 72 | 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 Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 75 | |
| 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. |
| 81 | type 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 | |
| 92 | type ModuleConfig struct { |
Victor Hsieh | d181c8b | 2019-01-29 13:00:33 -0800 | [diff] [blame] | 93 | Name string |
| 94 | DexLocation string // dex location on device |
| 95 | BuildPath string |
| 96 | DexPath string |
Victor Hsieh | d181c8b | 2019-01-29 13:00:33 -0800 | [diff] [blame] | 97 | UncompressedDex bool |
| 98 | HasApkLibraries bool |
| 99 | PreoptFlags []string |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 100 | |
| 101 | ProfileClassListing string |
| 102 | ProfileIsTextListing bool |
| 103 | |
| 104 | EnforceUsesLibraries bool |
| 105 | OptionalUsesLibraries []string |
| 106 | UsesLibraries []string |
| 107 | LibraryPaths map[string]string |
| 108 | |
Colin Cross | 74ba962 | 2019-02-11 15:11:14 -0800 | [diff] [blame] | 109 | Archs []android.ArchType |
Colin Cross | c7e40aa | 2019-02-08 21:37:00 -0800 | [diff] [blame] | 110 | DexPreoptImages []string |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 111 | |
| 112 | PreoptExtractedApk bool // Overrides OnlyPreoptModules |
| 113 | |
| 114 | NoCreateAppImage bool |
| 115 | ForceCreateAppImage bool |
| 116 | |
| 117 | PresignedPrebuilt bool |
| 118 | |
Colin Cross | 8c6d250 | 2019-01-09 21:09:14 -0800 | [diff] [blame] | 119 | NoStripping bool |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 120 | StripInputPath string |
| 121 | StripOutputPath string |
| 122 | } |
| 123 | |
| 124 | func LoadGlobalConfig(path string) (GlobalConfig, error) { |
| 125 | config := GlobalConfig{} |
| 126 | err := loadConfig(path, &config) |
| 127 | return config, err |
| 128 | } |
| 129 | |
| 130 | func LoadModuleConfig(path string) (ModuleConfig, error) { |
| 131 | config := ModuleConfig{} |
| 132 | err := loadConfig(path, &config) |
| 133 | return config, err |
| 134 | } |
| 135 | |
| 136 | func 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 | } |