From 252ce9c52d304659eff6be558209c811b7191963 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Mon, 26 Apr 2021 13:09:24 -0400 Subject: [PATCH] Googletest export Fix iOS logging issues in tests PiperOrigin-RevId: 370484087 --- BUILD.bazel | 10 ++++++++++ googletest/src/gtest-port.cc | 12 +++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/BUILD.bazel b/BUILD.bazel index 965c518d..14661b6a 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -56,6 +56,12 @@ config_setting( values = {"define": "absl=1"}, ) +config_setting( + name = "ios", + values = {"apple_platform_type": "ios"}, + visibility = [":__subpackages__"], +) + # Library that defines the FRIEND_TEST macro. cc_library( name = "gtest_prod", @@ -86,6 +92,10 @@ cc_library( "googlemock/include/gmock/*.h", ]), copts = select({ + ":ios": [ + "-xobjective-c++", + "-pthread", + ], ":windows": [], "//conditions:default": ["-pthread"], }), diff --git a/googletest/src/gtest-port.cc b/googletest/src/gtest-port.cc index 3f39f71c..26bc8575 100644 --- a/googletest/src/gtest-port.cc +++ b/googletest/src/gtest-port.cc @@ -80,6 +80,10 @@ # include #endif // GTEST_OS_FUCHSIA +#if GTEST_OS_IOS +#import +#endif // GTEST_OS_IOS + #include "gtest/gtest-spi.h" #include "gtest/gtest-message.h" #include "gtest/internal/gtest-internal.h" @@ -1111,9 +1115,15 @@ class CapturedStream { // '/sdcard' and other variants cannot be relied on, as they are not // guaranteed to be mounted, or may have a delay in mounting. char name_template[] = "/data/local/tmp/gtest_captured_stream.XXXXXX"; +# elif GTEST_OS_IOS + NSString* temp_path = [NSTemporaryDirectory() + stringByAppendingPathComponent:@"gtest_captured_stream.XXXXXX"]; + + char name_template[PATH_MAX + 1]; + strncpy(name_template, [temp_path UTF8String], PATH_MAX); # else char name_template[] = "/tmp/captured_stream.XXXXXX"; -# endif // GTEST_OS_LINUX_ANDROID +# endif const int captured_fd = mkstemp(name_template); if (captured_fd == -1) { GTEST_LOG_(WARNING)