Skip to content

Commit

Permalink
Breaking change: Migrate to Abseil's logging library.
Browse files Browse the repository at this point in the history
This deletes our old branches of internal Abseil code in favor of their newly open-sourced library.  Notably, this removes the ability to turn CHECK crashes into exceptions.

PiperOrigin-RevId: 504460562
  • Loading branch information
mkruskal-google authored and Copybara-Service committed Jan 25, 2023
1 parent 79ee26a commit a9f1ea6
Show file tree
Hide file tree
Showing 234 changed files with 1,993 additions and 2,539 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codespell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ jobs:
with:
check_filenames: true
skip: ./.git,./third_party,./conformance/third_party,*.snk,*.pb,*.pb.cc,*.pb.h,./src/google/protobuf/testdata,./objectivec/Tests,./python/compatibility_tests/v2.5.0/tests/google/protobuf/internal,./.github/workflows/codespell.yml
ignore_words_list: "alow,alse,ba,chec,cleare,copyable,cloneable,dedup,dur,errorprone,falsy,files',fo,fundementals,hel,importd,inout,leapyear,nd,nin,ois,ons,parseable,process',ro,te,testof,ue,unparseable,wasn,wee,gae,keyserver,objext,od,optin,streem,sur,falsy"
ignore_words_list: "alow,alse,atleast,ba,chec,cleare,copyable,cloneable,dedup,dur,errorprone,falsy,files',fo,fundementals,hel,importd,inout,leapyear,nd,nin,ois,ons,parseable,process',ro,te,testof,ue,unparseable,wasn,wee,gae,keyserver,objext,od,optin,streem,sur,falsy"
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[submodule "third_party/abseil-cpp"]
path = third_party/abseil-cpp
url = https://github.com/abseil/abseil-cpp.git
branch = lts_2023_01_17
branch = lts_2023_01_24
[submodule "third_party/jsoncpp"]
path = third_party/jsoncpp
url = https://github.com/open-source-parsers/jsoncpp.git
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ else (protobuf_BUILD_SHARED_LIBS)
endif()
endif (protobuf_BUILD_SHARED_LIBS)

