Compare commits

...

42 Commits

Author SHA1 Message Date
Pavel Shevaev fcfa71aa0c Minor renaming
Publish PHP Package / docker (push) Successful in 6s Details
2025-02-24 19:07:07 +03:00
Pavel Shevaev 22ec477ddf Improving BHL_REF validation by better splitting code by namespaces
Publish PHP Package / docker (push) Successful in 6s Details
2025-02-12 17:13:42 +03:00
Pavel Shevaev 82ad2216da Removing touching of the result file on each run; Echoing debug information only if debug=true
Publish PHP Package / docker (push) Successful in 6s Details
2024-10-22 16:14:48 +03:00
Pavel Shevaev 4a85fa9b4d Ignoring exceptions for clean, fix
Publish PHP Package / docker (push) Successful in 5s Details
2024-10-16 17:15:45 +03:00
Pavel Shevaev d74b15c7ce Ignoring exceptions for clean
Publish PHP Package / docker (push) Successful in 6s Details
2024-10-16 17:10:36 +03:00
Pavel Shevaev 9c4c4521d8 Adding stripping of commented code during detection of BHL func signatures
Publish PHP Package / docker (push) Successful in 6s Details
2024-10-04 13:34:23 +03:00
Pavel Shevaev 63dee1f015 Removing UPM related stuff
Publish PHP Package / docker (push) Successful in 8s Details
2024-09-22 17:16:58 +03:00
Pavel Shevaev 5f52f0a4ad Removing Unity/mono dependency
Publish PHP Package / docker (push) Successful in 5s Details
2024-09-20 17:48:54 +03:00
Pavel Shevaev 20b3d26ece A bit improving function signature validation heuristics
Publish PHP Package / docker (push) Successful in 7s Details
2024-04-24 19:39:02 +03:00
Pavel Shevaev 7e3927cb72 Improving validation error messages
Publish PHP Package / docker (push) Successful in 6s Details
2024-04-24 16:51:03 +03:00
Pavel Shevaev f5d1c418ed Adding improved yet simple validation for functions within namespaces
Publish PHP Package / docker (push) Successful in 6s Details
2024-04-24 16:29:13 +03:00
Pavel Shevaev 3b466a105f Declaring property explicitely
Publish PHP Package / docker (push) Successful in 6s Details
2024-03-14 12:52:08 +03:00
Pavel Shevaev 307d25e303 Добавить .gitea/workflows/build_composer.yaml
Publish PHP Package / docker (push) Successful in 4s Details
2024-02-13 14:49:30 +03:00
Pavel Shevaev 7257fa920f Showing bundle CRC 2023-11-28 11:00:19 +03:00
Pavel Shevaev ae55e3ffb9 Using getIncPath() 2023-11-27 11:49:42 +03:00
Pavel Shevaev e4ba8a762f bhl_validate_func_ref(..) now kinda supports fully namespaced function names: it takes the last item and tries to match it 2023-11-24 16:32:58 +03:00
Pavel Shevaev 6c67e9ab37 Instead of passing BhlProj to routines we rather make it possible to set the active one 2023-11-24 13:43:39 +03:00
Pavel Shevaev 9ffca32323 Adding missing property to BhlProj 2023-11-16 11:20:41 +03:00
Pavel Shevaev 9cfff757c3 Introducing typed BhlProj instead of stdClass 2023-11-16 09:30:06 +03:00
wrenge 3e064092c7 Fixed missing arguments 2023-11-15 13:46:07 +03:00
wrenge 39ecdd39f8 Multiple projects support 2023-11-09 13:02:48 +03:00
Pavel Shevaev c26d06472c Изменил(а) на 'composer.json' 2023-10-24 18:25:15 +03:00
Pavel Shevaev 891db33a8f Tweaking composer autoload 2023-10-24 17:33:57 +03:00
Pavel Shevaev 773bc1b5d9 Making PHPStan happy 2023-08-16 14:10:54 +03:00
madpwnhammer df99a32846 fix windows rel path 2023-07-06 13:06:37 +03:00
Madpwnhammer e3e377d20a Added rel path support to BHL_REF module 2023-06-30 16:07:52 +03:00
Pavel Shevaev 4263855239 Getting rid of contraversary '.local' heuristics 2023-06-27 14:36:49 +03:00
Pavel Shevaev 4c32ed0d08 Adding support to <%BHL_REF(..)%> macro for .local/_Local overrides 2023-05-30 16:35:14 +03:00
Pavel Shevaev 852b90dc7a Adding bhl_make_upm_package(..) 2023-05-29 16:22:38 +03:00
Pavel Shevaev 09c71a0469 Adding BHL_REF macro 2023-05-26 12:00:22 +03:00
Pavel Shevaev 9a7a68499a Removing extra config dependencies and removing obsolete code 2023-05-25 18:07:27 +03:00
Pavel Shevaev 9e3680ff0a Adding @flt_bhl_ref filter 2023-05-18 15:09:35 +03:00
Pavel Shevaev 06e42eb56f Making clean more robust, removing cleaning of .gen.bhl files 2023-05-17 23:28:31 +03:00
Pavel Shevaev 41cef1cea4 Adding support for BHL_PROJ_FILE property 2023-04-25 14:49:13 +03:00
Pavel Shevaev 8febc2c08d Fixing typos 2023-04-18 13:42:35 +03:00
Pavel Shevaev d9243e3108 Migrating to bhl.proj usage 2023-04-18 13:13:45 +03:00
Pavel Shevaev 709d360e98 Showing error counter 2023-03-28 17:39:21 +03:00
Pavel Shevaev 57df25454c Now showing all errors for a compiled file, however showing the first error per line 2023-03-16 17:29:38 +03:00
Pavel Shevaev 91d9ad0946 For now showing only the first error per file 2023-03-02 19:52:11 +03:00
Pavel Shevaev 8839cf79b9 Making error reporting compatible with multiple errors 2023-03-02 18:54:49 +03:00
Pavel Shevaev 2ce0a48f03 Better error checking 2022-12-09 17:24:14 +03:00
Pavel Shevaev da5ce2bae0 Introducing BHL_USE_CACHE prop which is true by default 2022-10-27 15:07:41 +03:00
6 changed files with 362 additions and 288 deletions

