99from pathlib import Path
1010
1111
12+ def runBazelBuildForCompilationDatabase (bazel_options , bazel_targets ):
13+ query = 'attr(include_prefix, ".+", kind(cc_library, deps({})))' .format (
14+ ' union ' .join (bazel_targets ))
15+ build_targets = subprocess .check_output (["bazel" , "query" , query ]).decode ().splitlines ()
16+ subprocess .check_call (["bazel" , "build" ] + bazel_options + build_targets )
17+
18+
1219# This method is equivalent to https://github.com/grailbio/bazel-compilation-database/blob/master/generate.sh
1320def generateCompilationDatabase (args ):
1421 # We need to download all remote outputs for generated source code, we don't care about built
1522 # binaries so just always strip and use dynamic link to minimize download size.
1623 bazel_options = shlex .split (os .environ .get ("BAZEL_BUILD_OPTIONS" , "" )) + [
1724 "-c" , "fastbuild" , "--build_tag_filters=-manual" ,
18- "--experimental_remote_download_outputs=all" , "--strip=always" ,
19- "--define=dynamic_link_tests=true"
25+ "--experimental_remote_download_outputs=all" , "--strip=always"
2026 ]
2127 if args .run_bazel_build :
22- subprocess . check_call ([ "bazel" , "build" ] + bazel_options + args .bazel_targets )
28+ runBazelBuildForCompilationDatabase ( bazel_options , args .bazel_targets )
2329
2430 subprocess .check_call (["bazel" , "build" ] + bazel_options + [
2531 "--aspects=@bazel_compdb//:aspects.bzl%compilation_database_aspect" ,
@@ -60,7 +66,7 @@ def isCompileTarget(target, args):
6066
6167
6268def modifyCompileCommand (target , args ):
63- _ , options = target ["command" ].split (" " , 1 )
69+ cc , options = target ["command" ].split (" " , 1 )
6470
6571 # Workaround for bazel added C++11 options, those doesn't affect build itself but
6672 # clang-tidy will misinterpret them.
@@ -76,7 +82,7 @@ def modifyCompileCommand(target, args):
7682 options += " -Wno-pragma-once-outside-header -Wno-unused-const-variable"
7783 options += " -Wno-unused-function"
7884
79- target ["command" ] = " " .join (["clang++" , options ])
85+ target ["command" ] = " " .join ([cc , options ])
8086 return target
8187
8288
0 commit comments