-
Notifications
You must be signed in to change notification settings - Fork 158
Description
I've been using the extractor for a while now, and it has been working very well - thank you!
I just added the Google logger, glog
, as a dependency to one of my applications. When I run the extractor, it seems to find the correct file ("logging.h") but the path is wrong. I created a simple reproduce case.
WORKSPACE
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "com_github_gflags_gflags",
sha256 = "34af2f15cf7367513b352bdcd2493ab14ce43692d2dcd9dfc499492966c64dcf",
strip_prefix = "gflags-2.2.2",
urls = ["https://github.com/gflags/gflags/archive/v2.2.2.tar.gz"],
)
http_archive(
name = "com_github_google_glog",
sha256 = "122fb6b712808ef43fbf80f75c52a21c9760683dae470154f02bddfc61135022",
strip_prefix = "glog-0.6.0",
urls = ["https://github.com/google/glog/archive/v0.6.0.zip"],
)
http_archive(
name = "hedron_compile_commands",
# Replace the commit hash in both places (below) with the latest, rather than using the stale one here.
# Even better, set up Renovate and let it do the work for you (see "Suggestion: Updates" in the README).
url = "https://github.com/hedronvision/bazel-compile-commands-extractor/archive/3dddf205a1f5cde20faf2444c1757abe0564ff4c.tar.gz",
strip_prefix = "bazel-compile-commands-extractor-3dddf205a1f5cde20faf2444c1757abe0564ff4c",
# When you first run this tool, it'll recommend a sha256 hash to put here with a message like: "DEBUG: Rule 'hedron_compile_commands' indicated that a canonical reproducible form can be obtained by modifying arguments sha256 = ..."
)
load("@hedron_compile_commands//:workspace_setup.bzl", "hedron_compile_commands_setup")
hedron_compile_commands_setup()
BUILD
cc_binary(
name = "main",
srcs = ["main.cc"],
deps = ["@com_github_google_glog//:glog"],
)
main.cc
include <glog/logging.h>
int main(int argc, char** argv)
{
google::InitGoogleLogging(argv[0]);
LOG(INFO) << "this is a log message";
return 0;
}
Then I run:
bazel run @hedron_compile_commands//:refresh_all
When I open the code emacs/clangd complain that "logging.h" cannot be found. Now, looking in the resulting compile_commands.json file I see entries for "logging.h":
{
"file": "glog/logging.h",
"arguments": [
"/usr/bin/gcc",
"-xc++",
"-U_FORTIFY_SOURCE",
"-fstack-protector",
"-Wall",
"-Wunused-but-set-parameter",
"-Wno-free-nonheap-object",
"-fno-omit-frame-pointer",
"-std=c++0x",
"-MD",
"-MF",
"bazel-out/k8-fastbuild/bin/_objs/main/main.pic.d",
"-frandom-seed=bazel-out/k8-fastbuild/bin/_objs/main/main.pic.o",
"-fPIC",
"-DGLOG_DEPRECATED=__attribute__((deprecated))",
"-DGLOG_EXPORT=__attribute__((visibility(\"default\")))",
"-DBAZEL_CURRENT_REPOSITORY=\"\"",
"-iquote",
".",
"-iquote",
"bazel-out/k8-fastbuild/bin",
"-iquote",
"external/com_github_google_glog",
"-iquote",
"bazel-out/k8-fastbuild/bin/external/com_github_google_glog",
"-iquote",
"external/com_github_gflags_gflags",
"-iquote",
"bazel-out/k8-fastbuild/bin/external/com_github_gflags_gflags",
"-iquote",
"external/bazel_tools",
"-iquote",
"bazel-out/k8-fastbuild/bin/external/bazel_tools",
"-Ibazel-out/k8-fastbuild/bin/external/com_github_google_glog/_virtual_includes/glog",
"-Ibazel-out/k8-fastbuild/bin/external/com_github_gflags_gflags/_virtual_includes/gflags",
"-Wno-builtin-macro-redefined",
"-D__DATE__=\"redacted\"",
"-D__TIMESTAMP__=\"redacted\"",
"-D__TIME__=\"redacted\"",
"-c",
"main.cc",
"-o",
"bazel-out/k8-fastbuild/bin/_objs/main/main.pic.o"
],
"directory": "/scratch/james/glog_test2"
},
The file name glog/logging.h
looks incorrect to me. I would expect it to be somewhere under external/
. The code compiles and runs just fine.
I'm using bazel version: bazel 6.2.0- (@non-git)
on Ubuntu 22.04, with gcc 11.3.0. I also tested on my Mac - same thing.
The strange thing is this: when I first tried this it didn't work in my larger codebase, so then I built this smaller test example and it worked fine. I then modified this smaller one to be closer to my larger one (added gtest
in the WORKSPACE file, for example), and it broke. But now, I can't make it work even starting from scratch again.
I just followed the instructions here (https://github.com/google/glog#bazel) to add glog
.
If anyone has time to look into it, I'd appreciate it. Other than this one issue, your tool has definitely helped my development environment - thank you!