From f8fab9b8c66ed4ae56d8b257ebe65c3508d9a914 Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Mon, 2 Sep 2024 15:24:15 +0900 Subject: [PATCH 1/3] ndk_library depends on the correct arch variant of cc_library_headers Previously before aosp/3249712, ndk_library was assumed to depend only on ndk_headers, which do not have any variants. As ndk_library can now depend on cc_library_headers which has many variants for arch, sdk, and more, the previous assumption no longer holds. Therefore, when ndk_library makes a dependency to its export_lib_headers, it now uses either AddFarVariationDependency with (for ndk_headers) or AddVariationDependency (for others) depending on which module type it depends on. Bug: 357711733 Test: build with https://r.android.com/q/topic:%22no-cpp-in-ndk-2%22 Change-Id: Id0957e82736bd458e15674ffc45ca32b1e3a7250 --- cc/cc.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cc/cc.go b/cc/cc.go index 947dc1aee..eee2d61d4 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -2507,8 +2507,14 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { } if c.isNDKStubLibrary() { - // ndk_headers do not have any variations - actx.AddFarVariationDependencies([]blueprint.Variation{}, depTag, lib) + variationExists := actx.OtherModuleDependencyVariantExists(nil, lib) + if variationExists { + actx.AddVariationDependencies(nil, depTag, lib) + } else { + // dependencies to ndk_headers fall here as ndk_headers do not have + // any variants. + actx.AddFarVariationDependencies([]blueprint.Variation{}, depTag, lib) + } } else if c.IsStubs() && !c.isImportedApiLibrary() { actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()), depTag, lib) From bedc997c4031351aaf1739180af39d34b5af8c2a Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Tue, 3 Sep 2024 21:46:14 +0000 Subject: [PATCH 2/3] Reland "Truely re-export export_header_libs from ndk_library" This reverts commit 7f1ae59d94d95d56853f4e4b74b9292578faac78. Reason for revert: b/357711733, reland with allowlist Bug: 357711733 Change-Id: I11864eb2168c4333ad5759d0d057fda8529da24e Test: build --- cc/ndk_library.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cc/ndk_library.go b/cc/ndk_library.go index 3e35ef50a..5250b8610 100644 --- a/cc/ndk_library.go +++ b/cc/ndk_library.go @@ -484,7 +484,8 @@ func (c *stubDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) O // Add a dependency on the header modules of this ndk_library func (linker *stubDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps { return Deps{ - HeaderLibs: linker.properties.Export_header_libs, + ReexportHeaderLibHeaders: linker.properties.Export_header_libs, + HeaderLibs: linker.properties.Export_header_libs, } } From 0db999c45e4dc5c6544492d26728604fddce6011 Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Tue, 3 Sep 2024 22:06:24 +0000 Subject: [PATCH 3/3] ndk_library: limit exports The NDK should stand alone, and the libbinder_ndk case is created because libbinder_ndk in the NDK used to contain extra C++ headers, but these were moved into the SDK to be next to AIDL. Since many modules depend on these headers, exports are only allowed for this case. Bug: 357711733 Test: build with neverallow breaking, for instance: error: frameworks/wilhelm/Android.bp:56:1: module "libOpenSLES.ndk" variant "android_x86_64_silvermont_sdk_shared_21": violates neverallow requirements. Not allowed: module types: ["ndk_library"] properties matching: "Export_header_libs" matches: .is-set EXCEPT in dirs: ["frameworks/native/libs/binder/ndk/"] Change-Id: I9a32d3cb7f644fb5dbc1e8072894f2f585b2cd6d --- android/neverallow.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/android/neverallow.go b/android/neverallow.go index 0f363e78f..7f6999dfa 100644 --- a/android/neverallow.go +++ b/android/neverallow.go @@ -60,6 +60,7 @@ func init() { AddNeverAllowRules(createCcStubsRule()) AddNeverAllowRules(createJavaExcludeStaticLibsRule()) AddNeverAllowRules(createProhibitHeaderOnlyRule()) + AddNeverAllowRules(createLimitNdkExportRule()...) } // Add a NeverAllow rule to the set of rules to apply. @@ -266,6 +267,22 @@ func createProhibitHeaderOnlyRule() Rule { Because("headers_only can only be used for generating framework-minus-apex headers for non-updatable modules") } +func createLimitNdkExportRule() []Rule { + reason := "If the headers you're trying to export are meant to be a part of the NDK, they should be exposed by an ndk_headers module. If the headers shouldn't be a part of the NDK, the headers should instead be exposed from a separate `cc_library_headers` which consumers depend on." + // DO NOT ADD HERE - please consult danalbert@ + // b/357711733 + return []Rule{ + NeverAllow(). + NotIn("frameworks/native/libs/binder/ndk"). + ModuleType("ndk_library"). + WithMatcher("export_header_libs", isSetMatcherInstance).Because(reason), + NeverAllow().ModuleType("ndk_library").WithMatcher("export_generated_headers", isSetMatcherInstance).Because(reason), + NeverAllow().ModuleType("ndk_library").WithMatcher("export_include_dirs", isSetMatcherInstance).Because(reason), + NeverAllow().ModuleType("ndk_library").WithMatcher("export_shared_lib_headers", isSetMatcherInstance).Because(reason), + NeverAllow().ModuleType("ndk_library").WithMatcher("export_static_lib_headers", isSetMatcherInstance).Because(reason), + } +} + func neverallowMutator(ctx BottomUpMutatorContext) { m, ok := ctx.Module().(Module) if !ok {