1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
// Copyright 2019 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package java
import (
"android/soong/android"
"android/soong/dexpreopt"
"path/filepath"
"strings"
)
// dexpreoptGlobalConfig returns the global dexpreopt.config. It is loaded once the first time it is called for any
// ctx.Config(), and returns the same data for all future calls with the same ctx.Config(). A value can be inserted
// for tests using setDexpreoptTestGlobalConfig.
func dexpreoptGlobalConfig(ctx android.PathContext) dexpreopt.GlobalConfig {
return ctx.Config().Once(dexpreoptGlobalConfigKey, func() interface{} {
if f := ctx.Config().DexpreoptGlobalConfig(); f != "" {
ctx.AddNinjaFileDeps(f)
globalConfig, err := dexpreopt.LoadGlobalConfig(ctx, f)
if err != nil {
panic(err)
}
return globalConfig
}
// No global config filename set, see if there is a test config set
return ctx.Config().Once(dexpreoptTestGlobalConfigKey, func() interface{} {
// Nope, return a config with preopting disabled
return dexpreopt.GlobalConfig{
DisablePreopt: true,
}
})
}).(dexpreopt.GlobalConfig)
}
// setDexpreoptTestGlobalConfig sets a GlobalConfig that future calls to dexpreoptGlobalConfig will return. It must
// be called before the first call to dexpreoptGlobalConfig for the config.
func setDexpreoptTestGlobalConfig(config android.Config, globalConfig dexpreopt.GlobalConfig) {
config.Once(dexpreoptTestGlobalConfigKey, func() interface{} { return globalConfig })
}
var dexpreoptGlobalConfigKey = android.NewOnceKey("DexpreoptGlobalConfig")
var dexpreoptTestGlobalConfigKey = android.NewOnceKey("TestDexpreoptGlobalConfig")
// systemServerClasspath returns the on-device locations of the modules in the system server classpath. It is computed
// once the first time it is called for any ctx.Config(), and returns the same slice for all future calls with the same
// ctx.Config().
func systemServerClasspath(ctx android.PathContext) []string {
return ctx.Config().OnceStringSlice(systemServerClasspathKey, func() []string {
global := dexpreoptGlobalConfig(ctx)
var systemServerClasspathLocations []string
for _, m := range global.SystemServerJars {
systemServerClasspathLocations = append(systemServerClasspathLocations,
filepath.Join("/system/framework", m+".jar"))
}
return systemServerClasspathLocations
})
}
var systemServerClasspathKey = android.NewOnceKey("systemServerClasspath")
// defaultBootImageConfig returns the bootImageConfig that will be used to dexpreopt modules. It is computed once the
// first time it is called for any ctx.Config(), and returns the same slice for all future calls with the same
// ctx.Config().
func defaultBootImageConfig(ctx android.PathContext) bootImageConfig {
return ctx.Config().Once(defaultBootImageConfigKey, func() interface{} {
global := dexpreoptGlobalConfig(ctx)
runtimeModules := global.RuntimeApexJars
nonFrameworkModules := concat(runtimeModules, global.ProductUpdatableBootModules)
frameworkModules := android.RemoveListFromList(global.BootJars, nonFrameworkModules)
var nonUpdatableBootModules []string
var nonUpdatableBootLocations []string
for _, m := range runtimeModules {
nonUpdatableBootModules = append(nonUpdatableBootModules, m)
nonUpdatableBootLocations = append(nonUpdatableBootLocations,
filepath.Join("/apex/com.android.runtime/javalib", m+".jar"))
}
for _, m := range frameworkModules {
nonUpdatableBootModules = append(nonUpdatableBootModules, m)
nonUpdatableBootLocations = append(nonUpdatableBootLocations,
filepath.Join("/system/framework", m+".jar"))
}
// The path to bootclasspath dex files needs to be known at module GenerateAndroidBuildAction time, before
// the bootclasspath modules have been compiled. Set up known paths for them, the singleton rules will copy
// them there.
// TODO: use module dependencies instead
var nonUpdatableBootDexPaths android.WritablePaths
for _, m := range nonUpdatableBootModules {
nonUpdatableBootDexPaths = append(nonUpdatableBootDexPaths,
android.PathForOutput(ctx, ctx.Config().DeviceName(), "dex_bootjars_input", m+".jar"))
}
dir := android.PathForOutput(ctx, ctx.Config().DeviceName(), "dex_bootjars")
symbolsDir := android.PathForOutput(ctx, ctx.Config().DeviceName(), "dex_bootjars_unstripped")
images := make(map[android.ArchType]android.OutputPath)
for _, target := range ctx.Config().Targets[android.Android] {
images[target.Arch.ArchType] = dir.Join(ctx,
"system/framework", target.Arch.ArchType.String()).Join(ctx, "boot.art")
}
return bootImageConfig{
name: "boot",
modules: nonUpdatableBootModules,
dexLocations: nonUpdatableBootLocations,
dexPaths: nonUpdatableBootDexPaths,
dir: dir,
symbolsDir: symbolsDir,
images: images,
}
}).(bootImageConfig)
}
var defaultBootImageConfigKey = android.NewOnceKey("defaultBootImageConfig")
func apexBootImageConfig(ctx android.PathContext) bootImageConfig {
return ctx.Config().Once(apexBootImageConfigKey, func() interface{} {
global := dexpreoptGlobalConfig(ctx)
runtimeModules := global.RuntimeApexJars
nonFrameworkModules := concat(runtimeModules, global.ProductUpdatableBootModules)
frameworkModules := android.RemoveListFromList(global.BootJars, nonFrameworkModules)
imageModules := concat(runtimeModules, frameworkModules)
var bootLocations []string
for _, m := range runtimeModules {
bootLocations = append(bootLocations,
filepath.Join("/apex/com.android.runtime/javalib", m+".jar"))
}
for _, m := range frameworkModules {
bootLocations = append(bootLocations,
filepath.Join("/system/framework", m+".jar"))
}
// The path to bootclasspath dex files needs to be known at module GenerateAndroidBuildAction time, before
// the bootclasspath modules have been compiled. Set up known paths for them, the singleton rules will copy
// them there.
// TODO: use module dependencies instead
var bootDexPaths android.WritablePaths
for _, m := range imageModules {
bootDexPaths = append(bootDexPaths,
android.PathForOutput(ctx, ctx.Config().DeviceName(), "dex_apexjars_input", m+".jar"))
}
dir := android.PathForOutput(ctx, ctx.Config().DeviceName(), "dex_apexjars")
symbolsDir := android.PathForOutput(ctx, ctx.Config().DeviceName(), "dex_apexjars_unstripped")
images := make(map[android.ArchType]android.OutputPath)
for _, target := range ctx.Config().Targets[android.Android] {
images[target.Arch.ArchType] = dir.Join(ctx,
"system/framework", target.Arch.ArchType.String(), "apex.art")
}
return bootImageConfig{
name: "apex",
modules: imageModules,
dexLocations: bootLocations,
dexPaths: bootDexPaths,
dir: dir,
symbolsDir: symbolsDir,
images: images,
}
}).(bootImageConfig)
}
var apexBootImageConfigKey = android.NewOnceKey("apexBootImageConfig")
func defaultBootclasspath(ctx android.PathContext) []string {
return ctx.Config().OnceStringSlice(defaultBootclasspathKey, func() []string {
global := dexpreoptGlobalConfig(ctx)
image := defaultBootImageConfig(ctx)
bootclasspath := append(copyOf(image.dexLocations), global.ProductUpdatableBootLocations...)
return bootclasspath
})
}
var defaultBootclasspathKey = android.NewOnceKey("defaultBootclasspath")
var copyOf = android.CopyOf
func init() {
android.RegisterMakeVarsProvider(pctx, dexpreoptConfigMakevars)
}
func dexpreoptConfigMakevars(ctx android.MakeVarsContext) {
ctx.Strict("PRODUCT_BOOTCLASSPATH", strings.Join(defaultBootclasspath(ctx), ":"))
ctx.Strict("PRODUCT_DEX2OAT_BOOTCLASSPATH", strings.Join(defaultBootImageConfig(ctx).dexLocations, ":"))
ctx.Strict("PRODUCT_SYSTEM_SERVER_CLASSPATH", strings.Join(systemServerClasspath(ctx), ":"))
ctx.Strict("DEXPREOPT_BOOT_JARS_MODULES", strings.Join(defaultBootImageConfig(ctx).modules, ":"))
}
|