From 235e42bea386b9aa2e352aa61ad6d93f7779fedc Mon Sep 17 00:00:00 2001 From: Zachary Anderson Date: Tue, 28 Mar 2023 20:05:50 -0700 Subject: [PATCH] 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 --- impeller/tools/malioc_diff.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/impeller/tools/malioc_diff.py b/impeller/tools/malioc_diff.py index 2bab4588daf53..d7fdbbe6c2841 100755 --- a/impeller/tools/malioc_diff.py +++ b/impeller/tools/malioc_diff.py @@ -4,6 +4,7 @@ # found in the LICENSE file. import argparse +import difflib import json import os import sys @@ -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 @@ -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', @@ -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 <