Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame] | 1 | // Copyright 2019 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 java |
| 16 | |
| 17 | import ( |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame] | 18 | "path/filepath" |
| 19 | "strings" |
Colin Cross | 2d00f0d | 2019-05-09 21:50:00 -0700 | [diff] [blame] | 20 | |
| 21 | "android/soong/android" |
| 22 | "android/soong/dexpreopt" |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame] | 23 | ) |
| 24 | |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame] | 25 | // systemServerClasspath returns the on-device locations of the modules in the system server classpath. It is computed |
| 26 | // once the first time it is called for any ctx.Config(), and returns the same slice for all future calls with the same |
| 27 | // ctx.Config(). |
Ulya Trafimovich | f3ff010 | 2019-12-03 15:39:23 +0000 | [diff] [blame] | 28 | func systemServerClasspath(ctx android.MakeVarsContext) []string { |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame] | 29 | return ctx.Config().OnceStringSlice(systemServerClasspathKey, func() []string { |
Martin Stjernholm | 40f9f3c | 2020-01-20 18:12:23 +0000 | [diff] [blame^] | 30 | global := dexpreopt.GetGlobalConfig(ctx) |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame] | 31 | var systemServerClasspathLocations []string |
Ulya Trafimovich | f3ff010 | 2019-12-03 15:39:23 +0000 | [diff] [blame] | 32 | for _, m := range *DexpreoptedSystemServerJars(ctx.Config()) { |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame] | 33 | systemServerClasspathLocations = append(systemServerClasspathLocations, |
| 34 | filepath.Join("/system/framework", m+".jar")) |
| 35 | } |
Roshan Pius | 9b51a40 | 2019-11-21 12:36:53 -0800 | [diff] [blame] | 36 | for _, m := range global.UpdatableSystemServerJars { |
Roshan Pius | 9b51a40 | 2019-11-21 12:36:53 -0800 | [diff] [blame] | 37 | systemServerClasspathLocations = append(systemServerClasspathLocations, |
Roshan Pius | ccc26ef | 2019-11-27 09:37:46 -0800 | [diff] [blame] | 38 | dexpreopt.GetJarLocationFromApexJarPair(m)) |
Roshan Pius | 9b51a40 | 2019-11-21 12:36:53 -0800 | [diff] [blame] | 39 | } |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame] | 40 | return systemServerClasspathLocations |
| 41 | }) |
| 42 | } |
| 43 | |
| 44 | var systemServerClasspathKey = android.NewOnceKey("systemServerClasspath") |
| 45 | |
Colin Cross | c11e0c5 | 2019-05-08 15:18:22 -0700 | [diff] [blame] | 46 | // dexpreoptTargets returns the list of targets that are relevant to dexpreopting, which excludes architectures |
| 47 | // supported through native bridge. |
| 48 | func dexpreoptTargets(ctx android.PathContext) []android.Target { |
| 49 | var targets []android.Target |
Colin Cross | 3b19f5d | 2019-09-17 14:45:31 -0700 | [diff] [blame] | 50 | for _, target := range ctx.Config().Targets[android.Android] { |
Colin Cross | c11e0c5 | 2019-05-08 15:18:22 -0700 | [diff] [blame] | 51 | if target.NativeBridge == android.NativeBridgeDisabled { |
| 52 | targets = append(targets, target) |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | return targets |
| 57 | } |
| 58 | |
Jiyong Park | 0b23875 | 2019-10-29 11:23:10 +0900 | [diff] [blame] | 59 | func stemOf(moduleName string) string { |
| 60 | // b/139391334: the stem of framework-minus-apex is framework |
| 61 | // This is hard coded here until we find a good way to query the stem |
| 62 | // of a module before any other mutators are run |
| 63 | if moduleName == "framework-minus-apex" { |
| 64 | return "framework" |
| 65 | } |
| 66 | return moduleName |
| 67 | } |
| 68 | |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 69 | var ( |
Ulya Trafimovich | 4cdada2 | 2020-02-10 15:29:28 +0000 | [diff] [blame] | 70 | bootImageConfigKey = android.NewOnceKey("bootImageConfig") |
| 71 | artBootImageName = "art" |
| 72 | frameworkBootImageName = "boot" |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 73 | ) |
Ulyana Trafimovich | de53441 | 2019-11-08 10:51:01 +0000 | [diff] [blame] | 74 | |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 75 | // Construct the global boot image configs. |
| 76 | func genBootImageConfigs(ctx android.PathContext) map[string]*bootImageConfig { |
| 77 | return ctx.Config().Once(bootImageConfigKey, func() interface{} { |
| 78 | |
Martin Stjernholm | 40f9f3c | 2020-01-20 18:12:23 +0000 | [diff] [blame^] | 79 | global := dexpreopt.GetGlobalConfig(ctx) |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 80 | targets := dexpreoptTargets(ctx) |
| 81 | deviceDir := android.PathForOutput(ctx, ctx.Config().DeviceName()) |
Nicolas Geoffray | 72892f1 | 2019-02-22 15:34:40 +0000 | [diff] [blame] | 82 | |
Martin Stjernholm | cc4b0ad | 2019-07-05 22:38:25 +0100 | [diff] [blame] | 83 | artModules := global.ArtApexJars |
Ulya Trafimovich | 4456188 | 2020-01-03 13:25:54 +0000 | [diff] [blame] | 84 | // With EMMA_INSTRUMENT_FRAMEWORK=true the Core libraries depend on jacoco. |
| 85 | if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") { |
| 86 | artModules = append(artModules, "jacocoagent") |
| 87 | } |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 88 | frameworkModules := android.RemoveListFromList(global.BootJars, |
Ulya Trafimovich | f3ff010 | 2019-12-03 15:39:23 +0000 | [diff] [blame] | 89 | concat(artModules, dexpreopt.GetJarsFromApexJarPairs(global.UpdatableBootJars))) |
Nicolas Geoffray | 72892f1 | 2019-02-22 15:34:40 +0000 | [diff] [blame] | 90 | |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 91 | artSubdir := "apex/com.android.art/javalib" |
| 92 | frameworkSubdir := "system/framework" |
Nicolas Geoffray | 72892f1 | 2019-02-22 15:34:40 +0000 | [diff] [blame] | 93 | |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 94 | var artLocations, frameworkLocations []string |
Martin Stjernholm | cc4b0ad | 2019-07-05 22:38:25 +0100 | [diff] [blame] | 95 | for _, m := range artModules { |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 96 | artLocations = append(artLocations, filepath.Join("/"+artSubdir, stemOf(m)+".jar")) |
| 97 | } |
| 98 | for _, m := range frameworkModules { |
| 99 | frameworkLocations = append(frameworkLocations, filepath.Join("/"+frameworkSubdir, stemOf(m)+".jar")) |
Nicolas Geoffray | 72892f1 | 2019-02-22 15:34:40 +0000 | [diff] [blame] | 100 | } |
| 101 | |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 102 | // ART config for the primary boot image in the ART apex. |
| 103 | // It includes the Core Libraries. |
| 104 | artCfg := bootImageConfig{ |
| 105 | extension: false, |
| 106 | name: artBootImageName, |
| 107 | stem: "boot", |
| 108 | installSubdir: artSubdir, |
| 109 | modules: artModules, |
| 110 | dexLocations: artLocations, |
| 111 | dexLocationsDeps: artLocations, |
| 112 | } |
Ulyana Trafimovich | de53441 | 2019-11-08 10:51:01 +0000 | [diff] [blame] | 113 | |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 114 | // Framework config for the boot image extension. |
Ulyana Trafimovich | 5a4ccd1 | 2019-12-18 17:32:33 +0000 | [diff] [blame] | 115 | // It includes framework libraries and depends on the ART config. |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 116 | frameworkCfg := bootImageConfig{ |
Ulyana Trafimovich | 5a4ccd1 | 2019-12-18 17:32:33 +0000 | [diff] [blame] | 117 | extension: true, |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 118 | name: frameworkBootImageName, |
| 119 | stem: "boot", |
| 120 | installSubdir: frameworkSubdir, |
Ulyana Trafimovich | 5a4ccd1 | 2019-12-18 17:32:33 +0000 | [diff] [blame] | 121 | modules: frameworkModules, |
| 122 | dexLocations: frameworkLocations, |
| 123 | dexLocationsDeps: append(artLocations, frameworkLocations...), |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 124 | } |
| 125 | |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 126 | configs := map[string]*bootImageConfig{ |
Ulya Trafimovich | 4cdada2 | 2020-02-10 15:29:28 +0000 | [diff] [blame] | 127 | artBootImageName: &artCfg, |
| 128 | frameworkBootImageName: &frameworkCfg, |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | // common to all configs |
| 132 | for _, c := range configs { |
| 133 | c.targets = targets |
| 134 | |
| 135 | c.dir = deviceDir.Join(ctx, "dex_"+c.name+"jars") |
| 136 | c.symbolsDir = deviceDir.Join(ctx, "dex_"+c.name+"jars_unstripped") |
| 137 | |
| 138 | // expands to <stem>.art for primary image and <stem>-<1st module>.art for extension |
| 139 | imageName := c.firstModuleNameOrStem() + ".art" |
| 140 | |
| 141 | c.imageLocations = []string{c.dir.Join(ctx, c.installSubdir, imageName).String()} |
| 142 | |
| 143 | // The path to bootclasspath dex files needs to be known at module |
| 144 | // GenerateAndroidBuildAction time, before the bootclasspath modules have been compiled. |
| 145 | // Set up known paths for them, the singleton rules will copy them there. |
| 146 | // TODO(b/143682396): use module dependencies instead |
| 147 | inputDir := deviceDir.Join(ctx, "dex_"+c.name+"jars_input") |
| 148 | for _, m := range c.modules { |
| 149 | c.dexPaths = append(c.dexPaths, inputDir.Join(ctx, stemOf(m)+".jar")) |
| 150 | } |
| 151 | c.dexPathsDeps = c.dexPaths |
| 152 | |
| 153 | c.images = make(map[android.ArchType]android.OutputPath) |
| 154 | c.imagesDeps = make(map[android.ArchType]android.OutputPaths) |
| 155 | |
| 156 | for _, target := range targets { |
| 157 | arch := target.Arch.ArchType |
| 158 | imageDir := c.dir.Join(ctx, c.installSubdir, arch.String()) |
| 159 | c.images[arch] = imageDir.Join(ctx, imageName) |
| 160 | c.imagesDeps[arch] = c.moduleFiles(ctx, imageDir, ".art", ".oat", ".vdex") |
Ulyana Trafimovich | de53441 | 2019-11-08 10:51:01 +0000 | [diff] [blame] | 161 | } |
Colin Cross | 31bf00d | 2019-12-04 13:16:01 -0800 | [diff] [blame] | 162 | |
| 163 | c.zip = c.dir.Join(ctx, c.name+".zip") |
Nicolas Geoffray | feef2ef | 2019-04-30 09:43:22 +0100 | [diff] [blame] | 164 | } |
| 165 | |
Ulyana Trafimovich | 5a4ccd1 | 2019-12-18 17:32:33 +0000 | [diff] [blame] | 166 | // specific to the framework config |
| 167 | frameworkCfg.dexPathsDeps = append(artCfg.dexPathsDeps, frameworkCfg.dexPathsDeps...) |
Ulya Trafimovich | b0a2d37 | 2020-01-28 14:42:41 +0000 | [diff] [blame] | 168 | frameworkCfg.primaryImages = artCfg.images |
Ulyana Trafimovich | 5a4ccd1 | 2019-12-18 17:32:33 +0000 | [diff] [blame] | 169 | frameworkCfg.imageLocations = append(artCfg.imageLocations, frameworkCfg.imageLocations...) |
| 170 | |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 171 | return configs |
| 172 | }).(map[string]*bootImageConfig) |
Nicolas Geoffray | 72892f1 | 2019-02-22 15:34:40 +0000 | [diff] [blame] | 173 | } |
| 174 | |
Ulyana Trafimovich | de53441 | 2019-11-08 10:51:01 +0000 | [diff] [blame] | 175 | func artBootImageConfig(ctx android.PathContext) bootImageConfig { |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 176 | return *genBootImageConfigs(ctx)[artBootImageName] |
| 177 | } |
| 178 | |
Lingfeng Yang | 54191fa | 2019-12-19 16:40:09 +0000 | [diff] [blame] | 179 | func defaultBootImageConfig(ctx android.PathContext) bootImageConfig { |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 180 | return *genBootImageConfigs(ctx)[frameworkBootImageName] |
| 181 | } |
| 182 | |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame] | 183 | func defaultBootclasspath(ctx android.PathContext) []string { |
| 184 | return ctx.Config().OnceStringSlice(defaultBootclasspathKey, func() []string { |
Martin Stjernholm | 40f9f3c | 2020-01-20 18:12:23 +0000 | [diff] [blame^] | 185 | global := dexpreopt.GetGlobalConfig(ctx) |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame] | 186 | image := defaultBootImageConfig(ctx) |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 187 | |
Roshan Pius | ccc26ef | 2019-11-27 09:37:46 -0800 | [diff] [blame] | 188 | updatableBootclasspath := make([]string, len(global.UpdatableBootJars)) |
| 189 | for i, p := range global.UpdatableBootJars { |
| 190 | updatableBootclasspath[i] = dexpreopt.GetJarLocationFromApexJarPair(p) |
| 191 | } |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 192 | |
| 193 | bootclasspath := append(copyOf(image.dexLocationsDeps), updatableBootclasspath...) |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame] | 194 | return bootclasspath |
| 195 | }) |
| 196 | } |
| 197 | |
| 198 | var defaultBootclasspathKey = android.NewOnceKey("defaultBootclasspath") |
| 199 | |
| 200 | var copyOf = android.CopyOf |
| 201 | |
| 202 | func init() { |
| 203 | android.RegisterMakeVarsProvider(pctx, dexpreoptConfigMakevars) |
| 204 | } |
| 205 | |
| 206 | func dexpreoptConfigMakevars(ctx android.MakeVarsContext) { |
| 207 | ctx.Strict("PRODUCT_BOOTCLASSPATH", strings.Join(defaultBootclasspath(ctx), ":")) |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 208 | ctx.Strict("PRODUCT_DEX2OAT_BOOTCLASSPATH", strings.Join(defaultBootImageConfig(ctx).dexLocationsDeps, ":")) |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame] | 209 | ctx.Strict("PRODUCT_SYSTEM_SERVER_CLASSPATH", strings.Join(systemServerClasspath(ctx), ":")) |
Colin Cross | 9be4152 | 2019-02-20 10:40:13 -0800 | [diff] [blame] | 210 | |
| 211 | ctx.Strict("DEXPREOPT_BOOT_JARS_MODULES", strings.Join(defaultBootImageConfig(ctx).modules, ":")) |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame] | 212 | } |