2019-01-10 07:17:55 +01:00
|
|
|
// Copyright 2019 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package java
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"path/filepath"
|
2019-04-18 19:56:44 +02:00
|
|
|
|
2020-01-18 19:33:43 +01:00
|
|
|
"android/soong/android"
|
|
|
|
"android/soong/java/config"
|
|
|
|
|
2019-04-18 19:56:44 +02:00
|
|
|
"github.com/google/blueprint/pathtools"
|
2019-01-10 07:17:55 +01:00
|
|
|
)
|
|
|
|
|
2019-01-10 08:04:25 +01:00
|
|
|
func init() {
|
2023-05-16 02:58:37 +02:00
|
|
|
android.RegisterParallelSingletonType("sdk", sdkSingletonFactory)
|
2019-04-18 23:27:12 +02:00
|
|
|
android.RegisterMakeVarsProvider(pctx, sdkMakeVars)
|
2019-01-10 08:04:25 +01:00
|
|
|
}
|
|
|
|
|
2019-04-18 19:56:44 +02:00
|
|
|
var sdkFrameworkAidlPathKey = android.NewOnceKey("sdkFrameworkAidlPathKey")
|
2020-04-09 14:29:59 +02:00
|
|
|
var nonUpdatableFrameworkAidlPathKey = android.NewOnceKey("nonUpdatableFrameworkAidlPathKey")
|
2019-04-18 23:27:12 +02:00
|
|
|
var apiFingerprintPathKey = android.NewOnceKey("apiFingerprintPathKey")
|
2019-01-10 08:04:25 +01:00
|
|
|
|
2020-03-02 17:58:11 +01:00
|
|
|
func UseApiFingerprint(ctx android.BaseModuleContext) bool {
|
|
|
|
if ctx.Config().UnbundledBuild() &&
|
2020-07-07 18:09:23 +02:00
|
|
|
!ctx.Config().AlwaysUsePrebuiltSdks() &&
|
2020-01-25 00:15:44 +01:00
|
|
|
ctx.Config().IsEnvTrue("UNBUNDLED_BUILD_TARGET_SDK_WITH_API_FINGERPRINT") {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-03-29 13:11:58 +02:00
|
|
|
func defaultJavaLanguageVersion(ctx android.EarlyModuleContext, s android.SdkSpec) javaVersion {
|
|
|
|
sdk, err := s.EffectiveVersion(ctx)
|
2020-05-15 03:05:32 +02:00
|
|
|
if err != nil {
|
|
|
|
ctx.PropertyErrorf("sdk_version", "%s", err)
|
|
|
|
}
|
2021-03-31 11:17:53 +02:00
|
|
|
if sdk.FinalOrFutureInt() <= 23 {
|
2020-05-15 03:05:32 +02:00
|
|
|
return JAVA_VERSION_7
|
2021-03-31 11:17:53 +02:00
|
|
|
} else if sdk.FinalOrFutureInt() <= 29 {
|
2020-05-15 03:05:32 +02:00
|
|
|
return JAVA_VERSION_8
|
2022-01-23 10:01:07 +01:00
|
|
|
} else if sdk.FinalOrFutureInt() <= 31 {
|
2022-01-20 16:21:51 +01:00
|
|
|
return JAVA_VERSION_9
|
2023-03-03 11:18:00 +01:00
|
|
|
} else if sdk.FinalOrFutureInt() <= 33 {
|
2023-02-14 21:26:31 +01:00
|
|
|
return JAVA_VERSION_11
|
2023-02-15 18:52:27 +01:00
|
|
|
} else {
|
|
|
|
return JAVA_VERSION_17
|
2020-05-15 03:05:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-29 14:50:24 +02:00
|
|
|
// systemModuleKind returns the kind of system modules to use for the supplied combination of sdk
|
|
|
|
// kind and API level.
|
|
|
|
func systemModuleKind(sdkKind android.SdkKind, apiLevel android.ApiLevel) android.SdkKind {
|
|
|
|
systemModuleKind := sdkKind
|
|
|
|
if apiLevel.LessThanOrEqualTo(android.LastWithoutModuleLibCoreSystemModules) {
|
|
|
|
// API levels less than or equal to 31 did not provide a core-for-system-modules.jar
|
|
|
|
// specifically for the module-lib API. So, always use the public system modules for them.
|
|
|
|
systemModuleKind = android.SdkPublic
|
|
|
|
} else if systemModuleKind == android.SdkCore {
|
|
|
|
// Core is by definition what is included in the system module for the public API so should
|
|
|
|
// just use its system modules.
|
|
|
|
systemModuleKind = android.SdkPublic
|
2023-08-10 02:07:03 +02:00
|
|
|
} else if systemModuleKind == android.SdkSystem || systemModuleKind == android.SdkTest ||
|
|
|
|
systemModuleKind == android.SdkTestFrameworksCore {
|
2021-10-29 14:50:24 +02:00
|
|
|
// The core system and test APIs are currently the same as the public API so they should use
|
|
|
|
// its system modules.
|
|
|
|
systemModuleKind = android.SdkPublic
|
|
|
|
} else if systemModuleKind == android.SdkSystemServer {
|
|
|
|
// The core system server API is the same as the core module-lib API.
|
|
|
|
systemModuleKind = android.SdkModule
|
|
|
|
}
|
|
|
|
|
|
|
|
return systemModuleKind
|
2021-10-29 14:30:59 +02:00
|
|
|
}
|
|
|
|
|
2021-03-29 13:11:58 +02:00
|
|
|
func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext android.SdkContext) sdkDep {
|
2021-04-02 01:45:46 +02:00
|
|
|
sdkVersion := sdkContext.SdkVersion(ctx)
|
2021-03-29 13:11:58 +02:00
|
|
|
if !sdkVersion.Valid() {
|
|
|
|
ctx.PropertyErrorf("sdk_version", "invalid version %q", sdkVersion.Raw)
|
Abstract sdk_version string using sdkSpec type
The value format that sdk_version (and min_sdk_version, etc.) can have
has consistently evolved and is quite complicated. Furthermore, with the
Mainline module effort, we are expected to have more sdk_versions like
'module-app-current', 'module-lib-current', etc.
The goal of this change is to abstract the various sdk versions, which
are currently represented in string and is parsed in various places,
into a type called sdkSpec, so that adding new sdk veresions becomes
easier than before.
The sdk_version string is now parsed in only one place 'SdkSpecFrom', in
which it is converted into the sdkSpec struct. The struct type provides
several methods that again converts sdkSpec into context-specific
information such as the effective version number, etc.
Bug: 146757305
Bug: 147879031
Test: m
Change-Id: I252f3706544f00ea71c61c23460f07561dd28ab0
2020-01-20 18:03:43 +01:00
|
|
|
return sdkDep{}
|
|
|
|
}
|
|
|
|
|
2020-08-06 16:00:37 +02:00
|
|
|
if ctx.DeviceSpecific() || ctx.SocSpecific() {
|
2021-03-29 13:11:58 +02:00
|
|
|
sdkVersion = sdkVersion.ForVendorPartition(ctx)
|
2020-08-06 16:00:37 +02:00
|
|
|
}
|
|
|
|
|
2021-03-29 13:11:58 +02:00
|
|
|
if !sdkVersion.ValidateSystemSdk(ctx) {
|
2020-01-28 05:52:36 +01:00
|
|
|
return sdkDep{}
|
|
|
|
}
|
Abstract sdk_version string using sdkSpec type
The value format that sdk_version (and min_sdk_version, etc.) can have
has consistently evolved and is quite complicated. Furthermore, with the
Mainline module effort, we are expected to have more sdk_versions like
'module-app-current', 'module-lib-current', etc.
The goal of this change is to abstract the various sdk versions, which
are currently represented in string and is parsed in various places,
into a type called sdkSpec, so that adding new sdk veresions becomes
easier than before.
The sdk_version string is now parsed in only one place 'SdkSpecFrom', in
which it is converted into the sdkSpec struct. The struct type provides
several methods that again converts sdkSpec into context-specific
information such as the effective version number, etc.
Bug: 146757305
Bug: 147879031
Test: m
Change-Id: I252f3706544f00ea71c61c23460f07561dd28ab0
2020-01-20 18:03:43 +01:00
|
|
|
|
2021-03-29 13:11:58 +02:00
|
|
|
if sdkVersion.UsePrebuilt(ctx) {
|
2021-03-31 11:17:53 +02:00
|
|
|
dir := filepath.Join("prebuilts", "sdk", sdkVersion.ApiLevel.String(), sdkVersion.Kind.String())
|
2019-01-10 07:17:55 +01:00
|
|
|
jar := filepath.Join(dir, "android.jar")
|
|
|
|
// There's no aidl for other SDKs yet.
|
|
|
|
// TODO(77525052): Add aidl files for other SDKs too.
|
2021-03-31 11:17:53 +02:00
|
|
|
publicDir := filepath.Join("prebuilts", "sdk", sdkVersion.ApiLevel.String(), "public")
|
2020-12-21 18:11:10 +01:00
|
|
|
aidl := filepath.Join(publicDir, "framework.aidl")
|
2019-01-10 07:17:55 +01:00
|
|
|
jarPath := android.ExistentPathForSource(ctx, jar)
|
|
|
|
aidlPath := android.ExistentPathForSource(ctx, aidl)
|
|
|
|
lambdaStubsPath := android.PathForSource(ctx, config.SdkLambdaStubsPath)
|
|
|
|
|
|
|
|
if (!jarPath.Valid() || !aidlPath.Valid()) && ctx.Config().AllowMissingDependencies() {
|
|
|
|
return sdkDep{
|
|
|
|
invalidVersion: true,
|
2021-03-31 11:17:53 +02:00
|
|
|
bootclasspath: []string{fmt.Sprintf("sdk_%s_%s_android", sdkVersion.Kind, sdkVersion.ApiLevel.String())},
|
2019-01-10 07:17:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !jarPath.Valid() {
|
2021-03-29 13:11:58 +02:00
|
|
|
ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", sdkVersion.Raw, jar)
|
2019-01-10 07:17:55 +01:00
|
|
|
return sdkDep{}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !aidlPath.Valid() {
|
2021-03-29 13:11:58 +02:00
|
|
|
ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", sdkVersion.Raw, aidl)
|
2019-01-10 07:17:55 +01:00
|
|
|
return sdkDep{}
|
|
|
|
}
|
|
|
|
|
2020-05-15 03:05:32 +02:00
|
|
|
var systemModules string
|
2021-03-29 13:11:58 +02:00
|
|
|
if defaultJavaLanguageVersion(ctx, sdkVersion).usesJavaModules() {
|
2021-10-29 14:50:24 +02:00
|
|
|
systemModuleKind := systemModuleKind(sdkVersion.Kind, sdkVersion.ApiLevel)
|
2021-10-29 14:30:59 +02:00
|
|
|
systemModules = fmt.Sprintf("sdk_%s_%s_system_modules", systemModuleKind, sdkVersion.ApiLevel)
|
2020-05-15 03:05:32 +02:00
|
|
|
}
|
|
|
|
|
2019-01-10 07:17:55 +01:00
|
|
|
return sdkDep{
|
2020-05-15 03:05:32 +02:00
|
|
|
useFiles: true,
|
|
|
|
jars: android.Paths{jarPath.Path(), lambdaStubsPath},
|
|
|
|
aidl: android.OptionalPathForPath(aidlPath.Path()),
|
|
|
|
systemModules: systemModules,
|
2019-01-10 07:17:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-03 17:44:22 +01:00
|
|
|
toModule := func(module string, aidl android.Path) sdkDep {
|
|
|
|
// Select the kind of system modules needed for the sdk version.
|
|
|
|
systemModulesKind := systemModuleKind(sdkVersion.Kind, android.FutureApiLevel)
|
2023-06-15 00:43:25 +02:00
|
|
|
systemModules := fmt.Sprintf("core-%s-stubs-system-modules", systemModulesKind)
|
2019-10-17 23:23:50 +02:00
|
|
|
return sdkDep{
|
2019-01-10 07:17:55 +01:00
|
|
|
useModule: true,
|
2023-05-30 21:12:28 +02:00
|
|
|
bootclasspath: []string{module, config.DefaultLambdaStubsLibrary},
|
2023-03-30 04:59:22 +02:00
|
|
|
systemModules: systemModules,
|
2021-10-28 12:43:21 +02:00
|
|
|
java9Classpath: []string{module},
|
|
|
|
frameworkResModule: "framework-res",
|
2019-04-18 19:56:44 +02:00
|
|
|
aidl: android.OptionalPathForPath(aidl),
|
2019-01-10 07:17:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-29 13:11:58 +02:00
|
|
|
switch sdkVersion.Kind {
|
|
|
|
case android.SdkPrivate:
|
2019-01-10 07:17:55 +01:00
|
|
|
return sdkDep{
|
Remove the concept of useDefaultLibs from Soong.
This field in the java/sdk structure was used in two of the many
possible configurations, so it wasn't really a "default". It also
meant that, to understand those configurations, the reader had to know
what was considered the default, which was only possibly by reading
the code in java.go and droiddoc.go which implemented special code
paths when useDefaultLibs was true. By eliminating that setting and
explicitly setting the required values, the code is simpler and easier
to understand.
This change is a straight refactoring, in the sense that the output of
the build should be unchanged.
Regarding the changes to the proguardRaiseTag dependency in java.go:
- This is a noop for anything which had sdkDep.useModule = true prior
to this change, because they all had the same value for
hasFrameworkLibs() and hasStandardLibs().
- This is a noop for anything which had sdkDep.useDefaultLibs = true
prior to this change, because they do not use proguard settings.
- Therefore, it is a noop overall.
- Nevertheless, it is required to make sdkCorePlatform work. Without
this change, such modules would pick up a dependency on framework
libs via the (unused) proguardRaiseTag, which creates a circular
dependency, because this is the sdk_version used when building
framework libs themselves.
Bug: 157640067
Test: m java docs droid
Change-Id: I3a83b5edc1bd48c16b55f6f77e3e710fc8fbd8fa
2020-06-29 12:28:51 +02:00
|
|
|
useModule: true,
|
2020-07-09 19:03:41 +02:00
|
|
|
systemModules: corePlatformSystemModules(ctx),
|
|
|
|
bootclasspath: corePlatformBootclasspathLibraries(ctx),
|
Remove the concept of useDefaultLibs from Soong.
This field in the java/sdk structure was used in two of the many
possible configurations, so it wasn't really a "default". It also
meant that, to understand those configurations, the reader had to know
what was considered the default, which was only possibly by reading
the code in java.go and droiddoc.go which implemented special code
paths when useDefaultLibs was true. By eliminating that setting and
explicitly setting the required values, the code is simpler and easier
to understand.
This change is a straight refactoring, in the sense that the output of
the build should be unchanged.
Regarding the changes to the proguardRaiseTag dependency in java.go:
- This is a noop for anything which had sdkDep.useModule = true prior
to this change, because they all had the same value for
hasFrameworkLibs() and hasStandardLibs().
- This is a noop for anything which had sdkDep.useDefaultLibs = true
prior to this change, because they do not use proguard settings.
- Therefore, it is a noop overall.
- Nevertheless, it is required to make sdkCorePlatform work. Without
this change, such modules would pick up a dependency on framework
libs via the (unused) proguardRaiseTag, which creates a circular
dependency, because this is the sdk_version used when building
framework libs themselves.
Bug: 157640067
Test: m java docs droid
Change-Id: I3a83b5edc1bd48c16b55f6f77e3e710fc8fbd8fa
2020-06-29 12:28:51 +02:00
|
|
|
classpath: config.FrameworkLibraries,
|
2019-01-10 07:17:55 +01:00
|
|
|
frameworkResModule: "framework-res",
|
|
|
|
}
|
2021-03-29 13:11:58 +02:00
|
|
|
case android.SdkNone:
|
|
|
|
systemModules := sdkContext.SystemModules()
|
2019-10-11 14:50:28 +02:00
|
|
|
if systemModules == "" {
|
|
|
|
ctx.PropertyErrorf("sdk_version",
|
|
|
|
`system_modules is required to be set to a non-empty value when sdk_version is "none", did you mean sdk_version: "core_platform"?`)
|
|
|
|
} else if systemModules == "none" {
|
2019-10-28 23:10:03 +01:00
|
|
|
return sdkDep{
|
|
|
|
noStandardLibs: true,
|
|
|
|
}
|
2019-10-11 14:50:28 +02:00
|
|
|
}
|
|
|
|
|
2019-06-11 13:31:14 +02:00
|
|
|
return sdkDep{
|
2019-10-28 23:10:03 +01:00
|
|
|
useModule: true,
|
2019-06-11 13:31:14 +02:00
|
|
|
noStandardLibs: true,
|
2019-10-11 14:50:28 +02:00
|
|
|
systemModules: systemModules,
|
2019-10-17 23:23:50 +02:00
|
|
|
bootclasspath: []string{systemModules},
|
2019-06-11 13:31:14 +02:00
|
|
|
}
|
2021-03-29 13:11:58 +02:00
|
|
|
case android.SdkCorePlatform:
|
2019-06-12 14:25:22 +02:00
|
|
|
return sdkDep{
|
2020-07-01 14:05:32 +02:00
|
|
|
useModule: true,
|
2020-07-09 19:03:41 +02:00
|
|
|
systemModules: corePlatformSystemModules(ctx),
|
|
|
|
bootclasspath: corePlatformBootclasspathLibraries(ctx),
|
2020-07-01 14:05:32 +02:00
|
|
|
noFrameworksLibs: true,
|
2019-06-12 14:25:22 +02:00
|
|
|
}
|
2023-08-10 02:07:03 +02:00
|
|
|
case android.SdkPublic, android.SdkSystem, android.SdkTest, android.SdkTestFrameworksCore:
|
2023-05-30 21:12:28 +02:00
|
|
|
return toModule(sdkVersion.Kind.DefaultJavaLibraryName(), sdkFrameworkAidlPath(ctx))
|
2021-03-29 13:11:58 +02:00
|
|
|
case android.SdkCore:
|
2020-07-01 14:17:16 +02:00
|
|
|
return sdkDep{
|
|
|
|
useModule: true,
|
2023-05-30 21:12:28 +02:00
|
|
|
bootclasspath: []string{android.SdkCore.DefaultJavaLibraryName(), config.DefaultLambdaStubsLibrary},
|
2023-06-15 00:43:25 +02:00
|
|
|
systemModules: "core-public-stubs-system-modules",
|
2020-07-01 14:17:16 +02:00
|
|
|
noFrameworksLibs: true,
|
|
|
|
}
|
2021-03-29 13:11:58 +02:00
|
|
|
case android.SdkModule:
|
2020-01-30 10:00:15 +01:00
|
|
|
// TODO(146757305): provide .apk and .aidl that have more APIs for modules
|
2023-05-30 21:12:28 +02:00
|
|
|
return toModule(sdkVersion.Kind.DefaultJavaLibraryName(), nonUpdatableFrameworkAidlPath(ctx))
|
2021-03-29 13:11:58 +02:00
|
|
|
case android.SdkSystemServer:
|
2020-02-11 20:36:43 +01:00
|
|
|
// TODO(146757305): provide .apk and .aidl that have more APIs for modules
|
2023-05-30 21:12:28 +02:00
|
|
|
return toModule(sdkVersion.Kind.DefaultJavaLibraryName(), sdkFrameworkAidlPath(ctx))
|
2019-01-10 07:17:55 +01:00
|
|
|
default:
|
2021-03-29 13:11:58 +02:00
|
|
|
panic(fmt.Errorf("invalid sdk %q", sdkVersion.Raw))
|
2019-01-10 07:17:55 +01:00
|
|
|
}
|
|
|
|
}
|
2019-01-10 08:04:25 +01:00
|
|
|
|
2019-04-18 19:56:44 +02:00
|
|
|
func sdkSingletonFactory() android.Singleton {
|
|
|
|
return sdkSingleton{}
|
|
|
|
}
|
|
|
|
|
|
|
|
type sdkSingleton struct{}
|
|
|
|
|
|
|
|
func (sdkSingleton) GenerateBuildActions(ctx android.SingletonContext) {
|
2020-05-29 00:28:00 +02:00
|
|
|
if ctx.Config().AlwaysUsePrebuiltSdks() {
|
2019-04-18 19:56:44 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-04-18 23:27:12 +02:00
|
|
|
createSdkFrameworkAidl(ctx)
|
2020-04-09 14:29:59 +02:00
|
|
|
createNonUpdatableFrameworkAidl(ctx)
|
2019-04-18 23:27:12 +02:00
|
|
|
createAPIFingerprint(ctx)
|
|
|
|
}
|
2019-04-18 19:56:44 +02:00
|
|
|
|
2019-04-18 23:27:12 +02:00
|
|
|
// Create framework.aidl by extracting anything that implements android.os.Parcelable from the SDK stubs modules.
|
|
|
|
func createSdkFrameworkAidl(ctx android.SingletonContext) {
|
2019-04-18 19:56:44 +02:00
|
|
|
stubsModules := []string{
|
2023-05-30 21:12:28 +02:00
|
|
|
android.SdkPublic.DefaultJavaLibraryName(),
|
|
|
|
android.SdkTest.DefaultJavaLibraryName(),
|
|
|
|
android.SdkSystem.DefaultJavaLibraryName(),
|
2019-04-18 19:56:44 +02:00
|
|
|
}
|
|
|
|
|
2020-04-09 14:29:59 +02:00
|
|
|
combinedAidl := sdkFrameworkAidlPath(ctx)
|
2021-04-21 23:12:35 +02:00
|
|
|
tempPath := tempPathForRestat(ctx, combinedAidl)
|
2020-04-09 14:29:59 +02:00
|
|
|
|
|
|
|
rule := createFrameworkAidl(stubsModules, tempPath, ctx)
|
|
|
|
|
|
|
|
commitChangeForRestat(rule, tempPath, combinedAidl)
|
|
|
|
|
2020-11-17 02:32:30 +01:00
|
|
|
rule.Build("framework_aidl", "generate framework.aidl")
|
2020-04-09 14:29:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Creates a version of framework.aidl for the non-updatable part of the platform.
|
|
|
|
func createNonUpdatableFrameworkAidl(ctx android.SingletonContext) {
|
2023-05-30 21:12:28 +02:00
|
|
|
stubsModules := []string{android.SdkModule.DefaultJavaLibraryName()}
|
2020-04-09 14:29:59 +02:00
|
|
|
|
|
|
|
combinedAidl := nonUpdatableFrameworkAidlPath(ctx)
|
2021-04-21 23:12:35 +02:00
|
|
|
tempPath := tempPathForRestat(ctx, combinedAidl)
|
2020-04-09 14:29:59 +02:00
|
|
|
|
|
|
|
rule := createFrameworkAidl(stubsModules, tempPath, ctx)
|
|
|
|
|
|
|
|
commitChangeForRestat(rule, tempPath, combinedAidl)
|
|
|
|
|
2020-11-17 02:32:30 +01:00
|
|
|
rule.Build("framework_non_updatable_aidl", "generate framework_non_updatable.aidl")
|
2020-04-09 14:29:59 +02:00
|
|
|
}
|
|
|
|
|
2021-04-21 23:12:35 +02:00
|
|
|
func createFrameworkAidl(stubsModules []string, path android.WritablePath, ctx android.SingletonContext) *android.RuleBuilder {
|
2019-04-18 19:56:44 +02:00
|
|
|
stubsJars := make([]android.Paths, len(stubsModules))
|
|
|
|
|
|
|
|
ctx.VisitAllModules(func(module android.Module) {
|
|
|
|
// Collect dex jar paths for the modules listed above.
|
2021-02-01 22:59:03 +01:00
|
|
|
if ctx.ModuleHasProvider(module, JavaInfoProvider) {
|
|
|
|
j := ctx.ModuleProvider(module, JavaInfoProvider).(JavaInfo)
|
2019-04-18 19:56:44 +02:00
|
|
|
name := ctx.ModuleName(module)
|
|
|
|
if i := android.IndexList(name, stubsModules); i != -1 {
|
2021-02-01 22:59:03 +01:00
|
|
|
stubsJars[i] = j.HeaderJars
|
2019-04-18 19:56:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
var missingDeps []string
|
|
|
|
|
|
|
|
for i := range stubsJars {
|
|
|
|
if stubsJars[i] == nil {
|
|
|
|
if ctx.Config().AllowMissingDependencies() {
|
|
|
|
missingDeps = append(missingDeps, stubsModules[i])
|
|
|
|
} else {
|
2020-04-09 14:29:59 +02:00
|
|
|
ctx.Errorf("failed to find dex jar path for module %q", stubsModules[i])
|
2019-04-18 19:56:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-17 02:32:30 +01:00
|
|
|
rule := android.NewRuleBuilder(pctx, ctx)
|
2019-04-18 19:56:44 +02:00
|
|
|
rule.MissingDeps(missingDeps)
|
|
|
|
|
|
|
|
var aidls android.Paths
|
|
|
|
for _, jars := range stubsJars {
|
|
|
|
for _, jar := range jars {
|
|
|
|
aidl := android.PathForOutput(ctx, "aidl", pathtools.ReplaceExtension(jar.Base(), "aidl"))
|
|
|
|
|
|
|
|
rule.Command().
|
|
|
|
Text("rm -f").Output(aidl)
|
|
|
|
rule.Command().
|
2020-11-17 02:32:30 +01:00
|
|
|
BuiltTool("sdkparcelables").
|
2019-04-18 19:56:44 +02:00
|
|
|
Input(jar).
|
|
|
|
Output(aidl)
|
|
|
|
|
|
|
|
aidls = append(aidls, aidl)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rule.Command().
|
2020-04-09 14:29:59 +02:00
|
|
|
Text("rm -f").Output(path)
|
2019-04-18 19:56:44 +02:00
|
|
|
rule.Command().
|
|
|
|
Text("cat").
|
|
|
|
Inputs(aidls).
|
|
|
|
Text("| sort -u >").
|
2020-04-09 14:29:59 +02:00
|
|
|
Output(path)
|
2019-04-18 19:56:44 +02:00
|
|
|
|
2020-04-09 14:29:59 +02:00
|
|
|
return rule
|
2019-04-18 19:56:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func sdkFrameworkAidlPath(ctx android.PathContext) android.OutputPath {
|
|
|
|
return ctx.Config().Once(sdkFrameworkAidlPathKey, func() interface{} {
|
|
|
|
return android.PathForOutput(ctx, "framework.aidl")
|
|
|
|
}).(android.OutputPath)
|
|
|
|
}
|
|
|
|
|
2020-04-09 14:29:59 +02:00
|
|
|
func nonUpdatableFrameworkAidlPath(ctx android.PathContext) android.OutputPath {
|
|
|
|
return ctx.Config().Once(nonUpdatableFrameworkAidlPathKey, func() interface{} {
|
|
|
|
return android.PathForOutput(ctx, "framework_non_updatable.aidl")
|
|
|
|
}).(android.OutputPath)
|
|
|
|
}
|
|
|
|
|
2019-04-18 23:27:12 +02:00
|
|
|
// Create api_fingerprint.txt
|
|
|
|
func createAPIFingerprint(ctx android.SingletonContext) {
|
2019-04-18 10:25:49 +02:00
|
|
|
out := ApiFingerprintPath(ctx)
|
2019-04-18 23:27:12 +02:00
|
|
|
|
2020-11-17 02:32:30 +01:00
|
|
|
rule := android.NewRuleBuilder(pctx, ctx)
|
2019-04-18 23:27:12 +02:00
|
|
|
|
|
|
|
rule.Command().
|
|
|
|
Text("rm -f").Output(out)
|
|
|
|
cmd := rule.Command()
|
|
|
|
|
|
|
|
if ctx.Config().PlatformSdkCodename() == "REL" {
|
|
|
|
cmd.Text("echo REL >").Output(out)
|
2021-02-10 15:52:42 +01:00
|
|
|
} else if ctx.Config().FrameworksBaseDirExists(ctx) && !ctx.Config().AlwaysUsePrebuiltSdks() {
|
|
|
|
cmd.Text("cat")
|
|
|
|
apiTxtFileModules := []string{
|
2023-03-07 00:21:35 +01:00
|
|
|
"api_fingerprint",
|
2019-04-18 23:27:12 +02:00
|
|
|
}
|
2021-02-10 15:52:42 +01:00
|
|
|
count := 0
|
|
|
|
ctx.VisitAllModules(func(module android.Module) {
|
|
|
|
name := ctx.ModuleName(module)
|
|
|
|
if android.InList(name, apiTxtFileModules) {
|
|
|
|
cmd.Inputs(android.OutputFilesForModule(ctx, module, ""))
|
|
|
|
count++
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if count != len(apiTxtFileModules) {
|
2023-03-07 00:21:35 +01:00
|
|
|
ctx.Errorf("Could not find expected API module %v, found %d\n", apiTxtFileModules, count)
|
2021-02-10 15:52:42 +01:00
|
|
|
return
|
|
|
|
}
|
2023-03-07 00:21:35 +01:00
|
|
|
cmd.Text(">").
|
2019-04-18 23:27:12 +02:00
|
|
|
Output(out)
|
|
|
|
} else {
|
|
|
|
// Unbundled build
|
|
|
|
// TODO: use a prebuilt api_fingerprint.txt from prebuilts/sdk/current.txt once we have one
|
|
|
|
cmd.Text("echo").
|
|
|
|
Flag(ctx.Config().PlatformPreviewSdkVersion()).
|
|
|
|
Text(">").
|
|
|
|
Output(out)
|
|
|
|
}
|
|
|
|
|
2020-11-17 02:32:30 +01:00
|
|
|
rule.Build("api_fingerprint", "generate api_fingerprint.txt")
|
2019-04-18 23:27:12 +02:00
|
|
|
}
|
|
|
|
|
2019-04-18 10:25:49 +02:00
|
|
|
func ApiFingerprintPath(ctx android.PathContext) android.OutputPath {
|
2019-04-18 23:27:12 +02:00
|
|
|
return ctx.Config().Once(apiFingerprintPathKey, func() interface{} {
|
|
|
|
return android.PathForOutput(ctx, "api_fingerprint.txt")
|
|
|
|
}).(android.OutputPath)
|
|
|
|
}
|
|
|
|
|
|
|
|
func sdkMakeVars(ctx android.MakeVarsContext) {
|
2020-05-29 00:28:00 +02:00
|
|
|
if ctx.Config().AlwaysUsePrebuiltSdks() {
|
2019-04-18 19:56:44 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Strict("FRAMEWORK_AIDL", sdkFrameworkAidlPath(ctx).String())
|
2019-04-18 10:25:49 +02:00
|
|
|
ctx.Strict("API_FINGERPRINT", ApiFingerprintPath(ctx).String())
|
2019-01-10 08:04:25 +01:00
|
|
|
}
|