From 984558daef53884aca59f3d651061c10344ec450 Mon Sep 17 00:00:00 2001 From: Masaru Tsuchiyama Date: Mon, 24 Sep 2018 20:25:14 +0900 Subject: [PATCH 1/4] =?UTF-8?q?=E6=96=87=E5=AD=97=E3=82=B3=E3=83=BC?= =?UTF-8?q?=E3=83=89=E3=83=81=E3=82=A7=E3=83=83=E3=82=AF=E3=82=92=E5=AE=9F?= =?UTF-8?q?=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- checkEncoding.bat | 10 ++++++ checkEncoding.py | 82 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 checkEncoding.bat create mode 100644 checkEncoding.py diff --git a/checkEncoding.bat b/checkEncoding.bat new file mode 100644 index 0000000000..0587db3e5a --- /dev/null +++ b/checkEncoding.bat @@ -0,0 +1,10 @@ +@echo off +if not "%APPVEYOR_BUILD_NUMBER%" == "" ( + @echo installing chardet + pip install chardet --user +) else ( + @echo skip installing chardet +) + +python checkEncoding.py || exit /b 1 +exit /b 0 diff --git a/checkEncoding.py b/checkEncoding.py new file mode 100644 index 0000000000..358a2dbfad --- /dev/null +++ b/checkEncoding.py @@ -0,0 +1,82 @@ +from chardet.universaldetector import UniversalDetector +import chardet +import os +import sys +import subprocess + +# 指定したファイルの文字コードを返す +def check_encoding(file_path): + detector = UniversalDetector() + with open(file_path, mode='rb') as f: + for binary in f: + detector.feed(binary) + if detector.done: + break + detector.close() + return detector.result['encoding'] + +# チェック対象の拡張子か判断する +def checkExtension(file): + extensions = [ + ".cpp", + ".h", + ] + base, ext = os.path.splitext(file) + if ext in extensions: + return True + else: + return False + +def getMergeBase(): + output = subprocess.check_output('git show-branch --merge-base master HEAD') + outputDec = output.decode() + mergeBase = outputDec.splitlines() + return mergeBase[0] + +# ベースとの差分をチェック +def getDiffFiles(): + mergeBase = getMergeBase() + + output = subprocess.check_output('git diff ' + mergeBase + ' --name-only --diff-filter=dr') + diffFiles = output.decode() + return diffFiles.splitlines() + +def checkEncodingResult(encoding): + expectEncoding = [ + "utf-8", + "ascii", + ] + encoding = encoding.lower() + if encoding in expectEncoding: + return True + + return False + +# デバッグ用 +# すべてのファイルの文字コードを調べてチェックする +def checkAll(): + for rootdir, dirs, files in os.walk('.'): + for file in files: + if checkExtension(file): + full = os.path.join(rootdir, file) + encoding = check_encoding(full) + if not checkEncodingResult(encoding): + print (encoding, full) + +if __name__ == '__main__': + count = 0 + + files = getDiffFiles() + for file in files: + if checkExtension(file): + encoding = check_encoding(file) + if not checkEncodingResult(encoding): + print (encoding, file) + count = count + 1 + + if count > 0: + print ("return 1") + sys.exit(1) + else: + print ("return 0") + sys.exit(0) From e6cc441a9e91cc12b94c4df73c13477664e2d5d9 Mon Sep 17 00:00:00 2001 From: Masaru Tsuchiyama Date: Mon, 24 Sep 2018 20:26:32 +0900 Subject: [PATCH 2/4] =?UTF-8?q?=E6=96=87=E5=AD=97=E3=82=B3=E3=83=BC?= =?UTF-8?q?=E3=83=89=E3=83=81=E3=82=A7=E3=83=83=E3=82=AF=E3=82=92=20appvey?= =?UTF-8?q?or=20=E3=81=8B=E3=82=89=E5=AE=9F=E8=A1=8C=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- appveyor.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index c44a19728c..aac77a423d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -16,6 +16,8 @@ platform: build_script: - cmd: >- + call checkEncoding.bat + call build-all.bat %PLATFORM% %CONFIGURATION% call tests\build-and-test.bat %PLATFORM% %CONFIGURATION% From 08523e2283e9f53becfed8815eb8112e1c9c00a7 Mon Sep 17 00:00:00 2001 From: Masaru Tsuchiyama Date: Mon, 24 Sep 2018 20:48:33 +0900 Subject: [PATCH 3/4] =?UTF-8?q?master=20=E2=86=92=20origin/master=20?= =?UTF-8?q?=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- checkEncoding.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/checkEncoding.py b/checkEncoding.py index 358a2dbfad..b40b1fa5de 100644 --- a/checkEncoding.py +++ b/checkEncoding.py @@ -28,7 +28,7 @@ def checkExtension(file): return False def getMergeBase(): - output = subprocess.check_output('git show-branch --merge-base master HEAD') + output = subprocess.check_output('git show-branch --merge-base origin/master HEAD') outputDec = output.decode() mergeBase = outputDec.splitlines() return mergeBase[0] From 821c0e8610c362a696f5bd97e50588858676e966 Mon Sep 17 00:00:00 2001 From: Masaru Tsuchiyama Date: Mon, 24 Sep 2018 20:53:57 +0900 Subject: [PATCH 4/4] =?UTF-8?q?=E3=83=AD=E3=82=B0=E5=87=BA=E5=8A=9B?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- checkEncoding.bat | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/checkEncoding.bat b/checkEncoding.bat index 0587db3e5a..dd4beda17c 100644 --- a/checkEncoding.bat +++ b/checkEncoding.bat @@ -6,5 +6,8 @@ if not "%APPVEYOR_BUILD_NUMBER%" == "" ( @echo skip installing chardet ) -python checkEncoding.py || exit /b 1 +@echo ---- start python checkEncoding.py ---- +python checkEncoding.py || (echo error checkEncoding.py && exit /b 1) +@echo ---- end python checkEncoding.py ---- +@echo. exit /b 0