Skip to content

Commit 85b1dbc

Browse files
lizanhtuch
authored andcommitted
build: make compilation database generation faster (envoyproxy#8628)
Signed-off-by: Lizan Zhou <lizan@tetrate.io>
1 parent 39c323d commit 85b1dbc

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

tools/gen_compilation_database.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,23 @@
99
from 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
1320
def 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

6268
def 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

Comments
 (0)