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

Class GenerateAndroidBP

scripts/format_code.py:242–319  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

240 raise Exception("format-code failed with error code %d" % retval)
241
242class GenerateAndroidBP:
243 def __init__(self, folder):
244 self.folder = folder
245 self.bp_output_file = "Generated_Android.bp"
246
247 def run(self):
248 retval = 0
249 self.shell = Shell()
250 self.shell.save_cwd()
251 this_dir = os.path.dirname(__file__)
252
253 logger.debug("Running Android.bp check")
254 try:
255 self.shell.cd(self.folder)
256 cmd = "%s/generate_android_bp.py --folder %s --output_file %s" % (this_dir, self.folder, self.bp_output_file)
257 output = self.shell.run_single_to_str(cmd)
258 if len(output) > 0:
259 logger.info(output)
260 except subprocess.CalledProcessError as e:
261 retval = -1
262 logger.error(e)
263 logger.error("OUTPUT= %s" % e.output)
264
265 # Compare the genereated file with the one in the review
266 if not filecmp.cmp(self.bp_output_file, self.folder + "/Android.bp"):
267 is_mismatched = True
268
269 with open(self.bp_output_file, 'r') as generated_file:
270 with open(self.folder + "/Android.bp", 'r') as review_file:
271 diff = list(difflib.unified_diff(generated_file.readlines(), review_file.readlines(),
272 fromfile='Generated_Android.bp', tofile='Android.bp'))
273
274 # If the only mismatch in Android.bp file is the copyright year,
275 # the content of the file is considered unchanged and we don't need to update
276 # the copyright year. This will resolve the issue that emerges every new year.
277 num_added_lines = 0
278 num_removed_lines = 0
279 last_added_line = ""
280 last_removed_line = ""
281 expect_add_line = False
282
283 for line in diff:
284 if line.startswith("-") and not line.startswith("---"):
285 num_removed_lines += 1
286 if num_removed_lines > 1:
287 break
288 last_removed_line = line
289 expect_add_line = True
290 elif line.startswith("+") and not line.startswith("+++"):
291 num_added_lines += 1
292 if num_added_lines > 1:
293 break
294 if expect_add_line:
295 last_added_line = line
296 else:
297 expect_add_line = False
298
299 if num_added_lines == 1 and num_removed_lines == 1:

Callers 1

run_fix_code_formattingFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected