From 39ecdd39f84e9b69bf0894fd8766ff5a19b2f5ef Mon Sep 17 00:00:00 2001 From: wrenge Date: Thu, 9 Nov 2023 13:02:47 +0300 Subject: [PATCH] Multiple projects support --- bhl.inc.php | 62 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/bhl.inc.php b/bhl.inc.php index c67b661..8342511 100644 --- a/bhl.inc.php +++ b/bhl.inc.php @@ -1,6 +1,7 @@ file_path = $proj_file; //NOTE: adding path to the file for convenience + foreach($proj->src_dirs as $k => $v) $proj->src_dirs[$k] = _bhl_make_abs_path($proj_file, $v); @@ -40,15 +45,22 @@ function bhl_proj() $proj->bindings_sources[$k] = _bhl_make_abs_path($proj_file, $v); $proj->bindings_dll= _bhl_make_abs_path($proj_file, $proj->bindings_dll); - foreach($proj->postproc_sources as $k => $v) - $proj->postproc_sources[$k] = _bhl_make_abs_path($proj_file, $v); - $proj->postproc_dll= _bhl_make_abs_path($proj_file, $proj->postproc_dll); + if(isset($proj->postproc_sources)) + { + foreach($proj->postproc_sources as $k => $v) + $proj->postproc_sources[$k] = _bhl_make_abs_path($proj_file, $v); + } + + if(isset($proj->postproc_dll)) + $proj->postproc_dll = _bhl_make_abs_path($proj_file, $proj->postproc_dll); $proj->result_file = _bhl_make_abs_path($proj_file, $proj->result_file); $proj->error_file = _bhl_make_abs_path($proj_file, $proj->error_file); $proj->tmp_dir = _bhl_make_abs_path($proj_file, $proj->tmp_dir); + + $projs[$proj_file] = $proj; } - return $proj; + return $projs[$proj_file]; } function _bhl_make_abs_path($proj_file, $path) @@ -59,10 +71,10 @@ function _bhl_make_abs_path($proj_file, $path) return $path; } -function bhl_result_file() +function bhl_result_file(stdClass $bhl_proj = null) { - global $GAME_ROOT; - return bhl_proj()->result_file; + $bhl_proj ??= bhl_proj(); + return $bhl_proj->result_file; } function bhl_dir() @@ -92,20 +104,22 @@ function bhl_shell_ensure($cmd) throw new Exception("Error executing shell cmd: $ret_var"); } -function bhl_scan_files() +function bhl_scan_files(stdClass $bhl_proj = null) { - return scan_files_rec(bhl_proj()->src_dirs, array('.bhl')); + $bhl_proj ??= bhl_proj(); + return scan_files_rec($bhl_proj->src_dirs, array('.bhl')); } -function bhl_run($debug = true, $force = false, $exit_on_err = true) +function bhl_run($debug = true, $force = false, $exit_on_err = true, stdClass $bhl_proj = null) { global $GAME_ROOT; - $result_file = bhl_proj()->result_file; + $bhl_proj ??= bhl_proj(); + $result_file = $bhl_proj->result_file; if($force || need_to_regen($result_file, bhl_scan_files())) { - bhl_shell("compile -p " . bhl_proj_file() . " " . + bhl_shell("compile -p " . $bhl_proj->file_path . " " . ($debug ? " -d" : "") . " " . ($force || !getor("BHL_USE_CACHE", true) ? " -C" : ""), $ret_var, $ret_out @@ -113,7 +127,7 @@ function bhl_run($debug = true, $force = false, $exit_on_err = true) if($ret_var != 0) { - bhl_handle_error_result($ret_out, bhl_proj()->error_file, $exit_on_err); + bhl_handle_error_result($ret_out, $bhl_proj->error_file, $exit_on_err); if(!$exit_on_err) return false; } @@ -159,15 +173,16 @@ function bhl_handle_error_result(array $ret_out, $err_file, $exit = true) exit(1); } -function bhl_clean() +function bhl_clean(stdClass $bhl_proj = null) { - bhl_clean_cache(); + bhl_clean_cache($bhl_proj); bhl_shell_ensure("clean"); } -function bhl_clean_cache() +function bhl_clean_cache(stdClass $bhl_proj = null) { - ensure_rm(bhl_proj()->tmp_dir); + $bhl_proj ??= bhl_proj(); + ensure_rm($bhl_proj->tmp_dir); } function bhl_show_position($line, $row, array $lines) @@ -203,9 +218,10 @@ function bhl_line_row_to_pos($file, $line, $row) return $pos; } -function bhl_map_module_to_file($module) +function bhl_map_module_to_file($module, stdClass $bhl_proj = null) { - foreach(bhl_proj()->src_dirs as $dir) + $bhl_proj ??= bhl_proj(); + foreach($bhl_proj->src_dirs as $dir) { $tmp = $dir.'/'.$module.'.bhl'; if(file_exists($tmp))