浏览代码

Fix file formatting script dependencies and cleanup

Aaron Franke 2 年之前
父节点
当前提交
06450bfb0f
共有 2 个文件被更改,包括 11 次插入9 次删除
  1. 1 1
      .github/workflows/static_checks.yml
  2. 10 8
      misc/scripts/file_format.sh

+ 1 - 1
.github/workflows/static_checks.yml

@@ -24,7 +24,7 @@ jobs:
 
 
       - name: Install dependencies
       - name: Install dependencies
         run: |
         run: |
-          sudo apt-get install -qq dos2unix recode clang-format-15 libxml2-utils python3-pip moreutils
+          sudo apt-get install -qq dos2unix clang-format-15 libxml2-utils python3-pip moreutils
           sudo update-alternatives --remove-all clang-format || true
           sudo update-alternatives --remove-all clang-format || true
           sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-15 100
           sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-15 100
           sudo pip3 install black==22.3.0 pygments pytest==7.1.2 mypy==0.971
           sudo pip3 install black==22.3.0 pygments pytest==7.1.2 mypy==0.971

+ 10 - 8
misc/scripts/file_format.sh

@@ -4,9 +4,9 @@
 # This is supplementary to clang_format.sh and black_format.sh, but should be
 # This is supplementary to clang_format.sh and black_format.sh, but should be
 # run before them.
 # run before them.
 
 
-# We need dos2unix and recode.
-if [ ! -x "$(command -v dos2unix)" -o ! -x "$(command -v recode)" ]; then
-    printf "Install 'dos2unix' and 'recode' to use this script.\n"
+# We need dos2unix and isutf8.
+if [ ! -x "$(command -v dos2unix)" -o ! -x "$(command -v isutf8)" ]; then
+    printf "Install 'dos2unix' and 'isutf8' (moreutils package) to use this script.\n"
 fi
 fi
 
 
 set -uo pipefail
 set -uo pipefail
@@ -53,22 +53,24 @@ done
 
 
 diff=$(git diff --color)
 diff=$(git diff --color)
 
 
-# If no UTF-8 violations were collected and no diff has been
-# generated all is OK, clean up, and exit.
 if [ ! -s utf8-validation.txt ] && [ -z "$diff" ] ; then
 if [ ! -s utf8-validation.txt ] && [ -z "$diff" ] ; then
+    # If no UTF-8 violations were collected (the file is empty) and
+    # no diff has been generated all is OK, clean up, and exit.
     printf "Files in this commit comply with the formatting rules.\n"
     printf "Files in this commit comply with the formatting rules.\n"
-    rm -f utf8-violations.txt
+    rm -f utf8-validation.txt
     exit 0
     exit 0
 fi
 fi
 
 
-# Violations detected, notify the user, clean up, and exit.
 if [ -s utf8-validation.txt ]
 if [ -s utf8-validation.txt ]
 then
 then
+    # If the file has content and is not empty, violations
+    # detected, notify the user, clean up, and exit.
     printf "\n*** The following files contain invalid UTF-8 character sequences:\n\n"
     printf "\n*** The following files contain invalid UTF-8 character sequences:\n\n"
     cat utf8-validation.txt
     cat utf8-validation.txt
-    rm -f utf8-validation.txt
 fi
 fi
 
 
+rm -f utf8-validation.txt
+
 if [ ! -z "$diff" ]
 if [ ! -z "$diff" ]
 then
 then
     printf "\n*** The following differences were found between the code "
     printf "\n*** The following differences were found between the code "