diff --git a/tools/checkpatch.sh b/tools/checkpatch.sh index c05834e784..1324235de0 100755 --- a/tools/checkpatch.sh +++ b/tools/checkpatch.sh @@ -23,6 +23,7 @@ check=check_patch fail=0 range=0 spell=0 +encoding=0 message=0 usage() { @@ -30,7 +31,8 @@ usage() { echo "" echo "Options:" echo "-h" - echo "-c spell check with codespell(install with: pip install codespell)" + echo "-c spell check with codespell (install with: pip install codespell)" + echo "-u encoding check with cvt2utf (install with: pip install cvt2utf)" echo "-r range check only (coupled with -p or -g)" echo "-p (default)" echo "-m Change-Id check in commit message (coupled with -g)" @@ -75,6 +77,15 @@ check_file() { fail=1 fi fi + + if [ $encoding != 0 ]; then + md5="$(md5sum $@)" + cvt2utf convert --nobak "$@" &> /dev/null + if [ "$md5" != "$(md5sum $@)" ]; then + echo "$@: error: Non-UTF8 characters detected!" + fail=1 + fi + fi fi } @@ -147,6 +158,9 @@ while [ ! -z "$1" ]; do -c ) spell=1 ;; + -u ) + encoding=1 + ;; -f ) check=check_file ;; diff --git a/tools/ci/cibuild.sh b/tools/ci/cibuild.sh index a07bbbaab2..af09f3fe47 100755 --- a/tools/ci/cibuild.sh +++ b/tools/ci/cibuild.sh @@ -283,6 +283,7 @@ function python-tools { # cache restoration. pip3 install --force-reinstall \ CodeChecker \ + cvt2utf \ cxxfilt \ esptool==3.3.1 \ imgtool==1.9.0 \ diff --git a/tools/ci/docker/linux/Dockerfile b/tools/ci/docker/linux/Dockerfile index 31878e5d30..4f718c6af9 100644 --- a/tools/ci/docker/linux/Dockerfile +++ b/tools/ci/docker/linux/Dockerfile @@ -279,6 +279,8 @@ ENV PIP_NO_CACHE_DIR=0 RUN pip3 install setuptools wheel # Install CodeChecker and use it to statically analyze the code. RUN pip3 install CodeChecker +# Install cvt2utf to check for non-UTF characters. +RUN pip3 install cvt2utf # Install pytest RUN pip3 install cxxfilt RUN pip3 install esptool