-
Notifications
You must be signed in to change notification settings - Fork 0
/
clang-format-infer.sh
executable file
·64 lines (47 loc) · 2.16 KB
/
clang-format-infer.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
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
OPTS=$(getopt -o '' --long cxx-compiler:,clang-format:,constants:,source-dir:,extensions:,repetitions: -- "$@")
eval set -- "$OPTS"
CXX_COMPILER=$(whereis clang++ | cut -d ' ' -f 2)
CLANG_FORMAT=$(whereis clang-format | cut -d ' ' -f 2)
while true; do
case "$1" in
--cxx-compiler) CXX_COMPILER=$2; shift 2;;
--clang-format) CLANG_FORMAT=$2; shift 2;;
--constants) CONSTANTS=$2; shift 2;;
--source-dir) SOURCE_DIR=$2; shift 2;;
--extensions) EXTENSIONS=$2; shift 2;;
--repetitions) REPETITIONS=$2; shift 2;;
*) break;;
esac
done
REPETITIONS=${REPETITIONS:-"1"}
CLANG_DIR=$(dirname "${CLANG_FORMAT}")/..
THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
make --directory="${THIS_DIR}" --silent CXX="${CXX_COMPILER}" CLANG_DIR="${CLANG_DIR}"
CXX_COMPILER_DIR=$(dirname "${CXX_COMPILER}")/..
EXAMPLE_STYLES=$(mktemp)
LD_LIBRARY_PATH="${CXX_COMPILER_DIR}"/lib64:${LD_LIBRARY_PATH} \
"${THIS_DIR}/example-styles.exe" > "${EXAMPLE_STYLES}"
if [[ "${EXTENSIONS}" ]]
then
OLD_SOURCE_DIR="${SOURCE_DIR}"
NEW_SOURCE_DIR="$(mktemp -d)/$(basename ${OLD_SOURCE_DIR})"
unset SOURCE_DIR
cp -r "${OLD_SOURCE_DIR}" "${NEW_SOURCE_DIR}"
find "${NEW_SOURCE_DIR}" -regextype posix-egrep -type f -not \
-regex "^.*\.($EXTENSIONS)$" -execdir rm {} \;
SOURCE_DIR="${NEW_SOURCE_DIR}"
fi
echo "Files: " $(find ${SOURCE_DIR} -type f | wc -l) >&2
BIG_CONFIG=$("${THIS_DIR}/search.py" --constants="${CONSTANTS}" \
--clang-format="${CLANG_FORMAT}" \
--source-dir="${SOURCE_DIR}" \
--repetitions="${REPETITIONS}" < "${EXAMPLE_STYLES}")
cat "${EXAMPLE_STYLES}" | xargs -L 1 ${THIS_DIR}/re-style.sh \
| "${THIS_DIR}/clang-format-reduce.py" --config "${BIG_CONFIG}" \
--source-dir="${SOURCE_DIR}" \
--clang-format="${CLANG_FORMAT}" \
--constants="${CONSTANTS}"
rm "${BIG_CONFIG}"
xargs rm < "${EXAMPLE_STYLES}"
rm "${EXAMPLE_STYLES}"