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