made multithreadded
This commit is contained in:
parent
04e3b5cada
commit
13a22ff182
@ -7,6 +7,12 @@ import time
|
|||||||
import json
|
import json
|
||||||
from remake_config import *
|
from remake_config import *
|
||||||
|
|
||||||
|
import threading
|
||||||
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||||
|
|
||||||
|
print_lock = threading.Lock()
|
||||||
|
|
||||||
|
|
||||||
# ========== COLOR UTILS ==========
|
# ========== COLOR UTILS ==========
|
||||||
class Colors:
|
class Colors:
|
||||||
HEADER = '\033[95m'
|
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)]
|
cmd = [compiler, *flags, *[f"-I{inc}" for inc in includes], "-MMD", "-MP", "-c", str(source), "-o", str(obj)]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
with print_lock:
|
||||||
print(f"\r{color('🔨 Compiling:', Colors.OKCYAN)} {source}{' ' * 40}", end="", flush=True)
|
print(f"\r{color('🔨 Compiling:', Colors.OKCYAN)} {source}{' ' * 40}", end="", flush=True)
|
||||||
subprocess.run(cmd, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
subprocess.run(cmd, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
log(f"[COMPILE] {' '.join(cmd)}")
|
log(f"[COMPILE] {' '.join(cmd)}")
|
||||||
|
return True
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
|
with print_lock:
|
||||||
print() # move to new line before showing error
|
print() # move to new line before showing error
|
||||||
error(f"Failed to compile {source}")
|
error(f"Failed to compile {source}")
|
||||||
print("🔧 Command:", " ".join(cmd))
|
print("🔧 Command:", " ".join(cmd))
|
||||||
print(e.stderr.decode())
|
print(e.stderr.decode())
|
||||||
log(f"[ERROR] {' '.join(cmd)}\n{e.stderr.decode()}")
|
log(f"[ERROR] {' '.join(cmd)}\n{e.stderr.decode()}")
|
||||||
sys.exit(1)
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -184,6 +194,8 @@ def build():
|
|||||||
link_dirs, libs, extra_includes = resolve_packages()
|
link_dirs, libs, extra_includes = resolve_packages()
|
||||||
all_includes = INCLUDE_DIRS + extra_includes
|
all_includes = INCLUDE_DIRS + extra_includes
|
||||||
|
|
||||||
|
compile_tasks = []
|
||||||
|
with ThreadPoolExecutor() as executor:
|
||||||
for source in cpp_files:
|
for source in cpp_files:
|
||||||
obj = obj_path(source)
|
obj = obj_path(source)
|
||||||
dep = dep_path(obj)
|
dep = dep_path(obj)
|
||||||
@ -201,17 +213,23 @@ def build():
|
|||||||
break
|
break
|
||||||
|
|
||||||
if needs_build:
|
if needs_build:
|
||||||
compile_source(source, obj, all_includes)
|
compile_tasks.append(executor.submit(compile_source, source, obj, all_includes))
|
||||||
else:
|
else:
|
||||||
|
with print_lock:
|
||||||
print(f"\r{color('👌 Up-to-date:', Colors.GRAY)} {source}{' ' * 20}", end="", flush=True)
|
print(f"\r{color('👌 Up-to-date:', Colors.GRAY)} {source}{' ' * 20}", end="", flush=True)
|
||||||
|
|
||||||
obj_files.append(obj)
|
obj_files.append(obj)
|
||||||
print()
|
|
||||||
|
|
||||||
|
for task in as_completed(compile_tasks):
|
||||||
|
if not task.result():
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
print()
|
||||||
link_objects(obj_files, link_dirs, libs)
|
link_objects(obj_files, link_dirs, libs)
|
||||||
banner("✅ Build Complete")
|
banner("✅ Build Complete")
|
||||||
print(color(f"⏱ Build time: {time.time() - build_start:.2f}s", Colors.OKCYAN))
|
print(color(f"⏱ Build time: {time.time() - build_start:.2f}s", Colors.OKCYAN))
|
||||||
|
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
build()
|
build()
|
||||||
if TARGET.exists():
|
if TARGET.exists():
|
||||||
|
Loading…
Reference in New Issue
Block a user