diff --git a/scripts/bundle.py b/scripts/bundle.py index 807be02..1b261d6 100644 --- a/scripts/bundle.py +++ b/scripts/bundle.py @@ -7,6 +7,7 @@ import subprocess from argparse import ArgumentParser from .log import * +from .version import install_dir def attach_bundle_commands(subparsers): diff --git a/scripts/dev.py b/scripts/dev.py index 1e81253..d965e3a 100644 --- a/scripts/dev.py +++ b/scripts/dev.py @@ -575,6 +575,8 @@ def install(args): dest = install_dir() bin_dir = os.path.join(dest, "bin") src_dir = os.path.join(dest, "src") + runtime_dir = os.path.join(dest, "build", "bin") + resources_dir = os.path.join(dest, "resources") version_file = os.path.join(dest, ".orcaversion") version = orca_version() @@ -597,6 +599,8 @@ def install(args): yeetdir(bin_dir) yeetdir(src_dir) + yeetdir(runtime_dir) + yeetdir(resources_dir) yeetfile(version_file) # The MS Store version of Python does some really stupid stuff with AppData: @@ -617,6 +621,8 @@ def install(args): shutil.copytree("scripts", os.path.join(bin_dir, "sys_scripts")) shutil.copy("orca", bin_dir) shutil.copytree("src", src_dir, dirs_exist_ok=True) + shutil.copytree(os.path.join("build", "bin"), runtime_dir, dirs_exist_ok=True) + shutil.copytree("resources", resources_dir, dirs_exist_ok=True) if platform.system() == "Windows": shutil.copy("orca.bat", bin_dir) with open(version_file, "w") as f: diff --git a/scripts/source.py b/scripts/source.py index f4170a6..59115c5 100644 --- a/scripts/source.py +++ b/scripts/source.py @@ -7,7 +7,7 @@ import shutil from .checksum import dirsum from .log import * from .utils import yeetdir -from .version import src_dir, orca_version +from .version import orca_version, install_dir def attach_source_commands(subparsers): @@ -15,7 +15,7 @@ def attach_source_commands(subparsers): source_sub = source_cmd.add_subparsers(required=True, title="commands") cflags_cmd = source_sub.add_parser("cflags", help="Get help setting up a C or C++ compiler to compile the Orca source.") - cflags_cmd.add_argument("srcdir", nargs="?", default=src_dir(), help="the directory containing the Orca source code (defaults to system installation)") + cflags_cmd.add_argument("srcdir", nargs="?", default=path_in_install("src"), help="the directory containing the Orca source code (defaults to system installation)") cflags_cmd.set_defaults(func=shellish(cflags)) vendor_cmd = source_sub.add_parser("vendor", help="Copy the Orca source code into your project.") @@ -23,6 +23,10 @@ def attach_source_commands(subparsers): vendor_cmd.set_defaults(func=shellish(vendor)) +def path_in_install(path): + return os.path.join(install_dir(), path) + + def vendor(args): # Verify that we are ok to vendor into the requested dir. if os.path.exists(args.dir): @@ -41,12 +45,19 @@ def vendor(args): exit(1) yeetdir(args.dir) - shutil.copytree(src_dir(), args.dir) + + vendor_src = os.path.join(args.dir, "src") + vendor_runtime = os.path.join(args.dir, "build", "bin") + vendor_resources = os.path.join(args.dir, "resources") + shutil.copytree(path_in_install("src"), vendor_src) + shutil.copytree(path_in_install("build/bin"), vendor_runtime) + shutil.copytree(path_in_install("resources"), vendor_resources) with open(vendor_file_path(args.dir), "w") as f: json.dump({ "version": orca_version(), "checksum": vendor_checksum(args.dir), }, f, indent=2) + print(f"Version {orca_version()} of the Orca source code has been copied to {args.dir}.") diff --git a/scripts/version.py b/scripts/version.py index e811730..ec60726 100644 --- a/scripts/version.py +++ b/scripts/version.py @@ -38,20 +38,13 @@ def is_orca_source(): return use_source -def actual_install_dir(): +def install_dir(): # The path adjustment in here is technically sort of fragile because it depends # on the current location of this actual file. But oh well. if is_orca_source(): - raise Exception("actual_install_dir should not be called when using the source version of the Orca tools") - return os.path.normpath(os.path.join(os.path.abspath(__file__), "../../..")) - - -def src_dir(): - # More fragile path adjustments! Yay! - if is_orca_source(): - return os.path.normpath(os.path.join(os.path.abspath(__file__), "../../src")) + return os.path.normpath(os.path.join(os.path.abspath(__file__), "../..")) else: - return os.path.normpath(os.path.join(os.path.abspath(__file__), "../../../src")) + return os.path.normpath(os.path.join(os.path.abspath(__file__), "../../..")) def orca_version(): @@ -68,7 +61,7 @@ def orca_version(): return f"dev-{version}" else: try: - with open(os.path.join(actual_install_dir(), ".orcaversion"), "r") as f: + with open(os.path.join(install_dir(), ".orcaversion"), "r") as f: version = f.read().strip() return version except FileNotFoundError: @@ -92,4 +85,4 @@ def print_orca_version(args): sys.stderr.write(f"Source dir: {source_dir}\n") else: sys.stderr.write(f"Orca is running from a system installation.\n") - sys.stderr.write(f"Install dir: {actual_install_dir()}\n") + sys.stderr.write(f"Install dir: {install_dir()}\n") diff --git a/src/platform/win32_subprocess.c b/src/platform/win32_subprocess.c index 4385971..ffca2e4 100644 --- a/src/platform/win32_subprocess.c +++ b/src/platform/win32_subprocess.c @@ -91,21 +91,22 @@ oc_str8 oc_run_cmd(oc_arena* arena, oc_str8 cmd) char* outputBuf = NULL; while(true) { - const int chunkSize = 1024; - char* chunk = oc_arena_push(arena, chunkSize); - if(outputBuf == NULL) - { - // Initialize output buffer to first allocated chunk - outputBuf = chunk; - } - +// TODO: apply smartness to this number +#define CHUNK_SIZE 1024 + char chunkBuf[CHUNK_SIZE]; DWORD nRead; - BOOL success = ReadFile(childStdoutRd, chunk, chunkSize, &nRead, NULL); + BOOL success = ReadFile(childStdoutRd, chunkBuf, CHUNK_SIZE, &nRead, NULL); if(!success || nRead == 0) { break; } + char* dst = oc_arena_push(arena, nRead); + if(!outputBuf) + { + outputBuf = dst; + } + memcpy(dst, chunkBuf, nRead); outputLen += nRead; }