summaryrefslogtreecommitdiff
path: root/scripts/maint
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2019-12-16 10:58:32 -0500
committerNick Mathewson <nickm@torproject.org>2020-02-06 14:33:05 -0500
commit573ab70bfe4c6239a3fffda89b1a95e4e7ca10aa (patch)
treefa9e5ae84837ab9a6088704a02685f005ec0cd99 /scripts/maint
parent5bd86b50b58ffcad48416df6fa6b411e92c4636e (diff)
downloadtor-573ab70bfe4c6239a3fffda89b1a95e4e7ca10aa.tar.gz
tor-573ab70bfe4c6239a3fffda89b1a95e4e7ca10aa.zip
Temporary clang-format configuration and script.
The format is the same as in my previous efforts here. The script is a little tricky, since it invokes both clang-format and codetool, and it makes sure that files do not have a changed mtime unless there is actually some change in the file.
Diffstat (limited to 'scripts/maint')
-rwxr-xr-xscripts/maint/clang-format.sh34
1 files changed, 34 insertions, 0 deletions
diff --git a/scripts/maint/clang-format.sh b/scripts/maint/clang-format.sh
new file mode 100755
index 0000000000..86430b9b26
--- /dev/null
+++ b/scripts/maint/clang-format.sh
@@ -0,0 +1,34 @@
+#!/bin/sh
+# Copyright 2020, The Tor Project, Inc.
+# See LICENSE for licensing information.
+
+# This script runs "clang-format" and "codetool" in sequence over each of
+# our source files, and replaces the original file only if it has changed.
+#
+# We can't just use clang-format -i, since we also want to use codetool to
+# reformat a few things back to how we want them, and we want avoid changing
+# the mtime on files that didn't actually change.
+
+set -e
+
+cd "$(dirname "$0")/../../src/"
+
+# Shellcheck complains that a for loop over find's output is unreliable,
+# since there might be special characters in the output. But we happen
+# to know that none of our C files have special characters or spaces in
+# their names, so this is safe.
+#
+# shellcheck disable=SC2044
+for fname in $(find lib core feature app test tools -name '[^.]*.[ch]'); do
+ tmpfname="${fname}.clang_fmt.tmp"
+ rm -f "${tmpfname}"
+ clang-format --style=file "${fname}" > "${tmpfname}"
+ ../scripts/maint/codetool.py "${tmpfname}"
+ if cmp "${fname}" "${tmpfname}" >/dev/null 2>&1; then
+ echo "No change in ${fname}"
+ rm -f "${tmpfname}"
+ else
+ echo "Change in ${fname}"
+ mv "${tmpfname}" "${fname}"
+ fi
+done