1 # -*- coding: utf-8 -*-
3 #-------------------------------------------------------------------------
4 # drawElements Quality Program utilities
5 # --------------------------------------
7 # Copyright 2015 The Android Open Source Project
9 # Licensed under the Apache License, Version 2.0 (the "License");
10 # you may not use this file except in compliance with the License.
11 # You may obtain a copy of the License at
13 # http://www.apache.org/licenses/LICENSE-2.0
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
21 #-------------------------------------------------------------------------
26 TEXT_FILE_EXTENSION = [
52 BINARY_FILE_EXTENSION = [
64 def isTextFile (filePath):
65 # Special case for a preprocessor test file that uses a non-ascii/utf8 encoding
66 if filePath.endswith("preprocessor.test"):
69 ext = os.path.splitext(filePath)[1]
70 if ext in TEXT_FILE_EXTENSION:
72 if ext in BINARY_FILE_EXTENSION:
75 # Analyze file contents, zero byte is the marker for a binary file
76 f = open(filePath, "rb")
83 while byte and numBytesTested < TEST_LIMIT:
94 def getProjectPath ():
95 # File system hierarchy is fixed
96 scriptDir = os.path.dirname(os.path.abspath(__file__))
97 projectDir = os.path.normpath(os.path.join(scriptDir, "../.."))
101 process = subprocess.Popen(['git'] + list(args), cwd=getProjectPath(), stdout=subprocess.PIPE)
102 output = process.communicate()[0]
103 if process.returncode != 0:
104 raise Exception("Failed to execute '%s', got %d" % (str(args), process.returncode))
107 def getAbsolutePathPathFromProjectRelativePath (projectRelativePath):
108 return os.path.normpath(os.path.join(getProjectPath(), projectRelativePath))
110 def getChangedFiles ():
111 # Added, Copied, Moved, Renamed
112 output = git('diff', '--cached', '--name-only', '-z', '--diff-filter=ACMR')
113 relativePaths = output.split('\0')[:-1] # remove trailing ''
114 return [getAbsolutePathPathFromProjectRelativePath(path) for path in relativePaths]
116 def getAllProjectFiles ():
117 output = git('ls-files', '--cached', '-z').decode()
118 relativePaths = output.split('\0')[:-1] # remove trailing ''
119 return [getAbsolutePathPathFromProjectRelativePath(path) for path in relativePaths]