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 ( |
| 18 | "android/soong/android" |
| 19 | "android/soong/java/config" |
| 20 | "fmt" |
| 21 | "path/filepath" |
Colin Cross | 98fd574 | 2019-01-09 23:04:25 -0800 | [diff] [blame] | 22 | "sort" |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 23 | "strconv" |
| 24 | "strings" |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 25 | |
| 26 | "github.com/google/blueprint/pathtools" |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 27 | ) |
| 28 | |
Colin Cross | 98fd574 | 2019-01-09 23:04:25 -0800 | [diff] [blame] | 29 | func init() { |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 30 | android.RegisterPreSingletonType("sdk_versions", sdkPreSingletonFactory) |
| 31 | android.RegisterSingletonType("sdk", sdkSingletonFactory) |
Colin Cross | 1093287 | 2019-04-18 14:27:12 -0700 | [diff] [blame] | 32 | android.RegisterMakeVarsProvider(pctx, sdkMakeVars) |
Colin Cross | 98fd574 | 2019-01-09 23:04:25 -0800 | [diff] [blame] | 33 | } |
| 34 | |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 35 | var sdkVersionsKey = android.NewOnceKey("sdkVersionsKey") |
| 36 | var sdkFrameworkAidlPathKey = android.NewOnceKey("sdkFrameworkAidlPathKey") |
Colin Cross | 1093287 | 2019-04-18 14:27:12 -0700 | [diff] [blame] | 37 | var apiFingerprintPathKey = android.NewOnceKey("apiFingerprintPathKey") |
Colin Cross | 98fd574 | 2019-01-09 23:04:25 -0800 | [diff] [blame] | 38 | |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 39 | type sdkContext interface { |
Paul Duffin | 250e619 | 2019-06-07 10:44:37 +0100 | [diff] [blame] | 40 | // sdkVersion returns the sdk_version property of the current module, or an empty string if it is not set. |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 41 | sdkVersion() string |
Paul Duffin | e25c644 | 2019-10-11 13:50:28 +0100 | [diff] [blame] | 42 | // systemModules returns the system_modules property of the current module, or an empty string if it is not set. |
| 43 | systemModules() string |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 44 | // minSdkVersion returns the min_sdk_version property of the current module, or sdkVersion() if it is not set. |
| 45 | minSdkVersion() string |
| 46 | // targetSdkVersion returns the target_sdk_version property of the current module, or sdkVersion() if it is not set. |
| 47 | targetSdkVersion() string |
| 48 | } |
| 49 | |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 50 | func sdkVersionOrDefault(ctx android.BaseModuleContext, v string) string { |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 51 | switch v { |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 52 | case "", "none", "current", "test_current", "system_current", "core_current", "core_platform": |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 53 | return ctx.Config().DefaultAppTargetSdk() |
| 54 | default: |
| 55 | return v |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | // Returns a sdk version as a number. For modules targeting an unreleased SDK (meaning it does not yet have a number) |
| 60 | // it returns android.FutureApiLevel (10000). |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 61 | func sdkVersionToNumber(ctx android.BaseModuleContext, v string) (int, error) { |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 62 | switch v { |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 63 | case "", "none", "current", "test_current", "system_current", "core_current", "core_platform": |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 64 | return ctx.Config().DefaultAppTargetSdkInt(), nil |
| 65 | default: |
| 66 | n := android.GetNumericSdkVersion(v) |
| 67 | if i, err := strconv.Atoi(n); err != nil { |
| 68 | return -1, fmt.Errorf("invalid sdk version %q", n) |
| 69 | } else { |
| 70 | return i, nil |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 75 | func sdkVersionToNumberAsString(ctx android.BaseModuleContext, v string) (string, error) { |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 76 | n, err := sdkVersionToNumber(ctx, v) |
| 77 | if err != nil { |
| 78 | return "", err |
| 79 | } |
| 80 | return strconv.Itoa(n), nil |
| 81 | } |
| 82 | |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 83 | func decodeSdkDep(ctx android.BaseModuleContext, sdkContext sdkContext) sdkDep { |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 84 | v := sdkContext.sdkVersion() |
Paul Duffin | 5c2f963 | 2019-06-12 14:21:31 +0100 | [diff] [blame] | 85 | |
Colin Cross | 98fd574 | 2019-01-09 23:04:25 -0800 | [diff] [blame] | 86 | // For PDK builds, use the latest SDK version instead of "current" |
| 87 | if ctx.Config().IsPdkBuild() && (v == "" || v == "current") { |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 88 | sdkVersions := ctx.Config().Get(sdkVersionsKey).([]int) |
Colin Cross | 98fd574 | 2019-01-09 23:04:25 -0800 | [diff] [blame] | 89 | latestSdkVersion := 0 |
| 90 | if len(sdkVersions) > 0 { |
| 91 | latestSdkVersion = sdkVersions[len(sdkVersions)-1] |
| 92 | } |
| 93 | v = strconv.Itoa(latestSdkVersion) |
| 94 | } |
| 95 | |
Colin Cross | ff0daf4 | 2019-04-02 16:10:56 -0700 | [diff] [blame] | 96 | numericSdkVersion, err := sdkVersionToNumber(ctx, v) |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 97 | if err != nil { |
| 98 | ctx.PropertyErrorf("sdk_version", "%s", err) |
| 99 | return sdkDep{} |
| 100 | } |
| 101 | |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 102 | toPrebuilt := func(sdk string) sdkDep { |
| 103 | var api, v string |
| 104 | if strings.Contains(sdk, "_") { |
| 105 | t := strings.Split(sdk, "_") |
| 106 | api = t[0] |
| 107 | v = t[1] |
| 108 | } else { |
| 109 | api = "public" |
| 110 | v = sdk |
| 111 | } |
| 112 | dir := filepath.Join("prebuilts", "sdk", v, api) |
| 113 | jar := filepath.Join(dir, "android.jar") |
| 114 | // There's no aidl for other SDKs yet. |
| 115 | // TODO(77525052): Add aidl files for other SDKs too. |
| 116 | public_dir := filepath.Join("prebuilts", "sdk", v, "public") |
| 117 | aidl := filepath.Join(public_dir, "framework.aidl") |
| 118 | jarPath := android.ExistentPathForSource(ctx, jar) |
| 119 | aidlPath := android.ExistentPathForSource(ctx, aidl) |
| 120 | lambdaStubsPath := android.PathForSource(ctx, config.SdkLambdaStubsPath) |
| 121 | |
| 122 | if (!jarPath.Valid() || !aidlPath.Valid()) && ctx.Config().AllowMissingDependencies() { |
| 123 | return sdkDep{ |
| 124 | invalidVersion: true, |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 125 | bootclasspath: []string{fmt.Sprintf("sdk_%s_%s_android", api, v)}, |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 126 | } |
| 127 | } |
| 128 | |
| 129 | if !jarPath.Valid() { |
| 130 | ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", v, jar) |
| 131 | return sdkDep{} |
| 132 | } |
| 133 | |
| 134 | if !aidlPath.Valid() { |
| 135 | ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", v, aidl) |
| 136 | return sdkDep{} |
| 137 | } |
| 138 | |
| 139 | return sdkDep{ |
| 140 | useFiles: true, |
| 141 | jars: android.Paths{jarPath.Path(), lambdaStubsPath}, |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 142 | aidl: android.OptionalPathForPath(aidlPath.Path()), |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 143 | } |
| 144 | } |
| 145 | |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 146 | toModule := func(m, r string, aidl android.Path) sdkDep { |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 147 | return sdkDep{ |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 148 | useModule: true, |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 149 | bootclasspath: []string{m, config.DefaultLambdaStubsLibrary}, |
| 150 | systemModules: "core-current-stubs-system-modules", |
| 151 | java9Classpath: []string{m}, |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 152 | frameworkResModule: r, |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 153 | aidl: android.OptionalPathForPath(aidl), |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 154 | } |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 155 | } |
| 156 | |
Colin Cross | 98fd574 | 2019-01-09 23:04:25 -0800 | [diff] [blame] | 157 | // Ensures that the specificed system SDK version is one of BOARD_SYSTEMSDK_VERSIONS (for vendor apks) |
| 158 | // or PRODUCT_SYSTEMSDK_VERSIONS (for other apks or when BOARD_SYSTEMSDK_VERSIONS is not set) |
Colin Cross | ff0daf4 | 2019-04-02 16:10:56 -0700 | [diff] [blame] | 159 | if strings.HasPrefix(v, "system_") && numericSdkVersion != android.FutureApiLevel { |
Colin Cross | 98fd574 | 2019-01-09 23:04:25 -0800 | [diff] [blame] | 160 | allowed_versions := ctx.DeviceConfig().PlatformSystemSdkVersions() |
| 161 | if ctx.DeviceSpecific() || ctx.SocSpecific() { |
| 162 | if len(ctx.DeviceConfig().SystemSdkVersions()) > 0 { |
| 163 | allowed_versions = ctx.DeviceConfig().SystemSdkVersions() |
| 164 | } |
| 165 | } |
Colin Cross | ff0daf4 | 2019-04-02 16:10:56 -0700 | [diff] [blame] | 166 | if len(allowed_versions) > 0 && !android.InList(strconv.Itoa(numericSdkVersion), allowed_versions) { |
Colin Cross | 98fd574 | 2019-01-09 23:04:25 -0800 | [diff] [blame] | 167 | ctx.PropertyErrorf("sdk_version", "incompatible sdk version %q. System SDK version should be one of %q", |
| 168 | v, allowed_versions) |
| 169 | } |
| 170 | } |
| 171 | |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 172 | if ctx.Config().UnbundledBuildUsePrebuiltSdks() && |
| 173 | v != "" && v != "none" && v != "core_platform" { |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 174 | return toPrebuilt(v) |
| 175 | } |
| 176 | |
| 177 | switch v { |
| 178 | case "": |
| 179 | return sdkDep{ |
| 180 | useDefaultLibs: true, |
| 181 | frameworkResModule: "framework-res", |
| 182 | } |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 183 | case "none": |
Paul Duffin | e25c644 | 2019-10-11 13:50:28 +0100 | [diff] [blame] | 184 | systemModules := sdkContext.systemModules() |
| 185 | if systemModules == "" { |
| 186 | ctx.PropertyErrorf("sdk_version", |
| 187 | `system_modules is required to be set to a non-empty value when sdk_version is "none", did you mean sdk_version: "core_platform"?`) |
| 188 | } else if systemModules == "none" { |
Colin Cross | 6d8d8c6 | 2019-10-28 15:10:03 -0700 | [diff] [blame] | 189 | return sdkDep{ |
| 190 | noStandardLibs: true, |
| 191 | } |
Paul Duffin | e25c644 | 2019-10-11 13:50:28 +0100 | [diff] [blame] | 192 | } |
| 193 | |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 194 | return sdkDep{ |
Colin Cross | 6d8d8c6 | 2019-10-28 15:10:03 -0700 | [diff] [blame] | 195 | useModule: true, |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 196 | noStandardLibs: true, |
Paul Duffin | e25c644 | 2019-10-11 13:50:28 +0100 | [diff] [blame] | 197 | systemModules: systemModules, |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 198 | bootclasspath: []string{systemModules}, |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 199 | } |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 200 | case "core_platform": |
| 201 | return sdkDep{ |
| 202 | useDefaultLibs: true, |
| 203 | frameworkResModule: "framework-res", |
| 204 | noFrameworksLibs: true, |
| 205 | } |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 206 | case "current": |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 207 | return toModule("android_stubs_current", "framework-res", sdkFrameworkAidlPath(ctx)) |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 208 | case "system_current": |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 209 | return toModule("android_system_stubs_current", "framework-res", sdkFrameworkAidlPath(ctx)) |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 210 | case "test_current": |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 211 | return toModule("android_test_stubs_current", "framework-res", sdkFrameworkAidlPath(ctx)) |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 212 | case "core_current": |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 213 | return toModule("core.current.stubs", "", nil) |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 214 | default: |
| 215 | return toPrebuilt(v) |
| 216 | } |
| 217 | } |
Colin Cross | 98fd574 | 2019-01-09 23:04:25 -0800 | [diff] [blame] | 218 | |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 219 | func sdkPreSingletonFactory() android.Singleton { |
| 220 | return sdkPreSingleton{} |
Colin Cross | 98fd574 | 2019-01-09 23:04:25 -0800 | [diff] [blame] | 221 | } |
| 222 | |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 223 | type sdkPreSingleton struct{} |
Colin Cross | 98fd574 | 2019-01-09 23:04:25 -0800 | [diff] [blame] | 224 | |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 225 | func (sdkPreSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
Colin Cross | 98fd574 | 2019-01-09 23:04:25 -0800 | [diff] [blame] | 226 | sdkJars, err := ctx.GlobWithDeps("prebuilts/sdk/*/public/android.jar", nil) |
| 227 | if err != nil { |
| 228 | ctx.Errorf("failed to glob prebuilts/sdk/*/public/android.jar: %s", err.Error()) |
| 229 | } |
| 230 | |
| 231 | var sdkVersions []int |
| 232 | for _, sdkJar := range sdkJars { |
| 233 | dir := filepath.Base(filepath.Dir(filepath.Dir(sdkJar))) |
| 234 | v, err := strconv.Atoi(dir) |
| 235 | if scerr, ok := err.(*strconv.NumError); ok && scerr.Err == strconv.ErrSyntax { |
| 236 | continue |
| 237 | } else if err != nil { |
| 238 | ctx.Errorf("invalid sdk jar %q, %s, %v", sdkJar, err.Error()) |
| 239 | } |
| 240 | sdkVersions = append(sdkVersions, v) |
| 241 | } |
| 242 | |
| 243 | sort.Ints(sdkVersions) |
| 244 | |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 245 | ctx.Config().Once(sdkVersionsKey, func() interface{} { return sdkVersions }) |
| 246 | } |
| 247 | |
| 248 | func sdkSingletonFactory() android.Singleton { |
| 249 | return sdkSingleton{} |
| 250 | } |
| 251 | |
| 252 | type sdkSingleton struct{} |
| 253 | |
| 254 | func (sdkSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
Colin Cross | 1093287 | 2019-04-18 14:27:12 -0700 | [diff] [blame] | 255 | if ctx.Config().UnbundledBuildUsePrebuiltSdks() || ctx.Config().IsPdkBuild() { |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 256 | return |
| 257 | } |
| 258 | |
Colin Cross | 1093287 | 2019-04-18 14:27:12 -0700 | [diff] [blame] | 259 | createSdkFrameworkAidl(ctx) |
| 260 | createAPIFingerprint(ctx) |
| 261 | } |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 262 | |
Colin Cross | 1093287 | 2019-04-18 14:27:12 -0700 | [diff] [blame] | 263 | // Create framework.aidl by extracting anything that implements android.os.Parcelable from the SDK stubs modules. |
| 264 | func createSdkFrameworkAidl(ctx android.SingletonContext) { |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 265 | stubsModules := []string{ |
| 266 | "android_stubs_current", |
| 267 | "android_test_stubs_current", |
| 268 | "android_system_stubs_current", |
| 269 | } |
| 270 | |
| 271 | stubsJars := make([]android.Paths, len(stubsModules)) |
| 272 | |
| 273 | ctx.VisitAllModules(func(module android.Module) { |
| 274 | // Collect dex jar paths for the modules listed above. |
| 275 | if j, ok := module.(Dependency); ok { |
| 276 | name := ctx.ModuleName(module) |
| 277 | if i := android.IndexList(name, stubsModules); i != -1 { |
| 278 | stubsJars[i] = j.HeaderJars() |
| 279 | } |
| 280 | } |
| 281 | }) |
| 282 | |
| 283 | var missingDeps []string |
| 284 | |
| 285 | for i := range stubsJars { |
| 286 | if stubsJars[i] == nil { |
| 287 | if ctx.Config().AllowMissingDependencies() { |
| 288 | missingDeps = append(missingDeps, stubsModules[i]) |
| 289 | } else { |
| 290 | ctx.Errorf("failed to find dex jar path for module %q", |
| 291 | stubsModules[i]) |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | rule := android.NewRuleBuilder() |
| 297 | rule.MissingDeps(missingDeps) |
| 298 | |
| 299 | var aidls android.Paths |
| 300 | for _, jars := range stubsJars { |
| 301 | for _, jar := range jars { |
| 302 | aidl := android.PathForOutput(ctx, "aidl", pathtools.ReplaceExtension(jar.Base(), "aidl")) |
| 303 | |
| 304 | rule.Command(). |
| 305 | Text("rm -f").Output(aidl) |
| 306 | rule.Command(). |
Colin Cross | ee94d6a | 2019-07-08 17:08:34 -0700 | [diff] [blame] | 307 | BuiltTool(ctx, "sdkparcelables"). |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 308 | Input(jar). |
| 309 | Output(aidl) |
| 310 | |
| 311 | aidls = append(aidls, aidl) |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | combinedAidl := sdkFrameworkAidlPath(ctx) |
| 316 | tempPath := combinedAidl.ReplaceExtension(ctx, "aidl.tmp") |
| 317 | |
| 318 | rule.Command(). |
| 319 | Text("rm -f").Output(tempPath) |
| 320 | rule.Command(). |
| 321 | Text("cat"). |
| 322 | Inputs(aidls). |
| 323 | Text("| sort -u >"). |
| 324 | Output(tempPath) |
| 325 | |
| 326 | commitChangeForRestat(rule, tempPath, combinedAidl) |
| 327 | |
| 328 | rule.Build(pctx, ctx, "framework_aidl", "generate framework.aidl") |
| 329 | } |
| 330 | |
| 331 | func sdkFrameworkAidlPath(ctx android.PathContext) android.OutputPath { |
| 332 | return ctx.Config().Once(sdkFrameworkAidlPathKey, func() interface{} { |
| 333 | return android.PathForOutput(ctx, "framework.aidl") |
| 334 | }).(android.OutputPath) |
| 335 | } |
| 336 | |
Colin Cross | 1093287 | 2019-04-18 14:27:12 -0700 | [diff] [blame] | 337 | // Create api_fingerprint.txt |
| 338 | func createAPIFingerprint(ctx android.SingletonContext) { |
Jiyong Park | 71b519d | 2019-04-18 17:25:49 +0900 | [diff] [blame] | 339 | out := ApiFingerprintPath(ctx) |
Colin Cross | 1093287 | 2019-04-18 14:27:12 -0700 | [diff] [blame] | 340 | |
| 341 | rule := android.NewRuleBuilder() |
| 342 | |
| 343 | rule.Command(). |
| 344 | Text("rm -f").Output(out) |
| 345 | cmd := rule.Command() |
| 346 | |
| 347 | if ctx.Config().PlatformSdkCodename() == "REL" { |
| 348 | cmd.Text("echo REL >").Output(out) |
| 349 | } else if ctx.Config().IsPdkBuild() { |
| 350 | // TODO: get this from the PDK artifacts? |
| 351 | cmd.Text("echo PDK >").Output(out) |
| 352 | } else if !ctx.Config().UnbundledBuildUsePrebuiltSdks() { |
| 353 | in, err := ctx.GlobWithDeps("frameworks/base/api/*current.txt", nil) |
| 354 | if err != nil { |
| 355 | ctx.Errorf("error globbing API files: %s", err) |
| 356 | } |
| 357 | |
| 358 | cmd.Text("cat"). |
| 359 | Inputs(android.PathsForSource(ctx, in)). |
Elliott Hughes | 34b49d1 | 2019-09-06 14:42:24 -0700 | [diff] [blame] | 360 | Text("| md5sum | cut -d' ' -f1 >"). |
Colin Cross | 1093287 | 2019-04-18 14:27:12 -0700 | [diff] [blame] | 361 | Output(out) |
| 362 | } else { |
| 363 | // Unbundled build |
| 364 | // TODO: use a prebuilt api_fingerprint.txt from prebuilts/sdk/current.txt once we have one |
| 365 | cmd.Text("echo"). |
| 366 | Flag(ctx.Config().PlatformPreviewSdkVersion()). |
| 367 | Text(">"). |
| 368 | Output(out) |
| 369 | } |
| 370 | |
| 371 | rule.Build(pctx, ctx, "api_fingerprint", "generate api_fingerprint.txt") |
| 372 | } |
| 373 | |
Jiyong Park | 71b519d | 2019-04-18 17:25:49 +0900 | [diff] [blame] | 374 | func ApiFingerprintPath(ctx android.PathContext) android.OutputPath { |
Colin Cross | 1093287 | 2019-04-18 14:27:12 -0700 | [diff] [blame] | 375 | return ctx.Config().Once(apiFingerprintPathKey, func() interface{} { |
| 376 | return android.PathForOutput(ctx, "api_fingerprint.txt") |
| 377 | }).(android.OutputPath) |
| 378 | } |
| 379 | |
| 380 | func sdkMakeVars(ctx android.MakeVarsContext) { |
| 381 | if ctx.Config().UnbundledBuildUsePrebuiltSdks() || ctx.Config().IsPdkBuild() { |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 382 | return |
| 383 | } |
| 384 | |
| 385 | ctx.Strict("FRAMEWORK_AIDL", sdkFrameworkAidlPath(ctx).String()) |
Jiyong Park | 71b519d | 2019-04-18 17:25:49 +0900 | [diff] [blame] | 386 | ctx.Strict("API_FINGERPRINT", ApiFingerprintPath(ctx).String()) |
Colin Cross | 98fd574 | 2019-01-09 23:04:25 -0800 | [diff] [blame] | 387 | } |