0

Fix problems with gtest_enable_absl_printers and enable by default.

* With this turned on, gtest unconditionally asks absl to initialize
  the symbol handler.  This causes base's attempt to do the same thing
  to fail.  Make base handle this by trying a force-reinit if this
  failure occurs.
* Allow gtest to see the full absl sources, since it unconditionally
  #includes banned headers.
* Fix include dirs not being set correctly, leading to compile failures.
* Narrow gtest absl dependency from public_deps to deps, since we don't
  want "all targets depending on gtest" to silently be able to use absl.
* Leave this flag disabled by default for NaCl, since the toolchain
  there can't compile some of the absl code.

Bug: none
Change-Id: I24930d1c2086bec1522922665708abee5ce8fc08
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2332038
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Bruce Dawson <brucedawson@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: Bruce Dawson <brucedawson@chromium.org>
Reviewed-by: Dirk Pranke <dpranke@google.com>
Cr-Commit-Position: refs/heads/master@{#793786}
This commit is contained in:
Peter Kasting
2020-07-31 22:35:47 +00:00
committed by Commit Bot
parent a4a07b1089
commit b5edda7710
4 changed files with 36 additions and 15 deletions
base/debug
build_overrides
third_party
abseil-cpp
googletest

@ -118,6 +118,28 @@ FilePath GetExePath() {
return FilePath(system_buffer);
}
bool SymInitializeCurrentProc() {
const HANDLE current_process = GetCurrentProcess();
if (SymInitialize(current_process, nullptr, TRUE))
return true;
g_init_error = GetLastError();
if (g_init_error != ERROR_INVALID_PARAMETER)
return false;
// SymInitialize() can fail with ERROR_INVALID_PARAMETER when something has
// already called SymInitialize() in this process. For example, when absl
// support for gtest is enabled, it results in absl calling SymInitialize()
// almost immediately after startup. In such a case, try to reinit to see if
// that succeeds.
SymCleanup(current_process);
if (SymInitialize(current_process, nullptr, TRUE))
return true;
g_init_error = GetLastError();
return false;
}
bool InitializeSymbols() {
if (g_initialized_symbols) {
// Force a reinitialization. Will ensure any modules loaded after process
@ -131,10 +153,7 @@ bool InitializeSymbols() {
SymSetOptions(SYMOPT_DEFERRED_LOADS |
SYMOPT_UNDNAME |
SYMOPT_LOAD_LINES);
if (!SymInitialize(GetCurrentProcess(), NULL, TRUE)) {
g_init_error = GetLastError();
// TODO(awong): Handle error: SymInitialize can fail with
// ERROR_INVALID_PARAMETER.
if (!SymInitializeCurrentProc()) {
// When it fails, we should not call debugbreak since it kills the current
// process (prevents future tests from running or kills the browser
// process).

@ -27,8 +27,9 @@ declare_args() {
# TODO(crbug/1006769): Switch to perfetto's client library.
use_perfetto_client_library = false
# Allows googletest to pretty-print various absl types.
gtest_enable_absl_printers = false
# Allows googletest to pretty-print various absl types. Disabled for nacl due
# to lack of toolchain support.
gtest_enable_absl_printers = !is_nacl
}
# Allows different projects to specify their own suppression/ignore lists for

@ -53,6 +53,10 @@ template("absl_source_set") {
# Abseil itself.
"//third_party/abseil-cpp/*",
# GTest. It unconditionally #includes any.h if pretty-print support
# for absl types is enabled.
"//third_party/googletest/*",
# WebRTC binary to run PSNR and SSIM video quality analysis. It
# statically links absl and it is used by "browser_tests" when
# is_component_build=false but it cannot depend on the absl

@ -34,7 +34,8 @@ config("gtest_config") {
cflags = [ "/wd4800" ] # Unused variable warning.
}
if (!build_with_chromium && gtest_enable_absl_printers) {
if (gtest_enable_absl_printers) {
configs = [ "//third_party/abseil-cpp:absl_include_config" ]
defines += [ "GTEST_HAS_ABSL=1" ]
}
}
@ -111,9 +112,6 @@ source_set("gtest") {
include_dirs = [ "src/googletest" ]
public_configs = [ ":gtest_config" ]
if (!build_with_chromium && gtest_enable_absl_printers) {
public_configs += [ "//third_party/abseil-cpp:absl_include_config" ]
}
configs -= [ "//build/config/compiler:chromium_code" ]
configs += [ "//build/config/compiler:no_chromium_code" ]
@ -127,11 +125,6 @@ source_set("gtest") {
"custom/gtest/internal/custom/stack_trace_getter.cc",
"custom/gtest/internal/custom/stack_trace_getter.h",
]
if (gtest_enable_absl_printers) {
public_deps += [
"//third_party/abseil-cpp:absl",
]
}
} else {
deps += [ "//base" ]
}
@ -142,6 +135,10 @@ source_set("gtest") {
"//third_party/fuchsia-sdk/sdk/pkg/zx",
]
}
if (gtest_enable_absl_printers) {
deps += [ "//third_party/abseil-cpp:absl" ]
}
}
# Do NOT depend on this directly. Use //testing/gtest:gtest_main instead.