File tree Expand file tree Collapse file tree 5 files changed +35
-0
lines changed Expand file tree Collapse file tree 5 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 3939bazel- *
4040
4141node_modules
42+ compile_commands.json
Original file line number Diff line number Diff line change @@ -6,3 +6,6 @@ Leetcode exercises
66
77### Run C++ Tests
88` bazel test --test_output=all //cpp:tests `
9+
10+ ### Generate Compilation Database (for better autocomplete)
11+ ` ./generate_compilation_db.sh `
Original file line number Diff line number Diff line change @@ -25,6 +25,12 @@ http_archive(
2525 strip_prefix = "rules_cc-40548a2974f1aea06215272d9c2b47a14a24e556" ,
2626)
2727
28+ http_archive (
29+ name = "com_grail_bazel_compdb" ,
30+ strip_prefix = "bazel-compilation-database-master" ,
31+ urls = ["https://github.com/grailbio/bazel-compilation-database/archive/master.tar.gz" ],
32+ )
33+
2834# Fetch rules_nodejs so we can install our npm dependencies
2935http_archive (
3036 name = "build_bazel_rules_nodejs" ,
Original file line number Diff line number Diff line change 11package (default_visibility = ["//visibility:public" ])
22load ("@rules_cc//cc:defs.bzl" , "cc_test" )
3+ load ("@com_grail_bazel_compdb//:aspects.bzl" , "compilation_database" )
34
45cc_library (
56 name = "exercises" ,
@@ -14,8 +15,17 @@ cc_library(
1415cc_test (
1516 name = "tests" ,
1617 srcs = glob (["**/**/*_test.cc" ]),
18+ testonly = False ,
1719 deps = [
1820 ":exercises" ,
1921 "@com_google_googletest//:gtest_main"
2022 ],
2123)
24+
25+ compilation_database (
26+ name = "compilation_db" ,
27+ targets = [
28+ ":exercises" ,
29+ ":tests"
30+ ],
31+ )
Original file line number Diff line number Diff line change 1+ # Command to generate the compilation database file.
2+ bazel build cpp:compilation_db
3+
4+ # Location of the compilation database file.
5+ outfile=" $( bazel info bazel-bin) /cpp/compile_commands.json"
6+
7+ # Command to replace the marker for exec_root in the file.
8+ execroot=$( bazel info execution_root)
9+ sed -i.bak " s@__EXEC_ROOT__@${execroot} @" " ${outfile} "
10+
11+ # The compilation database is now ready to use at this location.
12+ echo " Compilation Database: ${outfile} "
13+
14+ workspace=" $( bazel info workspace) "
15+ ln -s " ${outfile} " " ${workspace} "
You can’t perform that action at this time.
0 commit comments