From 13a22ff18205b3273d6c70ce26cacd52e03c49e5 Mon Sep 17 00:00:00 2001 From: OusmBlueNinja <89956790+OusmBlueNinja@users.noreply.github.com> Date: Fri, 18 Apr 2025 22:12:29 -0500 Subject: [PATCH] made multithreadded --- remake/remake.py | 66 ++++++++++++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 24 deletions(-) diff --git a/remake/remake.py b/remake/remake.py index 07f5ee3..2a60587 100644 --- a/remake/remake.py +++ b/remake/remake.py @@ -7,6 +7,12 @@ import time import json from remake_config import * +import threading +from concurrent.futures import ThreadPoolExecutor, as_completed + +print_lock = threading.Lock() + + # ========== COLOR UTILS ========== class Colors: HEADER = '\033[95m' @@ -148,16 +154,20 @@ def compile_source(source, obj, includes): cmd = [compiler, *flags, *[f"-I{inc}" for inc in includes], "-MMD", "-MP", "-c", str(source), "-o", str(obj)] try: - print(f"\r{color('🔨 Compiling:', Colors.OKCYAN)} {source}{' ' * 40}", end="", flush=True) + with print_lock: + print(f"\r{color('🔨 Compiling:', Colors.OKCYAN)} {source}{' ' * 40}", end="", flush=True) subprocess.run(cmd, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) log(f"[COMPILE] {' '.join(cmd)}") + return True except subprocess.CalledProcessError as e: - print() # move to new line before showing error - error(f"Failed to compile {source}") - print("🔧 Command:", " ".join(cmd)) - print(e.stderr.decode()) + with print_lock: + print() # move to new line before showing error + error(f"Failed to compile {source}") + print("🔧 Command:", " ".join(cmd)) + print(e.stderr.decode()) log(f"[ERROR] {' '.join(cmd)}\n{e.stderr.decode()}") - sys.exit(1) + return False + @@ -184,34 +194,42 @@ def build(): link_dirs, libs, extra_includes = resolve_packages() all_includes = INCLUDE_DIRS + extra_includes - for source in cpp_files: - obj = obj_path(source) - dep = dep_path(obj) - obj_mtime = obj.stat().st_mtime if obj.exists() else 0 - needs_build = not obj.exists() or source.stat().st_mtime > obj_mtime + compile_tasks = [] + with ThreadPoolExecutor() as executor: + for source in cpp_files: + obj = obj_path(source) + dep = dep_path(obj) + obj_mtime = obj.stat().st_mtime if obj.exists() else 0 + needs_build = not obj.exists() or source.stat().st_mtime > obj_mtime - if not needs_build and dep.exists(): - for dep_file in parse_dep_file(dep): - try: - if Path(dep_file).exists() and Path(dep_file).stat().st_mtime > obj_mtime: + if not needs_build and dep.exists(): + for dep_file in parse_dep_file(dep): + try: + if Path(dep_file).exists() and Path(dep_file).stat().st_mtime > obj_mtime: + needs_build = True + break + except Exception: needs_build = True break - except Exception: - needs_build = True - break - if needs_build: - compile_source(source, obj, all_includes) - else: - print(f"\r{color('👌 Up-to-date:', Colors.GRAY)} {source}{' ' * 20}", end="", flush=True) + if needs_build: + compile_tasks.append(executor.submit(compile_source, source, obj, all_includes)) + else: + with print_lock: + print(f"\r{color('👌 Up-to-date:', Colors.GRAY)} {source}{' ' * 20}", end="", flush=True) + + obj_files.append(obj) + + for task in as_completed(compile_tasks): + if not task.result(): + sys.exit(1) - obj_files.append(obj) print() - link_objects(obj_files, link_dirs, libs) banner("✅ Build Complete") print(color(f"⏱ Build time: {time.time() - build_start:.2f}s", Colors.OKCYAN)) + def run(): build() if TARGET.exists():