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