From a04c107bfaf9262daafecc9174bd9e85b79264bd Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Mon, 2 Mar 2020 10:16:35 +0000 Subject: Add support for multiple os types Updates the member snapshot creation code to support multiple os types. It basically sorts the variants by os type, then applies the code to optimize the arch properties and then it optimizes the properties that are common across architectures and extracts any properties that are common across os types. The java and cc member types needed to be modified to make the location of the generated files within the snapshot os type dependent when there is more than one os type. That was done by adding an OsPrefix() method to the SdkMemberPropertiesBase which returns the os prefix to use when there is > 1 os type and otherwise returns an empty string. Added three tests, one for cc shared libraries, one for cc binary and one for java header libraries. Bug: 150451422 Test: m nothing Change-Id: I08f5fbdd7852b06c9a9a2f1cfdc364338a3d5bac --- sdk/cc_sdk_test.go | 287 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 282 insertions(+), 5 deletions(-) (limited to 'sdk/cc_sdk_test.go') diff --git a/sdk/cc_sdk_test.go b/sdk/cc_sdk_test.go index 5366edfb5..11bc90238 100644 --- a/sdk/cc_sdk_test.go +++ b/sdk/cc_sdk_test.go @@ -25,11 +25,13 @@ func testSdkWithCc(t *testing.T, bp string) *testSdkResult { t.Helper() fs := map[string][]byte{ - "Test.cpp": nil, - "include/Test.h": nil, - "arm64/include/Arm64Test.h": nil, - "libfoo.so": nil, - "aidl/foo/bar/Test.aidl": nil, + "Test.cpp": nil, + "include/Test.h": nil, + "include-android/AndroidTest.h": nil, + "include-host/HostTest.h": nil, + "arm64/include/Arm64Test.h": nil, + "libfoo.so": nil, + "aidl/foo/bar/Test.aidl": nil, } return testSdkWithFs(t, bp, fs) } @@ -401,6 +403,108 @@ module_exports_snapshot { ) } +func TestMultipleHostOsTypesSnapshotWithCcBinary(t *testing.T) { + // b/145598135 - Generating host snapshots for anything other than linux is not supported. + SkipIfNotLinux(t) + + result := testSdkWithCc(t, ` + module_exports { + name: "myexports", + device_supported: false, + host_supported: true, + native_binaries: ["mynativebinary"], + target: { + windows: { + enabled: true, + }, + }, + } + + cc_binary { + name: "mynativebinary", + device_supported: false, + host_supported: true, + srcs: [ + "Test.cpp", + ], + compile_multilib: "both", + system_shared_libs: [], + stl: "none", + target: { + windows: { + enabled: true, + }, + }, + } + `) + + result.CheckSnapshot("myexports", "", + checkAndroidBpContents(` +// This is auto-generated. DO NOT EDIT. + +cc_prebuilt_binary { + name: "myexports_mynativebinary@current", + sdk_member_name: "mynativebinary", + device_supported: false, + host_supported: true, + target: { + linux_glibc: { + compile_multilib: "both", + }, + linux_glibc_x86_64: { + srcs: ["linux_glibc/x86_64/bin/mynativebinary"], + }, + linux_glibc_x86: { + srcs: ["linux_glibc/x86/bin/mynativebinary"], + }, + windows: { + compile_multilib: "64", + }, + windows_x86_64: { + srcs: ["windows/x86_64/bin/mynativebinary.exe"], + }, + }, +} + +cc_prebuilt_binary { + name: "mynativebinary", + prefer: false, + device_supported: false, + host_supported: true, + target: { + linux_glibc: { + compile_multilib: "both", + }, + linux_glibc_x86_64: { + srcs: ["linux_glibc/x86_64/bin/mynativebinary"], + }, + linux_glibc_x86: { + srcs: ["linux_glibc/x86/bin/mynativebinary"], + }, + windows: { + compile_multilib: "64", + }, + windows_x86_64: { + srcs: ["windows/x86_64/bin/mynativebinary.exe"], + }, + }, +} + +module_exports_snapshot { + name: "myexports@current", + device_supported: false, + host_supported: true, + native_binaries: ["myexports_mynativebinary@current"], +} +`), + checkAllCopyRules(` +.intermediates/mynativebinary/linux_glibc_x86_64/mynativebinary -> linux_glibc/x86_64/bin/mynativebinary +.intermediates/mynativebinary/linux_glibc_x86/mynativebinary -> linux_glibc/x86/bin/mynativebinary +.intermediates/mynativebinary/windows_x86_64/mynativebinary.exe -> windows/x86_64/bin/mynativebinary.exe +`), + ) +} + func TestSnapshotWithCcSharedLibrary(t *testing.T) { result := testSdkWithCc(t, ` sdk { @@ -588,6 +692,99 @@ include/Test.h -> include/include/Test.h ) } +func TestMultipleHostOsTypesSnapshotWithCcSharedLibrary(t *testing.T) { + // b/145598135 - Generating host snapshots for anything other than linux is not supported. + SkipIfNotLinux(t) + + result := testSdkWithCc(t, ` + sdk { + name: "mysdk", + device_supported: false, + host_supported: true, + native_shared_libs: ["mynativelib"], + target: { + windows: { + enabled: true, + }, + }, + } + + cc_library_shared { + name: "mynativelib", + device_supported: false, + host_supported: true, + srcs: [ + "Test.cpp", + ], + system_shared_libs: [], + stl: "none", + target: { + windows: { + enabled: true, + }, + }, + } + `) + + result.CheckSnapshot("mysdk", "", + checkAndroidBpContents(` +// This is auto-generated. DO NOT EDIT. + +cc_prebuilt_library_shared { + name: "mysdk_mynativelib@current", + sdk_member_name: "mynativelib", + device_supported: false, + host_supported: true, + target: { + linux_glibc_x86_64: { + srcs: ["linux_glibc/x86_64/lib/mynativelib.so"], + }, + linux_glibc_x86: { + srcs: ["linux_glibc/x86/lib/mynativelib.so"], + }, + windows_x86_64: { + srcs: ["windows/x86_64/lib/mynativelib.dll"], + }, + }, + stl: "none", + system_shared_libs: [], +} + +cc_prebuilt_library_shared { + name: "mynativelib", + prefer: false, + device_supported: false, + host_supported: true, + target: { + linux_glibc_x86_64: { + srcs: ["linux_glibc/x86_64/lib/mynativelib.so"], + }, + linux_glibc_x86: { + srcs: ["linux_glibc/x86/lib/mynativelib.so"], + }, + windows_x86_64: { + srcs: ["windows/x86_64/lib/mynativelib.dll"], + }, + }, + stl: "none", + system_shared_libs: [], +} + +sdk_snapshot { + name: "mysdk@current", + device_supported: false, + host_supported: true, + native_shared_libs: ["mysdk_mynativelib@current"], +} +`), + checkAllCopyRules(` +.intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> linux_glibc/x86_64/lib/mynativelib.so +.intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> linux_glibc/x86/lib/mynativelib.so +.intermediates/mynativelib/windows_x86_64_shared/mynativelib.dll -> windows/x86_64/lib/mynativelib.dll +`), + ) +} + func TestSnapshotWithCcStaticLibrary(t *testing.T) { result := testSdkWithCc(t, ` module_exports { @@ -958,3 +1155,83 @@ include/Test.h -> include/include/Test.h `), ) } + +func TestDeviceAndHostSnapshotWithCcHeadersLibrary(t *testing.T) { + // b/145598135 - Generating host snapshots for anything other than linux is not supported. + SkipIfNotLinux(t) + + result := testSdkWithCc(t, ` + sdk { + name: "mysdk", + host_supported: true, + native_header_libs: ["mynativeheaders"], + } + + cc_library_headers { + name: "mynativeheaders", + host_supported: true, + system_shared_libs: [], + stl: "none", + export_system_include_dirs: ["include"], + target: { + android: { + export_include_dirs: ["include-android"], + }, + host: { + export_include_dirs: ["include-host"], + }, + }, + } + `) + + result.CheckSnapshot("mysdk", "", + checkAndroidBpContents(` +// This is auto-generated. DO NOT EDIT. + +cc_prebuilt_library_headers { + name: "mysdk_mynativeheaders@current", + sdk_member_name: "mynativeheaders", + host_supported: true, + export_system_include_dirs: ["include/include"], + target: { + android: { + export_include_dirs: ["include/include-android"], + }, + linux_glibc: { + export_include_dirs: ["include/include-host"], + }, + }, + stl: "none", + system_shared_libs: [], +} + +cc_prebuilt_library_headers { + name: "mynativeheaders", + prefer: false, + host_supported: true, + export_system_include_dirs: ["include/include"], + target: { + android: { + export_include_dirs: ["include/include-android"], + }, + linux_glibc: { + export_include_dirs: ["include/include-host"], + }, + }, + stl: "none", + system_shared_libs: [], +} + +sdk_snapshot { + name: "mysdk@current", + host_supported: true, + native_header_libs: ["mysdk_mynativeheaders@current"], +} +`), + checkAllCopyRules(` +include/Test.h -> include/include/Test.h +include-android/AndroidTest.h -> include/include-android/AndroidTest.h +include-host/HostTest.h -> include/include-host/HostTest.h +`), + ) +} -- cgit v1.2.3-59-g8ed1b