# Export all symbols on Windows when building shared libraries
SET(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

if (MSVC)
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
# Build with multiple processes
Expand All @@ -268,6 +271,7 @@ if (MSVC)
# MSVC warning suppressions
add_compile_options(
/wd4065 # switch statement contains 'default' but no 'case' labels
/wd4146 # unary minus operator applied to unsigned type
/wd4244 # 'conversion' conversion from 'type1' to 'type2', possible loss of data
/wd4251 # 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2'
/wd4267 # 'var' : conversion from 'size_t' to 'type', possible loss of data
Expand Down Expand Up @@ -319,6 +323,10 @@ endif (protobuf_UNICODE)
set(protobuf_ABSL_PROVIDER "module" CACHE STRING "Provider of absl library")
set_property(CACHE protobuf_ABSL_PROVIDER PROPERTY STRINGS "module" "package")

if (protobuf_BUILD_TESTS)
include(${protobuf_SOURCE_DIR}/cmake/gtest.cmake)
endif (protobuf_BUILD_TESTS)

include(${protobuf_SOURCE_DIR}/cmake/abseil-cpp.cmake)

if (protobuf_BUILD_PROTOBUF_BINARIES)
Expand Down
1 change: 1 addition & 0 deletions build_defs/cpp_opts.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
COPTS = select({
"//build_defs:config_msvc": [
"/wd4065", # switch statement contains 'default' but no 'case' labels
"/wd4146", # unary minus operator applied to unsigned type
"/wd4244", # 'conversion' conversion from 'type1' to 'type2', possible loss of data
"/wd4251", # 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2'
"/wd4267", # 'var' : conversion from 'size_t' to 'type', possible loss of data
Expand Down
22 changes: 19 additions & 3 deletions cmake/abseil-cpp.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Setup our dependency on Abseil.

if(protobuf_BUILD_TESTS)
# Tell Abseil to build test-only helpers.
set(ABSL_BUILD_TEST_HELPERS ON)

# We depend on googletest too, so just tell Abseil to use the same one we've
# already setup.
set(ABSL_USE_EXTERNAL_GOOGLETEST ON)
set(ABSL_FIND_GOOGLETEST OFF)
endif()

if(TARGET absl::strings)
# If Abseil is included already, skip including it.
# (https://github.com/protocolbuffers/protobuf/issues/10435)
Expand Down Expand Up @@ -31,11 +41,11 @@ if (BUILD_SHARED_LIBS AND MSVC)
# On MSVC Abseil is bundled into a single DLL.
set(protobuf_ABSL_USED_TARGETS abseil_dll)

# As a workaround for https://github.com/abseil/abseil-cpp/issues/1118,
# make sure ABSL_CONSUME_DLL gets set for all subsequent builds.
add_definitions(-DABSL_CONSUME_DLL)
set(protobuf_ABSL_USED_TEST_TARGETS abseil_test_dll)
else()
set(protobuf_ABSL_USED_TARGETS
absl::absl_check
absl::absl_log
absl::algorithm
absl::base
absl::bind_front
Expand All @@ -45,13 +55,16 @@ else()
absl::cord
absl::core_headers
absl::debugging
absl::die_if_null
absl::dynamic_annotations
absl::flags
absl::flat_hash_map
absl::flat_hash_set
absl::function_ref
absl::hash
absl::layout
absl::log_initialize
absl::log_severity
absl::memory
absl::node_hash_map
absl::node_hash_set
Expand All @@ -66,4 +79,7 @@ else()
absl::utility
absl::variant
)
set(protobuf_ABSL_USED_TEST_TARGETS
absl::scoped_mock_log
)
endif ()
48 changes: 48 additions & 0 deletions cmake/gtest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
option(protobuf_USE_EXTERNAL_GTEST "Use external Google Test (i.e. not the one in third_party/googletest)" OFF)

if (protobuf_USE_EXTERNAL_GTEST)
find_package(GTest REQUIRED)
else()
if (NOT EXISTS "${protobuf_SOURCE_DIR}/third_party/googletest/CMakeLists.txt")
message(FATAL_ERROR
"Cannot find third_party/googletest directory that's needed to "
"build tests. If you use git, make sure you have cloned submodules:\n"
" git submodule update --init --recursive\n"
"If instead you want to skip tests, run cmake with:\n"
" cmake -Dprotobuf_BUILD_TESTS=OFF\n")
endif()

set(googlemock_source_dir "${protobuf_SOURCE_DIR}/third_party/googletest/googlemock")
set(googletest_source_dir "${protobuf_SOURCE_DIR}/third_party/googletest/googletest")
include_directories(
${googlemock_source_dir}
${googletest_source_dir}
${googletest_source_dir}/include
${googlemock_source_dir}/include
)

add_library(gmock ${protobuf_SHARED_OR_STATIC}
"${googlemock_source_dir}/src/gmock-all.cc"
"${googletest_source_dir}/src/gtest-all.cc"
)
if (protobuf_BUILD_SHARED_LIBS)
set_target_properties(gmock
PROPERTIES
COMPILE_DEFINITIONS
"GTEST_CREATE_SHARED_LIBRARY=1"
)
install(TARGETS gmock EXPORT protobuf-targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()

target_link_libraries(gmock ${CMAKE_THREAD_LIBS_INIT})
add_library(gmock_main STATIC "${googlemock_source_dir}/src/gmock_main.cc")
target_link_libraries(gmock_main gmock)

add_library(GTest::gmock ALIAS gmock)
add_library(GTest::gmock_main ALIAS gmock_main)
add_library(GTest::gtest ALIAS gmock)
add_library(GTest::gtest_main ALIAS gmock_main)
endif()
38 changes: 3 additions & 35 deletions cmake/tests.cmake
Original file line number Diff line number Diff line change
@@ -1,45 +1,10 @@
option(protobuf_USE_EXTERNAL_GTEST "Use external Google Test (i.e. not the one in third_party/googletest)" OFF)

option(protobuf_REMOVE_INSTALLED_HEADERS
"Remove local headers so that installed ones are used instead" OFF)

option(protobuf_ABSOLUTE_TEST_PLUGIN_PATH
"Using absolute test_plugin path in tests" ON)
mark_as_advanced(protobuf_ABSOLUTE_TEST_PLUGIN_PATH)

if (protobuf_USE_EXTERNAL_GTEST)
find_package(GTest REQUIRED)
else()
if (NOT EXISTS "${protobuf_SOURCE_DIR}/third_party/googletest/CMakeLists.txt")
message(FATAL_ERROR
"Cannot find third_party/googletest directory that's needed to "
"build tests. If you use git, make sure you have cloned submodules:\n"
" git submodule update --init --recursive\n"
"If instead you want to skip tests, run cmake with:\n"
" cmake -Dprotobuf_BUILD_TESTS=OFF\n")
endif()

set(googlemock_source_dir "${protobuf_SOURCE_DIR}/third_party/googletest/googlemock")
set(googletest_source_dir "${protobuf_SOURCE_DIR}/third_party/googletest/googletest")
include_directories(
${googlemock_source_dir}
${googletest_source_dir}
${googletest_source_dir}/include
${googlemock_source_dir}/include
)

add_library(gmock STATIC
"${googlemock_source_dir}/src/gmock-all.cc"
"${googletest_source_dir}/src/gtest-all.cc"
)
target_link_libraries(gmock ${CMAKE_THREAD_LIBS_INIT})
add_library(gmock_main STATIC "${googlemock_source_dir}/src/gmock_main.cc")
target_link_libraries(gmock_main gmock)

add_library(GTest::gmock ALIAS gmock)
add_library(GTest::gmock_main ALIAS gmock_main)
endif()

include(${protobuf_SOURCE_DIR}/src/file_lists.cmake)

set(lite_test_protos
Expand Down Expand Up @@ -133,6 +98,7 @@ target_link_libraries(tests
${protobuf_LIB_PROTOC}
${protobuf_LIB_PROTOBUF}
${protobuf_ABSL_USED_TARGETS}
${protobuf_ABSL_USED_TEST_TARGETS}
GTest::gmock_main
)

Expand All @@ -148,6 +114,7 @@ target_link_libraries(test_plugin
${protobuf_LIB_PROTOC}
${protobuf_LIB_PROTOBUF}
${protobuf_ABSL_USED_TARGETS}
${protobuf_ABSL_USED_TEST_TARGETS}
GTest::gmock
)

Expand All @@ -159,6 +126,7 @@ add_executable(lite-test
target_link_libraries(lite-test
${protobuf_LIB_PROTOBUF_LITE}
${protobuf_ABSL_USED_TARGETS}
${protobuf_ABSL_USED_TEST_TARGETS}
GTest::gmock_main
)

Expand Down
18 changes: 9 additions & 9 deletions conformance/binary_json_conformance_suite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
#include "google/protobuf/text_format.h"
#include "google/protobuf/util/json_util.h"
#include "google/protobuf/util/type_resolver_util.h"
#include "google/protobuf/stubs/logging.h"
#include "google/protobuf/stubs/logging.h"
#include "absl/log/absl_check.h"
#include "absl/log/absl_log.h"
#include "absl/status/status.h"
#include "absl/strings/str_cat.h"
#include "json/json.h"
Expand Down Expand Up @@ -241,7 +241,7 @@ const FieldDescriptor* GetFieldForType(FieldDescriptor::Type type,
if (packed == Packed::kFalse) {
packed_string = "Unpacked ";
}
GOOGLE_ABSL_LOG(FATAL) << "Couldn't find field with type: " << repeated_string
ABSL_LOG(FATAL) << "Couldn't find field with type: " << repeated_string
<< packed_string << FieldDescriptor::TypeName(type) << " for "
<< proto_string;
return nullptr;
Expand All @@ -265,7 +265,7 @@ const FieldDescriptor* GetFieldForMapType(FieldDescriptor::Type key_type,
}

const absl::string_view proto_string = is_proto3 ? "Proto3" : "Proto2";
GOOGLE_ABSL_LOG(FATAL) << "Couldn't find map field with type: "
ABSL_LOG(FATAL) << "Couldn't find map field with type: "
<< FieldDescriptor::TypeName(key_type) << " and "
<< FieldDescriptor::TypeName(key_type) << " for "
<< proto_string;
Expand All @@ -285,7 +285,7 @@ const FieldDescriptor* GetFieldForOneofType(FieldDescriptor::Type type,
}

const absl::string_view proto_string = is_proto3 ? "Proto3" : "Proto2";
GOOGLE_ABSL_LOG(FATAL) << "Couldn't find oneof field with type: "
ABSL_LOG(FATAL) << "Couldn't find oneof field with type: "
<< FieldDescriptor::TypeName(type) << " for " << proto_string;
return nullptr;
}
Expand Down Expand Up @@ -353,7 +353,7 @@ bool BinaryAndJsonConformanceSuite::ParseJsonResponse(
}

if (!test_message->ParseFromString(binary_protobuf)) {
GOOGLE_ABSL_LOG(FATAL) << "INTERNAL ERROR: internal JSON->protobuf transcode "
ABSL_LOG(FATAL) << "INTERNAL ERROR: internal JSON->protobuf transcode "
<< "yielded unparseable proto.";
return false;
}
Expand Down Expand Up @@ -407,7 +407,7 @@ bool BinaryAndJsonConformanceSuite::ParseResponse(
}

default:
GOOGLE_ABSL_LOG(FATAL) << test_name
ABSL_LOG(FATAL) << test_name
<< ": unknown payload type: " << response.result_case();
}

Expand Down Expand Up @@ -652,7 +652,7 @@ void BinaryAndJsonConformanceSuite::ExpectSerializeFailureForJson(
const string& test_name, ConformanceLevel level,
const string& text_format) {
TestAllTypesProto3 payload_message;
GOOGLE_ABSL_CHECK(TextFormat::ParseFromString(text_format, &payload_message))
ABSL_CHECK(TextFormat::ParseFromString(text_format, &payload_message))
<< "Failed to parse: " << text_format;

TestAllTypesProto3 prototype;
Expand Down Expand Up @@ -1414,7 +1414,7 @@ void BinaryAndJsonConformanceSuite::RunSuiteImpl() {
req.set_protobuf_payload("");
req.set_requested_output_format(conformance::WireFormat::PROTOBUF);
RunTest("FindFailures", req, &res);
GOOGLE_ABSL_CHECK(failure_set.MergeFromString(res.protobuf_payload()));
ABSL_CHECK(failure_set.MergeFromString(res.protobuf_payload()));
for (const string& failure : failure_set.failure()) {
AddExpectedFailedTest(failure);
}
Expand Down
18 changes: 9 additions & 9 deletions conformance/conformance_cpp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
#include "google/protobuf/text_format.h"
#include "google/protobuf/util/json_util.h"
#include "google/protobuf/util/type_resolver_util.h"
#include "google/protobuf/stubs/logging.h"
#include "google/protobuf/stubs/logging.h"
#include "absl/log/absl_check.h"
#include "absl/log/absl_log.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "conformance/conformance.pb.h"
Expand Down Expand Up @@ -187,14 +187,14 @@ absl::StatusOr<ConformanceResponse> Harness::RunTest(
return absl::InvalidArgumentError("unspecified output format");

case conformance::PROTOBUF: {
GOOGLE_ABSL_CHECK(
ABSL_CHECK(
test_message->SerializeToString(response.mutable_protobuf_payload()));
break;
}

case conformance::JSON: {
std::string proto_binary;
GOOGLE_ABSL_CHECK(test_message->SerializeToString(&proto_binary));
ABSL_CHECK(test_message->SerializeToString(&proto_binary));
absl::Status status =
BinaryToJsonString(resolver_.get(), type_url_, proto_binary,
response.mutable_json_payload());
Expand All @@ -208,7 +208,7 @@ absl::StatusOr<ConformanceResponse> Harness::RunTest(
case conformance::TEXT_FORMAT: {
TextFormat::Printer printer;
printer.SetHideUnknownFields(!request.print_unknown_fields());
GOOGLE_ABSL_CHECK(printer.PrintToString(*test_message,
ABSL_CHECK(printer.PrintToString(*test_message,
response.mutable_text_payload()));
break;
}
Expand All @@ -234,7 +234,7 @@ absl::StatusOr<bool> Harness::ServeConformanceRequest() {
RETURN_IF_ERROR(ReadFd(STDIN_FILENO, &serialized_input[0], in_len));

ConformanceRequest request;
GOOGLE_ABSL_CHECK(request.ParseFromString(serialized_input));
ABSL_CHECK(request.ParseFromString(serialized_input));

absl::StatusOr<ConformanceResponse> response = RunTest(request);
RETURN_IF_ERROR(response.status());
Expand All @@ -247,7 +247,7 @@ absl::StatusOr<bool> Harness::ServeConformanceRequest() {
RETURN_IF_ERROR(WriteFd(STDOUT_FILENO, serialized_output.data(), out_len));

if (verbose_) {
GOOGLE_ABSL_LOG(INFO) << "conformance-cpp: request=" << request.ShortDebugString()
ABSL_LOG(INFO) << "conformance-cpp: request=" << request.ShortDebugString()
<< ", response=" << response->ShortDebugString();
}
return false;
Expand All @@ -262,13 +262,13 @@ int main() {
while (true) {
auto is_done = harness.ServeConformanceRequest();
if (!is_done.ok()) {
GOOGLE_ABSL_LOG(FATAL) << is_done.status();
ABSL_LOG(FATAL) << is_done.status();
}
if (*is_done) {
break;
}
total_runs++;
}
GOOGLE_ABSL_LOG(INFO) << "conformance-cpp: received EOF from test runner after "
ABSL_LOG(INFO) << "conformance-cpp: received EOF from test runner after "
<< total_runs << " tests";
}
Loading

0 comments on commit a9f1ea6

Please sign in to comment.