Colin Cross | fb6d781 | 2019-01-09 22:17:55 -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 | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 18 | "fmt" |
| 19 | "path/filepath" |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 20 | |
Jaewoong Jung | 9befb0c | 2020-01-18 10:33:43 -0800 | [diff] [blame] | 21 | "android/soong/android" |
| 22 | "android/soong/java/config" |
| 23 | |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 24 | "github.com/google/blueprint/pathtools" |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 25 | ) |
| 26 | |
Colin Cross | 98fd574 | 2019-01-09 23:04:25 -0800 | [diff] [blame] | 27 | func init() { |
LaMont Jones | 0c10e4d | 2023-05-16 00:58:37 +0000 | [diff] [blame] | 28 | android.RegisterParallelSingletonType("sdk", sdkSingletonFactory) |
Colin Cross | 1093287 | 2019-04-18 14:27:12 -0700 | [diff] [blame] | 29 | android.RegisterMakeVarsProvider(pctx, sdkMakeVars) |
Colin Cross | 98fd574 | 2019-01-09 23:04:25 -0800 | [diff] [blame] | 30 | } |
| 31 | |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 32 | var sdkFrameworkAidlPathKey = android.NewOnceKey("sdkFrameworkAidlPathKey") |
Anton Hansson | 3f07ab2 | 2020-04-09 13:29:59 +0100 | [diff] [blame] | 33 | var nonUpdatableFrameworkAidlPathKey = android.NewOnceKey("nonUpdatableFrameworkAidlPathKey") |
Colin Cross | 1093287 | 2019-04-18 14:27:12 -0700 | [diff] [blame] | 34 | var apiFingerprintPathKey = android.NewOnceKey("apiFingerprintPathKey") |
Colin Cross | 98fd574 | 2019-01-09 23:04:25 -0800 | [diff] [blame] | 35 | |
Nikita Ioffe | 1f4f345 | 2020-03-02 16:58:11 +0000 | [diff] [blame] | 36 | func UseApiFingerprint(ctx android.BaseModuleContext) bool { |
| 37 | if ctx.Config().UnbundledBuild() && |
Jeongik Cha | 816a23a | 2020-07-08 01:09:23 +0900 | [diff] [blame] | 38 | !ctx.Config().AlwaysUsePrebuiltSdks() && |
Baligh Uddin | f620137 | 2020-01-24 23:15:44 +0000 | [diff] [blame] | 39 | ctx.Config().IsEnvTrue("UNBUNDLED_BUILD_TARGET_SDK_WITH_API_FINGERPRINT") { |
| 40 | return true |
| 41 | } |
| 42 | return false |
| 43 | } |
| 44 | |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 45 | func defaultJavaLanguageVersion(ctx android.EarlyModuleContext, s android.SdkSpec) javaVersion { |
| 46 | sdk, err := s.EffectiveVersion(ctx) |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 47 | if err != nil { |
| 48 | ctx.PropertyErrorf("sdk_version", "%s", err) |
| 49 | } |
Jiyong Park | 54105c4 | 2021-03-31 18:17:53 +0900 | [diff] [blame] | 50 | if sdk.FinalOrFutureInt() <= 23 { |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 51 | return JAVA_VERSION_7 |
Jiyong Park | 54105c4 | 2021-03-31 18:17:53 +0900 | [diff] [blame] | 52 | } else if sdk.FinalOrFutureInt() <= 29 { |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 53 | return JAVA_VERSION_8 |
Sorin Basca | 18ecf61 | 2022-01-23 09:01:07 +0000 | [diff] [blame] | 54 | } else if sdk.FinalOrFutureInt() <= 31 { |
Sorin Basca | 8d3e0bb | 2022-01-20 15:21:51 +0000 | [diff] [blame] | 55 | return JAVA_VERSION_9 |
Sorin Basca | 34e1f8c | 2023-03-03 10:18:00 +0000 | [diff] [blame] | 56 | } else if sdk.FinalOrFutureInt() <= 33 { |
Julien Desprez | 91ba6c7 | 2023-02-14 20:26:31 +0000 | [diff] [blame] | 57 | return JAVA_VERSION_11 |
Sorin Basca | be30273 | 2023-02-15 17:52:27 +0000 | [diff] [blame] | 58 | } else { |
| 59 | return JAVA_VERSION_17 |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 60 | } |
| 61 | } |
| 62 | |
Paul Duffin | 004547f | 2021-10-29 13:50:24 +0100 | [diff] [blame] | 63 | // systemModuleKind returns the kind of system modules to use for the supplied combination of sdk |
| 64 | // kind and API level. |
| 65 | func systemModuleKind(sdkKind android.SdkKind, apiLevel android.ApiLevel) android.SdkKind { |
| 66 | systemModuleKind := sdkKind |
| 67 | if apiLevel.LessThanOrEqualTo(android.LastWithoutModuleLibCoreSystemModules) { |
| 68 | // API levels less than or equal to 31 did not provide a core-for-system-modules.jar |
| 69 | // specifically for the module-lib API. So, always use the public system modules for them. |
| 70 | systemModuleKind = android.SdkPublic |
| 71 | } else if systemModuleKind == android.SdkCore { |
| 72 | // Core is by definition what is included in the system module for the public API so should |
| 73 | // just use its system modules. |
| 74 | systemModuleKind = android.SdkPublic |
Mark White | 9421c4c | 2023-08-10 00:07:03 +0000 | [diff] [blame] | 75 | } else if systemModuleKind == android.SdkSystem || systemModuleKind == android.SdkTest || |
| 76 | systemModuleKind == android.SdkTestFrameworksCore { |
Paul Duffin | 004547f | 2021-10-29 13:50:24 +0100 | [diff] [blame] | 77 | // The core system and test APIs are currently the same as the public API so they should use |
| 78 | // its system modules. |
| 79 | systemModuleKind = android.SdkPublic |
| 80 | } else if systemModuleKind == android.SdkSystemServer { |
| 81 | // The core system server API is the same as the core module-lib API. |
| 82 | systemModuleKind = android.SdkModule |
| 83 | } |
| 84 | |
| 85 | return systemModuleKind |
Paul Duffin | 1cad3a5 | 2021-10-29 13:30:59 +0100 | [diff] [blame] | 86 | } |
| 87 | |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 88 | func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext android.SdkContext) sdkDep { |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 89 | sdkVersion := sdkContext.SdkVersion(ctx) |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 90 | if !sdkVersion.Valid() { |
| 91 | ctx.PropertyErrorf("sdk_version", "invalid version %q", sdkVersion.Raw) |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 92 | return sdkDep{} |
| 93 | } |
| 94 | |
Jeongik Cha | 219141c | 2020-08-06 23:00:37 +0900 | [diff] [blame] | 95 | if ctx.DeviceSpecific() || ctx.SocSpecific() { |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 96 | sdkVersion = sdkVersion.ForVendorPartition(ctx) |
Jeongik Cha | 219141c | 2020-08-06 23:00:37 +0900 | [diff] [blame] | 97 | } |
| 98 | |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 99 | if !sdkVersion.ValidateSystemSdk(ctx) { |
Jeongik Cha | 7c70831 | 2020-01-28 13:52:36 +0900 | [diff] [blame] | 100 | return sdkDep{} |
| 101 | } |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 102 | |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 103 | if sdkVersion.UsePrebuilt(ctx) { |
Jiyong Park | 54105c4 | 2021-03-31 18:17:53 +0900 | [diff] [blame] | 104 | dir := filepath.Join("prebuilts", "sdk", sdkVersion.ApiLevel.String(), sdkVersion.Kind.String()) |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 105 | jar := filepath.Join(dir, "android.jar") |
| 106 | // There's no aidl for other SDKs yet. |
| 107 | // TODO(77525052): Add aidl files for other SDKs too. |
Jiyong Park | 54105c4 | 2021-03-31 18:17:53 +0900 | [diff] [blame] | 108 | publicDir := filepath.Join("prebuilts", "sdk", sdkVersion.ApiLevel.String(), "public") |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 109 | aidl := filepath.Join(publicDir, "framework.aidl") |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 110 | jarPath := android.ExistentPathForSource(ctx, jar) |
| 111 | aidlPath := android.ExistentPathForSource(ctx, aidl) |
| 112 | lambdaStubsPath := android.PathForSource(ctx, config.SdkLambdaStubsPath) |
| 113 | |
| 114 | if (!jarPath.Valid() || !aidlPath.Valid()) && ctx.Config().AllowMissingDependencies() { |
| 115 | return sdkDep{ |
| 116 | invalidVersion: true, |
Jiyong Park | 54105c4 | 2021-03-31 18:17:53 +0900 | [diff] [blame] | 117 | bootclasspath: []string{fmt.Sprintf("sdk_%s_%s_android", sdkVersion.Kind, sdkVersion.ApiLevel.String())}, |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 118 | } |
| 119 | } |
| 120 | |
| 121 | if !jarPath.Valid() { |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 122 | ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", sdkVersion.Raw, jar) |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 123 | return sdkDep{} |
| 124 | } |
| 125 | |
| 126 | if !aidlPath.Valid() { |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 127 | ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", sdkVersion.Raw, aidl) |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 128 | return sdkDep{} |
| 129 | } |
| 130 | |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 131 | var systemModules string |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 132 | if defaultJavaLanguageVersion(ctx, sdkVersion).usesJavaModules() { |
Paul Duffin | 004547f | 2021-10-29 13:50:24 +0100 | [diff] [blame] | 133 | systemModuleKind := systemModuleKind(sdkVersion.Kind, sdkVersion.ApiLevel) |
Paul Duffin | 1cad3a5 | 2021-10-29 13:30:59 +0100 | [diff] [blame] | 134 | systemModules = fmt.Sprintf("sdk_%s_%s_system_modules", systemModuleKind, sdkVersion.ApiLevel) |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 137 | return sdkDep{ |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 138 | useFiles: true, |
| 139 | jars: android.Paths{jarPath.Path(), lambdaStubsPath}, |
| 140 | aidl: android.OptionalPathForPath(aidlPath.Path()), |
| 141 | systemModules: systemModules, |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 142 | } |
| 143 | } |
| 144 | |
Paul Duffin | e5ad90c | 2021-11-03 16:44:22 +0000 | [diff] [blame] | 145 | toModule := func(module string, aidl android.Path) sdkDep { |
| 146 | // Select the kind of system modules needed for the sdk version. |
| 147 | systemModulesKind := systemModuleKind(sdkVersion.Kind, android.FutureApiLevel) |
Jihoon Kang | 6c0df88 | 2023-06-14 22:43:25 +0000 | [diff] [blame] | 148 | systemModules := fmt.Sprintf("core-%s-stubs-system-modules", systemModulesKind) |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 149 | return sdkDep{ |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 150 | useModule: true, |
Jihoon Kang | 91c8395 | 2023-05-30 19:12:28 +0000 | [diff] [blame] | 151 | bootclasspath: []string{module, config.DefaultLambdaStubsLibrary}, |
Spandan Das | e339a2d | 2023-03-30 02:59:22 +0000 | [diff] [blame] | 152 | systemModules: systemModules, |
Paul Duffin | e9758b0 | 2021-10-28 11:43:21 +0100 | [diff] [blame] | 153 | java9Classpath: []string{module}, |
| 154 | frameworkResModule: "framework-res", |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 155 | aidl: android.OptionalPathForPath(aidl), |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 156 | } |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 157 | } |
| 158 | |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 159 | switch sdkVersion.Kind { |
| 160 | case android.SdkPrivate: |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 161 | return sdkDep{ |
Pete Gillin | e3d44b2 | 2020-06-29 11:28:51 +0100 | [diff] [blame] | 162 | useModule: true, |
Pete Gillin | 84c3807 | 2020-07-09 18:03:41 +0100 | [diff] [blame] | 163 | systemModules: corePlatformSystemModules(ctx), |
| 164 | bootclasspath: corePlatformBootclasspathLibraries(ctx), |
Pete Gillin | e3d44b2 | 2020-06-29 11:28:51 +0100 | [diff] [blame] | 165 | classpath: config.FrameworkLibraries, |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 166 | frameworkResModule: "framework-res", |
| 167 | } |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 168 | case android.SdkNone: |
| 169 | systemModules := sdkContext.SystemModules() |
Paul Duffin | e25c644 | 2019-10-11 13:50:28 +0100 | [diff] [blame] | 170 | if systemModules == "" { |
| 171 | ctx.PropertyErrorf("sdk_version", |
| 172 | `system_modules is required to be set to a non-empty value when sdk_version is "none", did you mean sdk_version: "core_platform"?`) |
| 173 | } else if systemModules == "none" { |
Colin Cross | 6d8d8c6 | 2019-10-28 15:10:03 -0700 | [diff] [blame] | 174 | return sdkDep{ |
| 175 | noStandardLibs: true, |
| 176 | } |
Paul Duffin | e25c644 | 2019-10-11 13:50:28 +0100 | [diff] [blame] | 177 | } |
| 178 | |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 179 | return sdkDep{ |
Colin Cross | 6d8d8c6 | 2019-10-28 15:10:03 -0700 | [diff] [blame] | 180 | useModule: true, |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 181 | noStandardLibs: true, |
Paul Duffin | e25c644 | 2019-10-11 13:50:28 +0100 | [diff] [blame] | 182 | systemModules: systemModules, |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 183 | bootclasspath: []string{systemModules}, |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 184 | } |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 185 | case android.SdkCorePlatform: |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 186 | return sdkDep{ |
Pete Gillin | 7b0bdce | 2020-07-01 13:05:32 +0100 | [diff] [blame] | 187 | useModule: true, |
Pete Gillin | 84c3807 | 2020-07-09 18:03:41 +0100 | [diff] [blame] | 188 | systemModules: corePlatformSystemModules(ctx), |
| 189 | bootclasspath: corePlatformBootclasspathLibraries(ctx), |
Pete Gillin | 7b0bdce | 2020-07-01 13:05:32 +0100 | [diff] [blame] | 190 | noFrameworksLibs: true, |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 191 | } |
Mark White | 9421c4c | 2023-08-10 00:07:03 +0000 | [diff] [blame] | 192 | case android.SdkPublic, android.SdkSystem, android.SdkTest, android.SdkTestFrameworksCore: |
Jihoon Kang | 91c8395 | 2023-05-30 19:12:28 +0000 | [diff] [blame] | 193 | return toModule(sdkVersion.Kind.DefaultJavaLibraryName(), sdkFrameworkAidlPath(ctx)) |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 194 | case android.SdkCore: |
Pete Gillin | 880f964 | 2020-07-01 13:17:16 +0100 | [diff] [blame] | 195 | return sdkDep{ |
| 196 | useModule: true, |
Jihoon Kang | 91c8395 | 2023-05-30 19:12:28 +0000 | [diff] [blame] | 197 | bootclasspath: []string{android.SdkCore.DefaultJavaLibraryName(), config.DefaultLambdaStubsLibrary}, |
Jihoon Kang | 6c0df88 | 2023-06-14 22:43:25 +0000 | [diff] [blame] | 198 | systemModules: "core-public-stubs-system-modules", |
Pete Gillin | 880f964 | 2020-07-01 13:17:16 +0100 | [diff] [blame] | 199 | noFrameworksLibs: true, |
| 200 | } |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 201 | case android.SdkModule: |
Jiyong Park | 50146e9 | 2020-01-30 18:00:15 +0900 | [diff] [blame] | 202 | // TODO(146757305): provide .apk and .aidl that have more APIs for modules |
Jihoon Kang | 91c8395 | 2023-05-30 19:12:28 +0000 | [diff] [blame] | 203 | return toModule(sdkVersion.Kind.DefaultJavaLibraryName(), nonUpdatableFrameworkAidlPath(ctx)) |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 204 | case android.SdkSystemServer: |
Jiyong Park | aae9bd1 | 2020-02-12 04:36:43 +0900 | [diff] [blame] | 205 | // TODO(146757305): provide .apk and .aidl that have more APIs for modules |
Jihoon Kang | 91c8395 | 2023-05-30 19:12:28 +0000 | [diff] [blame] | 206 | return toModule(sdkVersion.Kind.DefaultJavaLibraryName(), sdkFrameworkAidlPath(ctx)) |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 207 | default: |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 208 | panic(fmt.Errorf("invalid sdk %q", sdkVersion.Raw)) |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 209 | } |
| 210 | } |
Colin Cross | 98fd574 | 2019-01-09 23:04:25 -0800 | [diff] [blame] | 211 | |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 212 | func sdkSingletonFactory() android.Singleton { |
| 213 | return sdkSingleton{} |
| 214 | } |
| 215 | |
| 216 | type sdkSingleton struct{} |
| 217 | |
| 218 | func (sdkSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
Dan Willemsen | 9f43597 | 2020-05-28 15:28:00 -0700 | [diff] [blame] | 219 | if ctx.Config().AlwaysUsePrebuiltSdks() { |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 220 | return |
| 221 | } |
| 222 | |
Colin Cross | 1093287 | 2019-04-18 14:27:12 -0700 | [diff] [blame] | 223 | createSdkFrameworkAidl(ctx) |
Anton Hansson | 3f07ab2 | 2020-04-09 13:29:59 +0100 | [diff] [blame] | 224 | createNonUpdatableFrameworkAidl(ctx) |
Colin Cross | 1093287 | 2019-04-18 14:27:12 -0700 | [diff] [blame] | 225 | createAPIFingerprint(ctx) |
| 226 | } |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 227 | |
Colin Cross | 1093287 | 2019-04-18 14:27:12 -0700 | [diff] [blame] | 228 | // Create framework.aidl by extracting anything that implements android.os.Parcelable from the SDK stubs modules. |
| 229 | func createSdkFrameworkAidl(ctx android.SingletonContext) { |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 230 | stubsModules := []string{ |
Jihoon Kang | 91c8395 | 2023-05-30 19:12:28 +0000 | [diff] [blame] | 231 | android.SdkPublic.DefaultJavaLibraryName(), |
| 232 | android.SdkTest.DefaultJavaLibraryName(), |
| 233 | android.SdkSystem.DefaultJavaLibraryName(), |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 234 | } |
| 235 | |
Anton Hansson | 3f07ab2 | 2020-04-09 13:29:59 +0100 | [diff] [blame] | 236 | combinedAidl := sdkFrameworkAidlPath(ctx) |
Paul Duffin | d3c1513 | 2021-04-21 22:12:35 +0100 | [diff] [blame] | 237 | tempPath := tempPathForRestat(ctx, combinedAidl) |
Anton Hansson | 3f07ab2 | 2020-04-09 13:29:59 +0100 | [diff] [blame] | 238 | |
| 239 | rule := createFrameworkAidl(stubsModules, tempPath, ctx) |
| 240 | |
| 241 | commitChangeForRestat(rule, tempPath, combinedAidl) |
| 242 | |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 243 | rule.Build("framework_aidl", "generate framework.aidl") |
Anton Hansson | 3f07ab2 | 2020-04-09 13:29:59 +0100 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | // Creates a version of framework.aidl for the non-updatable part of the platform. |
| 247 | func createNonUpdatableFrameworkAidl(ctx android.SingletonContext) { |
Jihoon Kang | 91c8395 | 2023-05-30 19:12:28 +0000 | [diff] [blame] | 248 | stubsModules := []string{android.SdkModule.DefaultJavaLibraryName()} |
Anton Hansson | 3f07ab2 | 2020-04-09 13:29:59 +0100 | [diff] [blame] | 249 | |
| 250 | combinedAidl := nonUpdatableFrameworkAidlPath(ctx) |
Paul Duffin | d3c1513 | 2021-04-21 22:12:35 +0100 | [diff] [blame] | 251 | tempPath := tempPathForRestat(ctx, combinedAidl) |
Anton Hansson | 3f07ab2 | 2020-04-09 13:29:59 +0100 | [diff] [blame] | 252 | |
| 253 | rule := createFrameworkAidl(stubsModules, tempPath, ctx) |
| 254 | |
| 255 | commitChangeForRestat(rule, tempPath, combinedAidl) |
| 256 | |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 257 | rule.Build("framework_non_updatable_aidl", "generate framework_non_updatable.aidl") |
Anton Hansson | 3f07ab2 | 2020-04-09 13:29:59 +0100 | [diff] [blame] | 258 | } |
| 259 | |
Paul Duffin | d3c1513 | 2021-04-21 22:12:35 +0100 | [diff] [blame] | 260 | func createFrameworkAidl(stubsModules []string, path android.WritablePath, ctx android.SingletonContext) *android.RuleBuilder { |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 261 | stubsJars := make([]android.Paths, len(stubsModules)) |
| 262 | |
| 263 | ctx.VisitAllModules(func(module android.Module) { |
| 264 | // Collect dex jar paths for the modules listed above. |
Colin Cross | 5a37718 | 2023-12-14 14:46:23 -0800 | [diff] [blame] | 265 | if j, ok := android.SingletonModuleProvider(ctx, module, JavaInfoProvider); ok { |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 266 | name := ctx.ModuleName(module) |
| 267 | if i := android.IndexList(name, stubsModules); i != -1 { |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 268 | stubsJars[i] = j.HeaderJars |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 269 | } |
| 270 | } |
| 271 | }) |
| 272 | |
| 273 | var missingDeps []string |
| 274 | |
| 275 | for i := range stubsJars { |
| 276 | if stubsJars[i] == nil { |
| 277 | if ctx.Config().AllowMissingDependencies() { |
| 278 | missingDeps = append(missingDeps, stubsModules[i]) |
| 279 | } else { |
Anton Hansson | 3f07ab2 | 2020-04-09 13:29:59 +0100 | [diff] [blame] | 280 | ctx.Errorf("failed to find dex jar path for module %q", stubsModules[i]) |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 281 | } |
| 282 | } |
| 283 | } |
| 284 | |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 285 | rule := android.NewRuleBuilder(pctx, ctx) |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 286 | rule.MissingDeps(missingDeps) |
| 287 | |
| 288 | var aidls android.Paths |
| 289 | for _, jars := range stubsJars { |
| 290 | for _, jar := range jars { |
| 291 | aidl := android.PathForOutput(ctx, "aidl", pathtools.ReplaceExtension(jar.Base(), "aidl")) |
| 292 | |
| 293 | rule.Command(). |
| 294 | Text("rm -f").Output(aidl) |
| 295 | rule.Command(). |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 296 | BuiltTool("sdkparcelables"). |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 297 | Input(jar). |
| 298 | Output(aidl) |
| 299 | |
| 300 | aidls = append(aidls, aidl) |
| 301 | } |
| 302 | } |
| 303 | |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 304 | rule.Command(). |
Anton Hansson | 3f07ab2 | 2020-04-09 13:29:59 +0100 | [diff] [blame] | 305 | Text("rm -f").Output(path) |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 306 | rule.Command(). |
| 307 | Text("cat"). |
| 308 | Inputs(aidls). |
| 309 | Text("| sort -u >"). |
Anton Hansson | 3f07ab2 | 2020-04-09 13:29:59 +0100 | [diff] [blame] | 310 | Output(path) |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 311 | |
Anton Hansson | 3f07ab2 | 2020-04-09 13:29:59 +0100 | [diff] [blame] | 312 | return rule |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | func sdkFrameworkAidlPath(ctx android.PathContext) android.OutputPath { |
| 316 | return ctx.Config().Once(sdkFrameworkAidlPathKey, func() interface{} { |
| 317 | return android.PathForOutput(ctx, "framework.aidl") |
| 318 | }).(android.OutputPath) |
| 319 | } |
| 320 | |
Anton Hansson | 3f07ab2 | 2020-04-09 13:29:59 +0100 | [diff] [blame] | 321 | func nonUpdatableFrameworkAidlPath(ctx android.PathContext) android.OutputPath { |
| 322 | return ctx.Config().Once(nonUpdatableFrameworkAidlPathKey, func() interface{} { |
| 323 | return android.PathForOutput(ctx, "framework_non_updatable.aidl") |
| 324 | }).(android.OutputPath) |
| 325 | } |
| 326 | |
Colin Cross | 1093287 | 2019-04-18 14:27:12 -0700 | [diff] [blame] | 327 | // Create api_fingerprint.txt |
| 328 | func createAPIFingerprint(ctx android.SingletonContext) { |
Jiyong Park | 71b519d | 2019-04-18 17:25:49 +0900 | [diff] [blame] | 329 | out := ApiFingerprintPath(ctx) |
Colin Cross | 1093287 | 2019-04-18 14:27:12 -0700 | [diff] [blame] | 330 | |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 331 | rule := android.NewRuleBuilder(pctx, ctx) |
Colin Cross | 1093287 | 2019-04-18 14:27:12 -0700 | [diff] [blame] | 332 | |
| 333 | rule.Command(). |
| 334 | Text("rm -f").Output(out) |
| 335 | cmd := rule.Command() |
| 336 | |
| 337 | if ctx.Config().PlatformSdkCodename() == "REL" { |
| 338 | cmd.Text("echo REL >").Output(out) |
Anton Hansson | 973d31c | 2021-02-10 14:52:42 +0000 | [diff] [blame] | 339 | } else if ctx.Config().FrameworksBaseDirExists(ctx) && !ctx.Config().AlwaysUsePrebuiltSdks() { |
| 340 | cmd.Text("cat") |
| 341 | apiTxtFileModules := []string{ |
Zi Wang | b31a833 | 2023-03-06 15:21:35 -0800 | [diff] [blame] | 342 | "api_fingerprint", |
Colin Cross | 1093287 | 2019-04-18 14:27:12 -0700 | [diff] [blame] | 343 | } |
Anton Hansson | 973d31c | 2021-02-10 14:52:42 +0000 | [diff] [blame] | 344 | count := 0 |
| 345 | ctx.VisitAllModules(func(module android.Module) { |
| 346 | name := ctx.ModuleName(module) |
| 347 | if android.InList(name, apiTxtFileModules) { |
| 348 | cmd.Inputs(android.OutputFilesForModule(ctx, module, "")) |
| 349 | count++ |
| 350 | } |
| 351 | }) |
| 352 | if count != len(apiTxtFileModules) { |
Zi Wang | b31a833 | 2023-03-06 15:21:35 -0800 | [diff] [blame] | 353 | ctx.Errorf("Could not find expected API module %v, found %d\n", apiTxtFileModules, count) |
Anton Hansson | 973d31c | 2021-02-10 14:52:42 +0000 | [diff] [blame] | 354 | return |
| 355 | } |
Zi Wang | b31a833 | 2023-03-06 15:21:35 -0800 | [diff] [blame] | 356 | cmd.Text(">"). |
Colin Cross | 1093287 | 2019-04-18 14:27:12 -0700 | [diff] [blame] | 357 | Output(out) |
| 358 | } else { |
| 359 | // Unbundled build |
| 360 | // TODO: use a prebuilt api_fingerprint.txt from prebuilts/sdk/current.txt once we have one |
| 361 | cmd.Text("echo"). |
| 362 | Flag(ctx.Config().PlatformPreviewSdkVersion()). |
| 363 | Text(">"). |
| 364 | Output(out) |
| 365 | } |
| 366 | |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 367 | rule.Build("api_fingerprint", "generate api_fingerprint.txt") |
Colin Cross | 1093287 | 2019-04-18 14:27:12 -0700 | [diff] [blame] | 368 | } |
| 369 | |
Jiyong Park | 71b519d | 2019-04-18 17:25:49 +0900 | [diff] [blame] | 370 | func ApiFingerprintPath(ctx android.PathContext) android.OutputPath { |
Colin Cross | 1093287 | 2019-04-18 14:27:12 -0700 | [diff] [blame] | 371 | return ctx.Config().Once(apiFingerprintPathKey, func() interface{} { |
| 372 | return android.PathForOutput(ctx, "api_fingerprint.txt") |
| 373 | }).(android.OutputPath) |
| 374 | } |
| 375 | |
| 376 | func sdkMakeVars(ctx android.MakeVarsContext) { |
Dan Willemsen | 9f43597 | 2020-05-28 15:28:00 -0700 | [diff] [blame] | 377 | if ctx.Config().AlwaysUsePrebuiltSdks() { |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 378 | return |
| 379 | } |
| 380 | |
| 381 | ctx.Strict("FRAMEWORK_AIDL", sdkFrameworkAidlPath(ctx).String()) |
Jiyong Park | 71b519d | 2019-04-18 17:25:49 +0900 | [diff] [blame] | 382 | ctx.Strict("API_FINGERPRINT", ApiFingerprintPath(ctx).String()) |
Colin Cross | 98fd574 | 2019-01-09 23:04:25 -0800 | [diff] [blame] | 383 | } |