Skip to content

Commit

Permalink
utils/release_tracking.py: Uses toml [patch] instead of cloning
Browse files Browse the repository at this point in the history
 * 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]>
  • Loading branch information
tgonzalezorlandoarm committed Nov 20, 2023
1 parent 4e43f2d commit b025029
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 46 deletions.
3 changes: 1 addition & 2 deletions ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,7 @@ done

if [ "$TEST_NEXT_BRANCH_TRACKING" ]; then
echo "Track next branches for parallaxsecond repositories"
mkdir -p /tmp/clonings
python3 $(pwd)/utils/release_tracking.py --clone_dir /tmp/clonings $(pwd)/Cargo.toml $(pwd)/e2e_tests/Cargo.toml
python3 $(pwd)/utils/release_tracking.py $(pwd)/Cargo.toml $(pwd)/e2e_tests/Cargo.toml
next_branch_result=$?
if [ "$next_branch_result" -ne 0 ]; then
error_msg "Failed to track next branches of parallaxsecond repositories."
Expand Down
2 changes: 1 addition & 1 deletion utils/dependency_cross_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def run_cargo_tree(path):
cmd += '--features tss-esapi/generate-bindings,cryptoki/generate-bindings -d'
prev_dir = os.getcwd()
os.chdir(os.path.join(path))
return subprocess.check_output(cmd.split(' ')).decode()
return subprocess.check_output(cmd, shell=True).decode()


def run_deps_mismatcher(lines):
Expand Down
69 changes: 26 additions & 43 deletions utils/release_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,55 +8,48 @@
def run_cargo_build(path):
print(f"cargo build, path: {path}")
command = f'cargo build'
subprocess.check_output(command.split(), cwd=path)
return subprocess.check_output(command, shell=True, cwd=path)


def clone_repo(clone_dir, repo_name, branch):
git_repo = f"https://github.com/parallaxsecond/{repo_name}.git"
future_repo_dir = os.path.join(clone_dir, repo_name)
if not os.path.isdir(future_repo_dir):
command = f"git clone {git_repo} -b {branch} {future_repo_dir}"
subprocess.check_output(command.split())
command = f"git submodule update --init"
subprocess.check_output(command.split(), cwd=future_repo_dir)
def run_cargo_update(path, dep):
print(f"cargo update, dep: {dep}")
command = f'cargo update --package {dep}'
return subprocess.check_output(command, shell=True, cwd=path)


def git_toml_deps(toml_path, updatable_deps, deps_repos):
def git_toml_deps(toml_path, deps_repo_links, deps_branches):
lines = None
with open(toml_path, 'r') as f:
lines = f.readlines()

for i in range(len(lines)):
line = lines[i]
for dep in updatable_deps.keys():
if line.startswith(dep + " ="):
# All occurences
line = line.replace("'", '"')
if "{" not in line:
# First occurence
line = line.replace('"', '{ version = "', 1)
line = line.rstrip() + ' }\n'
to_update = []
output_lines = lines + ['[patch.crates-io]\n']
for line in lines:
for dep in deps_repo_links.keys():
starter = dep + " ="
if line.startswith(starter):
to_update.append(dep)
new_line = f'git = "{deps_repo_links[dep]}", branch = "{deps_branches[dep]}"'
new_line = starter + ' { ' + new_line + ' }\n'
output_lines.append(new_line)

if 'path' not in line:
line = re.sub(r'version = "[0-9\.]+"', f'path = "{deps_repos[dep]}"', line)
lines[i] = line

dirname = os.path.relpath('.')
for updatable in to_update:
run_cargo_update(os.path.dirname(toml_path), updatable)

with open(toml_path, 'w') as f:
f.writelines(lines)
print(subprocess.check_output(['git', 'diff'], cwd=os.path.dirname(toml_path)).decode('utf-8'))
f.writelines(output_lines)
git_cmd = 'git diff'
print(subprocess.check_output(git_cmd,
shell=True,
cwd=os.path.dirname(toml_path)).decode('utf-8'))


def main(argv=[], prog_name=''):
parser = argparse.ArgumentParser(prog='ReleaseTracker',
description='Modifies the parsec Cargo.toml files to use the '
'main branches of parallaxsecond dependencies in '
'preparation for their publishing and release')
parser.add_argument('--clone_dir',
required=True,
help='Existing directory into which repositories should be cloned')
parser.add_argument('paths', nargs='+', help='Paths to Cargo.toml files to be modified')
parser.add_argument('paths', nargs='+', help='Absolute paths to the Cargo.toml files')
args = parser.parse_args()

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

repo_paths = { repo_name: f'{args.clone_dir}/{repo_folder}/{repo_name}' \
repo_links = { repo_name: f"https://github.com/parallaxsecond/{repo_folder}.git" \
for repo_name, repo_folder in parallaxsecond_deps.items() }
repo_paths['parsec-interface'] = f'{args.clone_dir}/parsec-interface-rs'
repo_paths['parsec-client'] = f'{args.clone_dir}/parsec-client-rust'

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

for repo_name, repo_folder in parallaxsecond_deps.items():
clone_repo(args.clone_dir, repo_folder, repo_branches[repo_name])
toml_path = os.path.join(repo_paths[repo_name], 'Cargo.toml')
git_toml_deps(toml_path, parallaxsecond_deps, repo_paths)

for repo_path in repo_paths.values():
run_cargo_build(repo_path)

for path in args.paths:
git_toml_deps(path, parallaxsecond_deps, repo_paths)
git_toml_deps(path, repo_links, repo_branches)
run_cargo_build(os.path.dirname(path))

return 0
Expand Down

0 comments on commit b025029

Please sign in to comment.