Skip to content

Commit b025029

Browse files
utils/release_tracking.py: Uses toml [patch] instead of cloning
* cargo update before building is key for avoiding an unused patch version, as the version in the Cargo.lock file will otherwise be preferred. * Improve python code quality. Signed-off-by: Tomás González <[email protected]>
1 parent 4e43f2d commit b025029

File tree

3 files changed

+28
-46
lines changed

3 files changed

+28
-46
lines changed

ci.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,7 @@ done
212212

213213
if [ "$TEST_NEXT_BRANCH_TRACKING" ]; then
214214
echo "Track next branches for parallaxsecond repositories"
215-
mkdir -p /tmp/clonings
216-
python3 $(pwd)/utils/release_tracking.py --clone_dir /tmp/clonings $(pwd)/Cargo.toml $(pwd)/e2e_tests/Cargo.toml
215+
python3 $(pwd)/utils/release_tracking.py $(pwd)/Cargo.toml $(pwd)/e2e_tests/Cargo.toml
217216
next_branch_result=$?
218217
if [ "$next_branch_result" -ne 0 ]; then
219218
error_msg "Failed to track next branches of parallaxsecond repositories."

utils/dependency_cross_matcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def run_cargo_tree(path):
1010
cmd += '--features tss-esapi/generate-bindings,cryptoki/generate-bindings -d'
1111
prev_dir = os.getcwd()
1212
os.chdir(os.path.join(path))
13-
return subprocess.check_output(cmd.split(' ')).decode()
13+
return subprocess.check_output(cmd, shell=True).decode()
1414

1515

1616
def run_deps_mismatcher(lines):

utils/release_tracking.py

Lines changed: 26 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,55 +8,48 @@
88
def run_cargo_build(path):
99
print(f"cargo build, path: {path}")
1010
command = f'cargo build'
11-
subprocess.check_output(command.split(), cwd=path)
11+
return subprocess.check_output(command, shell=True, cwd=path)
1212

1313

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)
2218

2319

24-
def git_toml_deps(toml_path, updatable_deps, deps_repos):
20+
def git_toml_deps(toml_path, deps_repo_links, deps_branches):
2521
lines = None
2622
with open(toml_path, 'r') as f:
2723
lines = f.readlines()
2824

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)
3935

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)
4538

4639
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'))
4945

5046

5147
def main(argv=[], prog_name=''):
5248
parser = argparse.ArgumentParser(prog='ReleaseTracker',
5349
description='Modifies the parsec Cargo.toml files to use the '
5450
'main branches of parallaxsecond dependencies in '
5551
'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')
6053
args = parser.parse_args()
6154

6255
# The order is important!
@@ -71,25 +64,15 @@ def main(argv=[], prog_name=''):
7164
'parsec-client': 'parsec-client-rust',
7265
}
7366

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" \
7568
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'
7869

7970
repo_branches = { repo_name: 'main' for repo_name in parallaxsecond_deps.keys() }
8071
repo_branches['tss-esapi-sys'] = '7.x.y'
8172
repo_branches['tss-esapi'] = '7.x.y'
8273

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-
9174
for path in args.paths:
92-
git_toml_deps(path, parallaxsecond_deps, repo_paths)
75+
git_toml_deps(path, repo_links, repo_branches)
9376
run_cargo_build(os.path.dirname(path))
9477

9578
return 0

0 commit comments

Comments
 (0)