File tree Expand file tree Collapse file tree 3 files changed +72
-10
lines changed
Expand file tree Collapse file tree 3 files changed +72
-10
lines changed Original file line number Diff line number Diff line change @@ -43,14 +43,15 @@ repos:
4343 - id : clang-format
4444 args : ['-fallback-style=none', '-i']
4545
46- # C++ static analysis (installs clang-tidy automatically via pip)
47- # - repo: https://github.com/mxmlnrdr/clang_tidy_hook
48- # rev: v0.3.1
49- # hooks:
50- # - id: clang-tidy
51- # args:
52- # - --config-file=.clang-tidy
53- # - -p=build
46+ # C++ static analysis via clangd-21 (skips if not installed)
47+ - repo : local
48+ hooks :
49+ - id : clang-tidy
50+ name : clang-tidy
51+ entry : ./run_clang_tidy_hook.sh
52+ language : script
53+ files : \.(cpp|hpp|h)$
54+ exclude : ^3rdparty/|^include/behaviortree_cpp/contrib/|^include/behaviortree_cpp/scripting/
5455
5556 # Spell check
5657 - repo : https://github.com/codespell-project/codespell
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+ # Pre-commit hook wrapper for clang-tidy.
3+ # - Skips if clangd-21 is not installed
4+ # - Skips if compile_commands.json not found
5+ # - Runs only on files passed as arguments (modified files)
6+ # - Fails if clang-tidy reports any errors
7+
8+ script_dir=${0%/* }
9+ build_dir=" ${script_dir} /build"
10+
11+ if ! command -v clangd-21 & > /dev/null; then
12+ echo " Skipping clang-tidy: clangd-21 not installed"
13+ exit 0
14+ fi
15+
16+ if [ ! -f " ${build_dir} /compile_commands.json" ]; then
17+ echo " Skipping clang-tidy: compile_commands.json not found (run cmake first)"
18+ exit 0
19+ fi
20+
21+ if [ $# -eq 0 ]; then
22+ echo " No files to check"
23+ exit 0
24+ fi
25+
26+ # Filter to only .cpp, .hpp, .h files and exclude 3rdparty/contrib/scripting
27+ files=()
28+ for f in " $@ " ; do
29+ case " $f " in
30+ 3rdparty/* |* /contrib/* |* /scripting/* |* _WIN.cpp) continue ;;
31+ * .cpp|* .hpp|* .h) files+=(" $f " ) ;;
32+ esac
33+ done
34+
35+ if [ ${# files[@]} -eq 0 ]; then
36+ exit 0
37+ fi
38+
39+ echo " Running clang-tidy on ${# files[@]} file(s)..."
40+
41+ failed=0
42+ for f in " ${files[@]} " ; do
43+ echo " Checking: $f "
44+ output=$( clangd-21 \
45+ --log=error \
46+ --clang-tidy \
47+ --compile-commands-dir=" $build_dir " \
48+ --check-locations=false \
49+ --check=" $f " 2>&1 )
50+ # Check for error lines (starts with E[)
51+ if echo " $output " | grep -q " ^E\[" ; then
52+ echo " $output " | grep " ^E\["
53+ failed=1
54+ fi
55+ done
56+
57+ exit $failed
Original file line number Diff line number Diff line change 2020
2121namespace BT
2222{
23-
23+ namespace
24+ {
2425// Thread-local stack tracking the current tick hierarchy.
2526// Used to build a backtrace when an exception is thrown during tick().
26- static thread_local std::vector<const TreeNode*> tick_stack_;
27+ thread_local std::vector<const TreeNode*> tick_stack_;
2728
2829// RAII guard to push/pop nodes from the tick stack
2930class TickStackGuard
@@ -39,6 +40,8 @@ class TickStackGuard
3940 }
4041 TickStackGuard (const TickStackGuard&) = delete ;
4142 TickStackGuard& operator =(const TickStackGuard&) = delete ;
43+ TickStackGuard (TickStackGuard&&) = delete ;
44+ TickStackGuard& operator =(TickStackGuard&&) = delete ;
4245
4346 // Build a backtrace from the current tick stack
4447 static std::vector<TickBacktraceEntry> buildBacktrace ()
@@ -52,6 +55,7 @@ class TickStackGuard
5255 return backtrace;
5356 }
5457};
58+ } // namespace
5559
5660struct TreeNode ::PImpl
5761{
You can’t perform that action at this time.
0 commit comments