From 5bb33a575737cb2f6e5acdeea8db25e088ea07f7 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Fri, 16 Aug 2019 14:22:26 -0700 Subject: Version vendor libprotobuf-cpp-* libraries Vendor prebuilts reference the protobuf runtime libraries, but the runtime libraries do not have a stable ABI. Add a version suffix to the names of the libraries when used by vendor modules so that old versions can be left in place when the protobuf version is updated. Also adds a test that verifies that the library names match the version number to ensure the version number gets updated when protobuf is updated. Bug: 117607748 Test: libprotobuf_vendor_suffix_test Change-Id: Iee5bbe95cb898f8ab552028f32e4b40d67f54f23 --- Android.bp | 18 ++++++++++++++++++ METADATA | 1 + TEST_MAPPING | 7 +++++++ vendor_suffix_test.config | 30 ++++++++++++++++++++++++++++++ vendor_suffix_test.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 98 insertions(+) create mode 100644 TEST_MAPPING create mode 100644 vendor_suffix_test.config create mode 100644 vendor_suffix_test.cpp diff --git a/Android.bp b/Android.bp index f0f13879e..e767f01dd 100644 --- a/Android.bp +++ b/Android.bp @@ -79,6 +79,10 @@ cc_defaults { android: { shared_libs: ["liblog"], }, + vendor: { + // This suffix must be updated when a new version is imported. + suffix: "-3.9.1", + }, }, } @@ -375,6 +379,20 @@ cc_binary_host { rtti: true, } +cc_test { + name: "libprotobuf_vendor_suffix_test", + vendor: true, + srcs: ["vendor_suffix_test.cpp"], + shared_libs: [ + "libprotobuf-cpp-lite", + "libprotobuf-cpp-full", + ], + static_libs: ["libbase"], + stl: "libc++", + test_suites: ["general-tests"], + test_config: "vendor_suffix_test.config", +} + java_defaults { name: "libprotobuf_errorprone_defaults", errorprone: { diff --git a/METADATA b/METADATA index 4617d9189..64306e4fe 100644 --- a/METADATA +++ b/METADATA @@ -11,6 +11,7 @@ third_party { type: GIT value: "https://github.com/protocolbuffers/protobuf" } + // Also update the suffix in Android.bp when updating the version. version: "v3.9.1" last_upgrade_date { year: 2019 month: 8 day: 23 } license_type: PERMISSIVE diff --git a/TEST_MAPPING b/TEST_MAPPING new file mode 100644 index 000000000..21a533459 --- /dev/null +++ b/TEST_MAPPING @@ -0,0 +1,7 @@ +{ + "presubmit": [ + { + "name": "libprotobuf_vendor_suffix_test" + } + ] +} diff --git a/vendor_suffix_test.config b/vendor_suffix_test.config new file mode 100644 index 000000000..eb8bab786 --- /dev/null +++ b/vendor_suffix_test.config @@ -0,0 +1,30 @@ + + + + diff --git a/vendor_suffix_test.cpp b/vendor_suffix_test.cpp new file mode 100644 index 000000000..bd0642234 --- /dev/null +++ b/vendor_suffix_test.cpp @@ -0,0 +1,42 @@ +#include + +#include +#include + +#include + +#include + +#include + +TEST(vendor_suffix, suffix) { + std::vector libs; + dl_iterate_phdr([](dl_phdr_info* info, size_t, void* data) -> int { + auto local_libs = static_cast(data); + std::string name = info->dlpi_name; + size_t libprotobuf = name.find("libprotobuf-cpp"); + if (libprotobuf != name.npos) { + local_libs->push_back(name.substr(libprotobuf, name.size())); + } + return 0; + }, &libs); + + std::sort(libs.begin(), libs.end()); + + std::string version = android::base::StringPrintf("-%d.%d.%d", + GOOGLE_PROTOBUF_VERSION / 1000000, + GOOGLE_PROTOBUF_VERSION / 1000 % 1000, + GOOGLE_PROTOBUF_VERSION % 1000); + + std::string suffix = GOOGLE_PROTOBUF_VERSION_SUFFIX; + if (suffix != "") { + version += "-" + suffix; + } + + std::vector expect = { + "libprotobuf-cpp-full" + version + ".so", + "libprotobuf-cpp-lite" + version + ".so", + }; + + ASSERT_EQ(expect, libs); +} -- cgit v1.2.3