MCPcopy Create free account
hub / github.com/ARM-software/ComputeLibrary / CopyrightCheckRun

Class CopyrightCheckRun

scripts/format_code.py:165–240  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

163 raise Exception("format-code failed with error code %d" % retval)
164
165class CopyrightCheckRun:
166 @staticmethod
167 def get_files(folder, strategy="git-head", file_list=None):
168 shell = Shell()
169 shell.cd(folder)
170 skip_copyright = skip_copyright_global
171
172 # Check if author e-mail is in arm.com domain
173 author_email_cmd = "git config --get user.email"
174 author_email = shell.run_single_to_str(author_email_cmd).strip()
175
176 if not author_email.endswith("@arm.com"):
177 skip_copyright = True
178
179 if file_list == None:
180 if strategy == "git-head":
181 raw_file_list = shell.run_single_to_str("git diff-tree --no-commit-id --name-status -r HEAD | grep \"^[AMRT]\" | cut -f 2")
182 elif strategy == "git-diff":
183 raw_file_list = shell.run_single_to_str("git diff --name-status --cached -r HEAD | grep \"^[AMRT]\" | rev | cut -f 1 | rev")
184 else:
185 raw_file_list = shell.run_single_to_str("git ls-tree -r HEAD --name-only")
186 # Skip copyright checks when running on all files because we don't know when they were last modified
187 # Therefore we can't tell if their copyright dates are correct
188 skip_copyright = True
189
190 file_list = raw_file_list.split("\n")
191
192 folder_pattern = re.compile(r"^(arm_compute|src|examples|tests|utils|support)/")
193 extension_pattern = re.compile(r"\.(cpp|h|hh|inl|cl|cs|hpp)$")
194
195 list_files = [ f for f in file_list if folder_pattern.search(f) and extension_pattern.search(f)]
196
197 # Check for scons files as they are excluded from the above list
198 scons_pattern = re.compile(r"SC")
199 list_files += [ f for f in file_list if scons_pattern.search(f)]
200
201 return (list_files, skip_copyright)
202
203 def __init__(self, files, folder, error_diff=False):
204 self.files = files
205 self.folder = folder
206 self.error_diff=error_diff
207
208 def error_on_diff(self, msg):
209 retval = 0
210 if self.error_diff:
211 diff = self.shell.run_single_to_str("git diff")
212 if len(diff) > 0:
213 retval = -1
214 logger.error(diff)
215 logger.error("\n"+msg)
216 return retval
217
218 def run(self):
219 if len(self.files) < 1:
220 logger.debug("No file: early exit")
221 retval = 0
222 self.shell = Shell()

Callers 1

run_fix_code_formattingFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected