From 1c456a7e93bc99f812c1bd510781f79706cea0da Mon Sep 17 00:00:00 2001 From: Ashok Menon Date: Wed, 5 Jul 2023 00:02:53 +0100 Subject: [PATCH] [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 ``` --- scripts/cut_execution_layer.sh | 94 ----------------------------- scripts/execution-layer | 104 +++++++++++++++++++++++++++++++++ sui-execution/README.md | 6 +- 3 files changed, 107 insertions(+), 97 deletions(-) delete mode 100755 scripts/cut_execution_layer.sh create mode 100755 scripts/execution-layer diff --git a/scripts/cut_execution_layer.sh b/scripts/cut_execution_layer.sh deleted file mode 100755 index 1913aeed96fed..0000000000000 --- a/scripts/cut_execution_layer.sh +++ /dev/null @@ -1,94 +0,0 @@ -#!/bin/bash -# Copyright (c) Mysten Labs, Inc. -# SPDX-License-Identifier: Apache-2.0 - -set -e - -if ! command -v git &> /dev/null; then - echo "Please install git" >&2 - exit 1 -fi - -if ! command -v cargo &> /dev/null; then - echo "Please install cargo" >&2 - exit 1 -fi - -if ! command -v cargo-hakari &> /dev/null; then - echo "Please install cargo-hakari (via cargo)" >&2 - exit 1 -fi - -function print_usage() { - >&2 echo "Usage: $0 [--dry-run] [-h] -f FEATURE" - >&2 echo - >&2 echo " Create a new copy of execution-related crates, and add them to the" - >&2 echo " workspace. Assigning an execution layer version to the new copy and" - >&2 echo " implementing the Executor and Verifier traits in crates/sui-execution" - >&2 echo " must be done manually as a follow-up." - >&2 echo - >&2 echo "Options:" - >&2 echo - >&2 echo " -f FEATURE The feature to label the new cut with." - >&2 echo " --dry-run Just print the operations, don't actually run them." - >&2 echo " -h, --help Print this usage." - - exit "$1" -} - -while getopts "f:-:h" OPT; do - case $OPT in - f) - FEATURE=$OPTARG ;; - h) - print_usage 0 ;; - -) # Parsing Long Options - case "$OPTARG" in - dry-run) - DRY_RUN="--dry-run" ;; - help) - print_usage 0 ;; - *) >&2 echo "Unrecognized option '--$OPTARG'" - >&2 echo - print_usage 1 - ;; - esac - ;; - \?) - >&2 echo "Unrecognized option '-$OPT'" - >&2 echo - print_usage 1 - ;; - esac -done - -if [ -z "$FEATURE" ]; then - >&2 echo "Error: No 'FEATURE' name given" - >&2 echo - print_usage 1 -fi - -REPO=$(git rev-parse --show-toplevel) - -cd "$REPO" - ->&2 echo "Cutting new release" -cargo run --bin cut -- \ - $DRY_RUN --feature "$FEATURE" \ - -d "sui-execution/latest:sui-execution/$FEATURE:-latest" \ - -d "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" - -if [ -z "$DRY_RUN" ]; then - # We need to remove some special-case files/directories from the cut: - rm -r "external-crates/move-execution/$FEATURE/move-bytecode-verifier/transactional-tests" - rm -r "external-crates/move-execution/$FEATURE/move-stdlib/src/main.rs" - rm -r "external-crates/move-execution/$FEATURE/move-stdlib/tests" - - cargo hakari generate -fi diff --git a/scripts/execution-layer b/scripts/execution-layer new file mode 100755 index 0000000000000..bba7ad663d42d --- /dev/null +++ b/scripts/execution-layer @@ -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) diff --git a/sui-execution/README.md b/sui-execution/README.md index 1d9249d312ab2..7fc3fef123a9a 100644 --- a/sui-execution/README.md +++ b/sui-execution/README.md @@ -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 +./scripts/execution-layer cut ``` Where `` is the new feature name. For a versioned snapshot