Meta+LibCore: Include git hash in version string

If the `LADYBIRD_GIT_VERSION` environment variable is set, then use it
to set the version number printed by the `--version` argument.
This commit is contained in:
Tim Ledbetter 2024-10-29 09:18:14 +00:00 committed by Tim Ledbetter
commit 472d5e87e9
Notes: github-actions[bot] 2024-10-29 13:31:21 +00:00

View file

@ -5,12 +5,27 @@
*/
#include <AK/String.h>
#include <LibCore/Environment.h>
#include <LibCore/Version.h>
namespace Core::Version {
ErrorOr<String> read_long_version_string()
{
auto validate_git_hash = [](auto hash) {
if (hash.length() < 4 || hash.length() > 40)
return false;
for (auto ch : hash) {
if (!is_ascii_hex_digit(ch))
return false;
}
return true;
};
auto maybe_git_hash = Core::Environment::get("LADYBIRD_GIT_VERSION"sv);
if (maybe_git_hash.has_value() && validate_git_hash(maybe_git_hash.value()))
return MUST(String::formatted("Version 1.0-{}", maybe_git_hash.value()));
return "Version 1.0"_string;
}