Skip to content

Commit 41df6ad

Browse files
oliverleeerenon
authored andcommitted
Allow external clang-tidy configs
In the clang-tidy wrapper script, create a symlink in the current working directory to the provided clang-tidy config if not already present.
1 parent 31d62bf commit 41df6ad

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

BUILD

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ label_flag(
1212
visibility = ["//visibility:public"],
1313
)
1414

15-
1615
filegroup(
1716
name = "clang_tidy_executable_default",
18-
srcs = [], # empty list: system clang-tidy
17+
srcs = [], # empty list: system clang-tidy
1918
)
2019

2120
label_flag(
@@ -24,7 +23,6 @@ label_flag(
2423
visibility = ["//visibility:public"],
2524
)
2625

27-
2826
filegroup(
2927
name = "clang_tidy_additional_deps_default",
3028
srcs = [],

clang_tidy/clang_tidy.bzl

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
22

3-
def _run_tidy(ctx, wrapper, exe, additional_deps, config, flags, compilation_context, infile, discriminator):
4-
inputs = depset(direct = [infile, config] + additional_deps.files.to_list() + ([exe.files_to_run.executable] if exe.files_to_run.executable else []), transitive = [compilation_context.headers])
3+
def _run_tidy(
4+
ctx,
5+
wrapper,
6+
exe,
7+
additional_deps,
8+
config,
9+
flags,
10+
compilation_context,
11+
infile,
12+
discriminator):
13+
inputs = depset(
14+
direct = (
15+
[infile, config] +
16+
additional_deps.files.to_list() +
17+
([exe.files_to_run.executable] if exe.files_to_run.executable else [])
18+
),
19+
transitive = [compilation_context.headers],
20+
)
521

622
args = ctx.actions.args()
723

@@ -12,11 +28,14 @@ def _run_tidy(ctx, wrapper, exe, additional_deps, config, flags, compilation_con
1228

1329
# this is consumed by the wrapper script
1430
if len(exe.files.to_list()) == 0:
15-
args.add("clang-tidy")
31+
args.add("clang-tidy")
1632
else:
1733
args.add(exe.files_to_run.executable)
1834

1935
args.add(outfile.path) # this is consumed by the wrapper script
36+
37+
args.add(config.path)
38+
2039
args.add("--export-fixes", outfile.path)
2140

2241
# add source to check

clang_tidy/run_clang_tidy.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! /bin/bash
1+
#!/usr/bin/env bash
22
# Usage: run_clang_tidy <OUTPUT> [ARGS...]
33
set -ue
44

@@ -8,10 +8,17 @@ shift
88
OUTPUT=$1
99
shift
1010

11+
CONFIG=$1
12+
shift
13+
1114
# clang-tidy doesn't create a patchfile if there are no errors.
1215
# make sure the output exists, and empty if there are no errors,
1316
# so the build system will not be confused.
1417
touch $OUTPUT
1518
truncate -s 0 $OUTPUT
1619

20+
# if $CONFIG is provided by some external workspace, we need to
21+
# place it in the current directory
22+
test -e .clang-tidy || ln -s -f $CONFIG .clang-tidy
23+
1724
"${CLANG_TIDY_BIN}" "$@"

0 commit comments

Comments
 (0)