[PATCH] D77428: Use in-tree clang-format-diff.py as Arcanist linter
Scott Linder via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 3 12:58:00 PDT 2020
scott.linder created this revision.
scott.linder added reviewers: starsid, mehdi_amini, vitalybuka, fhahn, kadircet.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
The only guarantee there seems to be in the clang-format packaging is
that an executable called `clang-format` is in the PATH. Use the
in-tree `clang-format-diff.py` to avoid assuming anything else.
Also remove dead code for SVN repo.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D77428
Files:
utils/arcanist/clang-format.sh
Index: utils/arcanist/clang-format.sh
===================================================================
--- utils/arcanist/clang-format.sh
+++ utils/arcanist/clang-format.sh
@@ -4,17 +4,23 @@
# "script-and-regex.regex": "/^(?P<severity>.*?)\n(?P<message>.*?)\n(?P<line>\\d),(?P<char>\\d)(\n(?P<original>.*?)>>>>\n(?P<replacement>.*?)<<<<?)$/s",
-# Arcanist linter that invokes clang-format.
+# Arcanist linter that invokes clang-format via clang/tools/clang-format/clang-format-diff.py
# stdout from this script is parsed into a regex and used by Arcanist.
# https://secure.phabricator.com/book/phabricator/article/arcanist_lint_script_and_regex/
# To skip running all linters when creating/updating a diff, use `arc diff --nolint`.
-if ! hash clang-format-diff >/dev/null; then
- # advice severity level is completely non-disruptive.
- # switch to warning or error if you want to prompt the user.
+# advice severity level is completely non-disruptive.
+# switch to warning or error if you want to prompt the user.
+if ! hash clang-format >/dev/null; then
echo "advice"
- echo "clang-format-diff not found in user's PATH; not linting file."
+ echo "clang-format not found in user's PATH; not linting file."
+ echo "===="
+ exit 0
+fi
+if ! git rev-parse --git-dir >/dev/null; then
+ echo "advice"
+ echo "not in git repostitory; not linting file."
echo "===="
exit 0
fi
@@ -37,14 +43,17 @@
# Arcanist can filter out lint messages for unchanged lines, but for that, we
# need to generate line by line lint messages. Instead, we generate one lint
-# message on line 1, char 1 with file content edited using clang-format-diff.
-if git rev-parse --git-dir >/dev/null; then
- arc_base_commit=$(arc which --show-base)
- # An alternative is to use git-clang-format.
- git diff -U0 --no-color "${arc_base_commit}"| clang-format-diff -style file -i -p1
-else
- svn diff --diff-cmd=diff -x -U0 "${src_file}" | clang-format-diff -style LLVM -i
-fi
+# message on line 1, char 1 with file content edited using clang-format-diff.py
+#
+# We do not use git-clang-format because it wants to modify the index,
+# and arc is already holding the lock.
+#
+# We do not look for clang-format-diff or clang-format-diff.py in the PATH
+# because whether/how these are installed differs between distributions,
+# and we have an executable copy in the tree anyway.
+arc_base_commit=$(arc which --show-base)
+git diff -U0 --no-color "${arc_base_commit}" \
+ | clang/tools/clang-format/clang-format-diff.py -style file -i -p1
cp -p "${src_file}" "${formatted_file}"
cp -p "${original_file}" "${src_file}"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77428.254892.patch
Type: text/x-patch
Size: 2623 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200403/ffd208d7/attachment.bin>
More information about the llvm-commits
mailing list