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