blob: 81be991e6e0846ee9d9cbd8d6ab8eff5d32531f2 [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 Cross3047fa22019-04-18 10:56:44 -070020
Jaewoong Jung9befb0c2020-01-18 10:33:43 -080021 "android/soong/android"
22 "android/soong/java/config"
23
Colin Cross3047fa22019-04-18 10:56:44 -070024 "github.com/google/blueprint/pathtools"
Colin Crossfb6d7812019-01-09 22:17:55 -080025)
26
Colin Cross98fd5742019-01-09 23:04:25 -080027func init() {
LaMont Jones0c10e4d2023-05-16 00:58:37 +000028 android.RegisterParallelSingletonType("sdk", sdkSingletonFactory)
Colin Cross10932872019-04-18 14:27:12 -070029 android.RegisterMakeVarsProvider(pctx, sdkMakeVars)
Colin Cross98fd5742019-01-09 23:04:25 -080030}
31
Colin Cross3047fa22019-04-18 10:56:44 -070032var sdkFrameworkAidlPathKey = android.NewOnceKey("sdkFrameworkAidlPathKey")
Anton Hansson3f07ab22020-04-09 13:29:59 +010033var nonUpdatableFrameworkAidlPathKey = android.NewOnceKey("nonUpdatableFrameworkAidlPathKey")
Colin Cross10932872019-04-18 14:27:12 -070034var apiFingerprintPathKey = android.NewOnceKey("apiFingerprintPathKey")
Colin Cross98fd5742019-01-09 23:04:25 -080035
Nikita Ioffe1f4f3452020-03-02 16:58:11 +000036func UseApiFingerprint(ctx android.BaseModuleContext) bool {
37 if ctx.Config().UnbundledBuild() &&
Jeongik Cha816a23a2020-07-08 01:09:23 +090038 !ctx.Config().AlwaysUsePrebuiltSdks() &&
Baligh Uddinf6201372020-01-24 23:15:44 +000039 ctx.Config().IsEnvTrue("UNBUNDLED_BUILD_TARGET_SDK_WITH_API_FINGERPRINT") {
40 return true
41 }
42 return false
43}
44
Jiyong Parkf1691d22021-03-29 20:11:58 +090045func defaultJavaLanguageVersion(ctx android.EarlyModuleContext, s android.SdkSpec) javaVersion {
46 sdk, err := s.EffectiveVersion(ctx)
Colin Cross17dec172020-05-14 18:05:32 -070047 if err != nil {
48 ctx.PropertyErrorf("sdk_version", "%s", err)
49 }
Sorin Bascad567a512024-01-15 16:38:46 +000050 if sdk.FinalOrFutureInt() <= 29 {
Colin Cross17dec172020-05-14 18:05:32 -070051 return JAVA_VERSION_8
Sorin Basca18ecf612022-01-23 09:01:07 +000052 } else if sdk.FinalOrFutureInt() <= 31 {
Sorin Basca8d3e0bb2022-01-20 15:21:51 +000053 return JAVA_VERSION_9
Sorin Basca34e1f8c2023-03-03 10:18:00 +000054 } else if sdk.FinalOrFutureInt() <= 33 {
Julien Desprez91ba6c72023-02-14 20:26:31 +000055 return JAVA_VERSION_11
Sorin Bascabe302732023-02-15 17:52:27 +000056 } else {
57 return JAVA_VERSION_17
Colin Cross17dec172020-05-14 18:05:32 -070058 }
59}
60
Paul Duffin004547f2021-10-29 13:50:24 +010061// systemModuleKind returns the kind of system modules to use for the supplied combination of sdk
62// kind and API level.
63func systemModuleKind(sdkKind android.SdkKind, apiLevel android.ApiLevel) android.SdkKind {
64 systemModuleKind := sdkKind
65 if apiLevel.LessThanOrEqualTo(android.LastWithoutModuleLibCoreSystemModules) {
66 // API levels less than or equal to 31 did not provide a core-for-system-modules.jar
67 // specifically for the module-lib API. So, always use the public system modules for them.
68 systemModuleKind = android.SdkPublic
69 } else if systemModuleKind == android.SdkCore {
70 // Core is by definition what is included in the system module for the public API so should
71 // just use its system modules.
72 systemModuleKind = android.SdkPublic
Mark White9421c4c2023-08-10 00:07:03 +000073 } else if systemModuleKind == android.SdkSystem || systemModuleKind == android.SdkTest ||
74 systemModuleKind == android.SdkTestFrameworksCore {
Paul Duffin004547f2021-10-29 13:50:24 +010075 // The core system and test APIs are currently the same as the public API so they should use
76 // its system modules.
77 systemModuleKind = android.SdkPublic
78 } else if systemModuleKind == android.SdkSystemServer {
79 // The core system server API is the same as the core module-lib API.
80 systemModuleKind = android.SdkModule
81 }
82
83 return systemModuleKind
Paul Duffin1cad3a52021-10-29 13:30:59 +010084}
85
Jiyong Parkf1691d22021-03-29 20:11:58 +090086func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext android.SdkContext) sdkDep {
Jiyong Park92315372021-04-02 08:45:46 +090087 sdkVersion := sdkContext.SdkVersion(ctx)
Jiyong Parkf1691d22021-03-29 20:11:58 +090088 if !sdkVersion.Valid() {
89 ctx.PropertyErrorf("sdk_version", "invalid version %q", sdkVersion.Raw)
Colin Crossfb6d7812019-01-09 22:17:55 -080090 return sdkDep{}
91 }
92
Jeongik Cha219141c2020-08-06 23:00:37 +090093 if ctx.DeviceSpecific() || ctx.SocSpecific() {
Jiyong Parkf1691d22021-03-29 20:11:58 +090094 sdkVersion = sdkVersion.ForVendorPartition(ctx)
Jeongik Cha219141c2020-08-06 23:00:37 +090095 }
96
Jiyong Parkf1691d22021-03-29 20:11:58 +090097 if !sdkVersion.ValidateSystemSdk(ctx) {
Jeongik Cha7c708312020-01-28 13:52:36 +090098 return sdkDep{}
99 }
Jiyong Park6a927c42020-01-21 02:03:43 +0900100
Jiyong Parkf1691d22021-03-29 20:11:58 +0900101 if sdkVersion.UsePrebuilt(ctx) {
Jiyong Park54105c42021-03-31 18:17:53 +0900102 dir := filepath.Join("prebuilts", "sdk", sdkVersion.ApiLevel.String(), sdkVersion.Kind.String())
Colin Crossfb6d7812019-01-09 22:17:55 -0800103 jar := filepath.Join(dir, "android.jar")
104 // There's no aidl for other SDKs yet.
105 // TODO(77525052): Add aidl files for other SDKs too.
Jiyong Park54105c42021-03-31 18:17:53 +0900106 publicDir := filepath.Join("prebuilts", "sdk", sdkVersion.ApiLevel.String(), "public")
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800107 aidl := filepath.Join(publicDir, "framework.aidl")
Colin Crossfb6d7812019-01-09 22:17:55 -0800108 jarPath := android.ExistentPathForSource(ctx, jar)
109 aidlPath := android.ExistentPathForSource(ctx, aidl)
110 lambdaStubsPath := android.PathForSource(ctx, config.SdkLambdaStubsPath)
111
112 if (!jarPath.Valid() || !aidlPath.Valid()) && ctx.Config().AllowMissingDependencies() {
113 return sdkDep{
114 invalidVersion: true,
Jiyong Park54105c42021-03-31 18:17:53 +0900115 bootclasspath: []string{fmt.Sprintf("sdk_%s_%s_android", sdkVersion.Kind, sdkVersion.ApiLevel.String())},
Colin Crossfb6d7812019-01-09 22:17:55 -0800116 }
117 }
118
119 if !jarPath.Valid() {
Jiyong Parkf1691d22021-03-29 20:11:58 +0900120 ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", sdkVersion.Raw, jar)
Colin Crossfb6d7812019-01-09 22:17:55 -0800121 return sdkDep{}
122 }
123
124 if !aidlPath.Valid() {
Jiyong Parkf1691d22021-03-29 20:11:58 +0900125 ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", sdkVersion.Raw, aidl)
Colin Crossfb6d7812019-01-09 22:17:55 -0800126 return sdkDep{}
127 }
128
Colin Cross17dec172020-05-14 18:05:32 -0700129 var systemModules string
Jiyong Parkf1691d22021-03-29 20:11:58 +0900130 if defaultJavaLanguageVersion(ctx, sdkVersion).usesJavaModules() {
Paul Duffin004547f2021-10-29 13:50:24 +0100131 systemModuleKind := systemModuleKind(sdkVersion.Kind, sdkVersion.ApiLevel)
Paul Duffin1cad3a52021-10-29 13:30:59 +0100132 systemModules = fmt.Sprintf("sdk_%s_%s_system_modules", systemModuleKind, sdkVersion.ApiLevel)
Colin Cross17dec172020-05-14 18:05:32 -0700133 }
134
Colin Crossfb6d7812019-01-09 22:17:55 -0800135 return sdkDep{
Colin Cross17dec172020-05-14 18:05:32 -0700136 useFiles: true,
137 jars: android.Paths{jarPath.Path(), lambdaStubsPath},
138 aidl: android.OptionalPathForPath(aidlPath.Path()),
139 systemModules: systemModules,
Colin Crossfb6d7812019-01-09 22:17:55 -0800140 }
141 }
142
Paul Duffine5ad90c2021-11-03 16:44:22 +0000143 toModule := func(module string, aidl android.Path) sdkDep {
144 // Select the kind of system modules needed for the sdk version.
145 systemModulesKind := systemModuleKind(sdkVersion.Kind, android.FutureApiLevel)
Jihoon Kang6c0df882023-06-14 22:43:25 +0000146 systemModules := fmt.Sprintf("core-%s-stubs-system-modules", systemModulesKind)
Colin Cross6cef4812019-10-17 14:23:50 -0700147 return sdkDep{
Colin Crossfb6d7812019-01-09 22:17:55 -0800148 useModule: true,
Jihoon Kang91c83952023-05-30 19:12:28 +0000149 bootclasspath: []string{module, config.DefaultLambdaStubsLibrary},
Spandan Dase339a2d2023-03-30 02:59:22 +0000150 systemModules: systemModules,
Paul Duffine9758b02021-10-28 11:43:21 +0100151 java9Classpath: []string{module},
152 frameworkResModule: "framework-res",
Colin Cross3047fa22019-04-18 10:56:44 -0700153 aidl: android.OptionalPathForPath(aidl),
Colin Crossfb6d7812019-01-09 22:17:55 -0800154 }
Colin Crossfb6d7812019-01-09 22:17:55 -0800155 }
156
Jiyong Parkf1691d22021-03-29 20:11:58 +0900157 switch sdkVersion.Kind {
158 case android.SdkPrivate:
Colin Crossfb6d7812019-01-09 22:17:55 -0800159 return sdkDep{
Pete Gilline3d44b22020-06-29 11:28:51 +0100160 useModule: true,
Pete Gillin84c38072020-07-09 18:03:41 +0100161 systemModules: corePlatformSystemModules(ctx),
162 bootclasspath: corePlatformBootclasspathLibraries(ctx),
Pete Gilline3d44b22020-06-29 11:28:51 +0100163 classpath: config.FrameworkLibraries,
Colin Crossfb6d7812019-01-09 22:17:55 -0800164 frameworkResModule: "framework-res",
165 }
Jiyong Parkf1691d22021-03-29 20:11:58 +0900166 case android.SdkNone:
167 systemModules := sdkContext.SystemModules()
Paul Duffine25c6442019-10-11 13:50:28 +0100168 if systemModules == "" {
169 ctx.PropertyErrorf("sdk_version",
170 `system_modules is required to be set to a non-empty value when sdk_version is "none", did you mean sdk_version: "core_platform"?`)
171 } else if systemModules == "none" {
Colin Cross6d8d8c62019-10-28 15:10:03 -0700172 return sdkDep{
173 noStandardLibs: true,
174 }
Paul Duffine25c6442019-10-11 13:50:28 +0100175 }
176
Paul Duffin52d398a2019-06-11 12:31:14 +0100177 return sdkDep{
Colin Cross6d8d8c62019-10-28 15:10:03 -0700178 useModule: true,
Paul Duffin52d398a2019-06-11 12:31:14 +0100179 noStandardLibs: true,
Paul Duffine25c6442019-10-11 13:50:28 +0100180 systemModules: systemModules,
Colin Cross6cef4812019-10-17 14:23:50 -0700181 bootclasspath: []string{systemModules},
Paul Duffin52d398a2019-06-11 12:31:14 +0100182 }
Jiyong Parkf1691d22021-03-29 20:11:58 +0900183 case android.SdkCorePlatform:
Paul Duffin50c217c2019-06-12 13:25:22 +0100184 return sdkDep{
Pete Gillin7b0bdce2020-07-01 13:05:32 +0100185 useModule: true,
Pete Gillin84c38072020-07-09 18:03:41 +0100186 systemModules: corePlatformSystemModules(ctx),
187 bootclasspath: corePlatformBootclasspathLibraries(ctx),
Pete Gillin7b0bdce2020-07-01 13:05:32 +0100188 noFrameworksLibs: true,
Paul Duffin50c217c2019-06-12 13:25:22 +0100189 }
Mark White9421c4c2023-08-10 00:07:03 +0000190 case android.SdkPublic, android.SdkSystem, android.SdkTest, android.SdkTestFrameworksCore:
Jihoon Kang91c83952023-05-30 19:12:28 +0000191 return toModule(sdkVersion.Kind.DefaultJavaLibraryName(), sdkFrameworkAidlPath(ctx))
Jiyong Parkf1691d22021-03-29 20:11:58 +0900192 case android.SdkCore:
Pete Gillin880f9642020-07-01 13:17:16 +0100193 return sdkDep{
194 useModule: true,
Jihoon Kang91c83952023-05-30 19:12:28 +0000195 bootclasspath: []string{android.SdkCore.DefaultJavaLibraryName(), config.DefaultLambdaStubsLibrary},
Jihoon Kang6c0df882023-06-14 22:43:25 +0000196 systemModules: "core-public-stubs-system-modules",
Pete Gillin880f9642020-07-01 13:17:16 +0100197 noFrameworksLibs: true,
198 }
Jiyong Parkf1691d22021-03-29 20:11:58 +0900199 case android.SdkModule:
Jiyong Park50146e92020-01-30 18:00:15 +0900200 // TODO(146757305): provide .apk and .aidl that have more APIs for modules
Jihoon Kang91c83952023-05-30 19:12:28 +0000201 return toModule(sdkVersion.Kind.DefaultJavaLibraryName(), nonUpdatableFrameworkAidlPath(ctx))
Jiyong Parkf1691d22021-03-29 20:11:58 +0900202 case android.SdkSystemServer:
Jiyong Parkaae9bd12020-02-12 04:36:43 +0900203 // TODO(146757305): provide .apk and .aidl that have more APIs for modules
Jihoon Kang91c83952023-05-30 19:12:28 +0000204 return toModule(sdkVersion.Kind.DefaultJavaLibraryName(), sdkFrameworkAidlPath(ctx))
Colin Crossfb6d7812019-01-09 22:17:55 -0800205 default:
Jiyong Parkf1691d22021-03-29 20:11:58 +0900206 panic(fmt.Errorf("invalid sdk %q", sdkVersion.Raw))
Colin Crossfb6d7812019-01-09 22:17:55 -0800207 }
208}
Colin Cross98fd5742019-01-09 23:04:25 -0800209
Colin Cross3047fa22019-04-18 10:56:44 -0700210func sdkSingletonFactory() android.Singleton {
211 return sdkSingleton{}
212}
213
214type sdkSingleton struct{}
215
216func (sdkSingleton) GenerateBuildActions(ctx android.SingletonContext) {
Dan Willemsen9f435972020-05-28 15:28:00 -0700217 if ctx.Config().AlwaysUsePrebuiltSdks() {
Colin Cross3047fa22019-04-18 10:56:44 -0700218 return
219 }
220
Colin Cross10932872019-04-18 14:27:12 -0700221 createSdkFrameworkAidl(ctx)
Anton Hansson3f07ab22020-04-09 13:29:59 +0100222 createNonUpdatableFrameworkAidl(ctx)
Colin Cross10932872019-04-18 14:27:12 -0700223 createAPIFingerprint(ctx)
224}
Colin Cross3047fa22019-04-18 10:56:44 -0700225
Colin Cross10932872019-04-18 14:27:12 -0700226// Create framework.aidl by extracting anything that implements android.os.Parcelable from the SDK stubs modules.
227func createSdkFrameworkAidl(ctx android.SingletonContext) {
Colin Cross3047fa22019-04-18 10:56:44 -0700228 stubsModules := []string{
Jihoon Kang91c83952023-05-30 19:12:28 +0000229 android.SdkPublic.DefaultJavaLibraryName(),
230 android.SdkTest.DefaultJavaLibraryName(),
231 android.SdkSystem.DefaultJavaLibraryName(),
Colin Cross3047fa22019-04-18 10:56:44 -0700232 }
233
Anton Hansson3f07ab22020-04-09 13:29:59 +0100234 combinedAidl := sdkFrameworkAidlPath(ctx)
Paul Duffind3c15132021-04-21 22:12:35 +0100235 tempPath := tempPathForRestat(ctx, combinedAidl)
Anton Hansson3f07ab22020-04-09 13:29:59 +0100236
237 rule := createFrameworkAidl(stubsModules, tempPath, ctx)
238
239 commitChangeForRestat(rule, tempPath, combinedAidl)
240
Colin Crossf1a035e2020-11-16 17:32:30 -0800241 rule.Build("framework_aidl", "generate framework.aidl")
Anton Hansson3f07ab22020-04-09 13:29:59 +0100242}
243
244// Creates a version of framework.aidl for the non-updatable part of the platform.
245func createNonUpdatableFrameworkAidl(ctx android.SingletonContext) {
Jihoon Kang91c83952023-05-30 19:12:28 +0000246 stubsModules := []string{android.SdkModule.DefaultJavaLibraryName()}
Anton Hansson3f07ab22020-04-09 13:29:59 +0100247
248 combinedAidl := nonUpdatableFrameworkAidlPath(ctx)
Paul Duffind3c15132021-04-21 22:12:35 +0100249 tempPath := tempPathForRestat(ctx, combinedAidl)
Anton Hansson3f07ab22020-04-09 13:29:59 +0100250
251 rule := createFrameworkAidl(stubsModules, tempPath, ctx)
252
253 commitChangeForRestat(rule, tempPath, combinedAidl)
254
Colin Crossf1a035e2020-11-16 17:32:30 -0800255 rule.Build("framework_non_updatable_aidl", "generate framework_non_updatable.aidl")
Anton Hansson3f07ab22020-04-09 13:29:59 +0100256}
257
Paul Duffind3c15132021-04-21 22:12:35 +0100258func createFrameworkAidl(stubsModules []string, path android.WritablePath, ctx android.SingletonContext) *android.RuleBuilder {
Colin Cross3047fa22019-04-18 10:56:44 -0700259 stubsJars := make([]android.Paths, len(stubsModules))
260
261 ctx.VisitAllModules(func(module android.Module) {
262 // Collect dex jar paths for the modules listed above.
Colin Cross5a377182023-12-14 14:46:23 -0800263 if j, ok := android.SingletonModuleProvider(ctx, module, JavaInfoProvider); ok {
Colin Cross3047fa22019-04-18 10:56:44 -0700264 name := ctx.ModuleName(module)
265 if i := android.IndexList(name, stubsModules); i != -1 {
Colin Crossdcf71b22021-02-01 13:59:03 -0800266 stubsJars[i] = j.HeaderJars
Colin Cross3047fa22019-04-18 10:56:44 -0700267 }
268 }
269 })
270
271 var missingDeps []string
272
273 for i := range stubsJars {
274 if stubsJars[i] == nil {
275 if ctx.Config().AllowMissingDependencies() {
276 missingDeps = append(missingDeps, stubsModules[i])
277 } else {
Anton Hansson3f07ab22020-04-09 13:29:59 +0100278 ctx.Errorf("failed to find dex jar path for module %q", stubsModules[i])
Colin Cross3047fa22019-04-18 10:56:44 -0700279 }
280 }
281 }
282
Colin Crossf1a035e2020-11-16 17:32:30 -0800283 rule := android.NewRuleBuilder(pctx, ctx)
Colin Cross3047fa22019-04-18 10:56:44 -0700284 rule.MissingDeps(missingDeps)
285
286 var aidls android.Paths
287 for _, jars := range stubsJars {
288 for _, jar := range jars {
289 aidl := android.PathForOutput(ctx, "aidl", pathtools.ReplaceExtension(jar.Base(), "aidl"))
290
291 rule.Command().
292 Text("rm -f").Output(aidl)
293 rule.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -0800294 BuiltTool("sdkparcelables").
Colin Cross3047fa22019-04-18 10:56:44 -0700295 Input(jar).
296 Output(aidl)
297
298 aidls = append(aidls, aidl)
299 }
300 }
301
Colin Cross3047fa22019-04-18 10:56:44 -0700302 rule.Command().
Anton Hansson3f07ab22020-04-09 13:29:59 +0100303 Text("rm -f").Output(path)
Colin Cross3047fa22019-04-18 10:56:44 -0700304 rule.Command().
305 Text("cat").
306 Inputs(aidls).
307 Text("| sort -u >").
Anton Hansson3f07ab22020-04-09 13:29:59 +0100308 Output(path)
Colin Cross3047fa22019-04-18 10:56:44 -0700309
Anton Hansson3f07ab22020-04-09 13:29:59 +0100310 return rule
Colin Cross3047fa22019-04-18 10:56:44 -0700311}
312
313func sdkFrameworkAidlPath(ctx android.PathContext) android.OutputPath {
314 return ctx.Config().Once(sdkFrameworkAidlPathKey, func() interface{} {
315 return android.PathForOutput(ctx, "framework.aidl")
316 }).(android.OutputPath)
317}
318
Anton Hansson3f07ab22020-04-09 13:29:59 +0100319func nonUpdatableFrameworkAidlPath(ctx android.PathContext) android.OutputPath {
320 return ctx.Config().Once(nonUpdatableFrameworkAidlPathKey, func() interface{} {
321 return android.PathForOutput(ctx, "framework_non_updatable.aidl")
322 }).(android.OutputPath)
323}
324
Colin Cross10932872019-04-18 14:27:12 -0700325// Create api_fingerprint.txt
326func createAPIFingerprint(ctx android.SingletonContext) {
Jiyong Park71b519d2019-04-18 17:25:49 +0900327 out := ApiFingerprintPath(ctx)
Colin Cross10932872019-04-18 14:27:12 -0700328
Colin Crossf1a035e2020-11-16 17:32:30 -0800329 rule := android.NewRuleBuilder(pctx, ctx)
Colin Cross10932872019-04-18 14:27:12 -0700330
331 rule.Command().
332 Text("rm -f").Output(out)
333 cmd := rule.Command()
334
335 if ctx.Config().PlatformSdkCodename() == "REL" {
336 cmd.Text("echo REL >").Output(out)
Anton Hansson973d31c2021-02-10 14:52:42 +0000337 } else if ctx.Config().FrameworksBaseDirExists(ctx) && !ctx.Config().AlwaysUsePrebuiltSdks() {
338 cmd.Text("cat")
339 apiTxtFileModules := []string{
Zi Wangb31a8332023-03-06 15:21:35 -0800340 "api_fingerprint",
Colin Cross10932872019-04-18 14:27:12 -0700341 }
Anton Hansson973d31c2021-02-10 14:52:42 +0000342 count := 0
343 ctx.VisitAllModules(func(module android.Module) {
344 name := ctx.ModuleName(module)
345 if android.InList(name, apiTxtFileModules) {
346 cmd.Inputs(android.OutputFilesForModule(ctx, module, ""))
347 count++
348 }
349 })
350 if count != len(apiTxtFileModules) {
Zi Wangb31a8332023-03-06 15:21:35 -0800351 ctx.Errorf("Could not find expected API module %v, found %d\n", apiTxtFileModules, count)
Anton Hansson973d31c2021-02-10 14:52:42 +0000352 return
353 }
Zi Wangb31a8332023-03-06 15:21:35 -0800354 cmd.Text(">").
Colin Cross10932872019-04-18 14:27:12 -0700355 Output(out)
356 } else {
357 // Unbundled build
358 // TODO: use a prebuilt api_fingerprint.txt from prebuilts/sdk/current.txt once we have one
359 cmd.Text("echo").
360 Flag(ctx.Config().PlatformPreviewSdkVersion()).
361 Text(">").
362 Output(out)
363 }
364
Colin Crossf1a035e2020-11-16 17:32:30 -0800365 rule.Build("api_fingerprint", "generate api_fingerprint.txt")
Colin Cross10932872019-04-18 14:27:12 -0700366}
367
Jiyong Park71b519d2019-04-18 17:25:49 +0900368func ApiFingerprintPath(ctx android.PathContext) android.OutputPath {
Colin Cross10932872019-04-18 14:27:12 -0700369 return ctx.Config().Once(apiFingerprintPathKey, func() interface{} {
370 return android.PathForOutput(ctx, "api_fingerprint.txt")
371 }).(android.OutputPath)
372}
373
374func sdkMakeVars(ctx android.MakeVarsContext) {
Dan Willemsen9f435972020-05-28 15:28:00 -0700375 if ctx.Config().AlwaysUsePrebuiltSdks() {
Colin Cross3047fa22019-04-18 10:56:44 -0700376 return
377 }
378
379 ctx.Strict("FRAMEWORK_AIDL", sdkFrameworkAidlPath(ctx).String())
Jiyong Park71b519d2019-04-18 17:25:49 +0900380 ctx.Strict("API_FINGERPRINT", ApiFingerprintPath(ctx).String())
Colin Cross98fd5742019-01-09 23:04:25 -0800381}