44# found in the LICENSE file.
55
66import argparse
7+ import difflib
78import json
89import os
910import sys
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+
3542CORES = [
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 ('\n You 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