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

Add an option to malioc_diff.py to print a unified diff #40732

Merged
merged 1 commit into from
Mar 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, didn't know difflib was a thing

)
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