Skip to content

Commit fe892ae

Browse files
authored
Add use-after-move check of clang-tidy (project-chip#8414)
Usage: gn --root=. gen --check --fail-on-unused-args ./out/debug "--args=target_os=\"all\" is_clang=true pw_command_launcher=\"`pwd`/scripts/helpers/clang-tidy-launcher.py\"" ninja -v -C out/debug More checks can be added by modifying .clang-tidy
1 parent 2a63309 commit fe892ae

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

.clang-tidy

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
Checks: '-*,bugprone-use-after-move'
3+
WarningsAsErrors: '*'
4+
HeaderFilterRegex: ''
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env python
2+
3+
import subprocess
4+
import sys
5+
6+
def main():
7+
if len(sys.argv) < 2:
8+
return 1;
9+
10+
cc = sys.argv[1]
11+
if not cc.startswith("clang"):
12+
return 0;
13+
14+
command = ["clang-tidy"]
15+
clang_args = []
16+
17+
i = 2
18+
while i < len(sys.argv):
19+
if sys.argv[i] == "-c":
20+
# Source file
21+
i += 1
22+
if i >= len(sys.argv):
23+
print("Got -c without argument", file=sys.stderr)
24+
return 1
25+
command.append(sys.argv[i])
26+
elif sys.argv[i] == "-o":
27+
# Ignore output
28+
i += 1
29+
if i >= len(sys.argv):
30+
print("Got -o without argument", file=sys.stderr)
31+
return 1
32+
else:
33+
clang_args.append(sys.argv[i])
34+
35+
i += 1
36+
37+
tidy_result = subprocess.run(command + ["--"] + clang_args)
38+
if tidy_result.returncode != 0:
39+
return tidy_result.returncode
40+
41+
clang_result = subprocess.run(sys.argv[1:])
42+
return clang_result.returncode
43+
44+
if __name__ == "__main__":
45+
sys.exit(main())

0 commit comments

Comments
 (0)