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