Skip to content

Commit

Permalink
Add an option to malioc_diff.py to print a unified diff (flutter#40732)
Browse files Browse the repository at this point in the history
Add an option to malioc_diff.py to print a unified diff
  • Loading branch information
zanderso authored Mar 29, 2023
1 parent 6852bea commit 235e42b
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions impeller/tools/malioc_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# found in the LICENSE file.

import argparse
import difflib
import json
import os
import sys
Expand Down Expand Up @@ -32,6 +33,12 @@
# If there are differences between before and after, whether positive or
# negative, the exit code for this script will be 1, and 0 otherwise.

SRC_ROOT = os.path.dirname(
os.path.dirname(
os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
)
)

CORES = [
'Mali-G78', # Pixel 6 / 2020
'Mali-T880', # 2016
Expand All @@ -54,6 +61,13 @@ def parse_args(argv):
type=str,
help='The path to a json file containing existing malioc results.',
)
parser.add_argument(
'--print-diff',
'-p',
default=False,
action='store_true',
help='Print a unified diff to stdout when differences are found.',
)
parser.add_argument(
'--update',
'-u',
Expand Down Expand Up @@ -303,6 +317,23 @@ def main(argv):
'$ ./flutter/impeller/tools/malioc_diff.py --before {} --after {} --update'
.format(args.before, args.after)
)
if args.print_diff:
before_lines = json.dumps(
before_json, sort_keys=True, indent=2
).splitlines(keepends=True)
after_lines = json.dumps(
after_json, sort_keys=True, indent=2
).splitlines(keepends=True)
before_path = os.path.relpath(
os.path.abspath(args.before), start=SRC_ROOT
)
diff = difflib.unified_diff(
before_lines, after_lines, fromfile=before_path
)
print('\nYou can alternately apply the diff below:')
print('patch -p0 <<DONE')
print(*diff, sep='')
print('DONE')

return 1 if changed else 0

Expand Down

0 comments on commit 235e42b

Please sign in to comment.