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