Adding more stuff

This commit is contained in:
Pavel Shevaev 2022-05-19 18:50:30 +03:00
parent b365b56211
commit 07100f700d
1 changed files with 167 additions and 1 deletions

View File

@ -32,7 +32,6 @@ task('unity_kill', function()
}
});
function unity_exec($func, $build_target = "", $quit = true, $batchmode = true)
{
global $GAME_ROOT;
@ -159,3 +158,170 @@ function get_unity_dir()
return "$app_dir/Unity.app/Contents/";
}
function mono_mcs_bin()
{
if(!get("USE_UNITY_MONO"))
return 'mcs';
$unity_dir = get_unity_dir();
if(!is_dir($unity_dir))
throw new Exception("Unity directory doesn't exist: $unity_dir");
$canidates = array(
"$unity_dir/Mono/bin/gmcs",
"$unity_dir/MonoBleedingEdge/bin/mcs",
"$unity_dir/Frameworks/Mono/bin/gmcs",
"$unity_dir/Mono/bin/gmcs",
);
foreach($canidates as $mcs_bin)
{
if(is_file($mcs_bin))
{
if(is_win())
return '"' . normalize_path($mcs_bin, false) . '"';
else
return $mcs_bin;
}
}
throw new Exception("Mono compiler binary not found");
}
function mono_try_override_path()
{
if(!get("USE_UNITY_MONO"))
return '';
$mono_dir = dirname(trim(mono_mcs_bin(), '"'));
$prev_path = getenv('PATH');
echo "UNITY MONO PATH=$mono_dir\n";
putenv("PATH=$mono_dir".(is_win() ? ";" : ":")."$prev_path");
return $prev_path;
}
function mono_try_restore_path($prev_path)
{
if(!get("USE_UNITY_MONO"))
return;
putenv("PATH=$prev_path");
}
function build_mono_dll($src_spec, $out_file, $ref_dlls = array(), $mcs_opts = "")
{
build_mono($src_spec, $out_file, $ref_dlls, "$mcs_opts -target:library");
}
function build_mono($src_spec, $out_file, $ref_dlls = array(), $mcs_opts = "")
{
global $GAME_ROOT;
$unity_dir = get_unity_dir();
$mcs_bin = mono_mcs_bin();
if(is_array($src_spec))
$sources = $src_spec;
else if(is_dir($src_spec))
$sources = scan_files_rec(array($src_spec), array('.cs'));
else
$sources = glob($src_spec);
$sources_str = '';
foreach($sources as $src)
{
if(is_win())
$sources_str .= '"'.normalize_path($src, !is_win()).'" ';
else
$sources_str .= '\''.normalize_path($src, !is_win()).'\' ';
}
$deps = $sources;
$refs_str = "";
foreach($ref_dlls as $ref_dll)
{
if($ref_dll === "UnityEngine.dll")
{
$ref_dll = "$unity_dir/Managed/UnityEngine.dll";
if(!is_file($ref_dll))
$ref_dll = "$unity_dir/Frameworks/Managed/UnityEngine.dll";
}
$ref_dll = normalize_path($ref_dll, !is_win());
$refs_str .= "-r:\"$ref_dll\" ";
$deps[] = $ref_dll;
}
$out_file = normalize_path($out_file, !is_win());
$cmd = "$mcs_bin $mcs_opts $refs_str -out:$out_file $sources_str";
if(is_string($src_spec) && is_dir($src_spec))
$cmd = "cd $src_spec && $cmd";
$cmd_hash = crc32($cmd);
$cmd_hash_file = "$GAME_ROOT/build/" . crc32($out_file) . ".mhash";
if(!is_file($cmd_hash_file) || file_get_contents($cmd_hash_file) != "$cmd_hash")
file_put_contents($cmd_hash_file, "$cmd_hash");
$deps[] = $cmd_hash_file;
if(need_to_regen($out_file, $deps))
{
ensure_mkdir(dirname($out_file));
shell($cmd);
echo "> $out_file " . round(filesize($out_file)/1024, 2) . "kb\n";
}
}
function run_mono($exe_file)
{
$app_dir = get('UNITY_APP_DIR');
if(is_win())
{
$unity_dir = "$app_dir/Editor/Data";
$mono_bin = '"' . normalize_path("$unity_dir/Mono/bin/mono", !is_win()) . '"';
}
else
{
$unity_dir = "$app_dir/Unity.app/Contents/";
if(is_dir("$unity_dir/Frameworks/Mono"))
$mono_bin = "$unity_dir/Frameworks/Mono/bin/mono";
else
$mono_bin = "$unity_dir/Mono/bin/mono";
}
$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?
$cmd = "$mono_bin $exe_file";
shell($cmd);
}
function build_option_exists($option)
{
return strpos(getor("BUILD_CLIENT_OPTS", ""), $option) !== FALSE;
}
function build_option_add($option)
{
if(build_option_exists($option))
return;
$propname = "BUILD_CLIENT_OPTS";
$opts = getor($propname, "");
if(strlen($opts) > 0)
$opts .= ",$option";
else
$opts = $option;
set($propname, $opts);
}
function is_gradle_project_export()
{
return build_option_exists("AcceptExternalModificationsToPlayer");
}