Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 235e42b

Browse files
authored
Add an option to malioc_diff.py to print a unified diff (#40732)
Add an option to malioc_diff.py to print a unified diff
1 parent 6852bea commit 235e42b

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

impeller/tools/malioc_diff.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# found in the LICENSE file.
55

66
import argparse
7+
import difflib
78
import json
89
import os
910
import sys
@@ -32,6 +33,12 @@
3233
# If there are differences between before and after, whether positive or
3334
# negative, the exit code for this script will be 1, and 0 otherwise.
3435

36+
SRC_ROOT = os.path.dirname(
37+
os.path.dirname(
38+
os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
39+
)
40+
)
41+
3542
CORES = [
3643
'Mali-G78', # Pixel 6 / 2020
3744
'Mali-T880', # 2016
@@ -54,6 +61,13 @@ def parse_args(argv):
5461
type=str,
5562
help='The path to a json file containing existing malioc results.',
5663
)
64+
parser.add_argument(
65+
'--print-diff',
66+
'-p',
67+
default=False,
68+
action='store_true',
69+
help='Print a unified diff to stdout when differences are found.',
70+
)
5771
parser.add_argument(
5872
'--update',
5973
'-u',
@@ -303,6 +317,23 @@ def main(argv):
303317
'$ ./flutter/impeller/tools/malioc_diff.py --before {} --after {} --update'
304318
.format(args.before, args.after)
305319
)
320+
if args.print_diff:
321+
before_lines = json.dumps(
322+
before_json, sort_keys=True, indent=2
323+
).splitlines(keepends=True)
324+
after_lines = json.dumps(
325+
after_json, sort_keys=True, indent=2
326+
).splitlines(keepends=True)
327+
before_path = os.path.relpath(
328+
os.path.abspath(args.before), start=SRC_ROOT
329+
)
330+
diff = difflib.unified_diff(
331+
before_lines, after_lines, fromfile=before_path
332+
)
333+
print('\nYou can alternately apply the diff below:')
334+
print('patch -p0 <<DONE')
335+
print(*diff, sep='')
336+
print('DONE')
306337

307338
return 1 if changed else 0
308339

0 commit comments

Comments
 (0)