Compare commits

...

10 Commits

Author SHA1 Message Date
Pavel Shevaev 4361e7579e Gradually migrating to iterable instead of arrays
Publish PHP Package / docker (push) Successful in 8s Details
2025-03-06 13:20:59 +03:00
Pavel Shevaev 616c2c46d1 Fixing names_hash_changed(..) so that it writes hex summ instead of binary one
Publish PHP Package / docker (push) Successful in 6s Details
2025-01-21 17:38:28 +03:00
Pavel Shevaev 720d851a23 Обновить CHANGELOG.md 2024-12-18 18:50:13 +03:00
Pavel Shevaev 9ad9c3acce Добавить CHANGELOG.md 2024-12-18 18:49:29 +03:00
wrenge fd241509a5 Revert dir need regen support
Publish PHP Package / docker (push) Successful in 8s Details
2024-12-18 08:06:04 +03:00
Pavel Shevaev 8e4a56f89c Adding a null check
Publish PHP Package / docker (push) Successful in 6s Details
2024-12-17 20:01:56 +03:00
wrenge 2e666d8b66 Dir need regen support
Publish PHP Package / docker (push) Successful in 7s Details
2024-12-16 18:02:33 +03:00
Pavel Shevaev 5b1a5ec442 Fixing weird lstat bug on Windows for rrmdir function for large amount of directory items
Publish PHP Package / docker (push) Successful in 6s Details
2024-08-30 11:56:34 +03:00
Pavel Shevaev 6b40e78795 Adding null check
Publish PHP Package / docker (push) Successful in 7s Details
2024-08-23 18:15:16 +03:00
Alexey Chubar 9500897b1e Speed-up git info tasks
Publish PHP Package / docker (push) Successful in 8s Details
2024-07-04 13:52:07 +03:00
2 changed files with 50 additions and 26 deletions

5
CHANGELOG.md Normal file
View File

@ -0,0 +1,5 @@
## v1.8.1
- Adding null check in need_to_regen_any(..)
## v1.7.2
- Fixing weird lstat bug on Windows for rrmdir function for large amount of directory items

View File

@ -87,8 +87,6 @@ function find_files(string $dir, array $fnmatch_patterns = []) : array
return $results;
}
//obsolete, use find_files instead
function scan_files_rec(array $dirs, array $only_extensions = [], int $mode = 1) : array
{
$files = array();
@ -168,7 +166,7 @@ function json_make_pretty(string $json) : string
return prettyJSON($json);
}
function need_to_regen(string $file, array $deps, bool $debug = false) : bool
function need_to_regen(string $file, iterable $deps, bool $debug = false) : bool
{
if(!is_file($file))
{
@ -178,9 +176,10 @@ function need_to_regen(string $file, array $deps, bool $debug = false) : bool
}
$fmtime = filemtime($file);
foreach($deps as $dep)
{
if(is_file($dep) && (filemtime($dep) > $fmtime))
if($dep && is_file($dep) && (filemtime($dep) > $fmtime))
{
if($debug)
echo "$dep > $file\n";
@ -215,6 +214,9 @@ function need_to_regen_any(array $files, array $deps, bool $debug = false) : boo
echo "need_to_regen_any, earliest file: $earliest_file ($date)\n";
}
if($earliest_file === null)
return true;
return need_to_regen($earliest_file, $deps, $debug);
}
@ -587,7 +589,7 @@ function rrmdir(string $dir, bool $remove_top_dir = true)
{
if($object != "." && $object != "..")
{
if(filetype($dir."/".$object) == "dir")
if(is_dir($dir."/".$object))
rrmdir($dir."/".$object);
else
unlink($dir."/".$object);
@ -604,49 +606,66 @@ function rrmdir(string $dir, bool $remove_top_dir = true)
}
}
function git_get_info() : array
define("GIT_INFO_REV_HASH" , 1 << 0);
define("GIT_INFO_BRANCH" , 1 << 1);
define("GIT_INFO_REV_NUMBER", 1 << 2);
define("GIT_INFO_ALL" , ~0);
function git_get_info($info = GIT_INFO_ALL) : array
{
global $GAME_ROOT;
$rev_hash = "";
$branch = "";
$revision_number = 0;
if(!is_dir("$GAME_ROOT/.git"))
throw new Exception("Not a Git repository");
$out = array();
exec("git rev-parse HEAD", $out);
$rev_hash = trim($out[0]);
if(!$rev_hash)
throw new Exception("Error getting git revision hash");
if($info & GIT_INFO_REV_HASH)
{
$out = array();
exec("git rev-parse HEAD", $out);
$rev_hash = trim($out[0]);
if(!$rev_hash)
throw new Exception("Error getting git revision hash");
}
$out = array();
exec("git rev-parse --abbrev-ref HEAD", $out);
$branch = trim($out[0]);
if(!$branch)
throw new Exception("Error getting git branch");
if($info & GIT_INFO_BRANCH)
{
$out = array();
exec("git rev-parse --abbrev-ref HEAD", $out);
$branch = trim($out[0]);
if(!$branch)
throw new Exception("Error getting git branch");
}
$out = array();
exec("git rev-list HEAD --count", $out);
$revision_number = (int)$out[0];
if(!$revision_number)
throw new Exception("Error getting git revision number");
if($info & GIT_INFO_REV_NUMBER)
{
$out = array();
exec("git rev-list HEAD --count", $out);
$revision_number = (int)$out[0];
if(!$revision_number)
throw new Exception("Error getting git revision number");
}
return array($rev_hash, $branch, $revision_number);
}
function git_get_rev_hash() : string
{
list($rev_hash, $_, $__) = git_get_info();
list($rev_hash, $_, $__) = git_get_info(GIT_INFO_REV_HASH);
return $rev_hash;
}
function git_get_branch() : string
{
list($_, $branch, $__) = git_get_info();
list($_, $branch, $__) = git_get_info(GIT_INFO_BRANCH);
return $branch;
}
function git_get_rev_number() : string
{
list($_, $__, $rev_number) = git_get_info();
list($_, $__, $rev_number) = git_get_info(GIT_INFO_REV_NUMBER);
return $rev_number;
}
@ -1174,12 +1193,12 @@ function are_you_sure_ask() : bool
return $resp == "YES";
}
function names_hash_changed(string $crc_file, array $names) : bool
function names_hash_changed(string $crc_file, iterable $names) : bool
{
$ctx = hash_init('crc32');
foreach($names as $name)
hash_update($ctx, $name);
$names_crc = hash_final($ctx, true);
$names_crc = hash_final($ctx, false);
$changed = !file_exists($crc_file) || ensure_read($crc_file) != $names_crc;
ensure_write($crc_file, $names_crc);
return $changed;