|
| 1 | +import argparse |
| 2 | +import re |
| 3 | +import os |
| 4 | +import subprocess |
| 5 | +import sys |
| 6 | + |
| 7 | + |
| 8 | +def run_cargo_build(path): |
| 9 | + print(f"cargo build, path: {path}") |
| 10 | + command = f'cargo build' |
| 11 | + return subprocess.check_output(command, shell=True, cwd=path) |
| 12 | + |
| 13 | + |
| 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) |
| 18 | + |
| 19 | + |
| 20 | +def git_toml_deps(toml_path, deps_repo_links, deps_branches): |
| 21 | + lines = None |
| 22 | + with open(toml_path, 'r') as f: |
| 23 | + lines = f.readlines() |
| 24 | + |
| 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) |
| 35 | + |
| 36 | + for updatable in to_update: |
| 37 | + run_cargo_update(os.path.dirname(toml_path), updatable) |
| 38 | + |
| 39 | + with open(toml_path, 'w') as f: |
| 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')) |
| 45 | + |
| 46 | + |
| 47 | +def main(argv=[], prog_name=''): |
| 48 | + parser = argparse.ArgumentParser(prog='ReleaseTracker', |
| 49 | + description='Modifies the parsec Cargo.toml files to use the ' |
| 50 | + 'main branches of parallaxsecond dependencies in ' |
| 51 | + 'preparation for their publishing and release') |
| 52 | + parser.add_argument('paths', nargs='+', help='Absolute paths to the Cargo.toml files') |
| 53 | + args = parser.parse_args() |
| 54 | + |
| 55 | + # The order is important! |
| 56 | + parallaxsecond_deps = { |
| 57 | + 'psa-crypto-sys': 'rust-psa-crypto', |
| 58 | + 'psa-crypto': 'rust-psa-crypto', |
| 59 | + 'tss-esapi-sys': 'rust-tss-esapi', |
| 60 | + 'tss-esapi': 'rust-tss-esapi', |
| 61 | + 'cryptoki-sys': 'rust-cryptoki', |
| 62 | + 'cryptoki': 'rust-cryptoki', |
| 63 | + 'parsec-interface': 'parsec-interface-rs', |
| 64 | + 'parsec-client': 'parsec-client-rust', |
| 65 | + } |
| 66 | + |
| 67 | + repo_links = { repo_name: f"https://github.com/parallaxsecond/{repo_folder}.git" \ |
| 68 | + for repo_name, repo_folder in parallaxsecond_deps.items() } |
| 69 | + |
| 70 | + repo_branches = { repo_name: 'main' for repo_name in parallaxsecond_deps.keys() } |
| 71 | + repo_branches['tss-esapi-sys'] = '7.x.y' |
| 72 | + repo_branches['tss-esapi'] = '7.x.y' |
| 73 | + |
| 74 | + for path in args.paths: |
| 75 | + git_toml_deps(path, repo_links, repo_branches) |
| 76 | + run_cargo_build(os.path.dirname(path)) |
| 77 | + |
| 78 | + return 0 |
| 79 | + |
| 80 | + |
| 81 | +if __name__ == '__main__': |
| 82 | + sys.exit(main(sys.argv[1:], sys.argv[0])) |
0 commit comments