Add support for native bridge trait
Adds a native bridge trait that if required will cause a
cc_library_header module to generate a cc_prebuilt_library_headers with
native_bridge_supported: true. It will fail if the cc_library_header's
native bridge variant would produce native bridge specific properties,
distinct from the other architecture variants, in the generated
cc_prebuilt_library_headers.
Bug: 195754365
Test: m nothing
Change-Id: I282fbb9095de6c6af57cca4eb4260e2c6c2da8cc
diff --git a/sdk/cc_sdk_test.go b/sdk/cc_sdk_test.go
index 25e35fc..da90c6d 100644
--- a/sdk/cc_sdk_test.go
+++ b/sdk/cc_sdk_test.go
@@ -32,6 +32,23 @@
"some/where/stubslib.map.txt": nil,
}
+// Adds a native bridge target to the configured list of targets.
+var prepareForTestWithNativeBridgeTarget = android.FixtureModifyConfig(func(config android.Config) {
+ config.Targets[android.Android] = append(config.Targets[android.Android], android.Target{
+ Os: android.Android,
+ Arch: android.Arch{
+ ArchType: android.Arm64,
+ ArchVariant: "armv8-a",
+ CpuVariant: "cpu",
+ Abi: nil,
+ ArchFeatures: nil,
+ },
+ NativeBridge: android.NativeBridgeEnabled,
+ NativeBridgeHostArchName: "x86_64",
+ NativeBridgeRelativePath: "native_bridge",
+ })
+})
+
func testSdkWithCc(t *testing.T, bp string) *android.TestResult {
t.Helper()
return testSdkWithFs(t, bp, ccTestFs)
@@ -1979,6 +1996,91 @@
)
}
+func TestSnapshotWithCcHeadersLibraryAndNativeBridgeSupport(t *testing.T) {
+ result := android.GroupFixturePreparers(
+ cc.PrepareForTestWithCcDefaultModules,
+ PrepareForTestWithSdkBuildComponents,
+ ccTestFs.AddToFixture(),
+ prepareForTestWithNativeBridgeTarget,
+ ).RunTestWithBp(t, `
+ sdk {
+ name: "mysdk",
+ native_header_libs: ["mynativeheaders"],
+ traits: {
+ native_bridge_support: ["mynativeheaders"],
+ },
+ }
+
+ cc_library_headers {
+ name: "mynativeheaders",
+ export_include_dirs: ["myinclude"],
+ stl: "none",
+ system_shared_libs: [],
+ native_bridge_supported: true,
+ }
+ `)
+
+ CheckSnapshot(t, result, "mysdk", "",
+ checkUnversionedAndroidBpContents(`
+// This is auto-generated. DO NOT EDIT.
+
+cc_prebuilt_library_headers {
+ name: "mynativeheaders",
+ prefer: false,
+ visibility: ["//visibility:public"],
+ apex_available: ["//apex_available:platform"],
+ native_bridge_supported: true,
+ stl: "none",
+ compile_multilib: "both",
+ system_shared_libs: [],
+ export_include_dirs: ["include/myinclude"],
+}
+`),
+ checkAllCopyRules(`
+myinclude/Test.h -> include/myinclude/Test.h
+`),
+ )
+}
+
+// TestSnapshotWithCcHeadersLibrary_DetectsNativeBridgeSpecificProperties verifies that when a
+// module that has different output files for a native bridge target requests the native bridge
+// variants are copied into the sdk snapshot that it reports an error.
+func TestSnapshotWithCcHeadersLibrary_DetectsNativeBridgeSpecificProperties(t *testing.T) {
+ android.GroupFixturePreparers(
+ cc.PrepareForTestWithCcDefaultModules,
+ PrepareForTestWithSdkBuildComponents,
+ ccTestFs.AddToFixture(),
+ prepareForTestWithNativeBridgeTarget,
+ ).ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
+ `\QArchitecture variant "arm64_native_bridge" of sdk member "mynativeheaders" has properties distinct from other variants; this is not yet supported. The properties are:
+ export_include_dirs: [
+ "arm64_native_bridge/include/myinclude_nativebridge",
+ "arm64_native_bridge/include/myinclude",
+ ],\E`)).
+ RunTestWithBp(t, `
+ sdk {
+ name: "mysdk",
+ native_header_libs: ["mynativeheaders"],
+ traits: {
+ native_bridge_support: ["mynativeheaders"],
+ },
+ }
+
+ cc_library_headers {
+ name: "mynativeheaders",
+ export_include_dirs: ["myinclude"],
+ stl: "none",
+ system_shared_libs: [],
+ native_bridge_supported: true,
+ target: {
+ native_bridge: {
+ export_include_dirs: ["myinclude_nativebridge"],
+ },
+ },
+ }
+ `)
+}
+
func TestHostSnapshotWithCcHeadersLibrary(t *testing.T) {
result := testSdkWithCc(t, `
sdk {