From 7f38b15fe770ad6244749a7d1077aac8689347c1 Mon Sep 17 00:00:00 2001 From: LeenkxTeam Date: Wed, 9 Apr 2025 20:33:24 +0000 Subject: [PATCH] Update leenkx/blender/lnx/make.py --- leenkx/blender/lnx/make.py | 113 +++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/leenkx/blender/lnx/make.py b/leenkx/blender/lnx/make.py index dfdae56..9f80de2 100644 --- a/leenkx/blender/lnx/make.py +++ b/leenkx/blender/lnx/make.py @@ -427,6 +427,19 @@ def build(target, is_play=False, is_publish=False, is_export=False): global profile_time profile_time = time.time() + wrd = bpy.data.worlds['Lnx'] + + if is_play and wrd.lnx_runtime == 'Hashlink': + current_os = lnx.utils.get_os() + if current_os == 'win': + target = 'windows-hl' + elif current_os == 'linux': + target = 'linux-hl' + elif current_os == 'macos': + target = 'macos-hl' + else: + log.error(f"Unsupported OS '{current_os}' for Hashlink runtime.") + state.target = target state.is_play = is_play state.is_publish = is_publish @@ -680,6 +693,106 @@ def build_success(): cmd.append(str(pid)) if wrd.lnx_audio == 'Disabled': cmd.append('--nosound') + + elif state.target.startswith(('windows-hl', 'linux-hl', 'macos-hl', 'Hashlink')): + log.info(f"Attempting to run Hashlink/C target: {state.target}") + + hl_build_dir, _, _ = lnx.utils.hashlink_paths(state.target) + + if not hl_build_dir: + log.error(f"Could not find build directory for target {state.target}. Playback aborted.") + return + + if state.target == 'windows-hl': + vs_version_major = wrd.lnx_project_win_list_vs + build_mode = wrd.lnx_project_win_build_mode # Debug or Release + build_arch = wrd.lnx_project_win_build_arch # x64 or x86 (maps to Win32 for MSBuild) + platform = 'x64' if build_arch == 'x64' else 'Win32' # MSBuild uses Win32 for x86 + + installation = lnx.utils_vs.get_installed_version(vs_version_major, re_fetch=True) + if installation is None: + vs_info = lnx.utils_vs.get_supported_version(vs_version_major) + log.error(f'Visual Studio {vs_info["name"]} not found. Cannot compile {state.target}.') + return + msbuild_path = os.path.join(installation['path'], 'MSBuild', 'Current', 'Bin', 'MSBuild.exe') + if not os.path.isfile(msbuild_path): + msbuild_path = os.path.join(installation['path'], 'MSBuild', '15.0', 'Bin', 'MSBuild.exe') # VS 2017 fallback + if not os.path.isfile(msbuild_path): + log.error(f'MSBuild.exe not found for {installation["name"]}. Cannot compile {state.target}.') + return + + proj_name = lnx.utils.blend_name() + vcxproj_path = os.path.join(hl_build_dir, proj_name + '.vcxproj') + if not os.path.isfile(vcxproj_path): + found_vcxproj = None + for file in os.listdir(hl_build_dir): + if file.endswith(".vcxproj"): + found_vcxproj = os.path.join(hl_build_dir, file) + log.warn(f"Could not find '{proj_name}.vcxproj', using found '{file}' instead.") + break + if not found_vcxproj: + log.error(f'.vcxproj file not found in {hl_build_dir}. Cannot compile.') + return + vcxproj_path = found_vcxproj + proj_name = os.path.splitext(os.path.basename(vcxproj_path))[0] + + msbuild_cmd = [ + msbuild_path, + vcxproj_path, + f'/p:Configuration={build_mode}', + f'/p:Platform={platform}', + '/m' + ] + + log.info(f"Compiling {state.target} project with MSBuild...") + log.info(f"Command: {' '.join(msbuild_cmd)}") + compile_success = False + try: + compile_result = subprocess.run(msbuild_cmd, cwd=hl_build_dir, check=False, capture_output=True, text=True) + if compile_result.returncode == 0: + log.info(f"MSBuild compilation successful.") + compile_success = True + else: + log.error(f"MSBuild compilation failed (Exit Code: {compile_result.returncode}).") + log.error(f"MSBuild Output:\n{compile_result.stdout}") + log.error(f"MSBuild Errors:\n{compile_result.stderr}") + except Exception as e: + log.error(f"Error running MSBuild: {e}") + traceback.print_exc() + + if not compile_success: + return + + # Path is typically: ///.exe + exe_path = os.path.join(hl_build_dir, platform, build_mode, proj_name + '.exe') + if not os.path.isfile(exe_path): + exe_path = os.path.join(hl_build_dir, build_mode, proj_name + '.exe') + if not os.path.isfile(exe_path): + log.error(f'Compiled executable not found at expected location: {exe_path} (or variants). Cannot run.') + return + + log.info(f"Found compiled executable: {exe_path}") + cmd = [exe_path] + exe_dir = os.path.dirname(exe_path) + log.info(f"Changing CWD to: {exe_dir}") + os.chdir(exe_dir) + + elif state.target in ('linux-hl', 'macos-hl'): + log.error(f"Compilation for {state.target} is not yet implemented in build_success.") + return + else: + log.error(f"Running logic for target {state.target} is not defined (expected Krom or Hashlink/C).") + return + + if cmd: + log.info(f"Executing final command: {' '.join(cmd)}") + try: + state.proc_play = run_proc(cmd, play_done) + except Exception: + traceback.print_exc() + else: + log.error("No command generated to run.") + try: state.proc_play = run_proc(cmd, play_done) except Exception: