From b643f679f931e944c5777d6db5dd5a3e8b12d733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Gonz=C3=A1lez?= Date: Wed, 8 Nov 2023 14:16:49 +0000 Subject: [PATCH] utils/release_tracking.py: Uses toml [patch] instead of cloning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * cargo update before building is key for avoiding an unused patch version, as the version in the Cargo.lock file will otherwise be preferred. Signed-off-by: Tomás González --- ci.sh | 3 +- utils/release_tracking.py | 63 ++++++++++++++------------------------- 2 files changed, 24 insertions(+), 42 deletions(-) diff --git a/ci.sh b/ci.sh index 1fe88dd9..e17d9491 100755 --- a/ci.sh +++ b/ci.sh @@ -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." diff --git a/utils/release_tracking.py b/utils/release_tracking.py index 25f09531..a60ff8a9 100644 --- a/utils/release_tracking.py +++ b/utils/release_tracking.py @@ -11,40 +11,37 @@ def run_cargo_build(path): return subprocess.check_output(command, shell=True, cwd=path) -def clone_repo(clone_dir, repo_link, repo_name, branch): - future_repo_dir = os.path.join(clone_dir, repo_name) - if not os.path.isdir(future_repo_dir): - command = f"git clone {repo_link} -b {branch} {future_repo_dir}" - subprocess.check_output(command, shell=True) - command = f"git submodule update --init" - return subprocess.check_output(command, shell=True, 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() - - output_lines = [] + to_update = [] + output_lines = lines + ['[patch.crates-io]\n'] for line in lines: - 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' - - if 'path' not in line: - line = re.sub(r'version = "[0-9\.]+"', f'path = "{deps_repos[dep]}"', line) - output_lines.append(line) + 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) + + for updatable in to_update: + run_cargo_update(os.path.dirname(toml_path), updatable) with open(toml_path, 'w') as f: 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')) + print(subprocess.check_output(git_cmd, + shell=True, + cwd=os.path.dirname(toml_path)).decode('utf-8')) def main(argv=[], prog_name=''): @@ -52,10 +49,7 @@ def main(argv=[], prog_name=''): 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! @@ -70,26 +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(): - repo_link = f"https://github.com/parallaxsecond/{repo_folder}.git" - clone_repo(args.clone_dir, repo_link, 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