forked from yahoo/proxy-verifier
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclang-format.sh
More file actions
executable file
·90 lines (77 loc) · 2.71 KB
/
clang-format.sh
File metadata and controls
executable file
·90 lines (77 loc) · 2.71 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#! /usr/bin/env bash
#
# Simple wrapper to run clang-format on a bunch of files
#
# Copyright 2021, Verizon Media
# SPDX-License-Identifier: Apache-2.0
#
# Update the PKGDATE with the new version date when making a new clang-format binary package.
PKGDATE="20200514"
function main() {
set -e # exit on error
ROOT=${ROOT:-$(cd $(dirname $0) && git rev-parse --show-toplevel)/.git/fmt/${PKGDATE}}
TOP_LEVEL=`cd $(dirname $0) && git rev-parse --show-toplevel`
DIR=${@:-"${TOP_LEVEL}/src ${TOP_LEVEL}/tests"}
PACKAGE="clang-format-${PKGDATE}.tar.bz2"
VERSION="clang-format version 10.0.0 (https://github.com/llvm/llvm-project.git d32170dbd5b0d54436537b6b75beaf44324e0c28)"
URL=${URL:-https://ci.trafficserver.apache.org/bintray/${PACKAGE}}
TAR=${TAR:-tar}
CURL=${CURL:-curl}
# default to using native sha1sum command when available
if [ $(which sha1sum) ] ; then
SHASUM=${SHASUM:-sha1sum}
else
SHASUM=${SHASUM:-shasum}
fi
ARCHIVE=$ROOT/$(basename ${URL})
case $(uname -s) in
Darwin)
FORMAT=${FORMAT:-${ROOT}/clang-format/clang-format.osx}
;;
Linux)
FORMAT=${FORMAT:-${ROOT}/clang-format/clang-format.linux}
;;
*)
echo "Leif needs to build a clang-format for $(uname -s)"
exit 2
esac
mkdir -p ${ROOT}
# Note that the two spaces between the hash and ${ARCHIVE) is needed
if [ ! -e ${FORMAT} -o ! -e ${ROOT}/${PACKAGE} ] ; then
${CURL} -L --progress-bar -o ${ARCHIVE} ${URL}
${TAR} -x -C ${ROOT} -f ${ARCHIVE}
cat > ${ROOT}/sha1 << EOF
5eec43e5c7f3010d6e6f37639491cabe51de0ab2 ${ARCHIVE}
EOF
${SHASUM} -c ${ROOT}/sha1
chmod +x ${FORMAT}
fi
# Make sure we only run this with our exact version
ver=$(${FORMAT} --version)
if [ "$ver" != "$VERSION" ]; then
echo "Wrong version of clang-format!"
echo "See https://bintray.com/apache/trafficserver/clang-format-tools/view for a newer version,"
echo "or alternatively, undefine the FORMAT environment variable"
exit 1
else
echo "Running clang-format. This may take a minute."
tmp_dir=$(mktemp -d -t tracked-clang-files.XXXXXXXXXX)
files=${tmp_dir}/clang_files.txt
start_time_file=${tmp_dir}/format_start.$$
find $DIR \
\( -path '*/.venv' -o -path '*/_build' -o -path '*/_destdir' -o -path '*/_scm' \) -prune \
-o \( -iname \*.[ch] -o -iname \*.cc \) -print > ${files}
touch ${start_time_file}
while read -r file; do
${FORMAT} -i "$file"
done < ${files}
find $(cat ${files}) -newer ${start_time_file}
rm -rf ${tmp_dir}
echo "clang-format completed."
fi
}
if [[ "$(basename -- "$0")" == 'clang-format.sh' ]]; then
main "$@"
else
ROOT=${ROOT:-$(git rev-parse --show-toplevel)/.git/fmt/${PKGDATE}}
fi