View File

@ -0,0 +1,29 @@
name: Publish PHP Package
on:
push:
tags:
- 'v*'
jobs:
docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Get tag name
run: echo "TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: zip and send
run: |
ls -la
apt-get update -y
apt-get install -y zip
cd ../
zip -r ${{ gitea.event.repository.name }}.zip ${{ gitea.event.repository.name }} -x '*.git*'
curl -v \
--user composer-pbl:${{ secrets.COMPOSER_PSWD }} \
--upload-file ${{ gitea.event.repository.name }}.zip \
https://git.bit5.ru/api/packages/bit/composer?version=${{ env.TAG }}

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
tags

View File

@ -12,352 +12,202 @@ task('bhl_clean_cache', function()
bhl_clean_cache();
});
task('bhl_try', function($args = [])
class BhlProj
{
global $GAME_ROOT;
public static ?BhlProj $active = null;
$all_files = array($args[0]);
public string $file_path;
public array $inc_dirs = array();
public array $src_dirs = array();
public array $defines = array();
public array $bindings_sources;
public array $postproc_sources;
public string $postproc_dll;
public string $bindings_dll;
public string $result_file;
public string $error_file;
public string $tmp_dir;
public int $max_threads;
public bool $deterministic;
$bhl_inc_dir = config_base_dir();
$res_file = "$GAME_ROOT/build/bhl.try";
bhl_run_ex(
$bhl_inc_dir,
$all_files,
$res_file,
false/*not debug*/,
true/*force*/
);
});
task('bhl_callstack', ['alias' => 'bhc'], function(array $args)
{
global $GAME_ROOT;
if(count($args) < 1)
function getIncPath() : array
{
echo "Usage: ./gamectl bhl_callstack \"<callstack>\"";
return;
}
$items = explode("\n", $args[0]);
foreach($items as $item)
{
$item = trim($item);
if(!$item)
continue;
if(preg_match('~(\d+)\s+\(\)\s+\(at (\d+):(\d+)\)~', $item, $m))
{
$func_hash = (int)$m[1];
$file_hash = (int)$m[2];
$line_num = (int)$m[3];
$func_name = key(bhl_find_name_hash($func_hash));
$file_name = bhl_find_module($file_hash);
if(!$file_name)
$file_name = "?";
else
$file_name = normalize_path($file_name, true);
echo ($func_name ? $func_name : $func_hash) . "() in $file_name@$line_num \n";
}
}
});
task('bhl_callstack_file', function(array $args)
{
global $GAME_ROOT;
if(count($args) < 1)
{
echo "Usage: ./gamectl bhl_callstack_file \"<path_to_callstack_file>\"";
return;
}
$callstack = ensure_read($args[0]);
run('bhl_callstack', [$callstack]);
});
task('bhl_find_module', function(array $args)
{
if(count($args) < 1)
{
echo "Usage: ./gamectl bhl_find_module <mod_id>";
return;
}
$mod_id = (int)$args[0];
$bhl_file = bhl_find_module($mod_id);
if($bhl_file)
echo "Found '$bhl_file'\n";
});
function bhl_find_name_hash($hash)
{
global $GAME_ROOT;
$result = array();
$files = scan_files_rec(array(config_base_dir()), array('bhl'));
foreach($files as $file)
{
$cont = file_get_contents($file);
if(preg_match_all('/(\w+)/', $cont, $ms))
{
foreach($ms[1] as $name)
{
$name = trim($name, '"');
$var_hash = crc32($name) & 0xFFFFFFF;
if($var_hash === $hash)
{
if(!isset($result[$name]))
$result[$name] = array();
$result[$name][$file] = true;
}
}
}
}
return $result;
}
function bhl_find_module($mod_id)
{
global $GAME_ROOT;
$files = scan_files_rec(array(config_base_dir()), array('.bhl'));
$conf_dir = normalize_path(config_base_dir(), true);
foreach($files as $bhl_file)
{
$module_path = str_replace($conf_dir, '', $bhl_file);
$module_path = ltrim(substr($module_path, 0, strlen($module_path)-4), '/');
if(crc32($module_path) === $mod_id)
return $bhl_file;
if($this->inc_dirs)
return $this->inc_dirs;
return $this->src_dirs;
}
}
function bhl_result_file()
function bhl_proj_file() : string
{
global $GAME_ROOT;
return "$GAME_ROOT/build/ext_config/bhl.bytes";
return get('BHL_PROJ_FILE');
}
function bhl_dir()
function bhl_proj_load(string $proj_file) : BhlProj
{
$arr = json_decode(ensure_read($proj_file), true);
if(!$arr)
throw new Exception("Bad bhl project file: $proj_file");
$proj = new BhlProj();
foreach($arr as $k => $v)
$proj->{$k} = $v;
//NOTE: adding path to the file for further convenience
$proj->file_path = $proj_file;
foreach($proj->inc_dirs as $k => $v)
$proj->inc_dirs[$k] = _bhl_make_abs_path($proj_file, $v);
foreach($proj->src_dirs as $k => $v)
$proj->src_dirs[$k] = _bhl_make_abs_path($proj_file, $v);
foreach($proj->bindings_sources as $k => $v)
$proj->bindings_sources[$k] = _bhl_make_abs_path($proj_file, $v);
$proj->bindings_dll = _bhl_make_abs_path($proj_file, $proj->bindings_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);
return $proj;
}
function bhl_proj_set_active(BhlProj $proj) : ?BhlProj
{
$prev = BhlProj::$active;
BhlProj::$active = $proj;
return $prev;
}
function bhl_proj() : BhlProj
{
if(BhlProj::$active == null)
{
$proj = bhl_proj_load(bhl_proj_file());
BhlProj::$active = $proj;
}
return BhlProj::$active;
}
function _bhl_make_abs_path(string $proj_file, string $path) : string
{
if($path && $path[0] == '.')
return dirname($proj_file) . '/' . $path;
else
return $path;
}
function bhl_result_file() : string
{
return bhl_proj()->result_file;
}
function bhl_dir() : string
{
global $GAME_ROOT;
return "$GAME_ROOT/composer/vendor/bit/bhl";
}
function bhl_shell($cmd, &$ret_var, &$ret_out)
function bhl_shell(string $cmd, &$ret_var, &$ret_out)
{
$prev_path = mono_try_override_path();
try
{
shell_try(bhl_dir()."/bhl $cmd", $ret_var, $ret_out);
}
finally
{
mono_try_restore_path($prev_path);
}
shell_try(bhl_dir()."/bhl $cmd", $ret_var, $ret_out);
}
function bhl_shell_ensure($cmd)
function bhl_shell_ensure(string $cmd)
{
bhl_shell($cmd, $ret_var, $ret_out);
if($ret_var !== 0)
throw new Exception("Error executing shell cmd: $ret_var");
}
function bhl_run($debug = true, $force = false, $check_deps = true, $exit_on_err = true)
function bhl_scan_files() : array
{
return scan_files_rec(bhl_proj()->src_dirs, array('.bhl'));
}
function bhl_run(bool $debug = true, bool $force = false, bool $exit_on_err = true)
{
global $GAME_ROOT;
$bhl_inc_dir = config_base_dir();
$bhl_proj = bhl_proj();
$result_file = $bhl_proj->result_file;
$all_files = scan_files_rec(array(config_base_dir()), array('.bhl'));
$res_file = bhl_result_file();
_bhl_shuffle_files($all_files);
$res_file = bhl_result_file();
$res = bhl_run_ex($bhl_inc_dir, $all_files, $res_file, $debug, $force, $check_deps, $exit_on_err);
return $res;
}
function _bhl_shuffle_files(&$files)
{
shuffle($files);
}
function bhl_run_ex($bhl_inc_dir, array $bhl_files, $result_file, $debug = true, $force = false, $check_deps = true, $exit_on_err = true)
{
global $GAME_ROOT;
ensure_mkdir("$GAME_ROOT/build");
$post_proc_file = "$GAME_ROOT/build/bhl.post.".crc32($result_file);
$err_file = "$GAME_ROOT/build/bhl.error";
ensure_rm($err_file);
$user_sources = getor("BHL_USER_SOURCES", array(
get("UNITY_ASSETS_DIR")."/Scripts/bhl/register.cs",
get("UNITY_ASSETS_DIR")."/Scripts/bhl/autobind.cs"
));
$postproc_sources = getor("BHL_POSTPROC_SOURCES", array(
get("UNITY_ASSETS_DIR")."/Scripts/bhl/postproc.cs",
));
$bhl_deps = $bhl_files;
$bhl_deps = array_merge($bhl_deps, $user_sources);
$bhl_deps = array_merge($bhl_deps, $postproc_sources);
$bhl_deps = array_merge($bhl_deps, scan_files_rec(array(bhl_dir()), array(".cs")));
if($force || need_to_regen($result_file, $bhl_deps) || need_to_regen($post_proc_file, $bhl_deps))
if($force || need_to_regen($result_file, bhl_scan_files()))
{
$bhl_file_list = "$GAME_ROOT/build/bhl/file_list.tmp";
ensure_write($bhl_file_list, implode("\n", $bhl_files));
putenv("POSTPROC_PROJ_ROOT=$GAME_ROOT");
putenv("POSTPROC_RESULT=$post_proc_file");
if($force)
putenv("POSTPROC_FORCE=1");
$bhl_dir = bhl_dir();
bhl_shell("compile " .
"--user-sources=".implode(",",$user_sources)." --postproc-sources=".implode(",",$postproc_sources)." " .
"--dir=$bhl_inc_dir --files=$bhl_file_list --result=$result_file " .
"--tmp-dir=$GAME_ROOT/build/bhl/ " .
"--error=$GAME_ROOT/build/bhl.error " .
"--deterministic " .
"--threads=" . getor("BHL_MAX_THREADS", is_win() ? 1 : 4) . " " .
bhl_shell("compile -p " . $bhl_proj->file_path . " " .
($debug ? " -d" : "") . " " .
($force ? " -C" : "") . " ".
(!$check_deps ? " -N" : "") . " ",
($force || !getor("BHL_USE_CACHE", true) ? " -C" : ""),
$ret_var, $ret_out
);
if($ret_var != 0)
{
bhl_handle_error_result($ret_out, $err_file, $exit_on_err);
bhl_handle_error_result($ret_out, $bhl_proj->error_file, $exit_on_err);
if(!$exit_on_err)
return false;
}
else
echo "BHL BUNDLE: total " . kb_len(filesize($result_file)) . "\n";
else if($debug)
echo "BHL BUNDLE: total " . kb_len(filesize($result_file)) . ", CRC " . hexdec(hash_file('CRC32', $result_file, false)) . "\n";
}
@touch($result_file);
@touch($post_proc_file);
$res = bhl_ast_post_proc($result_file, $post_proc_file);
return $res;
}
function bhl_handle_error_result(array $ret_out, $err_file, $exit = true)
function bhl_handle_error_result(array $ret_out, string $err_file, bool $exit = true)
{
if(!is_file($err_file))
{
stderr("Something went wrong: " . (is_array($ret_out) ? implode("\n", $ret_out) : "????"));
stderr("Something went wrong: " . implode("\n", $ret_out));
if($exit)
exit(1);
}
$err = file_get_contents($err_file);
$jerr = json_decode($err);
if(!$jerr)
$history = array();
$err_lines = file($err_file);
$err_count = 0;
foreach($err_lines as $err)
{
stderr("Something went wrong, bhl error is in invalid format: $err");
if($exit)
exit(1);
}
$file = $jerr->file;
$jerr = json_decode($err);
if(!$jerr)
{
stderr("Something went wrong, bhl error is in invalid format: $err\n");
continue;
}
stderr("BHL ERROR: \n" . $jerr->error . " \nin '$file', line {$jerr->line}\n");
stderr(bhl_show_position($jerr->line, $jerr->column, file($file)) . "\n");
if($exit)
$file = $jerr->file;
//let's show only one error per file's line
if(isset($history[$file.$jerr->line]))
continue;
$history[$file.$jerr->line] = true;
++$err_count;
stderr("BHL ERROR (#$err_count): " . $jerr->error . " \nin '$file', line {$jerr->line}\n");
if(file_exists($file))
stderr(bhl_show_position($jerr->line, $jerr->column, file($file)) . "\n");
}
if($err_lines && $exit)
exit(1);
}
class BhlAstProcResult
{
var $res_file;
var $func2assets_deep = array();
var $func2refs_deep = array();
}
function bhl_ast_post_proc($res_file, $post_proc_file)
{
$res = new BhlAstProcResult();
$res->res_file = $res_file;
$data = ensure_read($post_proc_file);
if(!$data)
return $res;
$data = config_msgpack_unpack($data);
if(!$data)
return $res;
$func2assets = $data[0];
foreach($func2assets as $item)
{
list($func1, $func2, $assets) = $item;
$func = ($func2 << 31) | $func1;
$res->func2assets_deep[$func] = array_flip($assets);
}
$func2crefs = $data[1];
foreach($func2crefs as $item)
{
list($func1, $func2, $crefs) = $item;
$func = ($func2 << 31) | $func1;
$res->func2refs_deep[$func] = array_flip($crefs);
}
return $res;
}
function bhl_clean()
{
global $GAME_ROOT;
$files = scan_files_rec(array(config_base_dir()), array('js', 'gen.bhl'));
foreach($files as $file)
{
$is_conf = strpos($file, '.gen.bhl') === false;
if($is_conf)
{
//skipping .def.js files
if(strpos($file, '.def.js') !== false)
continue;
@touch($file);
}
else if(!$is_conf)
{
ensure_rm($file);
}
}
bhl_clean_cache();
bhl_shell_ensure("clean");
bhl_shell("clean", $ret, $out);
}
function bhl_clean_cache()
{
global $GAME_ROOT;
ensure_rm("$GAME_ROOT/build/bhl/");
ensure_rm(bhl_proj()->tmp_dir);
}
function bhl_show_position($line, $row, array $lines)
function bhl_show_position(int $line, int $row, array $lines) : string
{
if($line > 0 && $line <= count($lines))
{
@ -377,7 +227,7 @@ function bhl_show_position($line, $row, array $lines)
return "??? @($line:$row)";
}
function bhl_line_row_to_pos($file, $line, $row)
function bhl_line_row_to_pos(string $file, int $line, int $row) : ?int
{
$pos = 0;
$lines = file($file);
@ -389,3 +239,127 @@ function bhl_line_row_to_pos($file, $line, $row)
$pos += $row;
return $pos;
}
function bhl_map_module_to_file(string $module) : ?string
{
$bhl_proj = bhl_proj();
foreach($bhl_proj->getIncPath() as $dir)
{
$tmp = $dir.'/'.$module.'.bhl';
if(file_exists($tmp))
return $tmp;
}
return null;
}
function bhl_validate_func_ref(string $module_file, string $func_full_name, array $signature)
{
if(sizeof($signature) == 0)
throw new Exception("Signature is invalid");
$name_items = explode('.', $func_full_name);
$func = array_pop($name_items);
$namespace = implode('.', $name_items);
$module_src = file_get_contents($module_file);
$module_src = _bhl_remove_comments($module_src);
if(!$module_src)
throw new Exception("Bad module file '{$module_file}'");
$ns_chunks = _bhl_split_by_namespaces($module_src);
$module_chunks = array();
if($namespace)
{
if(!isset($ns_chunks[$namespace]))
throw new Exception("No namespace '$namespace' found in '$module_file'");
foreach($ns_chunks[$namespace] as $ns_src)
$module_chunks[] = $ns_src;
}
else
{
if(!isset($ns_chunks['']))
throw new Exception("No global namespace found in '$module_file'");
foreach($ns_chunks[''] as $ns_src)
$module_chunks[] = $ns_src;
}
$signature_pattern = '';
$signature_pattern .= '~func\s+';
if($signature[0] !== 'void')
{
$signature_pattern .= preg_quote($signature[0]);
$signature_pattern .= '\s+';
}
$signature_pattern .= $func;
$signature_pattern .= '\s*\(';
array_shift($signature);
foreach($signature as $type)
{
$signature_pattern .= '\s*';
$signature_pattern .= preg_quote($type);
$signature_pattern .= '\s*\S+';
$signature_pattern .= '\s*,';
}
$signature_pattern = rtrim($signature_pattern, '\s*,');
$signature_pattern .= '\s*\)';
$signature_pattern .= '~';
foreach($module_chunks as $module_chunk_src)
{
if(preg_match($signature_pattern, $module_chunk_src))
return;
}
throw new Exception("Func '$func_full_name(".implode(',', $signature).")' not found in '$module_file'");
}
function _bhl_remove_comments(string $txt) : string
{
//block comments
if(strpos($txt, '/*') !== false)
{
$regex = '~/\*.*?\*/~s';
$txt = preg_replace_callback(
$regex,
//preserve the new lines for better error reporting
function($m) { return str_repeat("\n", substr_count($m[0], "\n")); },
$txt);
}
//line comments
$txt = preg_replace("~\s*(?<!:)//.*~", "\n", $txt);
return $txt;
}
function _bhl_split_by_namespaces(string $src) : array
{
$nss = array();
$chunks = preg_split('~^\s*(namespace\s+[^\{]+){~m', $src, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
for($i=0;$i<count($chunks);)
{
$chunk = $chunks[$i];
if(strpos(ltrim($chunk), 'namespace ') === 0)
{
$ns = trim(substr(ltrim($chunk), 9));
$body = $chunks[$i+1];
if(!isset($nss[$ns]))
$nss[$ns] = array();
$nss[$ns][] = $body;
$i+=2;
}
else
{
if(!isset($nss['']))
$nss[''] = array();
$nss[''][] = $chunk;
++$i;
}
}
return $nss;
}

26
bhl_flt.inc.php Normal file
View File

@ -0,0 +1,26 @@
<?php
namespace metagen_php;
use Exception;
function flt_bhl_ref($val, $name, $data, $str_args)
{
if(!$val)
return $val;
if(!isset($val['module']))
throw new Exception("Missing 'module'");
$module_file = \taskman\bhl_map_module_to_file($val['module']);
if(!$module_file)
throw new Exception("Module not found '{$val['module']}");
if(!isset($val['fn']))
throw new Exception("Missing 'fn'");
$args = explode(",", $str_args);
\taskman\bhl_validate_func_ref($module_file, $val['fn'], $args);
return $val;
}

47
bhl_macro.inc.php Normal file
View File

@ -0,0 +1,47 @@
<?php
/**
* @global
*/
function macro_BHL_REF($proc, $module, $func, $signature_json = '')
{
//check if it's a relative path
if($module[0] == '.')
{
$abs_module = \taskman\normalize_path(dirname($proc->getRootFile()) . '/' . $module);
$mapped = false;
$bhl_proj = \taskman\bhl_proj();
$inc_path = $bhl_proj->getIncPath();
foreach($inc_path as $dir)
{
$rel_module = str_replace(\taskman\normalize_path($dir), '', $abs_module);
if($rel_module != $abs_module)
{
$mapped = true;
$rel_module = str_replace('\\', '/', $rel_module);
$module = "/" . $rel_module;
break;
}
}
if(!$mapped)
throw new Exception("Could not map relative module: $module");
}
$module_file = \taskman\bhl_map_module_to_file($module);
if(!$module_file)
throw new Exception("Module not found '{$module}'");
//validate signature only if it's explicitely passed
if($signature_json)
{
$signature = json_decode($signature_json, false);
if(!is_array($signature))
throw new Exception("Signature is invalid '$module'");
\taskman\bhl_validate_func_ref($module_file, $func, $signature);
}
return array('module' => ltrim($module, '/'), 'fn' => $func);
}

View File

@ -4,8 +4,5 @@
"homepage": "https://git.bit5.ru/composer/taskman_bhl",
"require": {
"php": ">=7.4"
},
"autoload": {
"classmap": ["bhl.inc.php"]
}
}