From 956ad51072bbc292a3a618b050bf44581faa2f61 Mon Sep 17 00:00:00 2001 From: Ben Visness Date: Sat, 29 Jul 2023 15:11:20 -0500 Subject: [PATCH] Add Orca install workflow --- orca | 31 ++++++++++++++++ scripts/bundle.py | 2 +- scripts/checksum.py | 2 +- scripts/dev.py | 77 ++++++++++++++++++++++++++++++--------- scripts/{orca => orca.py} | 4 +- 5 files changed, 95 insertions(+), 21 deletions(-) create mode 100755 orca rename scripts/{orca => orca.py} (76%) mode change 100755 => 100644 diff --git a/orca b/orca new file mode 100755 index 0000000..17ee216 --- /dev/null +++ b/orca @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 + +# This file is copied into the user's home directory on install, +# but also can be run from the root of an Orca source checkout. + +import os +import sys + + +root = True +try: + os.stat(".orcaroot") +except FileNotFoundError: + root = False + +if root: + # Running from Orca source checkout; use local source's scripts. + + scriptdir = os.path.dirname(os.path.abspath(__file__)) + if scriptdir != os.getcwd(): + # Only print this warning if running the system-installed Orca. + # It's annoying to see this if you run ./orca from the source. + print("The Orca tool is running from a local source checkout and will") + print("use that instead of the system Orca installation.") + print() + + sys.path.append(os.getcwd()) + import scripts.orca +else: + # Running from outside Orca source checkout; use system Orca install. + import sys_scripts.orca diff --git a/scripts/bundle.py b/scripts/bundle.py index 1e58b73..ca7a62c 100644 --- a/scripts/bundle.py +++ b/scripts/bundle.py @@ -6,7 +6,7 @@ import shutil import subprocess from argparse import ArgumentParser -from log import * +from .log import * def attach_bundle_commands(subparsers): diff --git a/scripts/checksum.py b/scripts/checksum.py index e404081..972ce9a 100644 --- a/scripts/checksum.py +++ b/scripts/checksum.py @@ -1,7 +1,7 @@ import hashlib import json -from log import * +from .log import * def checkfile(filepath): diff --git a/scripts/dev.py b/scripts/dev.py index 8b453b4..d9a4574 100644 --- a/scripts/dev.py +++ b/scripts/dev.py @@ -8,11 +8,11 @@ import shutil import subprocess from zipfile import ZipFile -import checksum -from bindgen import bindgen -from bindgen2 import bindgen2 -from log import * -from utils import pushd, removeall +from . import checksum +from .bindgen import bindgen +from .bindgen2 import bindgen2 +from .log import * +from .utils import pushd, removeall ANGLE_VERSION = "2023-07-05" @@ -20,21 +20,28 @@ ANGLE_VERSION = "2023-07-05" def attach_dev_commands(subparsers): dev_cmd = subparsers.add_parser("dev", help="Commands for building Orca itself. Must be run from the root of an Orca source checkout.") + dev_cmd.set_defaults(func=orca_root_only) - try: - os.stat(".orcaroot") - except FileNotFoundError: - dev_cmd.set_defaults(func=orca_root_only) - return - - dev_sub = dev_cmd.add_subparsers(required=True, title='commands') + dev_sub = dev_cmd.add_subparsers(required=is_orca_root(), title='commands') build_cmd = dev_sub.add_parser("build-runtime", help="Build the Orca runtime from source.") build_cmd.add_argument("--release", action="store_true", help="compile Orca in release mode (default is debug)") - build_cmd.set_defaults(func=shellish(build_runtime)) + build_cmd.set_defaults(func=dev_shellish(build_runtime)) clean_cmd = dev_sub.add_parser("clean", help="Delete all build artifacts and start fresh.") - clean_cmd.set_defaults(func=shellish(clean)) + clean_cmd.set_defaults(func=dev_shellish(clean)) + + install_cmd = dev_sub.add_parser("install", help="Install the Orca tools into a system folder.") + install_cmd.add_argument("--no-confirm", action="store_true", help="don't ask the user for confirmation before installing") + install_cmd.set_defaults(func=dev_shellish(install)) + + +def is_orca_root(): + try: + os.stat(".orcaroot") + return True + except FileNotFoundError: + return False def orca_root_only(args): @@ -45,6 +52,10 @@ def orca_root_only(args): exit(1) +def dev_shellish(func): + return shellish(func) if is_orca_root() else orca_root_only + + def build_runtime(args): ensure_programs() ensure_angle() @@ -55,9 +66,6 @@ def build_runtime(args): def clean(args): - def yeet(path): - os.makedirs(path, exist_ok=True) - shutil.rmtree(path) yeet("build") yeet("milepost/build") yeet("scripts/files") @@ -530,3 +538,38 @@ def embed_text_glsl(outputpath, prefix, shaders): output.write("#endif // __%s_H__\n" % outSymbol) output.close() + + +def yeet(path): + os.makedirs(path, exist_ok=True) + shutil.rmtree(path) + + +def install(args): + if not args.no_confirm: + dest = os.path.expanduser(os.path.join("~", ".orca")) + + print("The Orca command-line tools will be installed to your home directory in:") + print(dest) + print() + while True: + answer = input("Proceed with the installation? (y/n) >") + if answer.lower() in ["y", "yes"]: + break + elif answer.lower() in ["n", "no"]: + return + else: + print("Please enter \"yes\" or \"no\" and press return.") + + bin_dir = os.path.join(dest, "bin") + yeet(bin_dir) + shutil.copytree("scripts", os.path.join(bin_dir, "sys_scripts")) + shutil.copy("orca", bin_dir) + + # TODO: Customize these instructions for Windows + print() + print("Orca has been installed. Make sure the Orca tools are on your PATH by adding the") + print("following to your shell config:") + print() + print(f"export PATH=\"{bin_dir}:$PATH\"") + print() diff --git a/scripts/orca b/scripts/orca.py old mode 100755 new mode 100644 similarity index 76% rename from scripts/orca rename to scripts/orca.py index f8b9750..f161b05 --- a/scripts/orca +++ b/scripts/orca.py @@ -2,8 +2,8 @@ import argparse -from bundle import attach_bundle_commands -from dev import attach_dev_commands +from .bundle import attach_bundle_commands +from .dev import attach_dev_commands parser = argparse.ArgumentParser()