Compare commits

..

16 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
4 changed files with 120 additions and 86 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 }}

View File

@ -12,10 +12,6 @@ task('bhl_clean_cache', function()
bhl_clean_cache(); bhl_clean_cache();
}); });
task('bhl_make_upm_package', function() {
bhl_make_upm_package();
});
class BhlProj class BhlProj
{ {
public static ?BhlProj $active = null; public static ?BhlProj $active = null;
@ -23,6 +19,7 @@ class BhlProj
public string $file_path; public string $file_path;
public array $inc_dirs = array(); public array $inc_dirs = array();
public array $src_dirs = array(); public array $src_dirs = array();
public array $defines = array();
public array $bindings_sources; public array $bindings_sources;
public array $postproc_sources; public array $postproc_sources;
public string $postproc_dll; public string $postproc_dll;
@ -102,7 +99,7 @@ function bhl_proj() : BhlProj
return BhlProj::$active; return BhlProj::$active;
} }
function _bhl_make_abs_path($proj_file, $path) function _bhl_make_abs_path(string $proj_file, string $path) : string
{ {
if($path && $path[0] == '.') if($path && $path[0] == '.')
return dirname($proj_file) . '/' . $path; return dirname($proj_file) . '/' . $path;
@ -110,44 +107,35 @@ function _bhl_make_abs_path($proj_file, $path)
return $path; return $path;
} }
function bhl_result_file() function bhl_result_file() : string
{ {
return bhl_proj()->result_file; return bhl_proj()->result_file;
} }
function bhl_dir() function bhl_dir() : string
{ {
global $GAME_ROOT; global $GAME_ROOT;
return "$GAME_ROOT/composer/vendor/bit/bhl"; 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); shell_try(bhl_dir()."/bhl $cmd", $ret_var, $ret_out);
}
finally
{
mono_try_restore_path($prev_path);
}
} }
function bhl_shell_ensure($cmd) function bhl_shell_ensure(string $cmd)
{ {
bhl_shell($cmd, $ret_var, $ret_out); bhl_shell($cmd, $ret_var, $ret_out);
if($ret_var !== 0) if($ret_var !== 0)
throw new Exception("Error executing shell cmd: $ret_var"); throw new Exception("Error executing shell cmd: $ret_var");
} }
function bhl_scan_files() function bhl_scan_files() : array
{ {
return scan_files_rec(bhl_proj()->src_dirs, array('.bhl')); return scan_files_rec(bhl_proj()->src_dirs, array('.bhl'));
} }
function bhl_run($debug = true, $force = false, $exit_on_err = true) function bhl_run(bool $debug = true, bool $force = false, bool $exit_on_err = true)
{ {
global $GAME_ROOT; global $GAME_ROOT;
@ -168,14 +156,12 @@ function bhl_run($debug = true, $force = false, $exit_on_err = true)
if(!$exit_on_err) if(!$exit_on_err)
return false; return false;
} }
else else if($debug)
echo "BHL BUNDLE: total " . kb_len(filesize($result_file)) . "\n"; echo "BHL BUNDLE: total " . kb_len(filesize($result_file)) . ", CRC " . hexdec(hash_file('CRC32', $result_file, false)) . "\n";
} }
@touch($result_file);
} }
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)) if(!is_file($err_file))
{ {
@ -213,7 +199,7 @@ function bhl_handle_error_result(array $ret_out, $err_file, $exit = true)
function bhl_clean() function bhl_clean()
{ {
bhl_clean_cache(); bhl_clean_cache();
bhl_shell_ensure("clean"); bhl_shell("clean", $ret, $out);
} }
function bhl_clean_cache() function bhl_clean_cache()
@ -221,7 +207,7 @@ function bhl_clean_cache()
ensure_rm(bhl_proj()->tmp_dir); 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)) if($line > 0 && $line <= count($lines))
{ {
@ -241,7 +227,7 @@ function bhl_show_position($line, $row, array $lines)
return "??? @($line:$row)"; 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; $pos = 0;
$lines = file($file); $lines = file($file);
@ -254,7 +240,7 @@ function bhl_line_row_to_pos($file, $line, $row)
return $pos; return $pos;
} }
function bhl_map_module_to_file($module) function bhl_map_module_to_file(string $module) : ?string
{ {
$bhl_proj = bhl_proj(); $bhl_proj = bhl_proj();
foreach($bhl_proj->getIncPath() as $dir) foreach($bhl_proj->getIncPath() as $dir)
@ -266,16 +252,41 @@ function bhl_map_module_to_file($module)
return null; return null;
} }
function bhl_validate_func_ref($module_file, $func, array $signature) function bhl_validate_func_ref(string $module_file, string $func_full_name, array $signature)
{ {
if(sizeof($signature) == 0) if(sizeof($signature) == 0)
throw new Exception("Signature is invalid"); 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 = file_get_contents($module_file);
$module_src = _bhl_remove_comments($module_src);
if(!$module_src) if(!$module_src)
throw new Exception("Bad module file '{$module_file}'"); 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 = '';
$signature_pattern .= '~func\s+'; $signature_pattern .= '~func\s+';
if($signature[0] !== 'void') if($signature[0] !== 'void')
@ -297,64 +308,58 @@ function bhl_validate_func_ref($module_file, $func, array $signature)
$signature_pattern .= '\s*\)'; $signature_pattern .= '\s*\)';
$signature_pattern .= '~'; $signature_pattern .= '~';
if(!preg_match($signature_pattern, $module_src)) foreach($module_chunks as $module_chunk_src)
throw new Exception("Func '$func' signature '".implode(',', $signature)."' not found in module '$module_file'"); {
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_upm_path() function _bhl_remove_comments(string $txt) : string
{ {
global $GAME_ROOT; //block comments
$pkg_dir = get("UNITY_ASSETS_DIR") . '/../Packages/bhl'; if(strpos($txt, '/*') !== false)
return $pkg_dir; {
$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_clean_upm_package() function _bhl_split_by_namespaces(string $src) : array
{ {
ensure_rm(bhl_upm_path() . '/Runtime/code/'); $nss = array();
}
$chunks = preg_split('~^\s*(namespace\s+[^\{]+){~m', $src, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
function bhl_make_upm_package()
{ for($i=0;$i<count($chunks);)
global $GAME_ROOT; {
$chunk = $chunks[$i];
$pkg_dir = bhl_upm_path(); if(strpos(ltrim($chunk), 'namespace ') === 0)
ensure_mkdir($pkg_dir); {
$ns = trim(substr(ltrim($chunk), 9));
$srcs = array(); $body = $chunks[$i+1];
$lines = file(bhl_dir() . '/bhl.cs'); if(!isset($nss[$ns]))
$started = false; $nss[$ns] = array();
foreach($lines as $line) $nss[$ns][] = $body;
{ $i+=2;
if(!$started && strpos($line, 'static readonly string[] VM_SRC = new string[] {') !== false) }
{ else
$started = true; {
continue; if(!isset($nss['']))
} $nss[''] = array();
else if($started && strpos($line, '};') !== false) $nss[''][] = $chunk;
break; ++$i;
else if($started) }
{ }
$mask = trim($line);
$mask = str_replace('$"{BHL_ROOT}/', '', $mask); return $nss;
$mask = str_replace('",', '', $mask);
$srcs = array_merge($srcs, glob(bhl_dir() . '/' . $mask));
}
}
$trgs = array();
$changed = false;
foreach($srcs as $src)
{
$trg = $pkg_dir . '/Runtime/code/' . str_replace(bhl_dir(), '', $src);
if(!is_file($trg) || file_get_contents($src) != file_get_contents($trg))
$changed = true;
$trgs[$src] = $trg;
}
if($changed)
{
bhl_clean_upm_package();
foreach($trgs as $src => $trg)
ensure_copy($src, $trg);
}
} }

View File

@ -2,7 +2,7 @@
namespace metagen_php; namespace metagen_php;
use Exception; use Exception;
function flt_bhl_ref($val, $name, $struct, $str_args) function flt_bhl_ref($val, $name, $data, $str_args)
{ {
if(!$val) if(!$val)
return $val; return $val;

View File

@ -12,7 +12,7 @@ function macro_BHL_REF($proc, $module, $func, $signature_json = '')
$mapped = false; $mapped = false;
$bhl_proj = \taskman\bhl_proj(); $bhl_proj = \taskman\bhl_proj();
$inc_path = isset($bhl_proj->inc_dirs) ? $bhl_proj->inc_dirs : $bhl_proj->src_dirs; $inc_path = $bhl_proj->getIncPath();
foreach($inc_path as $dir) foreach($inc_path as $dir)
{ {