Skip to content

Commit

Permalink
[sui-execution] Re-implement wrapper script in Python
Browse files Browse the repository at this point in the history
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
amnn committed Jul 7, 2023
1 parent 9f777e6 commit 1c456a7
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 97 deletions.
94 changes: 0 additions & 94 deletions scripts/cut_execution_layer.sh

This file was deleted.

104 changes: 104 additions & 0 deletions scripts/execution-layer
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)
6 changes: 3 additions & 3 deletions sui-execution/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@ To use this flow:
## Making a Cut

Cuts are always made from `latest`, with the process part automated by
a script: `./scripts/cut_execution_layer.sh`. To copy the relevant
crates for a new cut, call:
a script: `./scripts/execution-layer`. To copy the relevant crates for
a new cut, call:

``` shell
./scripts/cut_execution_layer.sh -f <FEATURE>
./scripts/execution-layer cut <FEATURE>
```

Where `<FEATURE>` is the new feature name. For a versioned snapshot
Expand Down

0 comments on commit 1c456a7

Please sign in to comment.