From 472d5e87e9979665a7579839eb887dcad2cb3163 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Tue, 29 Oct 2024 09:18:14 +0000 Subject: [PATCH] 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. --- Userland/Libraries/LibCore/Version.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Userland/Libraries/LibCore/Version.cpp b/Userland/Libraries/LibCore/Version.cpp index 8f5b646c734..fa9437595a6 100644 --- a/Userland/Libraries/LibCore/Version.cpp +++ b/Userland/Libraries/LibCore/Version.cpp @@ -5,12 +5,27 @@ */ #include +#include #include namespace Core::Version { ErrorOr 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; }