From 9d9c46a8ef6f256fd2a284699db7a2b980a9e43d Mon Sep 17 00:00:00 2001 From: Pavel Shevaev Date: Tue, 21 Mar 2023 18:39:27 +0300 Subject: [PATCH] Making unity_exec(..) more robust and reliable --- unity.inc.php | 78 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 32 deletions(-) diff --git a/unity.inc.php b/unity.inc.php index ada0b04..82dae78 100644 --- a/unity.inc.php +++ b/unity.inc.php @@ -20,17 +20,7 @@ task('unity', function() task('unity_kill', function() { - $proc_id = unity_find_proc_id(); - if($proc_id) - { - echo "Found Unity process '$proc_id', killing it...\n"; - system("kill -9 $proc_id"); - sleep(5); - } - else - { - echo "No Unity process found to kill\n"; - } + unity_kill(); }); function unity_exec($func, $build_target = "", $quit = true, $batchmode = true) @@ -67,31 +57,42 @@ function unity_exec($func, $build_target = "", $quit = true, $batchmode = true) return array($log_file, $pid); } -function unity_batch_exec($func, $build_target = "", $notify = true) +function unity_batch_exec($func, $build_target = "") { global $GAME_ROOT; - try - { - list($log_file, $pid) = unity_exec($func, $build_target, /*$quit = */ true, /*$batchmode = */ true); + unity_kill(); - watch_running_process($pid, $log_file, - array( - 'Exiting batchmode successfully' - ), - array( - 'Build Finished, Result: Failure', - 'Aborting batchmode due to failure', - 'Launching bug reporter', + list($log_file, $pid) = unity_exec($func, $build_target, /*$quit = */ true, /*$batchmode = */ true); + + watch_running_process( + $pid, + $log_file, + array( + 'Exiting batchmode successfully', + 'Batchmode quit successfully invoked - shutting down!' + ), + array( + 'Build Finished, Result: Failure', + 'UnityException:', + 'Aborting batchmode due to failure', + 'Launching bug reporter', + 'Unrecognized assets cannot be included in AssetBundles:' + ), + true, + -1, + //ignored errors: + array( + //NOTE: weird editor crash, sometimes happens on exit after batch task is actually done + // seems like it's never been fixed though issue tracker says otherwise (https://vk.cc/bYpyUS) + "Fatal Error! GetManagerFromContext: pointer to object of manager 'MonoManager' is NULL (table index 5)" + ), + + //noted warnings: they don't abort execution but show up at the end of the log if command fails + array( ': error CS', - 'Unrecognized assets cannot be included in AssetBundles:' - ) - ); - } - catch(Exception $e) - { - throw $e; - } + ) + ); } function unity_run_proc($shared_cmd) @@ -115,6 +116,19 @@ function unity_run_proc($shared_cmd) return trim($out[0]); } +function unity_kill() +{ + $proc_id = unity_find_proc_id(); + if($proc_id) + { + echo "Found Unity process '$proc_id', killing it...\n"; + system("kill -9 $proc_id"); + sleep(5); + } + else + echo "No Unity process found to kill\n"; +} + function unity_find_proc_id() { global $GAME_ROOT; @@ -295,7 +309,7 @@ function run_mono($exe_file) $exe_file = normalize_path($exe_file, !is_win()); $mono_path = realpath(dirname($mono_bin) . '/../lib/mono/unity'); - putenv("MONO_PATH=$mono_path"); //To LOCATION_PATH? + putenv("MONO_PATH=$mono_path"); $cmd = "$mono_bin $exe_file"; shell($cmd); }