Removing extra config dependencies and removing obsolete code

This commit is contained in:
Pavel Shevaev 2023-05-25 18:07:27 +03:00
parent 9e3680ff0a
commit 9a7a68499a
1 changed files with 7 additions and 113 deletions

View File

@ -12,120 +12,9 @@ task('bhl_clean_cache', function()
bhl_clean_cache();
});
task('bhl_callstack', ['alias' => 'bhc'], function(array $args)
{
global $GAME_ROOT;
if(count($args) < 1)
{
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;
}
}
function bhl_proj_file()
{
return getor('BHL_PROJ_FILE', config_base_dir() . '/bhl.proj');
return get('BHL_PROJ_FILE');
}
function bhl_proj()
@ -199,13 +88,18 @@ function bhl_shell_ensure($cmd)
throw new Exception("Error executing shell cmd: $ret_var");
}
function bhl_scan_files()
{
return scan_files_rec(bhl_proj()->src_dirs, array('.bhl'));
}
function bhl_run($debug = true, $force = false, $exit_on_err = true)
{
global $GAME_ROOT;
$result_file = bhl_proj()->result_file;
if($force || need_to_regen($result_file, scan_files_rec(bhl_proj()->src_dirs, array('.bhl'))))
if($force || need_to_regen($result_file, bhl_scan_files()))
{
bhl_shell("compile -p " . bhl_proj_file() . " " .
($debug ? " -d" : "") . " " .