From eeb31321f706679740d13fd04d40d5c08c8077f4 Mon Sep 17 00:00:00 2001 From: Scott Graham Date: Thu, 30 Nov 2017 12:38:27 -0800 Subject: [PATCH] gn, fuchsia: Add //testing forwarding and GN build file third_party/gtest/BUILD.gn mostly written by rsesek. Also includes DEPS roll of mini_chromium for Wexit_time_destructors config. $ git log --oneline dd0c3e96..fa146c12 fa146c1 (HEAD, origin/master, origin/HEAD) gn: Extract Wexit-time-destructors into separate config 95bfddb fuchsia: Fix base::RandBytes() after 5a1c5f82ce75 b79608a fuchsia: Use llvm-ar from the Fuchsia clang package c34725b fuchsia: Look for the toolchain and SDK in per-build-host directories e8e1ee4 fuchsia: Don't assume that kernel will provide all requested rand bytes 5a1c5f8 fuchsia: Implement RandBytes() df359ca fuchsia: Enable -fPIC bd50c95 Restore accidentally changed license a70db15 Improvements to GN build config 7de4d23 fuchsia: Fix compile of base/logging.cc 25a8b57 Add link GN rules to non-win build, set c++14 in CC flags. 7d15806 fuchsia: The very basics of compiling mini_chromium/base with GN Bug: crashpad:79, crashpad:196 Change-Id: I3e741f185b028a96705eefc1f993037830d97448 Reviewed-on: https://chromium-review.googlesource.com/797414 Commit-Queue: Scott Graham Reviewed-by: Mark Mentovai Reviewed-by: Robert Sesek --- DEPS | 2 +- build/BUILDCONFIG.gn | 1 + .../testing/gmock/BUILD.gn | 7 +- .../testing/gtest/BUILD.gn | 7 +- test/BUILD.gn | 14 +- test/gtest_death.h | 52 ++++--- third_party/gtest/BUILD.gn | 132 ++++++++++++++++++ 7 files changed, 181 insertions(+), 34 deletions(-) create mode 100644 third_party/gtest/BUILD.gn diff --git a/DEPS b/DEPS index fa58f6f8..cfc308f9 100644 --- a/DEPS +++ b/DEPS @@ -28,7 +28,7 @@ deps = { '5e2b3ddde7cda5eb6bc09a5546a76b00e49d888f', 'crashpad/third_party/mini_chromium/mini_chromium': Var('chromium_git') + '/chromium/mini_chromium@' + - 'dd0c3e9680ae3c4c22f2221a2a75e48dd4a562ec', + 'fa146c1264953b42baccfc261dc6aa59a1661d26', 'crashpad/third_party/zlib/zlib': Var('chromium_git') + '/chromium/src/third_party/zlib@' + '13dc246a58e4b72104d35f9b1809af95221ebda7', diff --git a/build/BUILDCONFIG.gn b/build/BUILDCONFIG.gn index 840978fa..73b7da56 100644 --- a/build/BUILDCONFIG.gn +++ b/build/BUILDCONFIG.gn @@ -65,6 +65,7 @@ if (is_win) { _default_configs = [ "//third_party/mini_chromium/mini_chromium/build:default", + "//third_party/mini_chromium/mini_chromium/build:Wexit_time_destructors", # This (no-op) is added here so that build files that expect to be able to # remove it can do so without causing an error. diff --git a/build/chromium_compatibility/testing/gmock/BUILD.gn b/build/chromium_compatibility/testing/gmock/BUILD.gn index 81001042..06c404c8 100644 --- a/build/chromium_compatibility/testing/gmock/BUILD.gn +++ b/build/chromium_compatibility/testing/gmock/BUILD.gn @@ -12,8 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -# TODO(GN): This is a placeholder that matches the name of Chromium's location -# for this file. It will need to be filled out to cause a gmock dependency. +# This is a forwarding target to match the location that Chromium uses. group("gmock") { + public_configs = [ "//third_party/gtest:gmock_public_config" ] + public_deps = [ + "//third_party/gtest:gmock", + ] } diff --git a/build/chromium_compatibility/testing/gtest/BUILD.gn b/build/chromium_compatibility/testing/gtest/BUILD.gn index 03d30464..236359fd 100644 --- a/build/chromium_compatibility/testing/gtest/BUILD.gn +++ b/build/chromium_compatibility/testing/gtest/BUILD.gn @@ -12,8 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -# TODO(GN): This is a placeholder that matches the name of Chromium's location -# for this file. It will need to be filled out to cause a gtest dependency. +# This is a forwarding target to match the location that Chromium uses. group("gtest") { + public_configs = [ "//third_party/gtest:gtest_public_config" ] + public_deps = [ + "//third_party/gtest:gtest", + ] } diff --git a/test/BUILD.gn b/test/BUILD.gn index a44779f0..899743a9 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -82,7 +82,7 @@ static_library("test") { public_configs = [ "..:crashpad_config" ] - defines = [ "CRASHPAD_IN_CHROMIUM" ] + configs += [ "../build:crashpad_in_chromium" ] data = [ "test_paths_test_data_root.txt", @@ -153,10 +153,8 @@ static_library("gmock_main") { sources = [ "gtest_main.cc", ] - defines = [ - "CRASHPAD_IN_CHROMIUM", - "CRASHPAD_TEST_LAUNCHER_GMOCK", - ] + configs += [ "../build:crashpad_in_chromium" ] + defines = [ "CRASHPAD_TEST_LAUNCHER_GMOCK" ] deps = [ ":test", "//base", @@ -171,10 +169,8 @@ static_library("gtest_main") { sources = [ "gtest_main.cc", ] - defines = [ - "CRASHPAD_IN_CHROMIUM", - "CRASHPAD_TEST_LAUNCHER_GTEST", - ] + configs += [ "../build:crashpad_in_chromium" ] + defines = [ "CRASHPAD_TEST_LAUNCHER_GTEST" ] deps = [ ":test", "//base", diff --git a/test/gtest_death.h b/test/gtest_death.h index 493c9c6b..69f6361e 100644 --- a/test/gtest_death.h +++ b/test/gtest_death.h @@ -27,32 +27,42 @@ #if defined(OS_MACOSX) || DOXYGEN -//! \brief Wraps the gtest `ASSERT_DEATH()` macro to make assertions about death -//! caused by crashes. +//! \brief Wraps the gtest `ASSERT_DEATH_IF_SUPPORTED()` macro to make +//! assertions about death caused by crashes. //! //! On macOS, this macro prevents the system’s crash reporter from handling //! crashes that occur in \a statement. Crashes are normally visible to the //! system’s crash reporter, but it is undesirable for intentional //! ASSERT_DEATH_CRASH() crashes to be handled by any crash reporter. //! +//! `ASSERT_DEATH_IF_SUPPORTED()` is used instead of `ASSERT_DEATH()` to +//! support platforms where death tests are not implemented by gtest (e.g. +//! Fuchsia). On platforms where death tests are not implemented, a warning +//! will be logged and the remainder of the test body skipped. +//! //! \sa ASSERT_DEATH_CHECK() //! \sa EXPECT_DEATH_CRASH() -#define ASSERT_DEATH_CRASH(statement, regex) \ - do { \ - crashpad::test::ExceptionSwallower exception_swallower; \ - ASSERT_DEATH(crashpad::test::ExceptionSwallower::SwallowExceptions(); \ - { statement; }, \ - regex); \ +#define ASSERT_DEATH_CRASH(statement, regex) \ + do { \ + crashpad::test::ExceptionSwallower exception_swallower; \ + ASSERT_DEATH_IF_SUPPORTED( \ + crashpad::test::ExceptionSwallower::SwallowExceptions(); \ + { statement; }, regex); \ } while (false) -//! \brief Wraps the gtest `EXPECT_DEATH()` macro to make assertions about death -//! caused by crashes. +//! \brief Wraps the gtest `EXPECT_DEATH_IF_SUPPORTED()` macro to make +//! assertions about death caused by crashes. //! //! On macOS, this macro prevents the system’s crash reporter from handling //! crashes that occur in \a statement. Crashes are normally visible to the //! system’s crash reporter, but it is undesirable for intentional //! EXPECT_DEATH_CRASH() crashes to be handled by any crash reporter. //! +//! `EXPECT_DEATH_IF_SUPPORTED()` is used instead of `EXPECT_DEATH()` to +//! support platforms where death tests are not implemented by gtest (e.g. +//! Fuchsia). On platforms where death tests are not implemented, a warning +//! will be logged and the remainder of the test body skipped. +//! //! \sa EXPECT_DEATH_CHECK() //! \sa ASSERT_DEATH_CRASH() #define EXPECT_DEATH_CRASH(statement, regex) \ @@ -65,8 +75,10 @@ #else // OS_MACOSX -#define ASSERT_DEATH_CRASH(statement, regex) ASSERT_DEATH(statement, regex) -#define EXPECT_DEATH_CRASH(statement, regex) EXPECT_DEATH(statement, regex) +#define ASSERT_DEATH_CRASH(statement, regex) \ + ASSERT_DEATH_IF_SUPPORTED(statement, regex) +#define EXPECT_DEATH_CRASH(statement, regex) \ + EXPECT_DEATH_IF_SUPPORTED(statement, regex) #endif // OS_MACOSX @@ -84,10 +96,10 @@ //! for any particular output on the standard error stream. In other build //! configurations, the \a regex pattern is left intact. //! -//! `CHECK()` failures normally show up as crashes to the system’s crash -//! reporter, but it is undesirable for intentional ASSERT_DEATH_CHECK() crashes -//! to be handled by any crash reporter, so this is implemented in terms of -//! ASSERT_DEATH_CRASH() instead of `ASSERT_DEATH()`. +//! On macOS, `CHECK()` failures normally show up as crashes to the system’s +//! crash reporter, but it is undesirable for intentional ASSERT_DEATH_CHECK() +//! crashes to be handled by any crash reporter, so this is implemented in +//! terms of ASSERT_DEATH_CRASH() instead of `ASSERT_DEATH()`. //! //! \sa EXPECT_DEATH_CHECK() #define ASSERT_DEATH_CHECK(statement, regex) \ @@ -102,10 +114,10 @@ //! for any particular output on the standard error stream. In other build //! configurations, the \a regex pattern is left intact. //! -//! `CHECK()` failures normally show up as crashes to the system’s crash -//! reporter, but it is undesirable for intentional EXPECT_DEATH_CHECK() crashes -//! to be handled by any crash reporter, so this is implemented in terms of -//! EXPECT_DEATH_CRASH() instead of `EXPECT_DEATH()`. +//! On macOS, `CHECK()` failures normally show up as crashes to the system’s +//! crash reporter, but it is undesirable for intentional EXPECT_DEATH_CHECK() +//! crashes to be handled by any crash reporter, so this is implemented in +//! terms of EXPECT_DEATH_CRASH() instead of `EXPECT_DEATH()`. //! //! \sa ASSERT_DEATH_CHECK() #define EXPECT_DEATH_CHECK(statement, regex) \ diff --git a/third_party/gtest/BUILD.gn b/third_party/gtest/BUILD.gn new file mode 100644 index 00000000..97fe1839 --- /dev/null +++ b/third_party/gtest/BUILD.gn @@ -0,0 +1,132 @@ +# Copyright 2017 The Crashpad Authors. All rights reserved. +# +# 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. + +config("gtest_private_config") { + visibility = [ ":*" ] + include_dirs = [ "gtest/googletest" ] + defines = [ "GUNIT_NO_GOOGLE3=1" ] +} + +config("gtest_public_config") { + include_dirs = [ "gtest/googletest/include" ] +} + +static_library("gtest") { + sources = [ + "gtest/googletest/include/gtest/gtest-death-test.h", + "gtest/googletest/include/gtest/gtest-message.h", + "gtest/googletest/include/gtest/gtest-param-test.h", + "gtest/googletest/include/gtest/gtest-printers.h", + "gtest/googletest/include/gtest/gtest-spi.h", + "gtest/googletest/include/gtest/gtest-test-part.h", + "gtest/googletest/include/gtest/gtest-typed-test.h", + "gtest/googletest/include/gtest/gtest.h", + "gtest/googletest/include/gtest/gtest_pred_impl.h", + "gtest/googletest/include/gtest/gtest_prod.h", + "gtest/googletest/include/gtest/internal/custom/gtest-port.h", + "gtest/googletest/include/gtest/internal/custom/gtest-printers.h", + "gtest/googletest/include/gtest/internal/custom/gtest.h", + "gtest/googletest/include/gtest/internal/gtest-death-test-internal.h", + "gtest/googletest/include/gtest/internal/gtest-filepath.h", + "gtest/googletest/include/gtest/internal/gtest-internal.h", + "gtest/googletest/include/gtest/internal/gtest-linked_ptr.h", + "gtest/googletest/include/gtest/internal/gtest-param-util-generated.h", + "gtest/googletest/include/gtest/internal/gtest-param-util.h", + "gtest/googletest/include/gtest/internal/gtest-port-arch.h", + "gtest/googletest/include/gtest/internal/gtest-port.h", + "gtest/googletest/include/gtest/internal/gtest-string.h", + "gtest/googletest/include/gtest/internal/gtest-tuple.h", + "gtest/googletest/include/gtest/internal/gtest-type-util.h", + "gtest/googletest/src/gtest-all.cc", + "gtest/googletest/src/gtest-death-test.cc", + "gtest/googletest/src/gtest-filepath.cc", + "gtest/googletest/src/gtest-internal-inl.h", + "gtest/googletest/src/gtest-port.cc", + "gtest/googletest/src/gtest-printers.cc", + "gtest/googletest/src/gtest-test-part.cc", + "gtest/googletest/src/gtest-typed-test.cc", + "gtest/googletest/src/gtest.cc", + ] + sources -= [ "gtest/googletest/src/gtest-all.cc" ] + configs -= [ "//third_party/mini_chromium/mini_chromium/build:Wexit_time_destructors" ] + configs += [ ":gtest_private_config" ] + public_configs = [ ":gtest_public_config" ] +} + +config("gmock_private_config") { + visibility = [ ":*" ] + include_dirs = [ "gtest/googlemock" ] +} + +config("gmock_public_config") { + include_dirs = [ "gtest/googlemock/include" ] + + # The MOCK_METHODn() macros do not specify “override”, which triggers this + # warning in users: “error: 'Method' overrides a member function but is not + # marked 'override' [-Werror,-Winconsistent-missing-override]”. Suppress + # these warnings, and add -Wno-unknown-warning-option because only recent + # versions of clang (trunk r220703 and later, version + # 3.6 and later) recognize it. + if (is_clang) { + cflags_cc = [ + "-Wno-inconsistent-missing-override", + "-Wno-unknown-warning-option", + ] + } +} + +static_library("gmock") { + sources = [ + "gtest/googlemock/include/gmock/gmock-actions.h", + "gtest/googlemock/include/gmock/gmock-cardinalities.h", + "gtest/googlemock/include/gmock/gmock-generated-actions.h", + "gtest/googlemock/include/gmock/gmock-generated-function-mockers.h", + "gtest/googlemock/include/gmock/gmock-generated-matchers.h", + "gtest/googlemock/include/gmock/gmock-generated-nice-strict.h", + "gtest/googlemock/include/gmock/gmock-matchers.h", + "gtest/googlemock/include/gmock/gmock-more-actions.h", + "gtest/googlemock/include/gmock/gmock-more-matchers.h", + "gtest/googlemock/include/gmock/gmock-spec-builders.h", + "gtest/googlemock/include/gmock/gmock.h", + "gtest/googlemock/include/gmock/internal/custom/gmock-generated-actions.h", + "gtest/googlemock/include/gmock/internal/custom/gmock-matchers.h", + "gtest/googlemock/include/gmock/internal/custom/gmock-port.h", + "gtest/googlemock/include/gmock/internal/gmock-generated-internal-utils.h", + "gtest/googlemock/include/gmock/internal/gmock-internal-utils.h", + "gtest/googlemock/include/gmock/internal/gmock-port.h", + "gtest/googlemock/src/gmock-all.cc", + "gtest/googlemock/src/gmock-cardinalities.cc", + "gtest/googlemock/src/gmock-internal-utils.cc", + "gtest/googlemock/src/gmock-matchers.cc", + "gtest/googlemock/src/gmock-spec-builders.cc", + "gtest/googlemock/src/gmock.cc", + ] + sources -= [ "gtest/googlemock/src/gmock-all.cc" ] + deps = [ + ":gtest", + ] + configs -= [ "//third_party/mini_chromium/mini_chromium/build:Wexit_time_destructors" ] + configs += [ ":gmock_private_config" ] + public_configs = [ ":gmock_public_config" ] +} + +static_library("gmock_main") { + sources = [ + "gtest/googlemock/src/gmock_main.cc", + ] + deps = [ + ":gmock", + ":gtest", + ] +}