diff options
-rw-r--r-- | aidl_checkapi.cpp | 1 | ||||
-rw-r--r-- | aidl_language.cpp | 5 | ||||
-rw-r--r-- | aidl_language.h | 2 | ||||
-rw-r--r-- | build/aidl_interface.go | 41 | ||||
-rw-r--r-- | build/aidl_interface_backends.go | 69 | ||||
-rw-r--r-- | build/properties.go | 19 |
6 files changed, 76 insertions, 61 deletions
diff --git a/aidl_checkapi.cpp b/aidl_checkapi.cpp index 47733c1b..b132494f 100644 --- a/aidl_checkapi.cpp +++ b/aidl_checkapi.cpp @@ -86,6 +86,7 @@ static vector<string> get_strict_annotations(const AidlAnnotatable& node) { AidlAnnotation::Type::NULLABLE, // @JavaDerive doesn't affect read/write AidlAnnotation::Type::JAVA_DERIVE, + AidlAnnotation::Type::JAVA_DEFAULT, AidlAnnotation::Type::JAVA_ONLY_IMMUTABLE, // @Backing for a enum type is checked by the enum checker AidlAnnotation::Type::BACKING, diff --git a/aidl_language.cpp b/aidl_language.cpp index 5bff95e5..22104774 100644 --- a/aidl_language.cpp +++ b/aidl_language.cpp @@ -128,6 +128,7 @@ const std::vector<AidlAnnotation::Schema>& AidlAnnotation::AllSchemas() { "JavaDerive", CONTEXT_TYPE_STRUCTURED_PARCELABLE | CONTEXT_TYPE_UNION, {{"toString", kBooleanType}, {"equals", kBooleanType}}}, + {AidlAnnotation::Type::JAVA_DEFAULT, "JavaDefault", CONTEXT_TYPE_INTERFACE, {}}, {AidlAnnotation::Type::JAVA_ONLY_IMMUTABLE, "JavaOnlyImmutable", CONTEXT_TYPE_STRUCTURED_PARCELABLE | CONTEXT_TYPE_UNION | @@ -403,6 +404,10 @@ bool AidlAnnotatable::JavaDerive(const std::string& method) const { return false; } +bool AidlAnnotatable::IsJavaDefault() const { + return GetAnnotation(annotations_, AidlAnnotation::Type::JAVA_DEFAULT); +} + std::string AidlAnnotatable::GetDescriptor() const { auto annotation = GetAnnotation(annotations_, AidlAnnotation::Type::DESCRIPTOR); if (annotation != nullptr) { diff --git a/aidl_language.h b/aidl_language.h index 931c606c..36c50664 100644 --- a/aidl_language.h +++ b/aidl_language.h @@ -209,6 +209,7 @@ class AidlAnnotation : public AidlNode { SENSITIVE_DATA, JAVA_PASSTHROUGH, JAVA_DERIVE, + JAVA_DEFAULT, JAVA_ONLY_IMMUTABLE, FIXED_SIZE, DESCRIPTOR, @@ -325,6 +326,7 @@ class AidlAnnotatable : public AidlCommentable { bool IsStableApiParcelable(Options::Language lang) const; bool IsHide() const; bool JavaDerive(const std::string& method) const; + bool IsJavaDefault() const; std::string GetDescriptor() const; const AidlAnnotation* UnsupportedAppUsage() const; diff --git a/build/aidl_interface.go b/build/aidl_interface.go index 251d0d63..80ba3d6a 100644 --- a/build/aidl_interface.go +++ b/build/aidl_interface.go @@ -40,8 +40,10 @@ const ( langCpp = "cpp" langJava = "java" langNdk = "ndk" - langNdkPlatform = "ndk_platform" langRust = "rust" + // TODO(b/161456198) remove the NDK platform backend as the 'platform' variant of the NDK + // backend serves the same purpose. + langNdkPlatform = "ndk_platform" currentVersion = "current" ) @@ -380,19 +382,18 @@ type aidlInterfaceProperties struct { Cpp struct { CommonNativeBackendProperties } - // Backend of the compiler generating code for C++ clients using - // libbinder_ndk (stable C interface to system's libbinder) - // When enabled, this creates a target called "<name>-ndk" - // (for apps) and "<name>-ndk_platform" (for platform usage). + // Backend of the compiler generating code for C++ clients using libbinder_ndk + // (stable C interface to system's libbinder) When enabled, this creates a target + // called "<name>-V<ver>-ndk" (for both apps and platform) and + // "<name>-V<ver>-ndk_platform" (for platform only). + // TODO(b/161456198): remove the ndk_platform backend as the ndk backend can serve + // the same purpose. Ndk struct { CommonNativeBackendProperties - // Currently, all ndk-supported interfaces generate two variants: - // - ndk - for apps to use, against an NDK - // - ndk_platform - for the platform to use - // - // This adds an option to disable the 'ndk' variant in cases where APIs - // only available in the platform version work. + // If set to false, the ndk backend is exclusive to platform and is not + // available to applications. Default is true (i.e. available to both + // applications and platform). Apps_enabled *bool } // Backend of the compiler generating code for Rust clients. @@ -426,25 +427,27 @@ type aidlInterface struct { func (i *aidlInterface) shouldGenerateJavaBackend() bool { // explicitly true if not specified to give early warning to devs - return i.properties.Backend.Java.Enabled == nil || *i.properties.Backend.Java.Enabled + return proptools.BoolDefault(i.properties.Backend.Java.Enabled, true) } func (i *aidlInterface) shouldGenerateCppBackend() bool { // explicitly true if not specified to give early warning to devs - return i.properties.Backend.Cpp.Enabled == nil || *i.properties.Backend.Cpp.Enabled + return proptools.BoolDefault(i.properties.Backend.Cpp.Enabled, true) } func (i *aidlInterface) shouldGenerateNdkBackend() bool { // explicitly true if not specified to give early warning to devs + return proptools.BoolDefault(i.properties.Backend.Ndk.Enabled, true) return i.properties.Backend.Ndk.Enabled == nil || *i.properties.Backend.Ndk.Enabled } +// Returns whether the ndk backend supports applications or not. Default is `true`. `false` is +// returned only when `apps_enabled` is explicitly set to false. Note that the ndk_platform backend +// (which will be removed in the future) is not affected by this. In other words, it is always +// exclusive for the platform, as its name clearly shows. func (i *aidlInterface) shouldGenerateAppNdkBackend() bool { - if !i.shouldGenerateNdkBackend() { - return false - } - // explicitly true if not specified to give early warning to devs - return i.properties.Backend.Ndk.Apps_enabled == nil || *i.properties.Backend.Ndk.Apps_enabled + return i.shouldGenerateNdkBackend() && + proptools.BoolDefault(i.properties.Backend.Ndk.Apps_enabled, true) } func (i *aidlInterface) shouldGenerateRustBackend() bool { @@ -685,7 +688,7 @@ func aidlInterfaceHook(mctx android.LoadHookContext, i *aidlInterface) { nextVersion := i.nextVersion() shouldGenerateLangBackendMap := map[string]bool{ langCpp: i.shouldGenerateCppBackend(), - langNdk: i.shouldGenerateAppNdkBackend(), + langNdk: i.shouldGenerateNdkBackend(), langNdkPlatform: i.shouldGenerateNdkBackend(), langJava: i.shouldGenerateJavaBackend(), langRust: i.shouldGenerateRustBackend()} diff --git a/build/aidl_interface_backends.go b/build/aidl_interface_backends.go index 79b66254..6c778af7 100644 --- a/build/aidl_interface_backends.go +++ b/build/aidl_interface_backends.go @@ -97,6 +97,19 @@ func addCppLibrary(mctx android.LoadHookContext, i *aidlInterface, version strin var cpp_std *string var hostSupported *bool var addCflags []string + targetProp := ccTargetProperties{ + // Currently necessary for host builds + // TODO(b/31559095): bionic on host should define this + // TODO(b/146436251): default isn't applied because the module is created + // in PreArchMutators, when import behavior becomes explicit, the logic can + // be moved back to LoadHook + Host: hostProperties{Cflags: []string{ + "-D__INTRODUCED_IN(n)=", + "-D__assert(a,b,c)=", + // We want all the APIs to be available on the host. + "-D__ANDROID_API__=10000"}}, + Darwin: darwinProperties{Enabled: proptools.BoolPtr(false)}, + } if lang == langCpp { importExportDependencies = append(importExportDependencies, "libbinder", "libutils") @@ -105,23 +118,27 @@ func addCppLibrary(mctx android.LoadHookContext, i *aidlInterface, version strin } hostSupported = i.properties.Host_supported minSdkVersion = i.properties.Backend.Cpp.Min_sdk_version - } else if lang == langNdk { + } else if lang == langNdk || lang == langNdkPlatform { importExportDependencies = append(importExportDependencies, "libbinder_ndk") + nonAppProps := imageProperties{ + Cflags: []string{"-DBINDER_STABILITY_SUPPORT"}, + } if genTrace { sharedLibDependency = append(sharedLibDependency, "libandroid") + nonAppProps.Exclude_shared_libs = []string{"libandroid"} + nonAppProps.Header_libs = []string{"libandroid_aidltrace"} + nonAppProps.Shared_libs = []string{"libcutils"} } - sdkVersion = proptools.StringPtr("current") - stl = proptools.StringPtr("c++_shared") + targetProp.Platform = nonAppProps + targetProp.Vendor = nonAppProps + targetProp.Product = nonAppProps minSdkVersion = i.properties.Backend.Ndk.Min_sdk_version - } else if lang == langNdkPlatform { - importExportDependencies = append(importExportDependencies, "libbinder_ndk") - if genTrace { - headerLibs = append(headerLibs, "libandroid_aidltrace") - sharedLibDependency = append(sharedLibDependency, "libcutils") - } hostSupported = i.properties.Host_supported - addCflags = append(addCflags, "-DBINDER_STABILITY_SUPPORT") - minSdkVersion = i.properties.Backend.Ndk.Min_sdk_version + if lang == langNdk && i.shouldGenerateAppNdkBackend() { + sdkVersion = proptools.StringPtr("current") + // Don't worry! This maps to libc++.so for the platform variant. + stl = proptools.StringPtr("c++_shared") + } } else { panic("Unrecognized language: " + lang) } @@ -145,19 +162,6 @@ func addCppLibrary(mctx android.LoadHookContext, i *aidlInterface, version strin productAvailable = nil } - if lang == langNdk { - // TODO(b/121157555): when the NDK variant is its own variant, these wouldn't interact, - // but we can't create a vendor or product version of an NDK variant - // - // nil (unspecified) is used instead of false so that this can't conflict with - // 'vendor: true', for instance. - vendorAvailable = nil - odmAvailable = nil - productAvailable = nil - overrideVndkProperties.Vndk.Enabled = proptools.BoolPtr(false) - overrideVndkProperties.Vndk.Support_system_process = proptools.BoolPtr(false) - } - mctx.CreateModule(aidlImplementationGeneratorFactory, &nameProperties{ Name: proptools.StringPtr(cppModuleGen + "-generator"), }, &aidlImplementationGeneratorProperties{ @@ -186,19 +190,8 @@ func addCppLibrary(mctx android.LoadHookContext, i *aidlInterface, version strin Apex_available: commonProperties.Apex_available, Min_sdk_version: minSdkVersion, UseApexNameMacro: true, - Target: ccTargetProperties{ - // Currently necessary for host builds - // TODO(b/31559095): bionic on host should define this - // TODO(b/146436251): default isn't applied because the module is created - // in PreArchMutators, when import behavior becomes explicit, the logic can - // be moved back to LoadHook - Host: hostProperties{Cflags: []string{ - "-D__INTRODUCED_IN(n)=", - "-D__assert(a,b,c)=", - // We want all the APIs to be available on the host. - "-D__ANDROID_API__=10000"}}, - Darwin: perTargetProperties{Enabled: proptools.BoolPtr(false)}}, - Tidy: proptools.BoolPtr(true), + Target: targetProp, + Tidy: proptools.BoolPtr(true), // Do the tidy check only for the generated headers Tidy_flags: []string{"--header-filter=" + android.PathForOutput(mctx).String() + ".*"}, Tidy_checks_as_errors: []string{"*"}, @@ -303,7 +296,7 @@ func addRustLibrary(mctx android.LoadHookContext, i *aidlInterface, version stri Defaults: []string{"aidl-rust-module-defaults"}, Host_supported: i.properties.Host_supported, Apex_available: i.properties.Backend.Rust.Apex_available, - Target: rustTargetProperties{Darwin: perTargetProperties{Enabled: proptools.BoolPtr(false)}}, + Target: rustTargetProperties{Darwin: darwinProperties{Enabled: proptools.BoolPtr(false)}}, }, &rust.SourceProviderProperties{ Source_stem: proptools.StringPtr(versionedRustName), }, &aidlRustSourceProviderProperties{ diff --git a/build/properties.go b/build/properties.go index 69914edd..1b302a92 100644 --- a/build/properties.go +++ b/build/properties.go @@ -21,17 +21,28 @@ type nameProperties struct { type hostProperties struct { Cflags []string } -type perTargetProperties struct { + +type darwinProperties struct { Enabled *bool } +type imageProperties struct { + Shared_libs []string + Header_libs []string + Exclude_shared_libs []string + Cflags []string +} + type ccTargetProperties struct { - Host hostProperties - Darwin perTargetProperties + Host hostProperties + Darwin darwinProperties + Platform imageProperties + Vendor imageProperties + Product imageProperties } type rustTargetProperties struct { - Darwin perTargetProperties + Darwin darwinProperties } type ccProperties struct { |