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" |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 19 | "strings" |
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 | |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 24 | // GlobalConfig stores the configuration for dex preopting. The fields are set |
Hans Boehm | e4b5342 | 2020-01-25 01:44:30 +0000 | [diff] [blame] | 25 | // from product variables via dex_preopt_config.mk, except for SoongConfig |
| 26 | // which come from CreateGlobalSoongConfig. |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 27 | type GlobalConfig struct { |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 28 | DisablePreopt bool // disable preopt for all modules |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 29 | DisablePreoptModules []string // modules with preopt disabled by product-specific config |
| 30 | |
| 31 | OnlyPreoptBootImageAndSystemServer bool // only preopt jars in the boot image or system server |
| 32 | |
Vladimir Marko | 40139d6 | 2020-02-06 15:14:29 +0000 | [diff] [blame] | 33 | UseArtImage bool // use the art image (use other boot class path dex files without image) |
| 34 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 35 | HasSystemOther bool // store odex files that match PatternsOnSystemOther on the system_other partition |
| 36 | PatternsOnSystemOther []string // patterns (using '%' to denote a prefix match) to put odex on the system_other partition |
| 37 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 38 | DisableGenerateProfile bool // don't generate profiles |
| 39 | ProfileDir string // directory to find profiles in |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 40 | |
Roshan Pius | ccc26ef | 2019-11-27 09:37:46 -0800 | [diff] [blame] | 41 | BootJars []string // modules for jars that form the boot class path |
| 42 | UpdatableBootJars []string // jars within apex that form the boot class path |
Vladimir Marko | d2ee532 | 2018-12-19 17:57:57 +0000 | [diff] [blame] | 43 | |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 44 | ArtApexJars []string // modules for jars that are in the ART APEX |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 45 | |
Roshan Pius | 9b51a40 | 2019-11-21 12:36:53 -0800 | [diff] [blame] | 46 | SystemServerJars []string // jars that form the system server |
| 47 | SystemServerApps []string // apps that are loaded into system server |
| 48 | UpdatableSystemServerJars []string // jars within apex that are loaded into system server |
| 49 | SpeedApps []string // apps that should be speed optimized |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 50 | |
| 51 | PreoptFlags []string // global dex2oat flags that should be used if no module-specific dex2oat flags are specified |
| 52 | |
| 53 | DefaultCompilerFilter string // default compiler filter to pass to dex2oat, overridden by --compiler-filter= in module-specific dex2oat flags |
| 54 | SystemServerCompilerFilter string // default compiler filter to pass to dex2oat for system server jars |
| 55 | |
Nicolas Geoffray | c1bf724 | 2019-10-18 14:51:38 +0100 | [diff] [blame] | 56 | GenerateDMFiles bool // generate Dex Metadata files |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 57 | |
| 58 | NoDebugInfo bool // don't generate debug info by default |
Mathieu Chartier | 3f7ddbb | 2019-04-29 09:33:50 -0700 | [diff] [blame] | 59 | DontResolveStartupStrings bool // don't resolve string literals loaded during application startup. |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 60 | AlwaysSystemServerDebugInfo bool // always generate mini debug info for system server modules (overrides NoDebugInfo=true) |
| 61 | NeverSystemServerDebugInfo bool // never generate mini debug info for system server modules (overrides NoDebugInfo=false) |
| 62 | AlwaysOtherDebugInfo bool // always generate mini debug info for non-system server modules (overrides NoDebugInfo=true) |
| 63 | NeverOtherDebugInfo bool // never generate mini debug info for non-system server modules (overrides NoDebugInfo=true) |
| 64 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 65 | IsEng bool // build is a eng variant |
| 66 | SanitizeLite bool // build is the second phase of a SANITIZE_LITE build |
| 67 | |
| 68 | DefaultAppImages bool // build app images (TODO: .art files?) by default |
| 69 | |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 70 | Dex2oatXmx string // max heap size for dex2oat |
| 71 | Dex2oatXms string // initial heap size for dex2oat |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 72 | |
| 73 | EmptyDirectory string // path to an empty directory |
| 74 | |
Colin Cross | 74ba962 | 2019-02-11 15:11:14 -0800 | [diff] [blame] | 75 | CpuVariant map[android.ArchType]string // cpu variant for each architecture |
| 76 | InstructionSetFeatures map[android.ArchType]string // instruction set for each architecture |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 77 | |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 78 | // Only used for boot image |
Mathieu Chartier | 6adeee1 | 2019-06-26 10:01:36 -0700 | [diff] [blame] | 79 | DirtyImageObjects android.OptionalPath // path to a dirty-image-objects file |
| 80 | BootImageProfiles android.Paths // path to a boot-image-profile.txt file |
| 81 | BootFlags string // extra flags to pass to dex2oat for the boot image |
| 82 | Dex2oatImageXmx string // max heap size for dex2oat for the boot image |
| 83 | Dex2oatImageXms string // initial heap size for dex2oat for the boot image |
Hans Boehm | e4b5342 | 2020-01-25 01:44:30 +0000 | [diff] [blame] | 84 | |
| 85 | SoongConfig GlobalSoongConfig // settings read from dexpreopt_soong.config |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 86 | } |
| 87 | |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 88 | // GlobalSoongConfig contains the global config that is generated from Soong, |
| 89 | // stored in dexpreopt_soong.config. |
| 90 | type GlobalSoongConfig struct { |
| 91 | // Paths to tools possibly used by the generated commands. |
| 92 | Profman android.Path |
| 93 | Dex2oat android.Path |
| 94 | Aapt android.Path |
| 95 | SoongZip android.Path |
| 96 | Zip2zip android.Path |
| 97 | ManifestCheck android.Path |
Colin Cross | 38b9685 | 2019-05-22 10:21:09 -0700 | [diff] [blame] | 98 | ConstructContext android.Path |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | type ModuleConfig struct { |
Victor Hsieh | d181c8b | 2019-01-29 13:00:33 -0800 | [diff] [blame] | 102 | Name string |
| 103 | DexLocation string // dex location on device |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 104 | BuildPath android.OutputPath |
| 105 | DexPath android.Path |
Colin Cross | 38b9685 | 2019-05-22 10:21:09 -0700 | [diff] [blame] | 106 | ManifestPath android.Path |
Victor Hsieh | d181c8b | 2019-01-29 13:00:33 -0800 | [diff] [blame] | 107 | UncompressedDex bool |
| 108 | HasApkLibraries bool |
| 109 | PreoptFlags []string |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 110 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 111 | ProfileClassListing android.OptionalPath |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 112 | ProfileIsTextListing bool |
Nicolas Geoffray | e710242 | 2019-07-24 13:19:29 +0100 | [diff] [blame] | 113 | ProfileBootListing android.OptionalPath |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 114 | |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 115 | EnforceUsesLibraries bool |
| 116 | PresentOptionalUsesLibraries []string |
| 117 | UsesLibraries []string |
| 118 | LibraryPaths map[string]android.Path |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 119 | |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 120 | Archs []android.ArchType |
| 121 | DexPreoptImages []android.Path |
| 122 | DexPreoptImagesDeps []android.OutputPaths |
| 123 | DexPreoptImageLocations []string |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 124 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 125 | PreoptBootClassPathDexFiles android.Paths // file paths of boot class path files |
| 126 | PreoptBootClassPathDexLocations []string // virtual locations of boot class path files |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 127 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 128 | PreoptExtractedApk bool // Overrides OnlyPreoptModules |
| 129 | |
| 130 | NoCreateAppImage bool |
| 131 | ForceCreateAppImage bool |
| 132 | |
| 133 | PresignedPrebuilt bool |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 134 | } |
| 135 | |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 136 | type globalSoongConfigSingleton struct{} |
| 137 | |
| 138 | var pctx = android.NewPackageContext("android/soong/dexpreopt") |
| 139 | |
| 140 | func init() { |
| 141 | pctx.Import("android/soong/android") |
| 142 | android.RegisterSingletonType("dexpreopt-soong-config", func() android.Singleton { |
| 143 | return &globalSoongConfigSingleton{} |
| 144 | }) |
| 145 | } |
| 146 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 147 | func constructPath(ctx android.PathContext, path string) android.Path { |
| 148 | buildDirPrefix := ctx.Config().BuildDir() + "/" |
| 149 | if path == "" { |
| 150 | return nil |
| 151 | } else if strings.HasPrefix(path, buildDirPrefix) { |
| 152 | return android.PathForOutput(ctx, strings.TrimPrefix(path, buildDirPrefix)) |
| 153 | } else { |
| 154 | return android.PathForSource(ctx, path) |
| 155 | } |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 156 | } |
| 157 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 158 | func constructPaths(ctx android.PathContext, paths []string) android.Paths { |
| 159 | var ret android.Paths |
| 160 | for _, path := range paths { |
| 161 | ret = append(ret, constructPath(ctx, path)) |
| 162 | } |
| 163 | return ret |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 164 | } |
| 165 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 166 | func constructPathMap(ctx android.PathContext, paths map[string]string) map[string]android.Path { |
| 167 | ret := map[string]android.Path{} |
| 168 | for key, path := range paths { |
| 169 | ret[key] = constructPath(ctx, path) |
| 170 | } |
| 171 | return ret |
| 172 | } |
| 173 | |
| 174 | func constructWritablePath(ctx android.PathContext, path string) android.WritablePath { |
| 175 | if path == "" { |
| 176 | return nil |
| 177 | } |
| 178 | return constructPath(ctx, path).(android.WritablePath) |
| 179 | } |
| 180 | |
Hans Boehm | 453bf09 | 2020-01-25 01:44:30 +0000 | [diff] [blame] | 181 | // LoadGlobalConfig reads the global dexpreopt.config file into a GlobalConfig |
Hans Boehm | e4b5342 | 2020-01-25 01:44:30 +0000 | [diff] [blame] | 182 | // struct, except the SoongConfig field which is set from the provided |
| 183 | // soongConfig argument. LoadGlobalConfig is used directly in Soong and in |
| 184 | // dexpreopt_gen called from Make to read the $OUT/dexpreopt.config written by |
| 185 | // Make. |
| 186 | func LoadGlobalConfig(ctx android.PathContext, data []byte, soongConfig GlobalSoongConfig) (GlobalConfig, error) { |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 187 | type GlobalJSONConfig struct { |
| 188 | GlobalConfig |
| 189 | |
| 190 | // Copies of entries in GlobalConfig that are not constructable without extra parameters. They will be |
| 191 | // used to construct the real value manually below. |
| 192 | DirtyImageObjects string |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 193 | BootImageProfiles []string |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | config := GlobalJSONConfig{} |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 197 | err := json.Unmarshal(data, &config) |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 198 | if err != nil { |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 199 | return config.GlobalConfig, err |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | // Construct paths that require a PathContext. |
| 203 | config.GlobalConfig.DirtyImageObjects = android.OptionalPathForPath(constructPath(ctx, config.DirtyImageObjects)) |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 204 | config.GlobalConfig.BootImageProfiles = constructPaths(ctx, config.BootImageProfiles) |
| 205 | |
Hans Boehm | e4b5342 | 2020-01-25 01:44:30 +0000 | [diff] [blame] | 206 | // Set this here to force the caller to provide a value for this struct (from |
| 207 | // either CreateGlobalSoongConfig or LoadGlobalSoongConfig). |
| 208 | config.GlobalConfig.SoongConfig = soongConfig |
| 209 | |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 210 | return config.GlobalConfig, nil |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 211 | } |
| 212 | |
Hans Boehm | 453bf09 | 2020-01-25 01:44:30 +0000 | [diff] [blame] | 213 | // LoadModuleConfig reads a per-module dexpreopt.config file into a ModuleConfig struct. It is not used in Soong, which |
| 214 | // receives a ModuleConfig struct directly from java/dexpreopt.go. It is used in dexpreopt_gen called from oMake to |
| 215 | // read the module dexpreopt.config written by Make. |
| 216 | func LoadModuleConfig(ctx android.PathContext, data []byte) (ModuleConfig, error) { |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 217 | type ModuleJSONConfig struct { |
| 218 | ModuleConfig |
| 219 | |
| 220 | // Copies of entries in ModuleConfig that are not constructable without extra parameters. They will be |
| 221 | // used to construct the real value manually below. |
| 222 | BuildPath string |
| 223 | DexPath string |
Colin Cross | 38b9685 | 2019-05-22 10:21:09 -0700 | [diff] [blame] | 224 | ManifestPath string |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 225 | ProfileClassListing string |
| 226 | LibraryPaths map[string]string |
| 227 | DexPreoptImages []string |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 228 | DexPreoptImageLocations []string |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 229 | PreoptBootClassPathDexFiles []string |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | config := ModuleJSONConfig{} |
| 233 | |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 234 | err := json.Unmarshal(data, &config) |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 235 | if err != nil { |
| 236 | return config.ModuleConfig, err |
| 237 | } |
| 238 | |
| 239 | // Construct paths that require a PathContext. |
| 240 | config.ModuleConfig.BuildPath = constructPath(ctx, config.BuildPath).(android.OutputPath) |
| 241 | config.ModuleConfig.DexPath = constructPath(ctx, config.DexPath) |
Colin Cross | 38b9685 | 2019-05-22 10:21:09 -0700 | [diff] [blame] | 242 | config.ModuleConfig.ManifestPath = constructPath(ctx, config.ManifestPath) |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 243 | config.ModuleConfig.ProfileClassListing = android.OptionalPathForPath(constructPath(ctx, config.ProfileClassListing)) |
| 244 | config.ModuleConfig.LibraryPaths = constructPathMap(ctx, config.LibraryPaths) |
| 245 | config.ModuleConfig.DexPreoptImages = constructPaths(ctx, config.DexPreoptImages) |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 246 | config.ModuleConfig.DexPreoptImageLocations = config.DexPreoptImageLocations |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 247 | config.ModuleConfig.PreoptBootClassPathDexFiles = constructPaths(ctx, config.PreoptBootClassPathDexFiles) |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 248 | |
Dan Willemsen | 0f41678 | 2019-06-13 21:44:53 +0000 | [diff] [blame] | 249 | // This needs to exist, but dependencies are already handled in Make, so we don't need to pass them through JSON. |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 250 | config.ModuleConfig.DexPreoptImagesDeps = make([]android.OutputPaths, len(config.ModuleConfig.DexPreoptImages)) |
Dan Willemsen | 0f41678 | 2019-06-13 21:44:53 +0000 | [diff] [blame] | 251 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 252 | return config.ModuleConfig, nil |
| 253 | } |
| 254 | |
Hans Boehm | e4b5342 | 2020-01-25 01:44:30 +0000 | [diff] [blame] | 255 | // CreateGlobalSoongConfig creates a GlobalSoongConfig from the current context. |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 256 | // Should not be used in dexpreopt_gen. |
Hans Boehm | e4b5342 | 2020-01-25 01:44:30 +0000 | [diff] [blame] | 257 | func CreateGlobalSoongConfig(ctx android.PathContext) GlobalSoongConfig { |
Hans Boehm | 7b2e6f3 | 2020-01-25 01:44:30 +0000 | [diff] [blame] | 258 | // Default to debug version to help find bugs. |
| 259 | // Set USE_DEX2OAT_DEBUG to false for only building non-debug versions. |
| 260 | var dex2oatBinary string |
| 261 | if ctx.Config().Getenv("USE_DEX2OAT_DEBUG") == "false" { |
| 262 | dex2oatBinary = "dex2oat" |
| 263 | } else { |
| 264 | dex2oatBinary = "dex2oatd" |
| 265 | } |
| 266 | |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 267 | return GlobalSoongConfig{ |
| 268 | Profman: ctx.Config().HostToolPath(ctx, "profman"), |
Hans Boehm | 7b2e6f3 | 2020-01-25 01:44:30 +0000 | [diff] [blame] | 269 | Dex2oat: ctx.Config().HostToolPath(ctx, dex2oatBinary), |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 270 | Aapt: ctx.Config().HostToolPath(ctx, "aapt"), |
| 271 | SoongZip: ctx.Config().HostToolPath(ctx, "soong_zip"), |
| 272 | Zip2zip: ctx.Config().HostToolPath(ctx, "zip2zip"), |
| 273 | ManifestCheck: ctx.Config().HostToolPath(ctx, "manifest_check"), |
| 274 | ConstructContext: android.PathForSource(ctx, "build/make/core/construct_context.sh"), |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | type globalJsonSoongConfig struct { |
| 279 | Profman string |
| 280 | Dex2oat string |
| 281 | Aapt string |
| 282 | SoongZip string |
| 283 | Zip2zip string |
| 284 | ManifestCheck string |
| 285 | ConstructContext string |
| 286 | } |
| 287 | |
Hans Boehm | 453bf09 | 2020-01-25 01:44:30 +0000 | [diff] [blame] | 288 | // LoadGlobalSoongConfig reads the dexpreopt_soong.config file into a |
| 289 | // GlobalSoongConfig struct. It is only used in dexpreopt_gen. |
| 290 | func LoadGlobalSoongConfig(ctx android.PathContext, data []byte) (GlobalSoongConfig, error) { |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 291 | var jc globalJsonSoongConfig |
| 292 | |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 293 | err := json.Unmarshal(data, &jc) |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 294 | if err != nil { |
| 295 | return GlobalSoongConfig{}, err |
| 296 | } |
| 297 | |
| 298 | config := GlobalSoongConfig{ |
| 299 | Profman: constructPath(ctx, jc.Profman), |
| 300 | Dex2oat: constructPath(ctx, jc.Dex2oat), |
| 301 | Aapt: constructPath(ctx, jc.Aapt), |
| 302 | SoongZip: constructPath(ctx, jc.SoongZip), |
| 303 | Zip2zip: constructPath(ctx, jc.Zip2zip), |
| 304 | ManifestCheck: constructPath(ctx, jc.ManifestCheck), |
| 305 | ConstructContext: constructPath(ctx, jc.ConstructContext), |
| 306 | } |
| 307 | |
| 308 | return config, nil |
| 309 | } |
| 310 | |
| 311 | func (s *globalSoongConfigSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
Hans Boehm | e4b5342 | 2020-01-25 01:44:30 +0000 | [diff] [blame] | 312 | config := CreateGlobalSoongConfig(ctx) |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 313 | jc := globalJsonSoongConfig{ |
| 314 | Profman: config.Profman.String(), |
| 315 | Dex2oat: config.Dex2oat.String(), |
| 316 | Aapt: config.Aapt.String(), |
| 317 | SoongZip: config.SoongZip.String(), |
| 318 | Zip2zip: config.Zip2zip.String(), |
| 319 | ManifestCheck: config.ManifestCheck.String(), |
| 320 | ConstructContext: config.ConstructContext.String(), |
| 321 | } |
| 322 | |
| 323 | data, err := json.Marshal(jc) |
| 324 | if err != nil { |
| 325 | ctx.Errorf("failed to JSON marshal GlobalSoongConfig: %v", err) |
| 326 | return |
| 327 | } |
| 328 | |
| 329 | ctx.Build(pctx, android.BuildParams{ |
| 330 | Rule: android.WriteFile, |
| 331 | Output: android.PathForOutput(ctx, "dexpreopt_soong.config"), |
| 332 | Args: map[string]string{ |
| 333 | "content": string(data), |
| 334 | }, |
| 335 | }) |
| 336 | } |
| 337 | |
| 338 | func (s *globalSoongConfigSingleton) MakeVars(ctx android.MakeVarsContext) { |
Hans Boehm | e4b5342 | 2020-01-25 01:44:30 +0000 | [diff] [blame] | 339 | config := CreateGlobalSoongConfig(ctx) |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 340 | |
| 341 | ctx.Strict("DEX2OAT", config.Dex2oat.String()) |
| 342 | ctx.Strict("DEXPREOPT_GEN_DEPS", strings.Join([]string{ |
| 343 | config.Profman.String(), |
| 344 | config.Dex2oat.String(), |
| 345 | config.Aapt.String(), |
| 346 | config.SoongZip.String(), |
| 347 | config.Zip2zip.String(), |
| 348 | config.ManifestCheck.String(), |
| 349 | config.ConstructContext.String(), |
| 350 | }, " ")) |
| 351 | } |
| 352 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 353 | func GlobalConfigForTests(ctx android.PathContext) GlobalConfig { |
| 354 | return GlobalConfig{ |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 355 | DisablePreopt: false, |
| 356 | DisablePreoptModules: nil, |
| 357 | OnlyPreoptBootImageAndSystemServer: false, |
| 358 | HasSystemOther: false, |
| 359 | PatternsOnSystemOther: nil, |
| 360 | DisableGenerateProfile: false, |
| 361 | ProfileDir: "", |
| 362 | BootJars: nil, |
Roshan Pius | ccc26ef | 2019-11-27 09:37:46 -0800 | [diff] [blame] | 363 | UpdatableBootJars: nil, |
Martin Stjernholm | cc4b0ad | 2019-07-05 22:38:25 +0100 | [diff] [blame] | 364 | ArtApexJars: nil, |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 365 | SystemServerJars: nil, |
| 366 | SystemServerApps: nil, |
Roshan Pius | 9b51a40 | 2019-11-21 12:36:53 -0800 | [diff] [blame] | 367 | UpdatableSystemServerJars: nil, |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 368 | SpeedApps: nil, |
| 369 | PreoptFlags: nil, |
| 370 | DefaultCompilerFilter: "", |
| 371 | SystemServerCompilerFilter: "", |
| 372 | GenerateDMFiles: false, |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 373 | NoDebugInfo: false, |
Mathieu Chartier | 3f7ddbb | 2019-04-29 09:33:50 -0700 | [diff] [blame] | 374 | DontResolveStartupStrings: false, |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 375 | AlwaysSystemServerDebugInfo: false, |
| 376 | NeverSystemServerDebugInfo: false, |
| 377 | AlwaysOtherDebugInfo: false, |
| 378 | NeverOtherDebugInfo: false, |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 379 | IsEng: false, |
| 380 | SanitizeLite: false, |
| 381 | DefaultAppImages: false, |
| 382 | Dex2oatXmx: "", |
| 383 | Dex2oatXms: "", |
| 384 | EmptyDirectory: "empty_dir", |
| 385 | CpuVariant: nil, |
| 386 | InstructionSetFeatures: nil, |
| 387 | DirtyImageObjects: android.OptionalPath{}, |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 388 | BootImageProfiles: nil, |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 389 | BootFlags: "", |
| 390 | Dex2oatImageXmx: "", |
| 391 | Dex2oatImageXms: "", |
Hans Boehm | e4b5342 | 2020-01-25 01:44:30 +0000 | [diff] [blame] | 392 | SoongConfig: GlobalSoongConfig{ |
Colin Cross | 38b9685 | 2019-05-22 10:21:09 -0700 | [diff] [blame] | 393 | Profman: android.PathForTesting("profman"), |
| 394 | Dex2oat: android.PathForTesting("dex2oat"), |
| 395 | Aapt: android.PathForTesting("aapt"), |
| 396 | SoongZip: android.PathForTesting("soong_zip"), |
| 397 | Zip2zip: android.PathForTesting("zip2zip"), |
| 398 | ManifestCheck: android.PathForTesting("manifest_check"), |
| 399 | ConstructContext: android.PathForTesting("construct_context.sh"), |
Hans Boehm | e4b5342 | 2020-01-25 01:44:30 +0000 | [diff] [blame] | 400 | }, |
| 401 | } |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 402 | } |