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