forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepeat_clang_tidy_helper.sh
executable file
·53 lines (44 loc) · 1.14 KB
/
repeat_clang_tidy_helper.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
set -eu
filename="${!#}"
printf "%s\n" "$filename"
tmpdir=$(mktemp --tmpdir -d repeat_clang_tidy.XXXXXX)
tmpfile="$tmpdir"/fixes.yaml
trap 'rm -rf "$tmpdir"' EXIT
start_time=$(date +%s.%N)
clang-tidy --export-fixes="$tmpfile" "$@" || printf "%s\n" "$filename" >&3
if [ ! -r "$tmpfile" ]
then
exit 0
fi
files_modified=$( \
grep -A1 Replacements: "$tmpfile" | \
grep 'FilePath:' | \
awk '{print $3}' | \
tr -d "'" \
)
if [ -z "$files_modified" ]
then
echo 'Fixes file created but no filenames found'
exit 0
fi
# If none of the files have changed since we started running, then apply the
# fixes. We need to do this under a lock to ensure that at most one script
# updates at a time
lockdir=repeat_clang_tidy.lock
while ! mkdir "$lockdir"
do
echo 'Waiting for lock...'
sleep 0.1
done
trap 'rm -rf "$lockdir" "$tmpdir"' EXIT
for file in $files_modified
do
mtime=$(find "$file" -printf %T@)
if awk -v n1=$start_time -v n2=$mtime 'BEGIN{exit n1 > n2}'
then
printf '%s was modified since clang-tidy run; aborting changes\n' "$file"
exit 0
fi
done
clang-apply-replacements $tmpdir