bazel: fix broken stacktrace (#851)

Since #846, `HAVE_UNWIND_H`  is not really in use. Instead we should use `HAVE__UNWIND_BACKTRACE` and `HAVE__UNWIND_GETIP` (added in #846). To prevent that from happening again, also added Bazel tests that confirm stacktrace are still working.
This commit is contained in:
Marek Cirkos 2022-08-16 17:48:59 +01:00 committed by GitHub
parent acc60d0c38
commit bfee415a1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 79 additions and 27 deletions

View File

@ -9,3 +9,10 @@ http_archive(
"https://github.com/gflags/gflags/archive/v2.2.2.tar.gz",
],
)
http_archive(
name = "com_github_google_googletest",
sha256 = "258f33ab1a8ee17adf48ec65e821d0ea9eafcbedeff6110f9eaed78472e73dde",
strip_prefix = "googletest-15460959cbbfa20e66ef0b5ab497367e47fc0a04",
urls = ["https://github.com/google/googletest/archive/15460959cbbfa20e66ef0b5ab497367e47fc0a04.tar.gz"],
)

View File

@ -33,7 +33,7 @@ def dict_union(x, y):
def glog_library(namespace = "google", with_gflags = 1, **kwargs):
if native.repository_name() != "@":
repo_name = native.repository_name()[1:] # Strip the first leading @
repo_name = native.repository_name()[1:] # Strip the first leading @
gendir = "$(GENDIR)/external/" + repo_name
src_windows = "external/%s/src/windows" % repo_name
else:
@ -75,7 +75,8 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs):
"-DHAVE_SYS_UTSNAME_H",
# For src/utilities.cc.
"-DHAVE_SYS_TIME_H",
"-DHAVE_UNWIND_H",
"-DHAVE__UNWIND_BACKTRACE",
"-DHAVE__UNWIND_GETIP",
# Enable dumping stacktrace upon sigaction.
"-DHAVE_SIGACTION",
# For logging.cc.
@ -127,6 +128,31 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs):
gflags_deps = ["@com_github_gflags_gflags//:gflags"] if with_gflags else []
final_lib_defines = select({
# GLOG_EXPORT is normally set by export.h, but that's not
# generated for Bazel.
"@bazel_tools//src/conditions:windows": [
"GLOG_EXPORT=",
"GLOG_DEPRECATED=__declspec(deprecated)",
"GLOG_NO_ABBREVIATED_SEVERITIES",
],
"//conditions:default": [
"GLOG_DEPRECATED=__attribute__((deprecated))",
"GLOG_EXPORT=__attribute__((visibility(\\\"default\\\")))",
],
})
final_lib_copts = select({
"@bazel_tools//src/conditions:windows": common_copts + windows_only_copts,
"@bazel_tools//src/conditions:darwin": common_copts + linux_or_darwin_copts + darwin_only_copts,
"@bazel_tools//src/conditions:freebsd": common_copts + linux_or_darwin_copts + freebsd_only_copts,
":wasm": common_copts + wasm_copts,
"//conditions:default": common_copts + linux_or_darwin_copts,
}) + select({
":clang-cl": clang_cl_only_copts,
"//conditions:default": [],
})
native.cc_library(
name = "glog",
visibility = ["//visibility:public"],
@ -165,31 +191,8 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs):
":vlog_is_on_h",
],
strip_include_prefix = "src",
defines = select({
# GLOG_EXPORT is normally set by export.h, but that's not
# generated for Bazel.
"@bazel_tools//src/conditions:windows": [
"GLOG_EXPORT=",
"GLOG_DEPRECATED=__declspec(deprecated)",
"GLOG_NO_ABBREVIATED_SEVERITIES",
],
"//conditions:default": [
"GLOG_DEPRECATED=__attribute__((deprecated))",
"GLOG_EXPORT=__attribute__((visibility(\\\"default\\\")))",
],
}),
copts =
select({
"@bazel_tools//src/conditions:windows": common_copts + windows_only_copts,
"@bazel_tools//src/conditions:darwin": common_copts + linux_or_darwin_copts + darwin_only_copts,
"@bazel_tools//src/conditions:freebsd": common_copts + linux_or_darwin_copts + freebsd_only_copts,
":wasm": common_copts + wasm_copts,
"//conditions:default": common_copts + linux_or_darwin_copts,
}) +
select({
":clang-cl": clang_cl_only_copts,
"//conditions:default": []
}),
defines = final_lib_defines,
copts = final_lib_copts,
deps = gflags_deps + select({
"@bazel_tools//src/conditions:windows": [":strip_include_prefix_hack"],
"//conditions:default": [],
@ -197,6 +200,42 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs):
**kwargs
)
test_list = [
"cleanup_immediately",
"cleanup_with_absolute_prefix",
"cleanup_with_relative_prefix",
# "demangle", # Broken
# "logging_custom_prefix", # Broken
# "logging", # Broken
# "mock-log", # Broken
# "signalhandler", # Pointless
"stacktrace",
"stl_logging",
"symbolize",
"utilities",
]
test_only_copts = [
"-DTEST_SRC_DIR=\\\"%s/tests\\\"" % gendir,
]
for test_name in test_list:
native.cc_test(
name = test_name + "_test",
visibility = ["//visibility:public"],
srcs = [
"src/googletest.h",
"src/" + test_name + "_unittest.cc",
],
defines = final_lib_defines,
copts = final_lib_copts + test_only_copts,
deps = [
":glog",
"@com_github_google_googletest//:gtest",
],
**kwargs
)
# Workaround https://github.com/bazelbuild/bazel/issues/6337 by declaring
# the dependencies without strip_include_prefix.
native.cc_library(

View File

@ -233,6 +233,12 @@ int main(int, char ** argv) {
#else
int main() {
#ifdef GLOG_BAZEL_BUILD
printf("HAVE_STACKTRACE is expected to be defined in Bazel tests\n");
exit(EXIT_FAILURE);
#endif // GLOG_BAZEL_BUILD
printf("PASS (no stacktrace support)\n");
return 0;
}