66
77import os
88import tempfile
9- import sys
109import json
10+ import argparse
1111
1212
1313def exec (command : str ):
@@ -22,77 +22,40 @@ def log(msg: str):
2222 print (msg )
2323
2424
25- def do_compare ():
26- if len (sys .argv ) < 3 :
27- print ('base or head commit not set' )
28- exit (1 )
29- base_commit = sys .argv [1 ]
30- head_commit = sys .argv [2 ]
31-
32- ya_make_command = os .getenv ('YA_MAKE_COMMAND' )
33- if not ya_make_command :
34- print ('YA_MAKE_COMMAND not set' )
25+ def do_compare (opts ):
26+ if opts .ya_make_command :
27+ print ('--ya-make-command not set' )
3528 exit (1 )
29+ ya = opts .ya_make_command .split (' ' )[0 ]
3630
3731 workdir = os .getenv ('workdir' )
3832 if not workdir :
3933 workdir = tempfile .mkdtemp ()
4034
4135 log (f'Workdir: { workdir } ' )
4236 log ('Checkout base commit...' )
43- exec (f'git checkout { base_commit } ' )
37+ exec (f'git checkout { opts . base_commit } ' )
4438 log ('Build graph for base commit...' )
45- exec (f'{ ya_make_command } ydb -k -A -- cache-tests -Gj0 > { workdir } /graph_base.json' )
39+ exec (f'{ opts . ya_make_command } ydb -k -- cache-tests --save-graph-to { workdir } /graph_base.json --save-context-to { workdir } /context_base .json' )
4640
4741 log ('Checkout head commit...' )
48- exec (f'git checkout { head_commit } ' )
42+ exec (f'git checkout { opts . head_commit } ' )
4943 log ('Build graph for head commit...' )
50- exec (f'{ ya_make_command } ydb -k -A -- cache-tests -Gj0 > { workdir } /graph_head.json' )
44+ exec (f'{ opts . ya_make_command } ydb -k -- cache-tests --save-graph-to { workdir } /graph_head.json --save-context-to { workdir } /context_head .json' )
5145
5246 log ('Generate diff graph...' )
53- exec (f'./ya tool ygdiff --old { workdir } /graph_base.json --new { workdir } /graph_head.json --cut { workdir } /graph_diff.json --dump-uids-for-affected-nodes { workdir } /affected_uids.json' )
54-
55- log ('Read diff graph...' )
56- with open (f'{ workdir } /graph_diff.json' , 'r' ) as f :
57- diff_graph = json .load (f )
58-
59- with open (f'{ workdir } /affected_uids.json' , 'r' ) as f :
60- uids = set (json .load (f ))
61-
62- tests = set ()
63- modules = set ()
64-
65- log ('Scan diff graph...' )
66- for target in diff_graph .get ('graph' , []):
67- if target .get ('uid' ) not in uids :
68- continue
69- if target .get ('node-type' ) == 'test' :
70- path = target .get ('kv' , {}).get ('path' )
71- if path is not None :
72- tests .add (os .path .dirname (path ))
73- tp = target .get ('target_properties' )
74- if (
75- tp is not None
76- and tp .get ('module_type' ) is not None
77- and tp .get ('module_dir' , '' ).startswith ('ydb' )
78- and tp .get ('module_tag' , '' ).find ('proto' ) < 0
79- ):
80- modules .add (tp .get ('module_dir' ))
81-
82- log ('Create ya.make' )
47+ exec (f'{ ya } tool ygdiff --old { workdir } /graph_base.json --new { workdir } /graph_head.json --cut { opts .result_graph_path } --dump-uids { workdir } /uids.json' )
8348
84- with open ('ya.make' , 'w' ) as ya_make :
85- ya_make .write ('RECURSE_FOR_TESTS(\n ' )
86- for test in sorted (tests ):
87- ya_make .write (f' { test } \n ' )
88- ya_make .write (')\n \n RECURSE (\n ' )
89- for module in sorted (modules ):
90- ya_make .write (f' { module } \n ' )
91- ya_make .write (')\n ' )
92- log ('ya.make content:' )
93- exec ('cat ya.make' )
49+ log ('Generate diff context...' )
50+ exec (f'{ ya } tool context_difference { workdir } /context_base.json { workdir } /context_head.json { opts .result_context_path } { workdir } /uids.json { opts .result_graph_path } ' )
9451 exit (0 )
9552
9653
9754if __name__ == '__main__' :
98- do_compare ()
55+ parser = argparse .ArgumentParser ()
56+ parser .add_argument ('--result-graph-path' , '-g' , type = str , help = 'Path for result graph' , dest = 'graph_path' , required = True )
57+ parser .add_argument ('--result-context-path' , '-c' , type = str , help = 'Path for result context' , dest = 'context_path' , required = True )
58+ parser .add_argument ('--ya-make-command' , '-y' , type = str , help = 'Ya make command' , dest = 'ya_make_command' , required = True )
59+ parser .add_argument (dest = 'base_commit' , help = 'Base commit' )
60+ parser .add_argument (dest = 'head_commit' , help = 'Head commit' )
61+ do_compare (parser .parse_args ())
0 commit comments