blob: f388358e5c76fcb085dacb58e3423a9127b6479b [file] [log] [blame]
Colin Crossfb6d7812019-01-09 22:17:55 -08001// 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
15package java
16
17import (
Colin Crossfb6d7812019-01-09 22:17:55 -080018 "fmt"
19 "path/filepath"
Colin Cross98fd5742019-01-09 23:04:25 -080020 "sort"
Colin Crossfb6d7812019-01-09 22:17:55 -080021 "strconv"
22 "strings"
Colin Cross3047fa22019-04-18 10:56:44 -070023
Jaewoong Jung9befb0c2020-01-18 10:33:43 -080024 "android/soong/android"
25 "android/soong/java/config"
26
Colin Cross3047fa22019-04-18 10:56:44 -070027 "github.com/google/blueprint/pathtools"
Colin Crossfb6d7812019-01-09 22:17:55 -080028)
29
Colin Cross98fd5742019-01-09 23:04:25 -080030func init() {
Colin Cross3047fa22019-04-18 10:56:44 -070031 android.RegisterPreSingletonType("sdk_versions", sdkPreSingletonFactory)
32 android.RegisterSingletonType("sdk", sdkSingletonFactory)
Colin Cross10932872019-04-18 14:27:12 -070033 android.RegisterMakeVarsProvider(pctx, sdkMakeVars)
Colin Cross98fd5742019-01-09 23:04:25 -080034}
35
Colin Cross3047fa22019-04-18 10:56:44 -070036var sdkVersionsKey = android.NewOnceKey("sdkVersionsKey")
37var sdkFrameworkAidlPathKey = android.NewOnceKey("sdkFrameworkAidlPathKey")
Colin Cross10932872019-04-18 14:27:12 -070038var apiFingerprintPathKey = android.NewOnceKey("apiFingerprintPathKey")
Colin Cross98fd5742019-01-09 23:04:25 -080039
Colin Crossfb6d7812019-01-09 22:17:55 -080040type sdkContext interface {
Jiyong Park6a927c42020-01-21 02:03:43 +090041 // sdkVersion returns sdkSpec that corresponds to the sdk_version property of the current module
42 sdkVersion() sdkSpec
Paul Duffine25c6442019-10-11 13:50:28 +010043 // systemModules returns the system_modules property of the current module, or an empty string if it is not set.
44 systemModules() string
Jiyong Park6a927c42020-01-21 02:03:43 +090045 // minSdkVersion returns sdkSpec that corresponds to the min_sdk_version property of the current module,
46 // or from sdk_version if it is not set.
47 minSdkVersion() sdkSpec
48 // targetSdkVersion returns the sdkSpec that corresponds to the target_sdk_version property of the current module,
49 // or from sdk_version if it is not set.
50 targetSdkVersion() sdkSpec
Colin Crossfb6d7812019-01-09 22:17:55 -080051}
52
Baligh Uddinf6201372020-01-24 23:15:44 +000053func UseApiFingerprint(ctx android.BaseModuleContext, v string) bool {
54 if v == ctx.Config().PlatformSdkCodename() &&
55 ctx.Config().UnbundledBuild() &&
56 !ctx.Config().UnbundledBuildUsePrebuiltSdks() &&
57 ctx.Config().IsEnvTrue("UNBUNDLED_BUILD_TARGET_SDK_WITH_API_FINGERPRINT") {
58 return true
59 }
60 return false
61}
62
Jiyong Park6a927c42020-01-21 02:03:43 +090063// sdkKind represents a particular category of an SDK spec like public, system, test, etc.
64type sdkKind int
65
66const (
67 sdkInvalid sdkKind = iota
68 sdkNone
69 sdkCore
70 sdkCorePlatform
71 sdkPublic
72 sdkSystem
73 sdkTest
74 sdkPrivate
75)
76
77// String returns the string representation of this sdkKind
78func (k sdkKind) String() string {
79 switch k {
80 case sdkPrivate:
81 return "private"
82 case sdkNone:
83 return "none"
84 case sdkPublic:
85 return "public"
86 case sdkSystem:
87 return "system"
88 case sdkTest:
89 return "test"
90 case sdkCore:
91 return "core"
92 case sdkCorePlatform:
93 return "core_platform"
Colin Crossfb6d7812019-01-09 22:17:55 -080094 default:
Jiyong Park6a927c42020-01-21 02:03:43 +090095 return "invalid"
Colin Crossfb6d7812019-01-09 22:17:55 -080096 }
97}
98
Jiyong Park6a927c42020-01-21 02:03:43 +090099// sdkVersion represents a specific version number of an SDK spec of a particular kind
100type sdkVersion int
101
102const (
103 // special version number for a not-yet-frozen SDK
104 sdkVersionCurrent sdkVersion = sdkVersion(android.FutureApiLevel)
105 // special version number to be used for SDK specs where version number doesn't
106 // make sense, e.g. "none", "", etc.
107 sdkVersionNone sdkVersion = sdkVersion(0)
108)
109
110// isCurrent checks if the sdkVersion refers to the not-yet-published version of an sdkKind
111func (v sdkVersion) isCurrent() bool {
112 return v == sdkVersionCurrent
113}
114
115// isNumbered checks if the sdkVersion refers to the published (a.k.a numbered) version of an sdkKind
116func (v sdkVersion) isNumbered() bool {
117 return !v.isCurrent() && v != sdkVersionNone
118}
119
120// String returns the string representation of this sdkVersion.
121func (v sdkVersion) String() string {
122 if v.isCurrent() {
123 return "current"
124 } else if v.isNumbered() {
125 return strconv.Itoa(int(v))
126 }
127 return "(no version)"
128}
129
130// asNumberString directly converts the numeric value of this sdk version as a string.
131// When isNumbered() is true, this method is the same as String(). However, for sdkVersionCurrent
132// and sdkVersionNone, this returns 10000 and 0 while String() returns "current" and "(no version"),
133// respectively.
134func (v sdkVersion) asNumberString() string {
135 return strconv.Itoa(int(v))
136}
137
138// sdkSpec represents the kind and the version of an SDK for a module to build against
139type sdkSpec struct {
140 kind sdkKind
141 version sdkVersion
142 raw string
143}
144
145// valid checks if this sdkSpec is well-formed. Note however that true doesn't mean that the
146// specified SDK actually exists.
147func (s sdkSpec) valid() bool {
148 return s.kind != sdkInvalid
149}
150
151// specified checks if this sdkSpec is well-formed and is not "".
152func (s sdkSpec) specified() bool {
153 return s.valid() && s.kind != sdkPrivate
154}
155
156// prebuiltSdkAvailableForUnbundledBuilt tells whether this sdkSpec can have a prebuilt SDK
157// that can be used for unbundled builds.
158func (s sdkSpec) prebuiltSdkAvailableForUnbundledBuild() bool {
159 // "", "none", and "core_platform" are not available for unbundled build
160 // as we don't/can't have prebuilt stub for the versions
161 return s.kind != sdkPrivate && s.kind != sdkNone && s.kind != sdkCorePlatform
162}
163
164// forPdkBuild converts this sdkSpec into another sdkSpec that is for the PDK builds.
165func (s sdkSpec) forPdkBuild(ctx android.EarlyModuleContext) sdkSpec {
166 // For PDK builds, use the latest SDK version instead of "current" or ""
167 if s.kind == sdkPrivate || s.kind == sdkPublic {
168 kind := s.kind
169 if kind == sdkPrivate {
170 // We don't have prebuilt SDK for private APIs, so use the public SDK
171 // instead. This looks odd, but that's how it has been done.
172 // TODO(b/148271073): investigate the need for this.
173 kind = sdkPublic
Colin Crossfb6d7812019-01-09 22:17:55 -0800174 }
Jiyong Park6a927c42020-01-21 02:03:43 +0900175 version := sdkVersion(LatestSdkVersionInt(ctx))
176 return sdkSpec{kind, version, s.raw}
Colin Crossfb6d7812019-01-09 22:17:55 -0800177 }
Jiyong Park6a927c42020-01-21 02:03:43 +0900178 return s
Colin Crossfb6d7812019-01-09 22:17:55 -0800179}
180
Jiyong Park6a927c42020-01-21 02:03:43 +0900181// usePrebuilt determines whether prebuilt SDK should be used for this sdkSpec with the given context.
182func (s sdkSpec) usePrebuilt(ctx android.EarlyModuleContext) bool {
183 if s.version.isCurrent() {
184 // "current" can be built from source and be from prebuilt SDK
185 return ctx.Config().UnbundledBuildUsePrebuiltSdks()
186 } else if s.version.isNumbered() {
187 // sanity check
188 if s.kind != sdkPublic && s.kind != sdkSystem && s.kind != sdkTest {
189 panic(fmt.Errorf("prebuilt SDK is not not available for sdkKind=%q", s.kind))
190 return false
191 }
192 // numbered SDKs are always from prebuilt
193 return true
Colin Crossfb6d7812019-01-09 22:17:55 -0800194 }
Jiyong Park6a927c42020-01-21 02:03:43 +0900195 // "", "none", "core_platform" fall here
196 return false
197}
198
199// effectiveVersion converts an sdkSpec into the concrete sdkVersion that the module
200// should use. For modules targeting an unreleased SDK (meaning it does not yet have a number)
201// it returns android.FutureApiLevel(10000).
202func (s sdkSpec) effectiveVersion(ctx android.EarlyModuleContext) (sdkVersion, error) {
203 if !s.valid() {
204 return s.version, fmt.Errorf("invalid sdk version %q", s.raw)
205 }
206 if ctx.Config().IsPdkBuild() {
207 s = s.forPdkBuild(ctx)
208 }
209 if s.version.isNumbered() {
210 return s.version, nil
211 }
212 return sdkVersion(ctx.Config().DefaultAppTargetSdkInt()), nil
213}
214
215// effectiveVersionString converts an sdkSpec into the concrete version string that the module
216// should use. For modules targeting an unreleased SDK (meaning it does not yet have a number)
217// it returns the codename (P, Q, R, etc.)
218func (s sdkSpec) effectiveVersionString(ctx android.EarlyModuleContext) (string, error) {
219 ver, err := s.effectiveVersion(ctx)
220 if err == nil && int(ver) == ctx.Config().DefaultAppTargetSdkInt() {
221 return ctx.Config().DefaultAppTargetSdk(), nil
222 }
223 return ver.String(), err
224}
225
226func sdkSpecFrom(str string) sdkSpec {
227 switch str {
228 // special cases first
229 case "":
230 return sdkSpec{sdkPrivate, sdkVersionNone, str}
231 case "none":
232 return sdkSpec{sdkNone, sdkVersionNone, str}
233 case "core_platform":
234 return sdkSpec{sdkCorePlatform, sdkVersionNone, str}
235 default:
236 // the syntax is [kind_]version
237 sep := strings.LastIndex(str, "_")
238
239 var kindString string
240 if sep == 0 {
241 return sdkSpec{sdkInvalid, sdkVersionNone, str}
242 } else if sep == -1 {
243 kindString = ""
244 } else {
245 kindString = str[0:sep]
246 }
247 versionString := str[sep+1 : len(str)]
248
249 var kind sdkKind
250 switch kindString {
251 case "":
252 kind = sdkPublic
253 case "core":
254 kind = sdkCore
255 case "system":
256 kind = sdkSystem
257 case "test":
258 kind = sdkTest
259 default:
260 return sdkSpec{sdkInvalid, sdkVersionNone, str}
261 }
262
263 var version sdkVersion
264 if versionString == "current" {
265 version = sdkVersionCurrent
266 } else if i, err := strconv.Atoi(versionString); err == nil {
267 version = sdkVersion(i)
268 } else {
269 return sdkSpec{sdkInvalid, sdkVersionNone, str}
270 }
271
272 return sdkSpec{kind, version, str}
273 }
Colin Crossfb6d7812019-01-09 22:17:55 -0800274}
275
Colin Cross1184b642019-12-30 18:43:07 -0800276func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext sdkContext) sdkDep {
Jiyong Park6a927c42020-01-21 02:03:43 +0900277 sdkVersion := sdkContext.sdkVersion()
278 if !sdkVersion.valid() {
279 ctx.PropertyErrorf("sdk_version", "invalid version %q", sdkVersion.raw)
Colin Crossfb6d7812019-01-09 22:17:55 -0800280 return sdkDep{}
281 }
282
Jiyong Park6a927c42020-01-21 02:03:43 +0900283 if ctx.Config().IsPdkBuild() {
284 sdkVersion = sdkVersion.forPdkBuild(ctx)
285 }
286
287 if sdkVersion.usePrebuilt(ctx) {
288 dir := filepath.Join("prebuilts", "sdk", sdkVersion.version.String(), sdkVersion.kind.String())
Colin Crossfb6d7812019-01-09 22:17:55 -0800289 jar := filepath.Join(dir, "android.jar")
290 // There's no aidl for other SDKs yet.
291 // TODO(77525052): Add aidl files for other SDKs too.
Jiyong Park6a927c42020-01-21 02:03:43 +0900292 public_dir := filepath.Join("prebuilts", "sdk", sdkVersion.version.String(), "public")
Colin Crossfb6d7812019-01-09 22:17:55 -0800293 aidl := filepath.Join(public_dir, "framework.aidl")
294 jarPath := android.ExistentPathForSource(ctx, jar)
295 aidlPath := android.ExistentPathForSource(ctx, aidl)
296 lambdaStubsPath := android.PathForSource(ctx, config.SdkLambdaStubsPath)
297
298 if (!jarPath.Valid() || !aidlPath.Valid()) && ctx.Config().AllowMissingDependencies() {
299 return sdkDep{
300 invalidVersion: true,
Jiyong Park6a927c42020-01-21 02:03:43 +0900301 bootclasspath: []string{fmt.Sprintf("sdk_%s_%s_android", sdkVersion.kind, sdkVersion.version.String())},
Colin Crossfb6d7812019-01-09 22:17:55 -0800302 }
303 }
304
305 if !jarPath.Valid() {
Jiyong Park6a927c42020-01-21 02:03:43 +0900306 ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", sdkVersion.raw, jar)
Colin Crossfb6d7812019-01-09 22:17:55 -0800307 return sdkDep{}
308 }
309
310 if !aidlPath.Valid() {
Jiyong Park6a927c42020-01-21 02:03:43 +0900311 ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", sdkVersion.raw, aidl)
Colin Crossfb6d7812019-01-09 22:17:55 -0800312 return sdkDep{}
313 }
314
315 return sdkDep{
316 useFiles: true,
317 jars: android.Paths{jarPath.Path(), lambdaStubsPath},
Colin Cross3047fa22019-04-18 10:56:44 -0700318 aidl: android.OptionalPathForPath(aidlPath.Path()),
Colin Crossfb6d7812019-01-09 22:17:55 -0800319 }
320 }
321
Colin Cross3047fa22019-04-18 10:56:44 -0700322 toModule := func(m, r string, aidl android.Path) sdkDep {
Colin Cross6cef4812019-10-17 14:23:50 -0700323 return sdkDep{
Colin Crossfb6d7812019-01-09 22:17:55 -0800324 useModule: true,
Colin Cross6cef4812019-10-17 14:23:50 -0700325 bootclasspath: []string{m, config.DefaultLambdaStubsLibrary},
326 systemModules: "core-current-stubs-system-modules",
327 java9Classpath: []string{m},
Colin Crossfb6d7812019-01-09 22:17:55 -0800328 frameworkResModule: r,
Colin Cross3047fa22019-04-18 10:56:44 -0700329 aidl: android.OptionalPathForPath(aidl),
Colin Crossfb6d7812019-01-09 22:17:55 -0800330 }
Colin Crossfb6d7812019-01-09 22:17:55 -0800331 }
332
Colin Cross98fd5742019-01-09 23:04:25 -0800333 // Ensures that the specificed system SDK version is one of BOARD_SYSTEMSDK_VERSIONS (for vendor apks)
334 // or PRODUCT_SYSTEMSDK_VERSIONS (for other apks or when BOARD_SYSTEMSDK_VERSIONS is not set)
Jiyong Park6a927c42020-01-21 02:03:43 +0900335 if sdkVersion.kind == sdkSystem && sdkVersion.version.isNumbered() {
Colin Cross98fd5742019-01-09 23:04:25 -0800336 allowed_versions := ctx.DeviceConfig().PlatformSystemSdkVersions()
337 if ctx.DeviceSpecific() || ctx.SocSpecific() {
338 if len(ctx.DeviceConfig().SystemSdkVersions()) > 0 {
339 allowed_versions = ctx.DeviceConfig().SystemSdkVersions()
340 }
341 }
Jiyong Park6a927c42020-01-21 02:03:43 +0900342 if len(allowed_versions) > 0 && !android.InList(sdkVersion.version.String(), allowed_versions) {
Colin Cross98fd5742019-01-09 23:04:25 -0800343 ctx.PropertyErrorf("sdk_version", "incompatible sdk version %q. System SDK version should be one of %q",
Jiyong Park6a927c42020-01-21 02:03:43 +0900344 sdkVersion.raw, allowed_versions)
Colin Cross98fd5742019-01-09 23:04:25 -0800345 }
346 }
347
Jiyong Park6a927c42020-01-21 02:03:43 +0900348 switch sdkVersion.kind {
349 case sdkPrivate:
Colin Crossfb6d7812019-01-09 22:17:55 -0800350 return sdkDep{
351 useDefaultLibs: true,
352 frameworkResModule: "framework-res",
353 }
Jiyong Park6a927c42020-01-21 02:03:43 +0900354 case sdkNone:
Paul Duffine25c6442019-10-11 13:50:28 +0100355 systemModules := sdkContext.systemModules()
356 if systemModules == "" {
357 ctx.PropertyErrorf("sdk_version",
358 `system_modules is required to be set to a non-empty value when sdk_version is "none", did you mean sdk_version: "core_platform"?`)
359 } else if systemModules == "none" {
Colin Cross6d8d8c62019-10-28 15:10:03 -0700360 return sdkDep{
361 noStandardLibs: true,
362 }
Paul Duffine25c6442019-10-11 13:50:28 +0100363 }
364
Paul Duffin52d398a2019-06-11 12:31:14 +0100365 return sdkDep{
Colin Cross6d8d8c62019-10-28 15:10:03 -0700366 useModule: true,
Paul Duffin52d398a2019-06-11 12:31:14 +0100367 noStandardLibs: true,
Paul Duffine25c6442019-10-11 13:50:28 +0100368 systemModules: systemModules,
Colin Cross6cef4812019-10-17 14:23:50 -0700369 bootclasspath: []string{systemModules},
Paul Duffin52d398a2019-06-11 12:31:14 +0100370 }
Jiyong Park6a927c42020-01-21 02:03:43 +0900371 case sdkCorePlatform:
Paul Duffin50c217c2019-06-12 13:25:22 +0100372 return sdkDep{
373 useDefaultLibs: true,
374 frameworkResModule: "framework-res",
375 noFrameworksLibs: true,
376 }
Jiyong Park6a927c42020-01-21 02:03:43 +0900377 case sdkPublic:
Colin Cross3047fa22019-04-18 10:56:44 -0700378 return toModule("android_stubs_current", "framework-res", sdkFrameworkAidlPath(ctx))
Jiyong Park6a927c42020-01-21 02:03:43 +0900379 case sdkSystem:
Colin Cross3047fa22019-04-18 10:56:44 -0700380 return toModule("android_system_stubs_current", "framework-res", sdkFrameworkAidlPath(ctx))
Jiyong Park6a927c42020-01-21 02:03:43 +0900381 case sdkTest:
Colin Cross3047fa22019-04-18 10:56:44 -0700382 return toModule("android_test_stubs_current", "framework-res", sdkFrameworkAidlPath(ctx))
Jiyong Park6a927c42020-01-21 02:03:43 +0900383 case sdkCore:
Colin Cross3047fa22019-04-18 10:56:44 -0700384 return toModule("core.current.stubs", "", nil)
Colin Crossfb6d7812019-01-09 22:17:55 -0800385 default:
Jiyong Park6a927c42020-01-21 02:03:43 +0900386 panic(fmt.Errorf("invalid sdk %q", sdkVersion.raw))
Colin Crossfb6d7812019-01-09 22:17:55 -0800387 }
388}
Colin Cross98fd5742019-01-09 23:04:25 -0800389
Colin Cross3047fa22019-04-18 10:56:44 -0700390func sdkPreSingletonFactory() android.Singleton {
391 return sdkPreSingleton{}
Colin Cross98fd5742019-01-09 23:04:25 -0800392}
393
Colin Cross3047fa22019-04-18 10:56:44 -0700394type sdkPreSingleton struct{}
Colin Cross98fd5742019-01-09 23:04:25 -0800395
Colin Cross3047fa22019-04-18 10:56:44 -0700396func (sdkPreSingleton) GenerateBuildActions(ctx android.SingletonContext) {
Colin Cross98fd5742019-01-09 23:04:25 -0800397 sdkJars, err := ctx.GlobWithDeps("prebuilts/sdk/*/public/android.jar", nil)
398 if err != nil {
399 ctx.Errorf("failed to glob prebuilts/sdk/*/public/android.jar: %s", err.Error())
400 }
401
402 var sdkVersions []int
403 for _, sdkJar := range sdkJars {
404 dir := filepath.Base(filepath.Dir(filepath.Dir(sdkJar)))
405 v, err := strconv.Atoi(dir)
406 if scerr, ok := err.(*strconv.NumError); ok && scerr.Err == strconv.ErrSyntax {
407 continue
408 } else if err != nil {
409 ctx.Errorf("invalid sdk jar %q, %s, %v", sdkJar, err.Error())
410 }
411 sdkVersions = append(sdkVersions, v)
412 }
413
414 sort.Ints(sdkVersions)
415
Colin Cross3047fa22019-04-18 10:56:44 -0700416 ctx.Config().Once(sdkVersionsKey, func() interface{} { return sdkVersions })
417}
418
Jiyong Park6a927c42020-01-21 02:03:43 +0900419func LatestSdkVersionInt(ctx android.EarlyModuleContext) int {
420 sdkVersions := ctx.Config().Get(sdkVersionsKey).([]int)
421 latestSdkVersion := 0
422 if len(sdkVersions) > 0 {
423 latestSdkVersion = sdkVersions[len(sdkVersions)-1]
424 }
425 return latestSdkVersion
426}
427
Colin Cross3047fa22019-04-18 10:56:44 -0700428func sdkSingletonFactory() android.Singleton {
429 return sdkSingleton{}
430}
431
432type sdkSingleton struct{}
433
434func (sdkSingleton) GenerateBuildActions(ctx android.SingletonContext) {
Colin Cross10932872019-04-18 14:27:12 -0700435 if ctx.Config().UnbundledBuildUsePrebuiltSdks() || ctx.Config().IsPdkBuild() {
Colin Cross3047fa22019-04-18 10:56:44 -0700436 return
437 }
438
Colin Cross10932872019-04-18 14:27:12 -0700439 createSdkFrameworkAidl(ctx)
440 createAPIFingerprint(ctx)
441}
Colin Cross3047fa22019-04-18 10:56:44 -0700442
Colin Cross10932872019-04-18 14:27:12 -0700443// Create framework.aidl by extracting anything that implements android.os.Parcelable from the SDK stubs modules.
444func createSdkFrameworkAidl(ctx android.SingletonContext) {
Colin Cross3047fa22019-04-18 10:56:44 -0700445 stubsModules := []string{
446 "android_stubs_current",
447 "android_test_stubs_current",
448 "android_system_stubs_current",
449 }
450
451 stubsJars := make([]android.Paths, len(stubsModules))
452
453 ctx.VisitAllModules(func(module android.Module) {
454 // Collect dex jar paths for the modules listed above.
455 if j, ok := module.(Dependency); ok {
456 name := ctx.ModuleName(module)
457 if i := android.IndexList(name, stubsModules); i != -1 {
458 stubsJars[i] = j.HeaderJars()
459 }
460 }
461 })
462
463 var missingDeps []string
464
465 for i := range stubsJars {
466 if stubsJars[i] == nil {
467 if ctx.Config().AllowMissingDependencies() {
468 missingDeps = append(missingDeps, stubsModules[i])
469 } else {
470 ctx.Errorf("failed to find dex jar path for module %q",
471 stubsModules[i])
472 }
473 }
474 }
475
476 rule := android.NewRuleBuilder()
477 rule.MissingDeps(missingDeps)
478
479 var aidls android.Paths
480 for _, jars := range stubsJars {
481 for _, jar := range jars {
482 aidl := android.PathForOutput(ctx, "aidl", pathtools.ReplaceExtension(jar.Base(), "aidl"))
483
484 rule.Command().
485 Text("rm -f").Output(aidl)
486 rule.Command().
Colin Crossee94d6a2019-07-08 17:08:34 -0700487 BuiltTool(ctx, "sdkparcelables").
Colin Cross3047fa22019-04-18 10:56:44 -0700488 Input(jar).
489 Output(aidl)
490
491 aidls = append(aidls, aidl)
492 }
493 }
494
495 combinedAidl := sdkFrameworkAidlPath(ctx)
496 tempPath := combinedAidl.ReplaceExtension(ctx, "aidl.tmp")
497
498 rule.Command().
499 Text("rm -f").Output(tempPath)
500 rule.Command().
501 Text("cat").
502 Inputs(aidls).
503 Text("| sort -u >").
504 Output(tempPath)
505
506 commitChangeForRestat(rule, tempPath, combinedAidl)
507
508 rule.Build(pctx, ctx, "framework_aidl", "generate framework.aidl")
509}
510
511func sdkFrameworkAidlPath(ctx android.PathContext) android.OutputPath {
512 return ctx.Config().Once(sdkFrameworkAidlPathKey, func() interface{} {
513 return android.PathForOutput(ctx, "framework.aidl")
514 }).(android.OutputPath)
515}
516
Colin Cross10932872019-04-18 14:27:12 -0700517// Create api_fingerprint.txt
518func createAPIFingerprint(ctx android.SingletonContext) {
Jiyong Park71b519d2019-04-18 17:25:49 +0900519 out := ApiFingerprintPath(ctx)
Colin Cross10932872019-04-18 14:27:12 -0700520
521 rule := android.NewRuleBuilder()
522
523 rule.Command().
524 Text("rm -f").Output(out)
525 cmd := rule.Command()
526
527 if ctx.Config().PlatformSdkCodename() == "REL" {
528 cmd.Text("echo REL >").Output(out)
529 } else if ctx.Config().IsPdkBuild() {
530 // TODO: get this from the PDK artifacts?
531 cmd.Text("echo PDK >").Output(out)
532 } else if !ctx.Config().UnbundledBuildUsePrebuiltSdks() {
533 in, err := ctx.GlobWithDeps("frameworks/base/api/*current.txt", nil)
534 if err != nil {
535 ctx.Errorf("error globbing API files: %s", err)
536 }
537
538 cmd.Text("cat").
539 Inputs(android.PathsForSource(ctx, in)).
Elliott Hughes34b49d12019-09-06 14:42:24 -0700540 Text("| md5sum | cut -d' ' -f1 >").
Colin Cross10932872019-04-18 14:27:12 -0700541 Output(out)
542 } else {
543 // Unbundled build
544 // TODO: use a prebuilt api_fingerprint.txt from prebuilts/sdk/current.txt once we have one
545 cmd.Text("echo").
546 Flag(ctx.Config().PlatformPreviewSdkVersion()).
547 Text(">").
548 Output(out)
549 }
550
551 rule.Build(pctx, ctx, "api_fingerprint", "generate api_fingerprint.txt")
552}
553
Jiyong Park71b519d2019-04-18 17:25:49 +0900554func ApiFingerprintPath(ctx android.PathContext) android.OutputPath {
Colin Cross10932872019-04-18 14:27:12 -0700555 return ctx.Config().Once(apiFingerprintPathKey, func() interface{} {
556 return android.PathForOutput(ctx, "api_fingerprint.txt")
557 }).(android.OutputPath)
558}
559
560func sdkMakeVars(ctx android.MakeVarsContext) {
561 if ctx.Config().UnbundledBuildUsePrebuiltSdks() || ctx.Config().IsPdkBuild() {
Colin Cross3047fa22019-04-18 10:56:44 -0700562 return
563 }
564
565 ctx.Strict("FRAMEWORK_AIDL", sdkFrameworkAidlPath(ctx).String())
Jiyong Park71b519d2019-04-18 17:25:49 +0900566 ctx.Strict("API_FINGERPRINT", ApiFingerprintPath(ctx).String())
Colin Cross98fd5742019-01-09 23:04:25 -0800567}