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 | 98fd574 | 2019-01-09 23:04:25 -0800 | [diff] [blame] | 20 | "sort" |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 21 | "strconv" |
| 22 | "strings" |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 23 | |
Jaewoong Jung | 9befb0c | 2020-01-18 10:33:43 -0800 | [diff] [blame] | 24 | "android/soong/android" |
| 25 | "android/soong/java/config" |
| 26 | |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 27 | "github.com/google/blueprint/pathtools" |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 28 | ) |
| 29 | |
Colin Cross | 98fd574 | 2019-01-09 23:04:25 -0800 | [diff] [blame] | 30 | func init() { |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 31 | android.RegisterPreSingletonType("sdk_versions", sdkPreSingletonFactory) |
| 32 | android.RegisterSingletonType("sdk", sdkSingletonFactory) |
Colin Cross | 1093287 | 2019-04-18 14:27:12 -0700 | [diff] [blame] | 33 | android.RegisterMakeVarsProvider(pctx, sdkMakeVars) |
Colin Cross | 98fd574 | 2019-01-09 23:04:25 -0800 | [diff] [blame] | 34 | } |
| 35 | |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 36 | var sdkVersionsKey = android.NewOnceKey("sdkVersionsKey") |
| 37 | var sdkFrameworkAidlPathKey = android.NewOnceKey("sdkFrameworkAidlPathKey") |
Anton Hansson | 3f07ab2 | 2020-04-09 13:29:59 +0100 | [diff] [blame] | 38 | var nonUpdatableFrameworkAidlPathKey = android.NewOnceKey("nonUpdatableFrameworkAidlPathKey") |
Colin Cross | 1093287 | 2019-04-18 14:27:12 -0700 | [diff] [blame] | 39 | var apiFingerprintPathKey = android.NewOnceKey("apiFingerprintPathKey") |
Colin Cross | 98fd574 | 2019-01-09 23:04:25 -0800 | [diff] [blame] | 40 | |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 41 | type sdkContext interface { |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 42 | // sdkVersion returns sdkSpec that corresponds to the sdk_version property of the current module |
| 43 | sdkVersion() sdkSpec |
Paul Duffin | e25c644 | 2019-10-11 13:50:28 +0100 | [diff] [blame] | 44 | // systemModules returns the system_modules property of the current module, or an empty string if it is not set. |
| 45 | systemModules() string |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 46 | // minSdkVersion returns sdkSpec that corresponds to the min_sdk_version property of the current module, |
| 47 | // or from sdk_version if it is not set. |
| 48 | minSdkVersion() sdkSpec |
| 49 | // targetSdkVersion returns the sdkSpec that corresponds to the target_sdk_version property of the current module, |
| 50 | // or from sdk_version if it is not set. |
| 51 | targetSdkVersion() sdkSpec |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 52 | } |
| 53 | |
Nikita Ioffe | 1f4f345 | 2020-03-02 16:58:11 +0000 | [diff] [blame] | 54 | func UseApiFingerprint(ctx android.BaseModuleContext) bool { |
| 55 | if ctx.Config().UnbundledBuild() && |
Jeongik Cha | 816a23a | 2020-07-08 01:09:23 +0900 | [diff] [blame] | 56 | !ctx.Config().AlwaysUsePrebuiltSdks() && |
Baligh Uddin | f620137 | 2020-01-24 23:15:44 +0000 | [diff] [blame] | 57 | ctx.Config().IsEnvTrue("UNBUNDLED_BUILD_TARGET_SDK_WITH_API_FINGERPRINT") { |
| 58 | return true |
| 59 | } |
| 60 | return false |
| 61 | } |
| 62 | |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 63 | // sdkKind represents a particular category of an SDK spec like public, system, test, etc. |
| 64 | type sdkKind int |
| 65 | |
| 66 | const ( |
| 67 | sdkInvalid sdkKind = iota |
| 68 | sdkNone |
| 69 | sdkCore |
| 70 | sdkCorePlatform |
| 71 | sdkPublic |
| 72 | sdkSystem |
| 73 | sdkTest |
Jiyong Park | 50146e9 | 2020-01-30 18:00:15 +0900 | [diff] [blame] | 74 | sdkModule |
Jiyong Park | aae9bd1 | 2020-02-12 04:36:43 +0900 | [diff] [blame] | 75 | sdkSystemServer |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 76 | sdkPrivate |
| 77 | ) |
| 78 | |
| 79 | // String returns the string representation of this sdkKind |
| 80 | func (k sdkKind) String() string { |
| 81 | switch k { |
| 82 | case sdkPrivate: |
| 83 | return "private" |
| 84 | case sdkNone: |
| 85 | return "none" |
| 86 | case sdkPublic: |
| 87 | return "public" |
| 88 | case sdkSystem: |
| 89 | return "system" |
| 90 | case sdkTest: |
| 91 | return "test" |
| 92 | case sdkCore: |
| 93 | return "core" |
| 94 | case sdkCorePlatform: |
| 95 | return "core_platform" |
Jiyong Park | 50146e9 | 2020-01-30 18:00:15 +0900 | [diff] [blame] | 96 | case sdkModule: |
Jiyong Park | 49062c8 | 2020-06-17 12:11:14 +0900 | [diff] [blame] | 97 | return "module-lib" |
Jiyong Park | aae9bd1 | 2020-02-12 04:36:43 +0900 | [diff] [blame] | 98 | case sdkSystemServer: |
Jiyong Park | 49062c8 | 2020-06-17 12:11:14 +0900 | [diff] [blame] | 99 | return "system-server" |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 100 | default: |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 101 | return "invalid" |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 102 | } |
| 103 | } |
| 104 | |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 105 | // sdkVersion represents a specific version number of an SDK spec of a particular kind |
| 106 | type sdkVersion int |
| 107 | |
| 108 | const ( |
| 109 | // special version number for a not-yet-frozen SDK |
Dan Albert | 0b176c8 | 2020-07-23 16:43:25 -0700 | [diff] [blame] | 110 | sdkVersionCurrent sdkVersion = sdkVersion(android.FutureApiLevelInt) |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 111 | // special version number to be used for SDK specs where version number doesn't |
| 112 | // make sense, e.g. "none", "", etc. |
| 113 | sdkVersionNone sdkVersion = sdkVersion(0) |
| 114 | ) |
| 115 | |
| 116 | // isCurrent checks if the sdkVersion refers to the not-yet-published version of an sdkKind |
| 117 | func (v sdkVersion) isCurrent() bool { |
| 118 | return v == sdkVersionCurrent |
| 119 | } |
| 120 | |
| 121 | // isNumbered checks if the sdkVersion refers to the published (a.k.a numbered) version of an sdkKind |
| 122 | func (v sdkVersion) isNumbered() bool { |
| 123 | return !v.isCurrent() && v != sdkVersionNone |
| 124 | } |
| 125 | |
| 126 | // String returns the string representation of this sdkVersion. |
| 127 | func (v sdkVersion) String() string { |
| 128 | if v.isCurrent() { |
| 129 | return "current" |
| 130 | } else if v.isNumbered() { |
| 131 | return strconv.Itoa(int(v)) |
| 132 | } |
| 133 | return "(no version)" |
| 134 | } |
| 135 | |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 136 | func (v sdkVersion) ApiLevel(ctx android.EarlyModuleContext) android.ApiLevel { |
| 137 | return android.ApiLevelOrPanic(ctx, v.String()) |
| 138 | } |
| 139 | |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 140 | // asNumberString directly converts the numeric value of this sdk version as a string. |
| 141 | // When isNumbered() is true, this method is the same as String(). However, for sdkVersionCurrent |
| 142 | // and sdkVersionNone, this returns 10000 and 0 while String() returns "current" and "(no version"), |
| 143 | // respectively. |
| 144 | func (v sdkVersion) asNumberString() string { |
| 145 | return strconv.Itoa(int(v)) |
| 146 | } |
| 147 | |
| 148 | // sdkSpec represents the kind and the version of an SDK for a module to build against |
| 149 | type sdkSpec struct { |
| 150 | kind sdkKind |
| 151 | version sdkVersion |
| 152 | raw string |
| 153 | } |
| 154 | |
Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 155 | func (s sdkSpec) String() string { |
| 156 | return fmt.Sprintf("%s_%s", s.kind, s.version) |
| 157 | } |
| 158 | |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 159 | // valid checks if this sdkSpec is well-formed. Note however that true doesn't mean that the |
| 160 | // specified SDK actually exists. |
| 161 | func (s sdkSpec) valid() bool { |
| 162 | return s.kind != sdkInvalid |
| 163 | } |
| 164 | |
| 165 | // specified checks if this sdkSpec is well-formed and is not "". |
| 166 | func (s sdkSpec) specified() bool { |
| 167 | return s.valid() && s.kind != sdkPrivate |
| 168 | } |
| 169 | |
Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 170 | // whether the API surface is managed and versioned, i.e. has .txt file that |
| 171 | // get frozen on SDK freeze and changes get reviewed by API council. |
| 172 | func (s sdkSpec) stable() bool { |
| 173 | if !s.specified() { |
| 174 | return false |
| 175 | } |
| 176 | switch s.kind { |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 177 | case sdkNone: |
| 178 | // there is nothing to manage and version in this case; de facto stable API. |
| 179 | return true |
Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 180 | case sdkCore, sdkPublic, sdkSystem, sdkModule, sdkSystemServer: |
| 181 | return true |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 182 | case sdkCorePlatform, sdkTest, sdkPrivate: |
Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 183 | return false |
| 184 | default: |
| 185 | panic(fmt.Errorf("unknown sdkKind=%v", s.kind)) |
| 186 | } |
| 187 | return false |
| 188 | } |
| 189 | |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 190 | // prebuiltSdkAvailableForUnbundledBuilt tells whether this sdkSpec can have a prebuilt SDK |
| 191 | // that can be used for unbundled builds. |
| 192 | func (s sdkSpec) prebuiltSdkAvailableForUnbundledBuild() bool { |
| 193 | // "", "none", and "core_platform" are not available for unbundled build |
| 194 | // as we don't/can't have prebuilt stub for the versions |
| 195 | return s.kind != sdkPrivate && s.kind != sdkNone && s.kind != sdkCorePlatform |
| 196 | } |
| 197 | |
Jeongik Cha | 219141c | 2020-08-06 23:00:37 +0900 | [diff] [blame] | 198 | func (s sdkSpec) forVendorPartition(ctx android.EarlyModuleContext) sdkSpec { |
| 199 | // If BOARD_CURRENT_API_LEVEL_FOR_VENDOR_MODULES has a numeric value, |
| 200 | // use it instead of "current" for the vendor partition. |
| 201 | currentSdkVersion := ctx.DeviceConfig().CurrentApiLevelForVendorModules() |
| 202 | if currentSdkVersion == "current" { |
| 203 | return s |
| 204 | } |
| 205 | |
| 206 | if s.kind == sdkPublic || s.kind == sdkSystem { |
| 207 | if s.version.isCurrent() { |
| 208 | if i, err := strconv.Atoi(currentSdkVersion); err == nil { |
| 209 | version := sdkVersion(i) |
| 210 | return sdkSpec{s.kind, version, s.raw} |
| 211 | } |
| 212 | panic(fmt.Errorf("BOARD_CURRENT_API_LEVEL_FOR_VENDOR_MODULES must be either \"current\" or a number, but was %q", currentSdkVersion)) |
| 213 | } |
| 214 | } |
| 215 | return s |
| 216 | } |
| 217 | |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 218 | // usePrebuilt determines whether prebuilt SDK should be used for this sdkSpec with the given context. |
| 219 | func (s sdkSpec) usePrebuilt(ctx android.EarlyModuleContext) bool { |
| 220 | if s.version.isCurrent() { |
| 221 | // "current" can be built from source and be from prebuilt SDK |
Jeongik Cha | 816a23a | 2020-07-08 01:09:23 +0900 | [diff] [blame] | 222 | return ctx.Config().AlwaysUsePrebuiltSdks() |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 223 | } else if s.version.isNumbered() { |
Patrice Arruda | b481b87 | 2020-07-28 18:30:44 +0000 | [diff] [blame] | 224 | // validation check |
Paul Duffin | fb6ae5b | 2020-09-30 15:17:25 +0100 | [diff] [blame] | 225 | if s.kind != sdkPublic && s.kind != sdkSystem && s.kind != sdkTest && s.kind != sdkModule { |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 226 | panic(fmt.Errorf("prebuilt SDK is not not available for sdkKind=%q", s.kind)) |
| 227 | return false |
| 228 | } |
| 229 | // numbered SDKs are always from prebuilt |
| 230 | return true |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 231 | } |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 232 | // "", "none", "core_platform" fall here |
| 233 | return false |
| 234 | } |
| 235 | |
| 236 | // effectiveVersion converts an sdkSpec into the concrete sdkVersion that the module |
| 237 | // should use. For modules targeting an unreleased SDK (meaning it does not yet have a number) |
| 238 | // it returns android.FutureApiLevel(10000). |
| 239 | func (s sdkSpec) effectiveVersion(ctx android.EarlyModuleContext) (sdkVersion, error) { |
| 240 | if !s.valid() { |
| 241 | return s.version, fmt.Errorf("invalid sdk version %q", s.raw) |
| 242 | } |
Jeongik Cha | 219141c | 2020-08-06 23:00:37 +0900 | [diff] [blame] | 243 | |
| 244 | if ctx.DeviceSpecific() || ctx.SocSpecific() { |
| 245 | s = s.forVendorPartition(ctx) |
| 246 | } |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 247 | if s.version.isNumbered() { |
| 248 | return s.version, nil |
| 249 | } |
Dan Albert | 4f378d7 | 2020-07-23 17:32:15 -0700 | [diff] [blame] | 250 | return sdkVersion(ctx.Config().DefaultAppTargetSdk(ctx).FinalOrFutureInt()), nil |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | // effectiveVersionString converts an sdkSpec into the concrete version string that the module |
| 254 | // should use. For modules targeting an unreleased SDK (meaning it does not yet have a number) |
| 255 | // it returns the codename (P, Q, R, etc.) |
| 256 | func (s sdkSpec) effectiveVersionString(ctx android.EarlyModuleContext) (string, error) { |
| 257 | ver, err := s.effectiveVersion(ctx) |
Dan Albert | 4f378d7 | 2020-07-23 17:32:15 -0700 | [diff] [blame] | 258 | if err == nil && int(ver) == ctx.Config().DefaultAppTargetSdk(ctx).FinalOrFutureInt() { |
| 259 | return ctx.Config().DefaultAppTargetSdk(ctx).String(), nil |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 260 | } |
| 261 | return ver.String(), err |
| 262 | } |
| 263 | |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 264 | func (s sdkSpec) defaultJavaLanguageVersion(ctx android.EarlyModuleContext) javaVersion { |
| 265 | sdk, err := s.effectiveVersion(ctx) |
| 266 | if err != nil { |
| 267 | ctx.PropertyErrorf("sdk_version", "%s", err) |
| 268 | } |
| 269 | if sdk <= 23 { |
| 270 | return JAVA_VERSION_7 |
| 271 | } else if sdk <= 29 { |
| 272 | return JAVA_VERSION_8 |
| 273 | } else { |
| 274 | return JAVA_VERSION_9 |
| 275 | } |
| 276 | } |
| 277 | |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 278 | func sdkSpecFrom(str string) sdkSpec { |
| 279 | switch str { |
| 280 | // special cases first |
| 281 | case "": |
| 282 | return sdkSpec{sdkPrivate, sdkVersionNone, str} |
| 283 | case "none": |
| 284 | return sdkSpec{sdkNone, sdkVersionNone, str} |
| 285 | case "core_platform": |
| 286 | return sdkSpec{sdkCorePlatform, sdkVersionNone, str} |
| 287 | default: |
| 288 | // the syntax is [kind_]version |
| 289 | sep := strings.LastIndex(str, "_") |
| 290 | |
| 291 | var kindString string |
| 292 | if sep == 0 { |
| 293 | return sdkSpec{sdkInvalid, sdkVersionNone, str} |
| 294 | } else if sep == -1 { |
| 295 | kindString = "" |
| 296 | } else { |
| 297 | kindString = str[0:sep] |
| 298 | } |
| 299 | versionString := str[sep+1 : len(str)] |
| 300 | |
| 301 | var kind sdkKind |
| 302 | switch kindString { |
| 303 | case "": |
| 304 | kind = sdkPublic |
| 305 | case "core": |
| 306 | kind = sdkCore |
| 307 | case "system": |
| 308 | kind = sdkSystem |
| 309 | case "test": |
| 310 | kind = sdkTest |
Jiyong Park | 50146e9 | 2020-01-30 18:00:15 +0900 | [diff] [blame] | 311 | case "module": |
| 312 | kind = sdkModule |
Jiyong Park | aae9bd1 | 2020-02-12 04:36:43 +0900 | [diff] [blame] | 313 | case "system_server": |
| 314 | kind = sdkSystemServer |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 315 | default: |
| 316 | return sdkSpec{sdkInvalid, sdkVersionNone, str} |
| 317 | } |
| 318 | |
| 319 | var version sdkVersion |
| 320 | if versionString == "current" { |
| 321 | version = sdkVersionCurrent |
| 322 | } else if i, err := strconv.Atoi(versionString); err == nil { |
| 323 | version = sdkVersion(i) |
| 324 | } else { |
| 325 | return sdkSpec{sdkInvalid, sdkVersionNone, str} |
| 326 | } |
| 327 | |
| 328 | return sdkSpec{kind, version, str} |
| 329 | } |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 330 | } |
| 331 | |
Jeongik Cha | 7c70831 | 2020-01-28 13:52:36 +0900 | [diff] [blame] | 332 | func (s sdkSpec) validateSystemSdk(ctx android.EarlyModuleContext) bool { |
| 333 | // Ensures that the specified system SDK version is one of BOARD_SYSTEMSDK_VERSIONS (for vendor/product Java module) |
| 334 | // Assuming that BOARD_SYSTEMSDK_VERSIONS := 28 29, |
| 335 | // sdk_version of the modules in vendor/product that use system sdk must be either system_28, system_29 or system_current |
| 336 | if s.kind != sdkSystem || !s.version.isNumbered() { |
| 337 | return true |
| 338 | } |
| 339 | allowedVersions := ctx.DeviceConfig().PlatformSystemSdkVersions() |
| 340 | if ctx.DeviceSpecific() || ctx.SocSpecific() || (ctx.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) { |
| 341 | systemSdkVersions := ctx.DeviceConfig().SystemSdkVersions() |
| 342 | if len(systemSdkVersions) > 0 { |
| 343 | allowedVersions = systemSdkVersions |
| 344 | } |
| 345 | } |
| 346 | if len(allowedVersions) > 0 && !android.InList(s.version.String(), allowedVersions) { |
| 347 | ctx.PropertyErrorf("sdk_version", "incompatible sdk version %q. System SDK version should be one of %q", |
| 348 | s.raw, allowedVersions) |
| 349 | return false |
| 350 | } |
| 351 | return true |
| 352 | } |
| 353 | |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 354 | func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext sdkContext) sdkDep { |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 355 | sdkVersion := sdkContext.sdkVersion() |
| 356 | if !sdkVersion.valid() { |
| 357 | ctx.PropertyErrorf("sdk_version", "invalid version %q", sdkVersion.raw) |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 358 | return sdkDep{} |
| 359 | } |
| 360 | |
Jeongik Cha | 219141c | 2020-08-06 23:00:37 +0900 | [diff] [blame] | 361 | if ctx.DeviceSpecific() || ctx.SocSpecific() { |
| 362 | sdkVersion = sdkVersion.forVendorPartition(ctx) |
| 363 | } |
| 364 | |
Jeongik Cha | 7c70831 | 2020-01-28 13:52:36 +0900 | [diff] [blame] | 365 | if !sdkVersion.validateSystemSdk(ctx) { |
| 366 | return sdkDep{} |
| 367 | } |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 368 | |
| 369 | if sdkVersion.usePrebuilt(ctx) { |
| 370 | dir := filepath.Join("prebuilts", "sdk", sdkVersion.version.String(), sdkVersion.kind.String()) |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 371 | jar := filepath.Join(dir, "android.jar") |
| 372 | // There's no aidl for other SDKs yet. |
| 373 | // TODO(77525052): Add aidl files for other SDKs too. |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 374 | publicDir := filepath.Join("prebuilts", "sdk", sdkVersion.version.String(), "public") |
| 375 | aidl := filepath.Join(publicDir, "framework.aidl") |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 376 | jarPath := android.ExistentPathForSource(ctx, jar) |
| 377 | aidlPath := android.ExistentPathForSource(ctx, aidl) |
| 378 | lambdaStubsPath := android.PathForSource(ctx, config.SdkLambdaStubsPath) |
| 379 | |
| 380 | if (!jarPath.Valid() || !aidlPath.Valid()) && ctx.Config().AllowMissingDependencies() { |
| 381 | return sdkDep{ |
| 382 | invalidVersion: true, |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 383 | bootclasspath: []string{fmt.Sprintf("sdk_%s_%s_android", sdkVersion.kind, sdkVersion.version.String())}, |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 384 | } |
| 385 | } |
| 386 | |
| 387 | if !jarPath.Valid() { |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 388 | 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] | 389 | return sdkDep{} |
| 390 | } |
| 391 | |
| 392 | if !aidlPath.Valid() { |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 393 | 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] | 394 | return sdkDep{} |
| 395 | } |
| 396 | |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 397 | var systemModules string |
| 398 | if sdkVersion.defaultJavaLanguageVersion(ctx).usesJavaModules() { |
| 399 | systemModules = "sdk_public_" + sdkVersion.version.String() + "_system_modules" |
| 400 | } |
| 401 | |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 402 | return sdkDep{ |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 403 | useFiles: true, |
| 404 | jars: android.Paths{jarPath.Path(), lambdaStubsPath}, |
| 405 | aidl: android.OptionalPathForPath(aidlPath.Path()), |
| 406 | systemModules: systemModules, |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 407 | } |
| 408 | } |
| 409 | |
Jiyong Park | aae9bd1 | 2020-02-12 04:36:43 +0900 | [diff] [blame] | 410 | toModule := func(modules []string, res string, aidl android.Path) sdkDep { |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 411 | return sdkDep{ |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 412 | useModule: true, |
Jiyong Park | aae9bd1 | 2020-02-12 04:36:43 +0900 | [diff] [blame] | 413 | bootclasspath: append(modules, config.DefaultLambdaStubsLibrary), |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 414 | systemModules: "core-current-stubs-system-modules", |
Jiyong Park | aae9bd1 | 2020-02-12 04:36:43 +0900 | [diff] [blame] | 415 | java9Classpath: modules, |
| 416 | frameworkResModule: res, |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 417 | aidl: android.OptionalPathForPath(aidl), |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 418 | } |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 419 | } |
| 420 | |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 421 | switch sdkVersion.kind { |
| 422 | case sdkPrivate: |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 423 | return sdkDep{ |
Pete Gillin | e3d44b2 | 2020-06-29 11:28:51 +0100 | [diff] [blame] | 424 | useModule: true, |
Pete Gillin | 84c3807 | 2020-07-09 18:03:41 +0100 | [diff] [blame] | 425 | systemModules: corePlatformSystemModules(ctx), |
| 426 | bootclasspath: corePlatformBootclasspathLibraries(ctx), |
Pete Gillin | e3d44b2 | 2020-06-29 11:28:51 +0100 | [diff] [blame] | 427 | classpath: config.FrameworkLibraries, |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 428 | frameworkResModule: "framework-res", |
| 429 | } |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 430 | case sdkNone: |
Paul Duffin | e25c644 | 2019-10-11 13:50:28 +0100 | [diff] [blame] | 431 | systemModules := sdkContext.systemModules() |
| 432 | if systemModules == "" { |
| 433 | ctx.PropertyErrorf("sdk_version", |
| 434 | `system_modules is required to be set to a non-empty value when sdk_version is "none", did you mean sdk_version: "core_platform"?`) |
| 435 | } else if systemModules == "none" { |
Colin Cross | 6d8d8c6 | 2019-10-28 15:10:03 -0700 | [diff] [blame] | 436 | return sdkDep{ |
| 437 | noStandardLibs: true, |
| 438 | } |
Paul Duffin | e25c644 | 2019-10-11 13:50:28 +0100 | [diff] [blame] | 439 | } |
| 440 | |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 441 | return sdkDep{ |
Colin Cross | 6d8d8c6 | 2019-10-28 15:10:03 -0700 | [diff] [blame] | 442 | useModule: true, |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 443 | noStandardLibs: true, |
Paul Duffin | e25c644 | 2019-10-11 13:50:28 +0100 | [diff] [blame] | 444 | systemModules: systemModules, |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 445 | bootclasspath: []string{systemModules}, |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 446 | } |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 447 | case sdkCorePlatform: |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 448 | return sdkDep{ |
Pete Gillin | 7b0bdce | 2020-07-01 13:05:32 +0100 | [diff] [blame] | 449 | useModule: true, |
Pete Gillin | 84c3807 | 2020-07-09 18:03:41 +0100 | [diff] [blame] | 450 | systemModules: corePlatformSystemModules(ctx), |
| 451 | bootclasspath: corePlatformBootclasspathLibraries(ctx), |
Pete Gillin | 7b0bdce | 2020-07-01 13:05:32 +0100 | [diff] [blame] | 452 | noFrameworksLibs: true, |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 453 | } |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 454 | case sdkPublic: |
Jiyong Park | aae9bd1 | 2020-02-12 04:36:43 +0900 | [diff] [blame] | 455 | return toModule([]string{"android_stubs_current"}, "framework-res", sdkFrameworkAidlPath(ctx)) |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 456 | case sdkSystem: |
Jiyong Park | aae9bd1 | 2020-02-12 04:36:43 +0900 | [diff] [blame] | 457 | return toModule([]string{"android_system_stubs_current"}, "framework-res", sdkFrameworkAidlPath(ctx)) |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 458 | case sdkTest: |
Jiyong Park | aae9bd1 | 2020-02-12 04:36:43 +0900 | [diff] [blame] | 459 | return toModule([]string{"android_test_stubs_current"}, "framework-res", sdkFrameworkAidlPath(ctx)) |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 460 | case sdkCore: |
Pete Gillin | 880f964 | 2020-07-01 13:17:16 +0100 | [diff] [blame] | 461 | return sdkDep{ |
| 462 | useModule: true, |
| 463 | bootclasspath: []string{"core.current.stubs", config.DefaultLambdaStubsLibrary}, |
| 464 | systemModules: "core-current-stubs-system-modules", |
| 465 | noFrameworksLibs: true, |
| 466 | } |
Jiyong Park | 50146e9 | 2020-01-30 18:00:15 +0900 | [diff] [blame] | 467 | case sdkModule: |
| 468 | // TODO(146757305): provide .apk and .aidl that have more APIs for modules |
Anton Hansson | 3f07ab2 | 2020-04-09 13:29:59 +0100 | [diff] [blame] | 469 | return toModule([]string{"android_module_lib_stubs_current"}, "framework-res", nonUpdatableFrameworkAidlPath(ctx)) |
Jiyong Park | aae9bd1 | 2020-02-12 04:36:43 +0900 | [diff] [blame] | 470 | case sdkSystemServer: |
| 471 | // TODO(146757305): provide .apk and .aidl that have more APIs for modules |
Anton Hansson | ba6ab2e | 2020-03-19 15:23:38 +0000 | [diff] [blame] | 472 | return toModule([]string{"android_system_server_stubs_current"}, "framework-res", sdkFrameworkAidlPath(ctx)) |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 473 | default: |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 474 | panic(fmt.Errorf("invalid sdk %q", sdkVersion.raw)) |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 475 | } |
| 476 | } |
Colin Cross | 98fd574 | 2019-01-09 23:04:25 -0800 | [diff] [blame] | 477 | |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 478 | func sdkPreSingletonFactory() android.Singleton { |
| 479 | return sdkPreSingleton{} |
Colin Cross | 98fd574 | 2019-01-09 23:04:25 -0800 | [diff] [blame] | 480 | } |
| 481 | |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 482 | type sdkPreSingleton struct{} |
Colin Cross | 98fd574 | 2019-01-09 23:04:25 -0800 | [diff] [blame] | 483 | |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 484 | func (sdkPreSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
Colin Cross | 98fd574 | 2019-01-09 23:04:25 -0800 | [diff] [blame] | 485 | sdkJars, err := ctx.GlobWithDeps("prebuilts/sdk/*/public/android.jar", nil) |
| 486 | if err != nil { |
| 487 | ctx.Errorf("failed to glob prebuilts/sdk/*/public/android.jar: %s", err.Error()) |
| 488 | } |
| 489 | |
| 490 | var sdkVersions []int |
| 491 | for _, sdkJar := range sdkJars { |
| 492 | dir := filepath.Base(filepath.Dir(filepath.Dir(sdkJar))) |
| 493 | v, err := strconv.Atoi(dir) |
| 494 | if scerr, ok := err.(*strconv.NumError); ok && scerr.Err == strconv.ErrSyntax { |
| 495 | continue |
| 496 | } else if err != nil { |
| 497 | ctx.Errorf("invalid sdk jar %q, %s, %v", sdkJar, err.Error()) |
| 498 | } |
| 499 | sdkVersions = append(sdkVersions, v) |
| 500 | } |
| 501 | |
| 502 | sort.Ints(sdkVersions) |
| 503 | |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 504 | ctx.Config().Once(sdkVersionsKey, func() interface{} { return sdkVersions }) |
| 505 | } |
| 506 | |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 507 | func LatestSdkVersionInt(ctx android.EarlyModuleContext) int { |
| 508 | sdkVersions := ctx.Config().Get(sdkVersionsKey).([]int) |
| 509 | latestSdkVersion := 0 |
| 510 | if len(sdkVersions) > 0 { |
| 511 | latestSdkVersion = sdkVersions[len(sdkVersions)-1] |
| 512 | } |
| 513 | return latestSdkVersion |
| 514 | } |
| 515 | |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 516 | func sdkSingletonFactory() android.Singleton { |
| 517 | return sdkSingleton{} |
| 518 | } |
| 519 | |
| 520 | type sdkSingleton struct{} |
| 521 | |
| 522 | func (sdkSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
Dan Willemsen | 9f43597 | 2020-05-28 15:28:00 -0700 | [diff] [blame] | 523 | if ctx.Config().AlwaysUsePrebuiltSdks() { |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 524 | return |
| 525 | } |
| 526 | |
Colin Cross | 1093287 | 2019-04-18 14:27:12 -0700 | [diff] [blame] | 527 | createSdkFrameworkAidl(ctx) |
Anton Hansson | 3f07ab2 | 2020-04-09 13:29:59 +0100 | [diff] [blame] | 528 | createNonUpdatableFrameworkAidl(ctx) |
Colin Cross | 1093287 | 2019-04-18 14:27:12 -0700 | [diff] [blame] | 529 | createAPIFingerprint(ctx) |
| 530 | } |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 531 | |
Colin Cross | 1093287 | 2019-04-18 14:27:12 -0700 | [diff] [blame] | 532 | // Create framework.aidl by extracting anything that implements android.os.Parcelable from the SDK stubs modules. |
| 533 | func createSdkFrameworkAidl(ctx android.SingletonContext) { |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 534 | stubsModules := []string{ |
| 535 | "android_stubs_current", |
| 536 | "android_test_stubs_current", |
| 537 | "android_system_stubs_current", |
| 538 | } |
| 539 | |
Anton Hansson | 3f07ab2 | 2020-04-09 13:29:59 +0100 | [diff] [blame] | 540 | combinedAidl := sdkFrameworkAidlPath(ctx) |
| 541 | tempPath := combinedAidl.ReplaceExtension(ctx, "aidl.tmp") |
| 542 | |
| 543 | rule := createFrameworkAidl(stubsModules, tempPath, ctx) |
| 544 | |
| 545 | commitChangeForRestat(rule, tempPath, combinedAidl) |
| 546 | |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 547 | rule.Build("framework_aidl", "generate framework.aidl") |
Anton Hansson | 3f07ab2 | 2020-04-09 13:29:59 +0100 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | // Creates a version of framework.aidl for the non-updatable part of the platform. |
| 551 | func createNonUpdatableFrameworkAidl(ctx android.SingletonContext) { |
| 552 | stubsModules := []string{"android_module_lib_stubs_current"} |
| 553 | |
| 554 | combinedAidl := nonUpdatableFrameworkAidlPath(ctx) |
| 555 | tempPath := combinedAidl.ReplaceExtension(ctx, "aidl.tmp") |
| 556 | |
| 557 | rule := createFrameworkAidl(stubsModules, tempPath, ctx) |
| 558 | |
| 559 | commitChangeForRestat(rule, tempPath, combinedAidl) |
| 560 | |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 561 | rule.Build("framework_non_updatable_aidl", "generate framework_non_updatable.aidl") |
Anton Hansson | 3f07ab2 | 2020-04-09 13:29:59 +0100 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | func createFrameworkAidl(stubsModules []string, path android.OutputPath, ctx android.SingletonContext) *android.RuleBuilder { |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 565 | stubsJars := make([]android.Paths, len(stubsModules)) |
| 566 | |
| 567 | ctx.VisitAllModules(func(module android.Module) { |
| 568 | // Collect dex jar paths for the modules listed above. |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 569 | if ctx.ModuleHasProvider(module, JavaInfoProvider) { |
| 570 | j := ctx.ModuleProvider(module, JavaInfoProvider).(JavaInfo) |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 571 | name := ctx.ModuleName(module) |
| 572 | if i := android.IndexList(name, stubsModules); i != -1 { |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 573 | stubsJars[i] = j.HeaderJars |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 574 | } |
| 575 | } |
| 576 | }) |
| 577 | |
| 578 | var missingDeps []string |
| 579 | |
| 580 | for i := range stubsJars { |
| 581 | if stubsJars[i] == nil { |
| 582 | if ctx.Config().AllowMissingDependencies() { |
| 583 | missingDeps = append(missingDeps, stubsModules[i]) |
| 584 | } else { |
Anton Hansson | 3f07ab2 | 2020-04-09 13:29:59 +0100 | [diff] [blame] | 585 | 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] | 586 | } |
| 587 | } |
| 588 | } |
| 589 | |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 590 | rule := android.NewRuleBuilder(pctx, ctx) |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 591 | rule.MissingDeps(missingDeps) |
| 592 | |
| 593 | var aidls android.Paths |
| 594 | for _, jars := range stubsJars { |
| 595 | for _, jar := range jars { |
| 596 | aidl := android.PathForOutput(ctx, "aidl", pathtools.ReplaceExtension(jar.Base(), "aidl")) |
| 597 | |
| 598 | rule.Command(). |
| 599 | Text("rm -f").Output(aidl) |
| 600 | rule.Command(). |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 601 | BuiltTool("sdkparcelables"). |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 602 | Input(jar). |
| 603 | Output(aidl) |
| 604 | |
| 605 | aidls = append(aidls, aidl) |
| 606 | } |
| 607 | } |
| 608 | |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 609 | rule.Command(). |
Anton Hansson | 3f07ab2 | 2020-04-09 13:29:59 +0100 | [diff] [blame] | 610 | Text("rm -f").Output(path) |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 611 | rule.Command(). |
| 612 | Text("cat"). |
| 613 | Inputs(aidls). |
| 614 | Text("| sort -u >"). |
Anton Hansson | 3f07ab2 | 2020-04-09 13:29:59 +0100 | [diff] [blame] | 615 | Output(path) |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 616 | |
Anton Hansson | 3f07ab2 | 2020-04-09 13:29:59 +0100 | [diff] [blame] | 617 | return rule |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | func sdkFrameworkAidlPath(ctx android.PathContext) android.OutputPath { |
| 621 | return ctx.Config().Once(sdkFrameworkAidlPathKey, func() interface{} { |
| 622 | return android.PathForOutput(ctx, "framework.aidl") |
| 623 | }).(android.OutputPath) |
| 624 | } |
| 625 | |
Anton Hansson | 3f07ab2 | 2020-04-09 13:29:59 +0100 | [diff] [blame] | 626 | func nonUpdatableFrameworkAidlPath(ctx android.PathContext) android.OutputPath { |
| 627 | return ctx.Config().Once(nonUpdatableFrameworkAidlPathKey, func() interface{} { |
| 628 | return android.PathForOutput(ctx, "framework_non_updatable.aidl") |
| 629 | }).(android.OutputPath) |
| 630 | } |
| 631 | |
Colin Cross | 1093287 | 2019-04-18 14:27:12 -0700 | [diff] [blame] | 632 | // Create api_fingerprint.txt |
| 633 | func createAPIFingerprint(ctx android.SingletonContext) { |
Jiyong Park | 71b519d | 2019-04-18 17:25:49 +0900 | [diff] [blame] | 634 | out := ApiFingerprintPath(ctx) |
Colin Cross | 1093287 | 2019-04-18 14:27:12 -0700 | [diff] [blame] | 635 | |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 636 | rule := android.NewRuleBuilder(pctx, ctx) |
Colin Cross | 1093287 | 2019-04-18 14:27:12 -0700 | [diff] [blame] | 637 | |
| 638 | rule.Command(). |
| 639 | Text("rm -f").Output(out) |
| 640 | cmd := rule.Command() |
| 641 | |
| 642 | if ctx.Config().PlatformSdkCodename() == "REL" { |
| 643 | cmd.Text("echo REL >").Output(out) |
Anton Hansson | 973d31c | 2021-02-10 14:52:42 +0000 | [diff] [blame] | 644 | } else if ctx.Config().FrameworksBaseDirExists(ctx) && !ctx.Config().AlwaysUsePrebuiltSdks() { |
| 645 | cmd.Text("cat") |
| 646 | apiTxtFileModules := []string{ |
| 647 | "frameworks-base-api-current.txt", |
| 648 | "frameworks-base-api-system-current.txt", |
| 649 | "frameworks-base-api-module-lib-current.txt", |
Colin Cross | 1093287 | 2019-04-18 14:27:12 -0700 | [diff] [blame] | 650 | } |
Anton Hansson | 973d31c | 2021-02-10 14:52:42 +0000 | [diff] [blame] | 651 | count := 0 |
| 652 | ctx.VisitAllModules(func(module android.Module) { |
| 653 | name := ctx.ModuleName(module) |
| 654 | if android.InList(name, apiTxtFileModules) { |
| 655 | cmd.Inputs(android.OutputFilesForModule(ctx, module, "")) |
| 656 | count++ |
| 657 | } |
| 658 | }) |
| 659 | if count != len(apiTxtFileModules) { |
| 660 | ctx.Errorf("Could not find all the expected API modules %v, found %d\n", apiTxtFileModules, count) |
| 661 | return |
| 662 | } |
| 663 | cmd.Input(android.PathForSource(ctx, "frameworks/base/services/api/current.txt")). |
Elliott Hughes | 34b49d1 | 2019-09-06 14:42:24 -0700 | [diff] [blame] | 664 | Text("| md5sum | cut -d' ' -f1 >"). |
Colin Cross | 1093287 | 2019-04-18 14:27:12 -0700 | [diff] [blame] | 665 | Output(out) |
| 666 | } else { |
| 667 | // Unbundled build |
| 668 | // TODO: use a prebuilt api_fingerprint.txt from prebuilts/sdk/current.txt once we have one |
| 669 | cmd.Text("echo"). |
| 670 | Flag(ctx.Config().PlatformPreviewSdkVersion()). |
| 671 | Text(">"). |
| 672 | Output(out) |
| 673 | } |
| 674 | |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 675 | rule.Build("api_fingerprint", "generate api_fingerprint.txt") |
Colin Cross | 1093287 | 2019-04-18 14:27:12 -0700 | [diff] [blame] | 676 | } |
| 677 | |
Jiyong Park | 71b519d | 2019-04-18 17:25:49 +0900 | [diff] [blame] | 678 | func ApiFingerprintPath(ctx android.PathContext) android.OutputPath { |
Colin Cross | 1093287 | 2019-04-18 14:27:12 -0700 | [diff] [blame] | 679 | return ctx.Config().Once(apiFingerprintPathKey, func() interface{} { |
| 680 | return android.PathForOutput(ctx, "api_fingerprint.txt") |
| 681 | }).(android.OutputPath) |
| 682 | } |
| 683 | |
| 684 | func sdkMakeVars(ctx android.MakeVarsContext) { |
Dan Willemsen | 9f43597 | 2020-05-28 15:28:00 -0700 | [diff] [blame] | 685 | if ctx.Config().AlwaysUsePrebuiltSdks() { |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 686 | return |
| 687 | } |
| 688 | |
| 689 | ctx.Strict("FRAMEWORK_AIDL", sdkFrameworkAidlPath(ctx).String()) |
Jiyong Park | 71b519d | 2019-04-18 17:25:49 +0900 | [diff] [blame] | 690 | ctx.Strict("API_FINGERPRINT", ApiFingerprintPath(ctx).String()) |
Colin Cross | 98fd574 | 2019-01-09 23:04:25 -0800 | [diff] [blame] | 691 | } |