4
4
# found in the LICENSE file.
5
5
6
6
import argparse
7
+ import difflib
7
8
import json
8
9
import os
9
10
import sys
32
33
# If there are differences between before and after, whether positive or
33
34
# negative, the exit code for this script will be 1, and 0 otherwise.
34
35
36
+ SRC_ROOT = os .path .dirname (
37
+ os .path .dirname (
38
+ os .path .dirname (os .path .dirname (os .path .abspath (__file__ )))
39
+ )
40
+ )
41
+
35
42
CORES = [
36
43
'Mali-G78' , # Pixel 6 / 2020
37
44
'Mali-T880' , # 2016
@@ -54,6 +61,13 @@ def parse_args(argv):
54
61
type = str ,
55
62
help = 'The path to a json file containing existing malioc results.' ,
56
63
)
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
+ )
57
71
parser .add_argument (
58
72
'--update' ,
59
73
'-u' ,
@@ -303,6 +317,23 @@ def main(argv):
303
317
'$ ./flutter/impeller/tools/malioc_diff.py --before {} --after {} --update'
304
318
.format (args .before , args .after )
305
319
)
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' )
306
337
307
338
return 1 if changed else 0
308
339
0 commit comments