Migrating to bhl.proj usage
This commit is contained in:
parent
709d360e98
commit
d9243e3108
171
bhl.inc.php
171
bhl.inc.php
|
@ -12,24 +12,6 @@ task('bhl_clean_cache', function()
|
||||||
bhl_clean_cache();
|
bhl_clean_cache();
|
||||||
});
|
});
|
||||||
|
|
||||||
task('bhl_try', function($args = [])
|
|
||||||
{
|
|
||||||
global $GAME_ROOT;
|
|
||||||
|
|
||||||
$all_files = array($args[0]);
|
|
||||||
|
|
||||||
$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)
|
task('bhl_callstack', ['alias' => 'bhc'], function(array $args)
|
||||||
{
|
{
|
||||||
global $GAME_ROOT;
|
global $GAME_ROOT;
|
||||||
|
@ -141,10 +123,53 @@ function bhl_find_module($mod_id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function bhl_proj_file()
|
||||||
|
{
|
||||||
|
return config_base_dir() . '/bhl.proj';
|
||||||
|
}
|
||||||
|
|
||||||
|
function bhl_proj()
|
||||||
|
{
|
||||||
|
global $GAME_ROOT;
|
||||||
|
|
||||||
|
static $proj;
|
||||||
|
if(!$proj)
|
||||||
|
{
|
||||||
|
$proj_file = bhl_proj_file();
|
||||||
|
$proj = json_decode(ensure_read($proj_file));
|
||||||
|
if(!$proj)
|
||||||
|
throw new Exception("Bad bhl project file: $proj_file");
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
$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_make_abs_path($proj_file, $path)
|
||||||
|
{
|
||||||
|
if($path[0] == '.')
|
||||||
|
return dirname($proj_file) . '/' . $path;
|
||||||
|
else
|
||||||
|
return $path;
|
||||||
|
}
|
||||||
|
|
||||||
function bhl_result_file()
|
function bhl_result_file()
|
||||||
{
|
{
|
||||||
global $GAME_ROOT;
|
global $GAME_ROOT;
|
||||||
return "$GAME_ROOT/build/ext_config/bhl.bytes";
|
return bhl_proj()->result_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
function bhl_dir()
|
function bhl_dir()
|
||||||
|
@ -174,74 +199,17 @@ function bhl_shell_ensure($cmd)
|
||||||
throw new Exception("Error executing shell cmd: $ret_var");
|
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_run($debug = true, $force = false, $exit_on_err = true)
|
||||||
{
|
{
|
||||||
global $GAME_ROOT;
|
global $GAME_ROOT;
|
||||||
|
|
||||||
$bhl_inc_dir = config_base_dir();
|
$result_file = bhl_proj()->result_file;
|
||||||
|
|
||||||
$all_files = scan_files_rec(array(config_base_dir()), array('.bhl'));
|
if($force || need_to_regen($result_file, scan_files_rec(bhl_proj()->src_dirs, 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))
|
|
||||||
{
|
{
|
||||||
$bhl_file_list = "$GAME_ROOT/build/bhl/file_list.tmp";
|
bhl_shell("compile -p " . bhl_proj_file() . " " .
|
||||||
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) . " " .
|
|
||||||
($debug ? " -d" : "") . " " .
|
($debug ? " -d" : "") . " " .
|
||||||
($force || !getor("BHL_USE_CACHE", true) ? " -C" : "") . " ".
|
($force || !getor("BHL_USE_CACHE", true) ? " -C" : ""),
|
||||||
(!$check_deps ? " -N" : "") . " ",
|
|
||||||
$ret_var, $ret_out
|
$ret_var, $ret_out
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -256,10 +224,6 @@ function bhl_run_ex($bhl_inc_dir, array $bhl_files, $result_file, $debug = true,
|
||||||
}
|
}
|
||||||
|
|
||||||
@touch($result_file);
|
@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, $err_file, $exit = true)
|
||||||
|
@ -297,43 +261,6 @@ function bhl_handle_error_result(array $ret_out, $err_file, $exit = true)
|
||||||
exit(1);
|
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()
|
function bhl_clean()
|
||||||
{
|
{
|
||||||
global $GAME_ROOT;
|
global $GAME_ROOT;
|
||||||
|
|
Loading…
Reference in New Issue