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" |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 19 | "fmt" |
Paul Duffin | 7d1d083 | 2021-04-23 11:39:41 +0100 | [diff] [blame] | 20 | "reflect" |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 21 | "strings" |
Colin Cross | 74ba962 | 2019-02-11 15:11:14 -0800 | [diff] [blame] | 22 | |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 23 | "github.com/google/blueprint" |
| 24 | |
Colin Cross | 74ba962 | 2019-02-11 15:11:14 -0800 | [diff] [blame] | 25 | "android/soong/android" |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 26 | ) |
| 27 | |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 28 | // GlobalConfig stores the configuration for dex preopting. The fields are set |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 29 | // from product variables via dex_preopt_config.mk. |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 30 | type GlobalConfig struct { |
Ulya Trafimovich | a4a1c4e | 2021-01-15 18:40:04 +0000 | [diff] [blame] | 31 | DisablePreopt bool // disable preopt for all modules (excluding boot images) |
| 32 | DisablePreoptBootImages bool // disable prepot for boot images |
| 33 | DisablePreoptModules []string // modules with preopt disabled by product-specific config |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 34 | |
| 35 | OnlyPreoptBootImageAndSystemServer bool // only preopt jars in the boot image or system server |
| 36 | |
Ulya Trafimovich | 9023b02 | 2021-03-22 16:02:28 +0000 | [diff] [blame] | 37 | PreoptWithUpdatableBcp bool // If updatable boot jars are included in dexpreopt or not. |
| 38 | |
Vladimir Marko | 40139d6 | 2020-02-06 15:14:29 +0000 | [diff] [blame] | 39 | UseArtImage bool // use the art image (use other boot class path dex files without image) |
| 40 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 41 | HasSystemOther bool // store odex files that match PatternsOnSystemOther on the system_other partition |
| 42 | PatternsOnSystemOther []string // patterns (using '%' to denote a prefix match) to put odex on the system_other partition |
| 43 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 44 | DisableGenerateProfile bool // don't generate profiles |
| 45 | ProfileDir string // directory to find profiles in |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 46 | |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 47 | BootJars android.ConfiguredJarList // modules for jars that form the boot class path |
| 48 | ApexBootJars android.ConfiguredJarList // jars within apex that form the boot class path |
Vladimir Marko | d2ee532 | 2018-12-19 17:57:57 +0000 | [diff] [blame] | 49 | |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 50 | ArtApexJars android.ConfiguredJarList // modules for jars that are in the ART APEX |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 51 | |
Jiakai Zhang | cee9e19 | 2021-10-29 19:46:45 +0000 | [diff] [blame^] | 52 | SystemServerJars android.ConfiguredJarList // system_server classpath jars on the platform |
| 53 | SystemServerApps []string // apps that are loaded into system server |
| 54 | ApexSystemServerJars android.ConfiguredJarList // system_server classpath jars delivered via apex |
| 55 | StandaloneSystemServerJars android.ConfiguredJarList // jars on the platform that system_server loads dynamically using separate classloaders |
| 56 | ApexStandaloneSystemServerJars android.ConfiguredJarList // jars delivered via apex that system_server loads dynamically using separate classloaders |
| 57 | SpeedApps []string // apps that should be speed optimized |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 58 | |
Ulya Trafimovich | cd3203f | 2020-03-27 11:30:00 +0000 | [diff] [blame] | 59 | BrokenSuboptimalOrderOfSystemServerJars bool // if true, sub-optimal order does not cause a build error |
| 60 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 61 | PreoptFlags []string // global dex2oat flags that should be used if no module-specific dex2oat flags are specified |
| 62 | |
| 63 | DefaultCompilerFilter string // default compiler filter to pass to dex2oat, overridden by --compiler-filter= in module-specific dex2oat flags |
| 64 | SystemServerCompilerFilter string // default compiler filter to pass to dex2oat for system server jars |
| 65 | |
Nicolas Geoffray | c1bf724 | 2019-10-18 14:51:38 +0100 | [diff] [blame] | 66 | GenerateDMFiles bool // generate Dex Metadata files |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 67 | |
| 68 | NoDebugInfo bool // don't generate debug info by default |
Mathieu Chartier | 3f7ddbb | 2019-04-29 09:33:50 -0700 | [diff] [blame] | 69 | DontResolveStartupStrings bool // don't resolve string literals loaded during application startup. |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 70 | AlwaysSystemServerDebugInfo bool // always generate mini debug info for system server modules (overrides NoDebugInfo=true) |
| 71 | NeverSystemServerDebugInfo bool // never generate mini debug info for system server modules (overrides NoDebugInfo=false) |
| 72 | AlwaysOtherDebugInfo bool // always generate mini debug info for non-system server modules (overrides NoDebugInfo=true) |
| 73 | NeverOtherDebugInfo bool // never generate mini debug info for non-system server modules (overrides NoDebugInfo=true) |
| 74 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 75 | IsEng bool // build is a eng variant |
| 76 | SanitizeLite bool // build is the second phase of a SANITIZE_LITE build |
| 77 | |
| 78 | DefaultAppImages bool // build app images (TODO: .art files?) by default |
| 79 | |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 80 | Dex2oatXmx string // max heap size for dex2oat |
| 81 | Dex2oatXms string // initial heap size for dex2oat |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 82 | |
| 83 | EmptyDirectory string // path to an empty directory |
| 84 | |
Colin Cross | 74ba962 | 2019-02-11 15:11:14 -0800 | [diff] [blame] | 85 | CpuVariant map[android.ArchType]string // cpu variant for each architecture |
| 86 | InstructionSetFeatures map[android.ArchType]string // instruction set for each architecture |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 87 | |
Nicolas Geoffray | 1086e60 | 2021-01-20 14:30:40 +0000 | [diff] [blame] | 88 | BootImageProfiles android.Paths // path to a boot-image-profile.txt file |
| 89 | BootFlags string // extra flags to pass to dex2oat for the boot image |
| 90 | Dex2oatImageXmx string // max heap size for dex2oat for the boot image |
| 91 | Dex2oatImageXms string // initial heap size for dex2oat for the boot image |
Ulya Trafimovich | 8c35fcf | 2021-02-17 16:23:28 +0000 | [diff] [blame] | 92 | |
Ulya Trafimovich | 4a13acb | 2021-03-02 12:25:02 +0000 | [diff] [blame] | 93 | // If true, downgrade the compiler filter of dexpreopt to "verify" when verify_uses_libraries |
Ulya Trafimovich | 8c35fcf | 2021-02-17 16:23:28 +0000 | [diff] [blame] | 94 | // check fails, instead of failing the build. This will disable any AOT-compilation. |
| 95 | // |
| 96 | // The intended use case for this flag is to have a smoother migration path for the Java |
| 97 | // modules that need to add <uses-library> information in their build files. The flag allows to |
| 98 | // quickly silence build errors. This flag should be used with caution and only as a temporary |
| 99 | // measure, as it masks real errors and affects performance. |
| 100 | RelaxUsesLibraryCheck bool |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 101 | } |
| 102 | |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 103 | // GlobalSoongConfig contains the global config that is generated from Soong, |
| 104 | // stored in dexpreopt_soong.config. |
| 105 | type GlobalSoongConfig struct { |
| 106 | // Paths to tools possibly used by the generated commands. |
| 107 | Profman android.Path |
| 108 | Dex2oat android.Path |
| 109 | Aapt android.Path |
| 110 | SoongZip android.Path |
| 111 | Zip2zip android.Path |
| 112 | ManifestCheck android.Path |
Colin Cross | 38b9685 | 2019-05-22 10:21:09 -0700 | [diff] [blame] | 113 | ConstructContext android.Path |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | type ModuleConfig struct { |
Victor Hsieh | d181c8b | 2019-01-29 13:00:33 -0800 | [diff] [blame] | 117 | Name string |
| 118 | DexLocation string // dex location on device |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 119 | BuildPath android.OutputPath |
| 120 | DexPath android.Path |
Jeongik Cha | 33a3a81 | 2021-04-15 09:12:49 +0900 | [diff] [blame] | 121 | ManifestPath android.OptionalPath |
Victor Hsieh | d181c8b | 2019-01-29 13:00:33 -0800 | [diff] [blame] | 122 | UncompressedDex bool |
| 123 | HasApkLibraries bool |
| 124 | PreoptFlags []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 | ProfileClassListing android.OptionalPath |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 127 | ProfileIsTextListing bool |
Nicolas Geoffray | e710242 | 2019-07-24 13:19:29 +0100 | [diff] [blame] | 128 | ProfileBootListing android.OptionalPath |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 129 | |
Ulya Trafimovich | 8c35fcf | 2021-02-17 16:23:28 +0000 | [diff] [blame] | 130 | EnforceUsesLibraries bool // turn on build-time verify_uses_libraries check |
| 131 | EnforceUsesLibrariesStatusFile android.Path // a file with verify_uses_libraries errors (if any) |
| 132 | ProvidesUsesLibrary string // library name (usually the same as module name) |
| 133 | ClassLoaderContexts ClassLoaderContextMap |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 134 | |
Jeongik Cha | 4dda75e | 2021-04-27 23:56:44 +0900 | [diff] [blame] | 135 | Archs []android.ArchType |
| 136 | DexPreoptImagesDeps []android.OutputPaths |
| 137 | |
| 138 | DexPreoptImageLocationsOnHost []string // boot image location on host (file path without the arch subdirectory) |
| 139 | DexPreoptImageLocationsOnDevice []string // boot image location on device (file path without the arch subdirectory) |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 140 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 141 | PreoptBootClassPathDexFiles android.Paths // file paths of boot class path files |
| 142 | PreoptBootClassPathDexLocations []string // virtual locations of boot class path files |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 143 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 144 | PreoptExtractedApk bool // Overrides OnlyPreoptModules |
| 145 | |
| 146 | NoCreateAppImage bool |
| 147 | ForceCreateAppImage bool |
| 148 | |
| 149 | PresignedPrebuilt bool |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 150 | } |
| 151 | |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 152 | type globalSoongConfigSingleton struct{} |
| 153 | |
| 154 | var pctx = android.NewPackageContext("android/soong/dexpreopt") |
| 155 | |
| 156 | func init() { |
| 157 | pctx.Import("android/soong/android") |
| 158 | android.RegisterSingletonType("dexpreopt-soong-config", func() android.Singleton { |
| 159 | return &globalSoongConfigSingleton{} |
| 160 | }) |
| 161 | } |
| 162 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 163 | func constructPath(ctx android.PathContext, path string) android.Path { |
Lukacs T. Berki | 9f6c24a | 2021-08-26 15:07:24 +0200 | [diff] [blame] | 164 | buildDirPrefix := ctx.Config().SoongOutDir() + "/" |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 165 | if path == "" { |
| 166 | return nil |
| 167 | } else if strings.HasPrefix(path, buildDirPrefix) { |
| 168 | return android.PathForOutput(ctx, strings.TrimPrefix(path, buildDirPrefix)) |
| 169 | } else { |
| 170 | return android.PathForSource(ctx, path) |
| 171 | } |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 172 | } |
| 173 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 174 | func constructPaths(ctx android.PathContext, paths []string) android.Paths { |
| 175 | var ret android.Paths |
| 176 | for _, path := range paths { |
| 177 | ret = append(ret, constructPath(ctx, path)) |
| 178 | } |
| 179 | return ret |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 180 | } |
| 181 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 182 | func constructWritablePath(ctx android.PathContext, path string) android.WritablePath { |
| 183 | if path == "" { |
| 184 | return nil |
| 185 | } |
| 186 | return constructPath(ctx, path).(android.WritablePath) |
| 187 | } |
| 188 | |
Martin Stjernholm | 40f9f3c | 2020-01-20 18:12:23 +0000 | [diff] [blame] | 189 | // ParseGlobalConfig parses the given data assumed to be read from the global |
| 190 | // dexpreopt.config file into a GlobalConfig struct. |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 191 | func ParseGlobalConfig(ctx android.PathContext, data []byte) (*GlobalConfig, error) { |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 192 | type GlobalJSONConfig struct { |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 193 | *GlobalConfig |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 194 | |
| 195 | // Copies of entries in GlobalConfig that are not constructable without extra parameters. They will be |
| 196 | // used to construct the real value manually below. |
Paul Duffin | 7ccacae | 2020-10-23 21:14:20 +0100 | [diff] [blame] | 197 | BootImageProfiles []string |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | config := GlobalJSONConfig{} |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 201 | err := json.Unmarshal(data, &config) |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 202 | if err != nil { |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 203 | return config.GlobalConfig, err |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | // Construct paths that require a PathContext. |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 207 | config.GlobalConfig.BootImageProfiles = constructPaths(ctx, config.BootImageProfiles) |
| 208 | |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 209 | return config.GlobalConfig, nil |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 210 | } |
| 211 | |
Martin Stjernholm | 40f9f3c | 2020-01-20 18:12:23 +0000 | [diff] [blame] | 212 | type globalConfigAndRaw struct { |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 213 | global *GlobalConfig |
Martin Stjernholm | 40f9f3c | 2020-01-20 18:12:23 +0000 | [diff] [blame] | 214 | data []byte |
| 215 | } |
| 216 | |
| 217 | // GetGlobalConfig returns the global dexpreopt.config that's created in the |
| 218 | // make config phase. It is loaded once the first time it is called for any |
| 219 | // ctx.Config(), and returns the same data for all future calls with the same |
| 220 | // ctx.Config(). A value can be inserted for tests using |
| 221 | // setDexpreoptTestGlobalConfig. |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 222 | func GetGlobalConfig(ctx android.PathContext) *GlobalConfig { |
Martin Stjernholm | 40f9f3c | 2020-01-20 18:12:23 +0000 | [diff] [blame] | 223 | return getGlobalConfigRaw(ctx).global |
| 224 | } |
| 225 | |
| 226 | // GetGlobalConfigRawData is the same as GetGlobalConfig, except that it returns |
| 227 | // the literal content of dexpreopt.config. |
| 228 | func GetGlobalConfigRawData(ctx android.PathContext) []byte { |
| 229 | return getGlobalConfigRaw(ctx).data |
| 230 | } |
| 231 | |
| 232 | var globalConfigOnceKey = android.NewOnceKey("DexpreoptGlobalConfig") |
| 233 | var testGlobalConfigOnceKey = android.NewOnceKey("TestDexpreoptGlobalConfig") |
| 234 | |
| 235 | func getGlobalConfigRaw(ctx android.PathContext) globalConfigAndRaw { |
| 236 | return ctx.Config().Once(globalConfigOnceKey, func() interface{} { |
| 237 | if data, err := ctx.Config().DexpreoptGlobalConfig(ctx); err != nil { |
| 238 | panic(err) |
| 239 | } else if data != nil { |
| 240 | globalConfig, err := ParseGlobalConfig(ctx, data) |
| 241 | if err != nil { |
| 242 | panic(err) |
| 243 | } |
| 244 | return globalConfigAndRaw{globalConfig, data} |
| 245 | } |
| 246 | |
| 247 | // No global config filename set, see if there is a test config set |
| 248 | return ctx.Config().Once(testGlobalConfigOnceKey, func() interface{} { |
| 249 | // Nope, return a config with preopting disabled |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 250 | return globalConfigAndRaw{&GlobalConfig{ |
Ulya Trafimovich | a4a1c4e | 2021-01-15 18:40:04 +0000 | [diff] [blame] | 251 | DisablePreopt: true, |
| 252 | DisablePreoptBootImages: true, |
| 253 | DisableGenerateProfile: true, |
Martin Stjernholm | 40f9f3c | 2020-01-20 18:12:23 +0000 | [diff] [blame] | 254 | }, nil} |
| 255 | }) |
| 256 | }).(globalConfigAndRaw) |
| 257 | } |
| 258 | |
| 259 | // SetTestGlobalConfig sets a GlobalConfig that future calls to GetGlobalConfig |
| 260 | // will return. It must be called before the first call to GetGlobalConfig for |
| 261 | // the config. |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 262 | func SetTestGlobalConfig(config android.Config, globalConfig *GlobalConfig) { |
Martin Stjernholm | 40f9f3c | 2020-01-20 18:12:23 +0000 | [diff] [blame] | 263 | config.Once(testGlobalConfigOnceKey, func() interface{} { return globalConfigAndRaw{globalConfig, nil} }) |
| 264 | } |
| 265 | |
Jeongik Cha | c624667 | 2021-04-08 00:00:19 +0900 | [diff] [blame] | 266 | // This struct is required to convert ModuleConfig from/to JSON. |
| 267 | // The types of fields in ModuleConfig are not convertible, |
| 268 | // so moduleJSONConfig has those fields as a convertible type. |
| 269 | type moduleJSONConfig struct { |
| 270 | *ModuleConfig |
| 271 | |
| 272 | BuildPath string |
| 273 | DexPath string |
| 274 | ManifestPath string |
| 275 | |
| 276 | ProfileClassListing string |
| 277 | ProfileBootListing string |
| 278 | |
| 279 | EnforceUsesLibrariesStatusFile string |
| 280 | ClassLoaderContexts jsonClassLoaderContextMap |
| 281 | |
Jeongik Cha | c624667 | 2021-04-08 00:00:19 +0900 | [diff] [blame] | 282 | DexPreoptImagesDeps [][]string |
| 283 | |
| 284 | PreoptBootClassPathDexFiles []string |
| 285 | } |
| 286 | |
Martin Stjernholm | 40f9f3c | 2020-01-20 18:12:23 +0000 | [diff] [blame] | 287 | // ParseModuleConfig parses a per-module dexpreopt.config file into a |
| 288 | // ModuleConfig struct. It is not used in Soong, which receives a ModuleConfig |
| 289 | // struct directly from java/dexpreopt.go. It is used in dexpreopt_gen called |
| 290 | // from Make to read the module dexpreopt.config written in the Make config |
| 291 | // stage. |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 292 | func ParseModuleConfig(ctx android.PathContext, data []byte) (*ModuleConfig, error) { |
Jeongik Cha | c624667 | 2021-04-08 00:00:19 +0900 | [diff] [blame] | 293 | config := moduleJSONConfig{} |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 294 | |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 295 | err := json.Unmarshal(data, &config) |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 296 | if err != nil { |
| 297 | return config.ModuleConfig, err |
| 298 | } |
| 299 | |
| 300 | // Construct paths that require a PathContext. |
| 301 | config.ModuleConfig.BuildPath = constructPath(ctx, config.BuildPath).(android.OutputPath) |
| 302 | config.ModuleConfig.DexPath = constructPath(ctx, config.DexPath) |
Jeongik Cha | 33a3a81 | 2021-04-15 09:12:49 +0900 | [diff] [blame] | 303 | config.ModuleConfig.ManifestPath = android.OptionalPathForPath(constructPath(ctx, config.ManifestPath)) |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 304 | config.ModuleConfig.ProfileClassListing = android.OptionalPathForPath(constructPath(ctx, config.ProfileClassListing)) |
Ulya Trafimovich | 8c35fcf | 2021-02-17 16:23:28 +0000 | [diff] [blame] | 305 | config.ModuleConfig.EnforceUsesLibrariesStatusFile = constructPath(ctx, config.EnforceUsesLibrariesStatusFile) |
Ulya Trafimovich | 8cbc5d2 | 2020-11-03 15:15:46 +0000 | [diff] [blame] | 306 | config.ModuleConfig.ClassLoaderContexts = fromJsonClassLoaderContext(ctx, config.ClassLoaderContexts) |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 307 | config.ModuleConfig.PreoptBootClassPathDexFiles = constructPaths(ctx, config.PreoptBootClassPathDexFiles) |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 308 | |
Dan Willemsen | 0f41678 | 2019-06-13 21:44:53 +0000 | [diff] [blame] | 309 | // This needs to exist, but dependencies are already handled in Make, so we don't need to pass them through JSON. |
Jeongik Cha | b19b58a | 2021-04-26 22:57:27 +0900 | [diff] [blame] | 310 | config.ModuleConfig.DexPreoptImagesDeps = make([]android.OutputPaths, len(config.ModuleConfig.Archs)) |
Dan Willemsen | 0f41678 | 2019-06-13 21:44:53 +0000 | [diff] [blame] | 311 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 312 | return config.ModuleConfig, nil |
| 313 | } |
| 314 | |
Jeongik Cha | c624667 | 2021-04-08 00:00:19 +0900 | [diff] [blame] | 315 | func pathsListToStringLists(pathsList []android.OutputPaths) [][]string { |
| 316 | ret := make([][]string, 0, len(pathsList)) |
| 317 | for _, paths := range pathsList { |
| 318 | ret = append(ret, paths.Strings()) |
| 319 | } |
| 320 | return ret |
| 321 | } |
| 322 | |
| 323 | func moduleConfigToJSON(config *ModuleConfig) ([]byte, error) { |
| 324 | return json.MarshalIndent(&moduleJSONConfig{ |
| 325 | BuildPath: config.BuildPath.String(), |
| 326 | DexPath: config.DexPath.String(), |
| 327 | ManifestPath: config.ManifestPath.String(), |
| 328 | ProfileClassListing: config.ProfileClassListing.String(), |
| 329 | ProfileBootListing: config.ProfileBootListing.String(), |
| 330 | EnforceUsesLibrariesStatusFile: config.EnforceUsesLibrariesStatusFile.String(), |
| 331 | ClassLoaderContexts: toJsonClassLoaderContext(config.ClassLoaderContexts), |
Jeongik Cha | c624667 | 2021-04-08 00:00:19 +0900 | [diff] [blame] | 332 | DexPreoptImagesDeps: pathsListToStringLists(config.DexPreoptImagesDeps), |
| 333 | PreoptBootClassPathDexFiles: config.PreoptBootClassPathDexFiles.Strings(), |
| 334 | ModuleConfig: config, |
| 335 | }, "", " ") |
| 336 | } |
| 337 | |
| 338 | // WriteModuleConfig serializes a ModuleConfig into a per-module dexpreopt.config JSON file. |
| 339 | // These config files are used for post-processing. |
| 340 | func WriteModuleConfig(ctx android.ModuleContext, config *ModuleConfig, path android.WritablePath) { |
Ulya Trafimovich | 76b0852 | 2021-01-14 17:52:43 +0000 | [diff] [blame] | 341 | if path == nil { |
| 342 | return |
| 343 | } |
| 344 | |
Jeongik Cha | c624667 | 2021-04-08 00:00:19 +0900 | [diff] [blame] | 345 | data, err := moduleConfigToJSON(config) |
Ulya Trafimovich | 76b0852 | 2021-01-14 17:52:43 +0000 | [diff] [blame] | 346 | if err != nil { |
| 347 | ctx.ModuleErrorf("failed to JSON marshal module dexpreopt.config: %v", err) |
| 348 | return |
| 349 | } |
| 350 | |
| 351 | android.WriteFileRule(ctx, path, string(data)) |
| 352 | } |
| 353 | |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 354 | // dex2oatModuleName returns the name of the module to use for the dex2oat host |
| 355 | // tool. It should be a binary module with public visibility that is compiled |
| 356 | // and installed for host. |
| 357 | func dex2oatModuleName(config android.Config) string { |
| 358 | // Default to the debug variant of dex2oat to help find bugs. |
| 359 | // Set USE_DEX2OAT_DEBUG to false for only building non-debug versions. |
| 360 | if config.Getenv("USE_DEX2OAT_DEBUG") == "false" { |
| 361 | return "dex2oat" |
| 362 | } else { |
| 363 | return "dex2oatd" |
| 364 | } |
| 365 | } |
| 366 | |
Paul Duffin | b506c9d | 2021-03-24 14:34:40 +0000 | [diff] [blame] | 367 | type dex2oatDependencyTag struct { |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 368 | blueprint.BaseDependencyTag |
Paul Duffin | b506c9d | 2021-03-24 14:34:40 +0000 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | func (d dex2oatDependencyTag) ExcludeFromVisibilityEnforcement() { |
| 372 | } |
| 373 | |
| 374 | func (d dex2oatDependencyTag) ExcludeFromApexContents() { |
| 375 | } |
| 376 | |
Martin Stjernholm | 0e4cceb | 2021-05-13 02:38:35 +0100 | [diff] [blame] | 377 | func (d dex2oatDependencyTag) AllowDisabledModuleDependency(target android.Module) bool { |
| 378 | // RegisterToolDeps may run after the prebuilt mutators and hence register a |
| 379 | // dependency on the source module even when the prebuilt is to be used. |
| 380 | // dex2oatPathFromDep takes that into account when it retrieves the path to |
| 381 | // the binary, but we also need to disable the check for dependencies on |
| 382 | // disabled modules. |
| 383 | return target.IsReplacedByPrebuilt() |
| 384 | } |
| 385 | |
Paul Duffin | b506c9d | 2021-03-24 14:34:40 +0000 | [diff] [blame] | 386 | // Dex2oatDepTag represents the dependency onto the dex2oatd module. It is added to any module that |
| 387 | // needs dexpreopting and so it makes no sense for it to be checked for visibility or included in |
| 388 | // the apex. |
| 389 | var Dex2oatDepTag = dex2oatDependencyTag{} |
| 390 | |
| 391 | var _ android.ExcludeFromVisibilityEnforcementTag = Dex2oatDepTag |
| 392 | var _ android.ExcludeFromApexContentsTag = Dex2oatDepTag |
Martin Stjernholm | 0e4cceb | 2021-05-13 02:38:35 +0100 | [diff] [blame] | 393 | var _ android.AllowDisabledModuleDependency = Dex2oatDepTag |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 394 | |
Martin Stjernholm | 6d41527 | 2020-01-31 17:10:36 +0000 | [diff] [blame] | 395 | // RegisterToolDeps adds the necessary dependencies to binary modules for tools |
| 396 | // that are required later when Get(Cached)GlobalSoongConfig is called. It |
| 397 | // should be called from a mutator that's registered with |
| 398 | // android.RegistrationContext.FinalDepsMutators. |
| 399 | func RegisterToolDeps(ctx android.BottomUpMutatorContext) { |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 400 | dex2oatBin := dex2oatModuleName(ctx.Config()) |
| 401 | v := ctx.Config().BuildOSTarget.Variations() |
Ulya Trafimovich | a4a1c4e | 2021-01-15 18:40:04 +0000 | [diff] [blame] | 402 | ctx.AddFarVariationDependencies(v, Dex2oatDepTag, dex2oatBin) |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | func dex2oatPathFromDep(ctx android.ModuleContext) android.Path { |
| 406 | dex2oatBin := dex2oatModuleName(ctx.Config()) |
| 407 | |
Martin Stjernholm | c004862 | 2020-08-18 17:37:41 +0100 | [diff] [blame] | 408 | // Find the right dex2oat module, trying to follow PrebuiltDepTag from source |
| 409 | // to prebuilt if there is one. We wouldn't have to do this if the |
| 410 | // prebuilt_postdeps mutator that replaces source deps with prebuilt deps was |
| 411 | // run after RegisterToolDeps above, but changing that leads to ordering |
| 412 | // problems between mutators (RegisterToolDeps needs to run late to act on |
| 413 | // final variants, while prebuilt_postdeps needs to run before many of the |
| 414 | // PostDeps mutators, like the APEX mutators). Hence we need to dig out the |
| 415 | // prebuilt explicitly here instead. |
| 416 | var dex2oatModule android.Module |
| 417 | ctx.WalkDeps(func(child, parent android.Module) bool { |
Ulya Trafimovich | a4a1c4e | 2021-01-15 18:40:04 +0000 | [diff] [blame] | 418 | if parent == ctx.Module() && ctx.OtherModuleDependencyTag(child) == Dex2oatDepTag { |
Martin Stjernholm | c004862 | 2020-08-18 17:37:41 +0100 | [diff] [blame] | 419 | // Found the source module, or prebuilt module that has replaced the source. |
| 420 | dex2oatModule = child |
Paul Duffin | f7c99f5 | 2021-04-28 10:41:21 +0100 | [diff] [blame] | 421 | if android.IsModulePrebuilt(child) { |
Martin Stjernholm | c004862 | 2020-08-18 17:37:41 +0100 | [diff] [blame] | 422 | return false // If it's the prebuilt we're done. |
| 423 | } else { |
| 424 | return true // Recurse to check if the source has a prebuilt dependency. |
| 425 | } |
| 426 | } |
| 427 | if parent == dex2oatModule && ctx.OtherModuleDependencyTag(child) == android.PrebuiltDepTag { |
Paul Duffin | f7c99f5 | 2021-04-28 10:41:21 +0100 | [diff] [blame] | 428 | if p := android.GetEmbeddedPrebuilt(child); p != nil && p.UsePrebuilt() { |
Martin Stjernholm | c004862 | 2020-08-18 17:37:41 +0100 | [diff] [blame] | 429 | dex2oatModule = child // Found a prebuilt that should be used. |
| 430 | } |
| 431 | } |
| 432 | return false |
| 433 | }) |
| 434 | |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 435 | if dex2oatModule == nil { |
| 436 | // If this happens there's probably a missing call to AddToolDeps in DepsMutator. |
| 437 | panic(fmt.Sprintf("Failed to lookup %s dependency", dex2oatBin)) |
| 438 | } |
| 439 | |
| 440 | dex2oatPath := dex2oatModule.(android.HostToolProvider).HostToolPath() |
| 441 | if !dex2oatPath.Valid() { |
| 442 | panic(fmt.Sprintf("Failed to find host tool path in %s", dex2oatModule)) |
| 443 | } |
| 444 | |
| 445 | return dex2oatPath.Path() |
| 446 | } |
| 447 | |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 448 | // createGlobalSoongConfig creates a GlobalSoongConfig from the current context. |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 449 | // Should not be used in dexpreopt_gen. |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 450 | func createGlobalSoongConfig(ctx android.ModuleContext) *GlobalSoongConfig { |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 451 | return &GlobalSoongConfig{ |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 452 | Profman: ctx.Config().HostToolPath(ctx, "profman"), |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 453 | Dex2oat: dex2oatPathFromDep(ctx), |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 454 | Aapt: ctx.Config().HostToolPath(ctx, "aapt"), |
| 455 | SoongZip: ctx.Config().HostToolPath(ctx, "soong_zip"), |
| 456 | Zip2zip: ctx.Config().HostToolPath(ctx, "zip2zip"), |
| 457 | ManifestCheck: ctx.Config().HostToolPath(ctx, "manifest_check"), |
Ulya Trafimovich | 5f364b6 | 2020-06-30 12:39:01 +0100 | [diff] [blame] | 458 | ConstructContext: ctx.Config().HostToolPath(ctx, "construct_context"), |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 459 | } |
| 460 | } |
| 461 | |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 462 | // The main reason for this Once cache for GlobalSoongConfig is to make the |
| 463 | // dex2oat path available to singletons. In ordinary modules we get it through a |
Ulya Trafimovich | a4a1c4e | 2021-01-15 18:40:04 +0000 | [diff] [blame] | 464 | // Dex2oatDepTag dependency, but in singletons there's no simple way to do the |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 465 | // same thing and ensure the right variant is selected, hence this cache to make |
| 466 | // the resolved path available to singletons. This means we depend on there |
Ulya Trafimovich | a4a1c4e | 2021-01-15 18:40:04 +0000 | [diff] [blame] | 467 | // being at least one ordinary module with a Dex2oatDepTag dependency. |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 468 | // |
| 469 | // TODO(b/147613152): Implement a way to deal with dependencies from singletons, |
Paul Duffin | 9f04524 | 2021-01-21 15:05:11 +0000 | [diff] [blame] | 470 | // and then possibly remove this cache altogether. |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 471 | var globalSoongConfigOnceKey = android.NewOnceKey("DexpreoptGlobalSoongConfig") |
| 472 | |
| 473 | // GetGlobalSoongConfig creates a GlobalSoongConfig the first time it's called, |
| 474 | // and later returns the same cached instance. |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 475 | func GetGlobalSoongConfig(ctx android.ModuleContext) *GlobalSoongConfig { |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 476 | globalSoong := ctx.Config().Once(globalSoongConfigOnceKey, func() interface{} { |
| 477 | return createGlobalSoongConfig(ctx) |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 478 | }).(*GlobalSoongConfig) |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 479 | |
| 480 | // Always resolve the tool path from the dependency, to ensure that every |
| 481 | // module has the dependency added properly. |
| 482 | myDex2oat := dex2oatPathFromDep(ctx) |
| 483 | if myDex2oat != globalSoong.Dex2oat { |
| 484 | panic(fmt.Sprintf("Inconsistent dex2oat path in cached config: expected %s, got %s", globalSoong.Dex2oat, myDex2oat)) |
| 485 | } |
| 486 | |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 487 | return globalSoong |
| 488 | } |
| 489 | |
| 490 | // GetCachedGlobalSoongConfig returns a cached GlobalSoongConfig created by an |
| 491 | // earlier GetGlobalSoongConfig call. This function works with any context |
| 492 | // compatible with a basic PathContext, since it doesn't try to create a |
Martin Stjernholm | 6d41527 | 2020-01-31 17:10:36 +0000 | [diff] [blame] | 493 | // GlobalSoongConfig with the proper paths (which requires a full |
| 494 | // ModuleContext). If there has been no prior call to GetGlobalSoongConfig, nil |
| 495 | // is returned. |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 496 | func GetCachedGlobalSoongConfig(ctx android.PathContext) *GlobalSoongConfig { |
Martin Stjernholm | 6d41527 | 2020-01-31 17:10:36 +0000 | [diff] [blame] | 497 | return ctx.Config().Once(globalSoongConfigOnceKey, func() interface{} { |
| 498 | return (*GlobalSoongConfig)(nil) |
| 499 | }).(*GlobalSoongConfig) |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 500 | } |
| 501 | |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 502 | type globalJsonSoongConfig struct { |
| 503 | Profman string |
| 504 | Dex2oat string |
| 505 | Aapt string |
| 506 | SoongZip string |
| 507 | Zip2zip string |
| 508 | ManifestCheck string |
| 509 | ConstructContext string |
| 510 | } |
| 511 | |
Martin Stjernholm | 40f9f3c | 2020-01-20 18:12:23 +0000 | [diff] [blame] | 512 | // ParseGlobalSoongConfig parses the given data assumed to be read from the |
| 513 | // global dexpreopt_soong.config file into a GlobalSoongConfig struct. It is |
| 514 | // only used in dexpreopt_gen. |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 515 | func ParseGlobalSoongConfig(ctx android.PathContext, data []byte) (*GlobalSoongConfig, error) { |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 516 | var jc globalJsonSoongConfig |
| 517 | |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 518 | err := json.Unmarshal(data, &jc) |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 519 | if err != nil { |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 520 | return &GlobalSoongConfig{}, err |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 521 | } |
| 522 | |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 523 | config := &GlobalSoongConfig{ |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 524 | Profman: constructPath(ctx, jc.Profman), |
| 525 | Dex2oat: constructPath(ctx, jc.Dex2oat), |
| 526 | Aapt: constructPath(ctx, jc.Aapt), |
| 527 | SoongZip: constructPath(ctx, jc.SoongZip), |
| 528 | Zip2zip: constructPath(ctx, jc.Zip2zip), |
| 529 | ManifestCheck: constructPath(ctx, jc.ManifestCheck), |
| 530 | ConstructContext: constructPath(ctx, jc.ConstructContext), |
| 531 | } |
| 532 | |
| 533 | return config, nil |
| 534 | } |
| 535 | |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 536 | // checkBootJarsConfigConsistency checks the consistency of BootJars and ApexBootJars fields in |
Paul Duffin | 7d1d083 | 2021-04-23 11:39:41 +0100 | [diff] [blame] | 537 | // DexpreoptGlobalConfig and Config.productVariables. |
| 538 | func checkBootJarsConfigConsistency(ctx android.SingletonContext, dexpreoptConfig *GlobalConfig, config android.Config) { |
| 539 | compareBootJars := func(property string, dexpreoptJars, variableJars android.ConfiguredJarList) { |
| 540 | dexpreoptPairs := dexpreoptJars.CopyOfApexJarPairs() |
| 541 | variablePairs := variableJars.CopyOfApexJarPairs() |
| 542 | if !reflect.DeepEqual(dexpreoptPairs, variablePairs) { |
| 543 | ctx.Errorf("Inconsistent configuration of %[1]s\n"+ |
| 544 | " dexpreopt.GlobalConfig.%[1]s = %[2]s\n"+ |
| 545 | " productVariables.%[1]s = %[3]s", |
| 546 | property, dexpreoptPairs, variablePairs) |
| 547 | } |
| 548 | } |
| 549 | |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 550 | compareBootJars("BootJars", dexpreoptConfig.BootJars, config.NonApexBootJars()) |
| 551 | compareBootJars("ApexBootJars", dexpreoptConfig.ApexBootJars, config.ApexBootJars()) |
Paul Duffin | 7d1d083 | 2021-04-23 11:39:41 +0100 | [diff] [blame] | 552 | } |
| 553 | |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 554 | func (s *globalSoongConfigSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
Paul Duffin | 7d1d083 | 2021-04-23 11:39:41 +0100 | [diff] [blame] | 555 | checkBootJarsConfigConsistency(ctx, GetGlobalConfig(ctx), ctx.Config()) |
| 556 | |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 557 | if GetGlobalConfig(ctx).DisablePreopt { |
| 558 | return |
| 559 | } |
| 560 | |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 561 | config := GetCachedGlobalSoongConfig(ctx) |
Martin Stjernholm | 6d41527 | 2020-01-31 17:10:36 +0000 | [diff] [blame] | 562 | if config == nil { |
| 563 | // No module has enabled dexpreopting, so we assume there will be no calls |
| 564 | // to dexpreopt_gen. |
| 565 | return |
| 566 | } |
| 567 | |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 568 | jc := globalJsonSoongConfig{ |
| 569 | Profman: config.Profman.String(), |
| 570 | Dex2oat: config.Dex2oat.String(), |
| 571 | Aapt: config.Aapt.String(), |
| 572 | SoongZip: config.SoongZip.String(), |
| 573 | Zip2zip: config.Zip2zip.String(), |
| 574 | ManifestCheck: config.ManifestCheck.String(), |
| 575 | ConstructContext: config.ConstructContext.String(), |
| 576 | } |
| 577 | |
| 578 | data, err := json.Marshal(jc) |
| 579 | if err != nil { |
| 580 | ctx.Errorf("failed to JSON marshal GlobalSoongConfig: %v", err) |
| 581 | return |
| 582 | } |
| 583 | |
Colin Cross | cf371cc | 2020-11-13 11:48:42 -0800 | [diff] [blame] | 584 | android.WriteFileRule(ctx, android.PathForOutput(ctx, "dexpreopt_soong.config"), string(data)) |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | func (s *globalSoongConfigSingleton) MakeVars(ctx android.MakeVarsContext) { |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 588 | if GetGlobalConfig(ctx).DisablePreopt { |
| 589 | return |
| 590 | } |
| 591 | |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 592 | config := GetCachedGlobalSoongConfig(ctx) |
Martin Stjernholm | 6d41527 | 2020-01-31 17:10:36 +0000 | [diff] [blame] | 593 | if config == nil { |
| 594 | return |
| 595 | } |
Martin Stjernholm | c52aaf1 | 2020-01-06 23:11:37 +0000 | [diff] [blame] | 596 | |
| 597 | ctx.Strict("DEX2OAT", config.Dex2oat.String()) |
| 598 | ctx.Strict("DEXPREOPT_GEN_DEPS", strings.Join([]string{ |
| 599 | config.Profman.String(), |
| 600 | config.Dex2oat.String(), |
| 601 | config.Aapt.String(), |
| 602 | config.SoongZip.String(), |
| 603 | config.Zip2zip.String(), |
| 604 | config.ManifestCheck.String(), |
| 605 | config.ConstructContext.String(), |
| 606 | }, " ")) |
| 607 | } |
| 608 | |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 609 | func GlobalConfigForTests(ctx android.PathContext) *GlobalConfig { |
| 610 | return &GlobalConfig{ |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 611 | DisablePreopt: false, |
| 612 | DisablePreoptModules: nil, |
| 613 | OnlyPreoptBootImageAndSystemServer: false, |
| 614 | HasSystemOther: false, |
| 615 | PatternsOnSystemOther: nil, |
| 616 | DisableGenerateProfile: false, |
| 617 | ProfileDir: "", |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 618 | BootJars: android.EmptyConfiguredJarList(), |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 619 | ApexBootJars: android.EmptyConfiguredJarList(), |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 620 | ArtApexJars: android.EmptyConfiguredJarList(), |
satayev | 9a6f87e | 2021-05-04 16:14:48 +0100 | [diff] [blame] | 621 | SystemServerJars: android.EmptyConfiguredJarList(), |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 622 | SystemServerApps: nil, |
satayev | 492b17d | 2021-07-28 14:04:49 +0100 | [diff] [blame] | 623 | ApexSystemServerJars: android.EmptyConfiguredJarList(), |
Jiakai Zhang | cee9e19 | 2021-10-29 19:46:45 +0000 | [diff] [blame^] | 624 | StandaloneSystemServerJars: android.EmptyConfiguredJarList(), |
| 625 | ApexStandaloneSystemServerJars: android.EmptyConfiguredJarList(), |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 626 | SpeedApps: nil, |
| 627 | PreoptFlags: nil, |
| 628 | DefaultCompilerFilter: "", |
| 629 | SystemServerCompilerFilter: "", |
| 630 | GenerateDMFiles: false, |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 631 | NoDebugInfo: false, |
Mathieu Chartier | 3f7ddbb | 2019-04-29 09:33:50 -0700 | [diff] [blame] | 632 | DontResolveStartupStrings: false, |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 633 | AlwaysSystemServerDebugInfo: false, |
| 634 | NeverSystemServerDebugInfo: false, |
| 635 | AlwaysOtherDebugInfo: false, |
| 636 | NeverOtherDebugInfo: false, |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 637 | IsEng: false, |
| 638 | SanitizeLite: false, |
| 639 | DefaultAppImages: false, |
| 640 | Dex2oatXmx: "", |
| 641 | Dex2oatXms: "", |
| 642 | EmptyDirectory: "empty_dir", |
| 643 | CpuVariant: nil, |
| 644 | InstructionSetFeatures: nil, |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 645 | BootImageProfiles: nil, |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 646 | BootFlags: "", |
| 647 | Dex2oatImageXmx: "", |
| 648 | Dex2oatImageXms: "", |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 649 | } |
| 650 | } |
| 651 | |
Paul Duffin | 9f04524 | 2021-01-21 15:05:11 +0000 | [diff] [blame] | 652 | func globalSoongConfigForTests() *GlobalSoongConfig { |
| 653 | return &GlobalSoongConfig{ |
| 654 | Profman: android.PathForTesting("profman"), |
| 655 | Dex2oat: android.PathForTesting("dex2oat"), |
| 656 | Aapt: android.PathForTesting("aapt"), |
| 657 | SoongZip: android.PathForTesting("soong_zip"), |
| 658 | Zip2zip: android.PathForTesting("zip2zip"), |
| 659 | ManifestCheck: android.PathForTesting("manifest_check"), |
| 660 | ConstructContext: android.PathForTesting("construct_context"), |
| 661 | } |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 662 | } |