8
8
def run_cargo_build (path ):
9
9
print (f"cargo build, path: { path } " )
10
10
command = f'cargo build'
11
- subprocess .check_output (command . split () , cwd = path )
11
+ return subprocess .check_output (command , shell = True , cwd = path )
12
12
13
13
14
- def clone_repo (clone_dir , repo_name , branch ):
15
- git_repo = f"https://github.com/parallaxsecond/{ repo_name } .git"
16
- future_repo_dir = os .path .join (clone_dir , repo_name )
17
- if not os .path .isdir (future_repo_dir ):
18
- command = f"git clone { git_repo } -b { branch } { future_repo_dir } "
19
- subprocess .check_output (command .split ())
20
- command = f"git submodule update --init"
21
- subprocess .check_output (command .split (), cwd = future_repo_dir )
14
+ def run_cargo_update (path , dep ):
15
+ print (f"cargo update, dep: { dep } " )
16
+ command = f'cargo update --package { dep } '
17
+ return subprocess .check_output (command , shell = True , cwd = path )
22
18
23
19
24
- def git_toml_deps (toml_path , updatable_deps , deps_repos ):
20
+ def git_toml_deps (toml_path , deps_repo_links , deps_branches ):
25
21
lines = None
26
22
with open (toml_path , 'r' ) as f :
27
23
lines = f .readlines ()
28
24
29
- for i in range ( len ( lines )):
30
- line = lines [ i ]
31
- for dep in updatable_deps . keys () :
32
- if line . startswith ( dep + " =" ):
33
- # All occurences
34
- line = line . replace ( "'" , '"' )
35
- if "{" not in line :
36
- # First occurence
37
- line = line . replace ( '"' , '{ version = "' , 1 )
38
- line = line . rstrip () + ' } \n '
25
+ to_update = []
26
+ output_lines = lines + [ '[patch.crates-io] \n ' ]
27
+ for line in lines :
28
+ for dep in deps_repo_links . keys ( ):
29
+ starter = dep + " ="
30
+ if line . startswith ( starter ):
31
+ to_update . append ( dep )
32
+ new_line = f'git = " { deps_repo_links [ dep ] } ", branch = " { deps_branches [ dep ] } "'
33
+ new_line = starter + ' { ' + new_line + ' } \n '
34
+ output_lines . append ( new_line )
39
35
40
- if 'path' not in line :
41
- line = re .sub (r'version = "[0-9\.]+"' , f'path = "{ deps_repos [dep ]} "' , line )
42
- lines [i ] = line
43
-
44
- dirname = os .path .relpath ('.' )
36
+ for updatable in to_update :
37
+ run_cargo_update (os .path .dirname (toml_path ), updatable )
45
38
46
39
with open (toml_path , 'w' ) as f :
47
- f .writelines (lines )
48
- print (subprocess .check_output (['git' , 'diff' ], cwd = os .path .dirname (toml_path )).decode ('utf-8' ))
40
+ f .writelines (output_lines )
41
+ git_cmd = 'git diff'
42
+ print (subprocess .check_output (git_cmd ,
43
+ shell = True ,
44
+ cwd = os .path .dirname (toml_path )).decode ('utf-8' ))
49
45
50
46
51
47
def main (argv = [], prog_name = '' ):
52
48
parser = argparse .ArgumentParser (prog = 'ReleaseTracker' ,
53
49
description = 'Modifies the parsec Cargo.toml files to use the '
54
50
'main branches of parallaxsecond dependencies in '
55
51
'preparation for their publishing and release' )
56
- parser .add_argument ('--clone_dir' ,
57
- required = True ,
58
- help = 'Existing directory into which repositories should be cloned' )
59
- parser .add_argument ('paths' , nargs = '+' , help = 'Paths to Cargo.toml files to be modified' )
52
+ parser .add_argument ('paths' , nargs = '+' , help = 'Absolute paths to the Cargo.toml files' )
60
53
args = parser .parse_args ()
61
54
62
55
# The order is important!
@@ -71,25 +64,15 @@ def main(argv=[], prog_name=''):
71
64
'parsec-client' : 'parsec-client-rust' ,
72
65
}
73
66
74
- repo_paths = { repo_name : f' { args . clone_dir } / { repo_folder } / { repo_name } ' \
67
+ repo_links = { repo_name : f"https://github.com/parallaxsecond/ { repo_folder } .git" \
75
68
for repo_name , repo_folder in parallaxsecond_deps .items () }
76
- repo_paths ['parsec-interface' ] = f'{ args .clone_dir } /parsec-interface-rs'
77
- repo_paths ['parsec-client' ] = f'{ args .clone_dir } /parsec-client-rust'
78
69
79
70
repo_branches = { repo_name : 'main' for repo_name in parallaxsecond_deps .keys () }
80
71
repo_branches ['tss-esapi-sys' ] = '7.x.y'
81
72
repo_branches ['tss-esapi' ] = '7.x.y'
82
73
83
- for repo_name , repo_folder in parallaxsecond_deps .items ():
84
- clone_repo (args .clone_dir , repo_folder , repo_branches [repo_name ])
85
- toml_path = os .path .join (repo_paths [repo_name ], 'Cargo.toml' )
86
- git_toml_deps (toml_path , parallaxsecond_deps , repo_paths )
87
-
88
- for repo_path in repo_paths .values ():
89
- run_cargo_build (repo_path )
90
-
91
74
for path in args .paths :
92
- git_toml_deps (path , parallaxsecond_deps , repo_paths )
75
+ git_toml_deps (path , repo_links , repo_branches )
93
76
run_cargo_build (os .path .dirname (path ))
94
77
95
78
return 0
0 commit comments