Update leenkx/blender/lnx/make.py

This commit is contained in:
Onek8 2025-04-10 15:54:53 +00:00
parent 5572494f3d
commit e079c94832

View File

@ -784,12 +784,57 @@ def build_success():
os.chdir(dest_dir)
elif state.target in ('linux-hl', 'macos-hl'):
log.error(f"Compilation for {state.target} is not yet implemented in build_success.")
wrd = bpy.data.worlds['Lnx']
paths = lnx.utils.hashlink_paths(state.target)
hl_build_dir = paths[0]
# TO DO switch from default Release
build_mode = 'Release'
proj_name = lnx.utils.blend_name()
exe_path = str(hl_build_dir + "/" + build_mode)
if not exe_path:
log.error(f"Build finished, but could not find the executable for {state.target}.")
return
else:
log.error(f"Running logic for target {state.target} is not defined (expected Krom or Hashlink/C).")
makefile_path = os.path.join(exe_path, 'makefile')
if not os.path.isfile(makefile_path):
log.error(f"Makefile not found at '{makefile_path}'. Cannot compile C code.")
return
make_cmd = ['make']
log.info(f"Compiling C code using 'make' in directory '{exe_path}'...")
log.info(f"Make command: {' '.join(make_cmd)}")
try:
result = subprocess.run(make_cmd, cwd=exe_path, check=True, capture_output=True, text=True, encoding='utf-8')
log.info("'make' compilation successful.")
except subprocess.CalledProcessError as e:
log.error(f"'make' compilation failed with return code {e.returncode}.")
log.error(f"Make Error Output:\n{e.stderr}")
return
except FileNotFoundError:
log.error("'make' command not found. Ensure 'make' is installed and in your system's PATH.")
return
except Exception as e:
log.error(f"An unexpected error occurred running make: {e}")
return
log.info(f"Found compiled executable: {exe_path}")
dest_exe_name = lnx.utils.safesrc(wrd.lnx_project_name + '-' + wrd.lnx_project_version)
base_build_dir = lnx.utils.get_fp_build()
dest_dir = os.path.join(base_build_dir, state.target)
og_path = os.path.join(exe_path, dest_exe_name)
dest_path = os.path.join(dest_dir, dest_exe_name)
os.makedirs(dest_dir, exist_ok=True)
try:
log.info(f"Moving '{og_path}' to '{dest_dir}'...")
shutil.move(og_path, dest_dir)
cmd = [dest_path]
except Exception as e:
log.error(f"Failed to move executable: {e}. Attempting to run from original location.")
cmd = [exe_path]
os.chdir(dest_dir)
log.info(f"Hashlink final command: {' '.join(cmd)}")
try:
state.proc_play = run_proc(cmd, play_done)
except Exception: