diff options
author | Colin Cross <ccross@android.com> | 2019-08-16 14:22:26 -0700 |
---|---|---|
committer | Colin Cross <ccross@android.com> | 2019-09-04 12:56:30 -0700 |
commit | 5bb33a575737cb2f6e5acdeea8db25e088ea07f7 (patch) | |
tree | a41056379107d3928a1ca0df4fe35611d64b244a | |
parent | b7ae2affb13dcb5663a272d1ced0fd20a490de70 (diff) | |
download | protobuf-5bb33a575737cb2f6e5acdeea8db25e088ea07f7.tar.gz |
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
-rw-r--r-- | Android.bp | 18 | ||||
-rw-r--r-- | METADATA | 1 | ||||
-rw-r--r-- | TEST_MAPPING | 7 | ||||
-rw-r--r-- | vendor_suffix_test.config | 30 | ||||
-rw-r--r-- | vendor_suffix_test.cpp | 42 |
5 files changed, 98 insertions, 0 deletions
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: { @@ -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 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2017 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<configuration description="Runs libprotobuf_vendor_suffix_test."> + <option name="test-suite-tag" value="apct" /> + <option name="test-suite-tag" value="apct-native" /> + + <target_preparer class="com.android.tradefed.targetprep.PushFilePreparer"> + <option name="cleanup" value="true" /> + <!-- This file could be autogenerated if the default config handled tests that linked against vendor libraries --> + <option name="push" value="libprotobuf_vendor_suffix_test->/data/nativetest/vendor/libprotobuf_vendor_suffix_test/libprotobuf_vendor_suffix_test" /> + </target_preparer> + + <test class="com.android.tradefed.testtype.GTest" > + <option name="native-test-device-path" value="/data/nativetest/vendor/libprotobuf_vendor_suffix_test" /> + <option name="module-name" value="libprotobuf_vendor_suffix_test" /> + </test> +</configuration> 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 <link.h> + +#include <string> +#include <vector> + +#include <android-base/stringprintf.h> + +#include <gtest/gtest.h> + +#include <google/protobuf/message_lite.h> + +TEST(vendor_suffix, suffix) { + std::vector<std::string> libs; + dl_iterate_phdr([](dl_phdr_info* info, size_t, void* data) -> int { + auto local_libs = static_cast<decltype(&libs)>(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<std::string> expect = { + "libprotobuf-cpp-full" + version + ".so", + "libprotobuf-cpp-lite" + version + ".so", + }; + + ASSERT_EQ(expect, libs); +} |