Skip to content

Commit a9f1ea6

Browse files
mkruskal-googlecopybara-github
authored andcommitted
Breaking change: Migrate to Abseil's logging library.
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
1 parent 79ee26a commit a9f1ea6

File tree

234 files changed

+1993
-2539
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

234 files changed

+1993
-2539
lines changed

.github/workflows/codespell.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ jobs:
1515
with:
1616
check_filenames: true
1717
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
18-
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"
18+
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"

.gitmodules

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[submodule "third_party/abseil-cpp"]
66
path = third_party/abseil-cpp
77
url = https://github.com/abseil/abseil-cpp.git
8-
branch = lts_2023_01_17
8+
branch = lts_2023_01_24
99
[submodule "third_party/jsoncpp"]
1010
path = third_party/jsoncpp
1111
url = https://github.com/open-source-parsers/jsoncpp.git

CMakeLists.txt

+8
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@ else (protobuf_BUILD_SHARED_LIBS)
258258
endif()
259259
endif (protobuf_BUILD_SHARED_LIBS)
260260

261+
# Export all symbols on Windows when building shared libraries
262+
SET(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
263+
261264
if (MSVC)
262265
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
263266
# Build with multiple processes
@@ -268,6 +271,7 @@ if (MSVC)
268271
# MSVC warning suppressions
269272
add_compile_options(
270273
/wd4065 # switch statement contains 'default' but no 'case' labels
274+
/wd4146 # unary minus operator applied to unsigned type
271275
/wd4244 # 'conversion' conversion from 'type1' to 'type2', possible loss of data
272276
/wd4251 # 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2'
273277
/wd4267 # 'var' : conversion from 'size_t' to 'type', possible loss of data
@@ -319,6 +323,10 @@ endif (protobuf_UNICODE)
319323
set(protobuf_ABSL_PROVIDER "module" CACHE STRING "Provider of absl library")
320324
set_property(CACHE protobuf_ABSL_PROVIDER PROPERTY STRINGS "module" "package")
321325

326+
if (protobuf_BUILD_TESTS)
327+
include(${protobuf_SOURCE_DIR}/cmake/gtest.cmake)
328+
endif (protobuf_BUILD_TESTS)
329+
322330
include(${protobuf_SOURCE_DIR}/cmake/abseil-cpp.cmake)
323331

324332
if (protobuf_BUILD_PROTOBUF_BINARIES)

build_defs/cpp_opts.bzl

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
COPTS = select({
44
"//build_defs:config_msvc": [
55
"/wd4065", # switch statement contains 'default' but no 'case' labels
6+
"/wd4146", # unary minus operator applied to unsigned type
67
"/wd4244", # 'conversion' conversion from 'type1' to 'type2', possible loss of data
78
"/wd4251", # 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2'
89
"/wd4267", # 'var' : conversion from 'size_t' to 'type', possible loss of data

cmake/abseil-cpp.cmake

+19-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Setup our dependency on Abseil.
22

3+
if(protobuf_BUILD_TESTS)
4+
# Tell Abseil to build test-only helpers.
5+
set(ABSL_BUILD_TEST_HELPERS ON)
6+
7+
# We depend on googletest too, so just tell Abseil to use the same one we've
8+
# already setup.
9+
set(ABSL_USE_EXTERNAL_GOOGLETEST ON)
10+
set(ABSL_FIND_GOOGLETEST OFF)
11+
endif()
12+
313
if(TARGET absl::strings)
414
# If Abseil is included already, skip including it.
515
# (https://github.com/protocolbuffers/protobuf/issues/10435)
@@ -31,11 +41,11 @@ if (BUILD_SHARED_LIBS AND MSVC)
3141
# On MSVC Abseil is bundled into a single DLL.
3242
set(protobuf_ABSL_USED_TARGETS abseil_dll)
3343

34-
# As a workaround for https://github.com/abseil/abseil-cpp/issues/1118,
35-
# make sure ABSL_CONSUME_DLL gets set for all subsequent builds.
36-
add_definitions(-DABSL_CONSUME_DLL)
44+
set(protobuf_ABSL_USED_TEST_TARGETS abseil_test_dll)
3745
else()
3846
set(protobuf_ABSL_USED_TARGETS
47+
absl::absl_check
48+
absl::absl_log
3949
absl::algorithm
4050
absl::base
4151
absl::bind_front
@@ -45,13 +55,16 @@ else()
4555
absl::cord
4656
absl::core_headers
4757
absl::debugging
58+
absl::die_if_null
4859
absl::dynamic_annotations
4960
absl::flags
5061
absl::flat_hash_map
5162
absl::flat_hash_set
5263
absl::function_ref
5364
absl::hash
5465
absl::layout
66+
absl::log_initialize
67+
absl::log_severity
5568
absl::memory
5669
absl::node_hash_map
5770
absl::node_hash_set
@@ -66,4 +79,7 @@ else()
6679
absl::utility
6780
absl::variant
6881
)
82+
set(protobuf_ABSL_USED_TEST_TARGETS
83+
absl::scoped_mock_log
84+
)
6985
endif ()

cmake/gtest.cmake

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
option(protobuf_USE_EXTERNAL_GTEST "Use external Google Test (i.e. not the one in third_party/googletest)" OFF)
2+
3+
if (protobuf_USE_EXTERNAL_GTEST)
4+
find_package(GTest REQUIRED)
5+
else()
6+
if (NOT EXISTS "${protobuf_SOURCE_DIR}/third_party/googletest/CMakeLists.txt")
7+
message(FATAL_ERROR
8+
"Cannot find third_party/googletest directory that's needed to "
9+
"build tests. If you use git, make sure you have cloned submodules:\n"
10+
" git submodule update --init --recursive\n"
11+
"If instead you want to skip tests, run cmake with:\n"
12+
" cmake -Dprotobuf_BUILD_TESTS=OFF\n")
13+
endif()
14+
15+
set(googlemock_source_dir "${protobuf_SOURCE_DIR}/third_party/googletest/googlemock")
16+
set(googletest_source_dir "${protobuf_SOURCE_DIR}/third_party/googletest/googletest")
17+
include_directories(
18+
${googlemock_source_dir}
19+
${googletest_source_dir}
20+
${googletest_source_dir}/include
21+
${googlemock_source_dir}/include
22+
)
23+
24+
add_library(gmock ${protobuf_SHARED_OR_STATIC}
25+
"${googlemock_source_dir}/src/gmock-all.cc"
26+
"${googletest_source_dir}/src/gtest-all.cc"
27+
)
28+
if (protobuf_BUILD_SHARED_LIBS)
29+
set_target_properties(gmock
30+
PROPERTIES
31+
COMPILE_DEFINITIONS
32+
"GTEST_CREATE_SHARED_LIBRARY=1"
33+
)
34+
install(TARGETS gmock EXPORT protobuf-targets
35+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
36+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
37+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
38+
endif()
39+
40+
target_link_libraries(gmock ${CMAKE_THREAD_LIBS_INIT})
41+
add_library(gmock_main STATIC "${googlemock_source_dir}/src/gmock_main.cc")
42+
target_link_libraries(gmock_main gmock)
43+
44+
add_library(GTest::gmock ALIAS gmock)
45+
add_library(GTest::gmock_main ALIAS gmock_main)
46+
add_library(GTest::gtest ALIAS gmock)
47+
add_library(GTest::gtest_main ALIAS gmock_main)
48+
endif()

cmake/tests.cmake

+3-35
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,10 @@
1-
option(protobuf_USE_EXTERNAL_GTEST "Use external Google Test (i.e. not the one in third_party/googletest)" OFF)
2-
31
option(protobuf_REMOVE_INSTALLED_HEADERS
42
"Remove local headers so that installed ones are used instead" OFF)
53

64
option(protobuf_ABSOLUTE_TEST_PLUGIN_PATH
75
"Using absolute test_plugin path in tests" ON)
86
mark_as_advanced(protobuf_ABSOLUTE_TEST_PLUGIN_PATH)
97

10-
if (protobuf_USE_EXTERNAL_GTEST)
11-
find_package(GTest REQUIRED)
12-
else()
13-
if (NOT EXISTS "${protobuf_SOURCE_DIR}/third_party/googletest/CMakeLists.txt")
14-
message(FATAL_ERROR
15-
"Cannot find third_party/googletest directory that's needed to "
16-
"build tests. If you use git, make sure you have cloned submodules:\n"
17-
" git submodule update --init --recursive\n"
18-
"If instead you want to skip tests, run cmake with:\n"
19-
" cmake -Dprotobuf_BUILD_TESTS=OFF\n")
20-
endif()
21-
22-
set(googlemock_source_dir "${protobuf_SOURCE_DIR}/third_party/googletest/googlemock")
23-
set(googletest_source_dir "${protobuf_SOURCE_DIR}/third_party/googletest/googletest")
24-
include_directories(
25-
${googlemock_source_dir}
26-
${googletest_source_dir}
27-
${googletest_source_dir}/include
28-
${googlemock_source_dir}/include
29-
)
30-
31-
add_library(gmock STATIC
32-
"${googlemock_source_dir}/src/gmock-all.cc"
33-
"${googletest_source_dir}/src/gtest-all.cc"
34-
)
35-
target_link_libraries(gmock ${CMAKE_THREAD_LIBS_INIT})
36-
add_library(gmock_main STATIC "${googlemock_source_dir}/src/gmock_main.cc")
37-
target_link_libraries(gmock_main gmock)
38-
39-
add_library(GTest::gmock ALIAS gmock)
40-
add_library(GTest::gmock_main ALIAS gmock_main)
41-
endif()
42-
438
include(${protobuf_SOURCE_DIR}/src/file_lists.cmake)
449

4510
set(lite_test_protos
@@ -133,6 +98,7 @@ target_link_libraries(tests
13398
${protobuf_LIB_PROTOC}
13499
${protobuf_LIB_PROTOBUF}
135100
${protobuf_ABSL_USED_TARGETS}
101+
${protobuf_ABSL_USED_TEST_TARGETS}
136102
GTest::gmock_main
137103
)
138104

@@ -148,6 +114,7 @@ target_link_libraries(test_plugin
148114
${protobuf_LIB_PROTOC}
149115
${protobuf_LIB_PROTOBUF}
150116
${protobuf_ABSL_USED_TARGETS}
117+
${protobuf_ABSL_USED_TEST_TARGETS}
151118
GTest::gmock
152119
)
153120

@@ -159,6 +126,7 @@ add_executable(lite-test
159126
target_link_libraries(lite-test
160127
${protobuf_LIB_PROTOBUF_LITE}
161128
${protobuf_ABSL_USED_TARGETS}
129+
${protobuf_ABSL_USED_TEST_TARGETS}
162130
GTest::gmock_main
163131
)
164132

conformance/binary_json_conformance_suite.cc

+9-9
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
#include "google/protobuf/text_format.h"
3939
#include "google/protobuf/util/json_util.h"
4040
#include "google/protobuf/util/type_resolver_util.h"
41-
#include "google/protobuf/stubs/logging.h"
42-
#include "google/protobuf/stubs/logging.h"
41+
#include "absl/log/absl_check.h"
42+
#include "absl/log/absl_log.h"
4343
#include "absl/status/status.h"
4444
#include "absl/strings/str_cat.h"
4545
#include "json/json.h"
@@ -241,7 +241,7 @@ const FieldDescriptor* GetFieldForType(FieldDescriptor::Type type,
241241
if (packed == Packed::kFalse) {
242242
packed_string = "Unpacked ";
243243
}
244-
GOOGLE_ABSL_LOG(FATAL) << "Couldn't find field with type: " << repeated_string
244+
ABSL_LOG(FATAL) << "Couldn't find field with type: " << repeated_string
245245
<< packed_string << FieldDescriptor::TypeName(type) << " for "
246246
<< proto_string;
247247
return nullptr;
@@ -265,7 +265,7 @@ const FieldDescriptor* GetFieldForMapType(FieldDescriptor::Type key_type,
265265
}
266266

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

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

355355
if (!test_message->ParseFromString(binary_protobuf)) {
356-
GOOGLE_ABSL_LOG(FATAL) << "INTERNAL ERROR: internal JSON->protobuf transcode "
356+
ABSL_LOG(FATAL) << "INTERNAL ERROR: internal JSON->protobuf transcode "
357357
<< "yielded unparseable proto.";
358358
return false;
359359
}
@@ -407,7 +407,7 @@ bool BinaryAndJsonConformanceSuite::ParseResponse(
407407
}
408408

409409
default:
410-
GOOGLE_ABSL_LOG(FATAL) << test_name
410+
ABSL_LOG(FATAL) << test_name
411411
<< ": unknown payload type: " << response.result_case();
412412
}
413413

@@ -652,7 +652,7 @@ void BinaryAndJsonConformanceSuite::ExpectSerializeFailureForJson(
652652
const string& test_name, ConformanceLevel level,
653653
const string& text_format) {
654654
TestAllTypesProto3 payload_message;
655-
GOOGLE_ABSL_CHECK(TextFormat::ParseFromString(text_format, &payload_message))
655+
ABSL_CHECK(TextFormat::ParseFromString(text_format, &payload_message))
656656
<< "Failed to parse: " << text_format;
657657

658658
TestAllTypesProto3 prototype;
@@ -1414,7 +1414,7 @@ void BinaryAndJsonConformanceSuite::RunSuiteImpl() {
14141414
req.set_protobuf_payload("");
14151415
req.set_requested_output_format(conformance::WireFormat::PROTOBUF);
14161416
RunTest("FindFailures", req, &res);
1417-
GOOGLE_ABSL_CHECK(failure_set.MergeFromString(res.protobuf_payload()));
1417+
ABSL_CHECK(failure_set.MergeFromString(res.protobuf_payload()));
14181418
for (const string& failure : failure_set.failure()) {
14191419
AddExpectedFailedTest(failure);
14201420
}

conformance/conformance_cpp.cc

+9-9
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
#include "google/protobuf/text_format.h"
4141
#include "google/protobuf/util/json_util.h"
4242
#include "google/protobuf/util/type_resolver_util.h"
43-
#include "google/protobuf/stubs/logging.h"
44-
#include "google/protobuf/stubs/logging.h"
43+
#include "absl/log/absl_check.h"
44+
#include "absl/log/absl_log.h"
4545
#include "absl/status/status.h"
4646
#include "absl/status/statusor.h"
4747
#include "conformance/conformance.pb.h"
@@ -187,14 +187,14 @@ absl::StatusOr<ConformanceResponse> Harness::RunTest(
187187
return absl::InvalidArgumentError("unspecified output format");
188188

189189
case conformance::PROTOBUF: {
190-
GOOGLE_ABSL_CHECK(
190+
ABSL_CHECK(
191191
test_message->SerializeToString(response.mutable_protobuf_payload()));
192192
break;
193193
}
194194

195195
case conformance::JSON: {
196196
std::string proto_binary;
197-
GOOGLE_ABSL_CHECK(test_message->SerializeToString(&proto_binary));
197+
ABSL_CHECK(test_message->SerializeToString(&proto_binary));
198198
absl::Status status =
199199
BinaryToJsonString(resolver_.get(), type_url_, proto_binary,
200200
response.mutable_json_payload());
@@ -208,7 +208,7 @@ absl::StatusOr<ConformanceResponse> Harness::RunTest(
208208
case conformance::TEXT_FORMAT: {
209209
TextFormat::Printer printer;
210210
printer.SetHideUnknownFields(!request.print_unknown_fields());
211-
GOOGLE_ABSL_CHECK(printer.PrintToString(*test_message,
211+
ABSL_CHECK(printer.PrintToString(*test_message,
212212
response.mutable_text_payload()));
213213
break;
214214
}
@@ -234,7 +234,7 @@ absl::StatusOr<bool> Harness::ServeConformanceRequest() {
234234
RETURN_IF_ERROR(ReadFd(STDIN_FILENO, &serialized_input[0], in_len));
235235

236236
ConformanceRequest request;
237-
GOOGLE_ABSL_CHECK(request.ParseFromString(serialized_input));
237+
ABSL_CHECK(request.ParseFromString(serialized_input));
238238

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

249249
if (verbose_) {
250-
GOOGLE_ABSL_LOG(INFO) << "conformance-cpp: request=" << request.ShortDebugString()
250+
ABSL_LOG(INFO) << "conformance-cpp: request=" << request.ShortDebugString()
251251
<< ", response=" << response->ShortDebugString();
252252
}
253253
return false;
@@ -262,13 +262,13 @@ int main() {
262262
while (true) {
263263
auto is_done = harness.ServeConformanceRequest();
264264
if (!is_done.ok()) {
265-
GOOGLE_ABSL_LOG(FATAL) << is_done.status();
265+
ABSL_LOG(FATAL) << is_done.status();
266266
}
267267
if (*is_done) {
268268
break;
269269
}
270270
total_runs++;
271271
}
272-
GOOGLE_ABSL_LOG(INFO) << "conformance-cpp: received EOF from test runner after "
272+
ABSL_LOG(INFO) << "conformance-cpp: received EOF from test runner after "
273273
<< total_runs << " tests";
274274
}

0 commit comments

Comments
 (0)