-
Notifications
You must be signed in to change notification settings - Fork 11.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sui-execution] Re-implement wrapper script in Python
Replace the bash script with an equivalent python script. This is to prepare for a couple of improvements: - Automating the creation of the new modules in `sui-execution`, and the `executor` and `verifier` dispatch functions. - Adding `rebase` and `merge` commands to simplify keeping up with other changes in the execution layer. Test Plan: ``` sui$ black scripts/execution-layer sui$ flake8 scripts/execution-layer sui$ ./scripts/execution-layer --dry-run cut v1 sui$ ./scripts/execution-layer cut v1 ```
- Loading branch information
Showing
3 changed files
with
107 additions
and
97 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (c) Mysten Labs, Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import argparse | ||
from os import chdir, remove | ||
from shutil import which, rmtree | ||
import subprocess | ||
from sys import stderr, stdout | ||
|
||
|
||
def parse_args(): | ||
parser = argparse.ArgumentParser( | ||
prog="execution-layer", | ||
) | ||
|
||
parser.add_argument( | ||
"--dry-run", | ||
action="store_true", | ||
help="Print the operations, without running them", | ||
) | ||
|
||
subparsers = parser.add_subparsers( | ||
description="Tools for managing cuts of the execution-layer", | ||
) | ||
|
||
cut = subparsers.add_parser( | ||
"cut", | ||
help=( | ||
"Create a new copy of execution-related crates, and add them to " | ||
"the workspace. Assigning an execution layer version to the new " | ||
"copy and implementing the Execution and Verifier traits in " | ||
"crates/sui-execution must be done manually as a follow-up." | ||
), | ||
) | ||
|
||
cut.set_defaults(do=do_cut) | ||
cut.add_argument("feature", help="The name of the new cut to make") | ||
|
||
return parser.parse_args() | ||
|
||
|
||
def do_cut(args): | ||
"""Perform the actions of the 'cut' sub-command. | ||
Accepts the parsed command-line arguments as a parameter.""" | ||
cmd = cut_command(args.feature) | ||
|
||
if args.dry_run: | ||
cmd.append("--dry-run") | ||
print(run(cmd)) | ||
else: | ||
print("Cutting new release", file=stderr) | ||
result = subprocess.run(cmd, stdout=stdout, stderr=stderr) | ||
|
||
if result.returncode != 0: | ||
print("Cut failed", file=stderr) | ||
exit(result.returncode) | ||
|
||
clean_up_cut(args.feature) | ||
run(["cargo", "hakari", "generate"]) | ||
|
||
|
||
def run(command): | ||
"""Run command, and return its stdout as a UTF-8 string.""" | ||
return subprocess.run(command, stdout=subprocess.PIPE).stdout.decode("utf-8") | ||
|
||
|
||
def repo_root(): | ||
"""Find the repository root, using git.""" | ||
return run(["git", "rev-parse", "--show-toplevel"]).strip() | ||
|
||
|
||
def cut_command(feature): | ||
"""Arguments for creating the cut for 'feature'.""" | ||
return [ | ||
*["cargo", "run", "--bin", "cut", "--"], | ||
*["--feature", feature], | ||
*["-d", f"sui-execution/latest:sui-execution/{feature}:-latest"], | ||
*["-d", f"external-crates/move:external-crates/move-execution/{feature}"], | ||
*["-p", "sui-adapter-latest"], | ||
*["-p", "sui-move-natives-latest"], | ||
*["-p", "sui-verifier-latest"], | ||
*["-p", "move-bytecode-verifier"], | ||
*["-p", "move-stdlib"], | ||
*["-p", "move-vm-runtime"], | ||
] | ||
|
||
|
||
def clean_up_cut(feature): | ||
"""Remove some special-case files/directories from a given cut""" | ||
move_exec = f"external-crates/move-execution/{feature}" | ||
rmtree(move_exec + "/move-bytecode-verifier/transactional-tests") | ||
remove(move_exec + "/move-stdlib/src/main.rs") | ||
rmtree(move_exec + "/move-stdlib/tests") | ||
|
||
|
||
if __name__ == "__main__": | ||
for bin in ["git", "cargo", "cargo-hakari"]: | ||
if not which(bin): | ||
print(f"Please install '{bin}'", file=stderr) | ||
|
||
args = parse_args() | ||
chdir(repo_root()) | ||
args.do(args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters