summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Rogucki <marcin.rogucki@mobica.com>2017-09-28 18:01:18 +0200
committerAlexander Galazin <Alexander.Galazin@arm.com>2017-10-02 08:31:08 -0400
commit69731671eed80fd6915375f22d88c0404a6accb6 (patch)
tree2c76bdd04d8e50990a24bdd96765a16b4777ddd0
parent308172f1771c4ed01b45faead3055da016cd8d3b (diff)
downloadVK-GL-CTS-69731671eed80fd6915375f22d88c0404a6accb6.tar.gz
VK-GL-CTS-69731671eed80fd6915375f22d88c0404a6accb6.tar.bz2
VK-GL-CTS-69731671eed80fd6915375f22d88c0404a6accb6.zip
Added script for checking & fixing BOMs in files.
Affects: doc/testspecs/GLES2/functional.rasterization.txt framework/platform/win32/tcuWin32VulkanPlatform.cpp modules/gles31/functional/es31fNegativeVertexArrayApiTests.cpp scripts/src_util/check_all.py Adds: scripts/src_util/check_boms.py Change-Id: I17dc821e44a30a119e22ff42afbdca775ecec046 Components: Vulkan
-rw-r--r--doc/testspecs/GLES2/functional.rasterization.txt2
-rw-r--r--framework/platform/win32/tcuWin32VulkanPlatform.cpp2
-rw-r--r--modules/gles31/functional/es31fNegativeVertexArrayApiTests.cpp2
-rw-r--r--scripts/src_util/check_all.py55
-rw-r--r--scripts/src_util/check_boms.py86
5 files changed, 117 insertions, 30 deletions
diff --git a/doc/testspecs/GLES2/functional.rasterization.txt b/doc/testspecs/GLES2/functional.rasterization.txt
index afa1703a7..96fb4bb72 100644
--- a/doc/testspecs/GLES2/functional.rasterization.txt
+++ b/doc/testspecs/GLES2/functional.rasterization.txt
@@ -1,4 +1,4 @@
--------------------------------------------------------------------------
+-------------------------------------------------------------------------
drawElements Quality Program Test Specification
-----------------------------------------------
diff --git a/framework/platform/win32/tcuWin32VulkanPlatform.cpp b/framework/platform/win32/tcuWin32VulkanPlatform.cpp
index 98fd928e8..3b6cdaaf9 100644
--- a/framework/platform/win32/tcuWin32VulkanPlatform.cpp
+++ b/framework/platform/win32/tcuWin32VulkanPlatform.cpp
@@ -1,4 +1,4 @@
-/*-------------------------------------------------------------------------
+/*-------------------------------------------------------------------------
* drawElements Quality Program Tester Core
* ----------------------------------------
*
diff --git a/modules/gles31/functional/es31fNegativeVertexArrayApiTests.cpp b/modules/gles31/functional/es31fNegativeVertexArrayApiTests.cpp
index 1ed5f2d86..72e0f0047 100644
--- a/modules/gles31/functional/es31fNegativeVertexArrayApiTests.cpp
+++ b/modules/gles31/functional/es31fNegativeVertexArrayApiTests.cpp
@@ -1,4 +1,4 @@
-/*-------------------------------------------------------------------------
+/*-------------------------------------------------------------------------
* drawElements Quality Program OpenGL ES 3.1 Module
* -------------------------------------------------
*
diff --git a/scripts/src_util/check_all.py b/scripts/src_util/check_all.py
index b8378a54e..507348fd1 100644
--- a/scripts/src_util/check_all.py
+++ b/scripts/src_util/check_all.py
@@ -20,36 +20,37 @@
#
#-------------------------------------------------------------------------
-import sys
-from argparse import ArgumentParser
-from common import getChangedFiles, getAllProjectFiles
-from check_include_guards import checkIncludeGuards
-from check_whitespace import checkWhitespace
-from check_license import checkLicense
-from check_invalid_types import checkInvalidTypes
+import sys
+from argparse import ArgumentParser
+from common import getChangedFiles, getAllProjectFiles
+from check_include_guards import checkIncludeGuards
+from check_whitespace import checkWhitespace
+from check_license import checkLicense
+from check_boms import checkBOMs
if __name__ == "__main__":
- parser = ArgumentParser()
- parser.add_argument("-e", "--only-errors", action="store_true", dest="onlyErrors", default=False, help="Print only on error")
- parser.add_argument("-i", "--only-changed", action="store_true", dest="useGitIndex", default=False, help="Check only modified files. Uses git.")
+ parser = ArgumentParser()
+ parser.add_argument("-e", "--only-errors", action="store_true", dest="onlyErrors", default=False, help="Print only on error")
+ parser.add_argument("-i", "--only-changed", action="store_true", dest="useGitIndex", default=False, help="Check only modified files. Uses git.")
+ parser.add_argument("-b", "--fix-bom", action="store_true", dest="fixBOMs", default=False, help="Attempt to fix BOMs")
- args = parser.parse_args()
+ args = parser.parse_args()
- if args.useGitIndex:
- files = getChangedFiles()
- else:
- files = getAllProjectFiles()
+ if args.useGitIndex:
+ files = getChangedFiles()
+ else:
+ files = getAllProjectFiles()
- error = not all([
- checkWhitespace(files),
- checkIncludeGuards(files),
- checkLicense(files),
- checkInvalidTypes(files),
- #todo checkRedundantIncludeGuards(files),
- ])
+ error = not all([
+ checkBOMs(files, args.fixBOMs),
+ checkWhitespace(files),
+ checkIncludeGuards(files),
+ checkLicense(files),
+ #todo checkRedundantIncludeGuards(files),
+ ])
- if error:
- print "One or more checks failed"
- sys.exit(1)
- if not args.onlyErrors:
- print "All checks passed"
+ if error:
+ print "One or more checks failed"
+ sys.exit(1)
+ if not args.onlyErrors:
+ print "All checks passed"
diff --git a/scripts/src_util/check_boms.py b/scripts/src_util/check_boms.py
new file mode 100644
index 000000000..55846d95b
--- /dev/null
+++ b/scripts/src_util/check_boms.py
@@ -0,0 +1,86 @@
+# -*- coding: utf-8 -*-
+
+#-------------------------------------------------------------------------
+# drawElements Quality Program utilities
+# --------------------------------------
+#
+# Copyright (c) 2017 The Khronos Group Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#-------------------------------------------------------------------------
+
+import os
+import sys
+import codecs
+from optparse import OptionParser
+
+FILE_PATTERNS = ["*.hpp", "*.h", "*.cpp", "*.py"]
+IGNORE_FILES = set()
+CHECK_END_COMMENT = True
+
+def hasBOM (file):
+ with open(file, 'rb') as f:
+ line0 = f.readline()
+ if line0.startswith(codecs.BOM_UTF8):
+ return True
+ return False
+
+def removeBOM (file):
+ with open(file, 'r+b') as f:
+ chunk = f.read(1024)
+ if chunk.startswith(codecs.BOM_UTF8):
+ chunk = chunk[3:]
+ else:
+ return
+ readpos = 1024;
+ writepos = 0;
+ while chunk:
+ f.seek(writepos, os.SEEK_SET)
+ f.write(chunk)
+ writepos += len(chunk)
+ f.seek(readpos, os.SEEK_SET)
+ chunk = f.read(1024)
+ readpos += len(chunk)
+ f.truncate(readpos-3)
+
+def getFileList (path):
+ if os.path.isfile(path):
+ yield path
+ elif os.path.isdir(path):
+ for root, dirs, files in os.walk(path):
+ for file in files:
+ yield os.path.join(root, file)
+
+def checkBOMs (files, fix):
+ correct = True
+ for file in files:
+ if hasBOM(file):
+ if fix:
+ removeBOM(file)
+ print "File %s contained BOM and was fixed" % file
+ else:
+ correct = False
+ print "File %s contains BOM" % file
+ return correct
+
+if __name__ == "__main__":
+ parser = OptionParser()
+ parser.add_option("-x", "--fix", action="store_true", dest="fix", default=False, help="attempt to fix BOMs")
+
+ (options, args) = parser.parse_args()
+ fix = options.fix
+
+ print "Checking BOMs..."
+ for dir in args:
+ checkBOMs(getFileList(os.path.normpath(dir)), fix) \ No newline at end of file