From 9fbe2eb35a82bcd77132bafa62742bff602ba200 Mon Sep 17 00:00:00 2001
From: OusmBlueNinja <89956790+OusmBlueNinja@users.noreply.github.com>
Date: Fri, 18 Apr 2025 22:17:07 -0500
Subject: [PATCH] idk, submodues dum

---
 remake/remake/remake.py | 68 ++++++++++++++++++++++++++---------------
 1 file changed, 44 insertions(+), 24 deletions(-)

diff --git a/remake/remake/remake.py b/remake/remake/remake.py
index 5bd1d36..2a60587 100644
--- a/remake/remake/remake.py
+++ b/remake/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():
@@ -262,6 +280,8 @@ if __name__ == "__main__":
     try:
         if "clean" in sys.argv:
             clean()
+        if "clear" in sys.argv:
+            clean()
         elif "run" in sys.argv:
             run()
         else: