build: allow common to read git version information at runtime

This commit is contained in:
Yusuf Bera Ertan 2022-09-03 16:26:10 +03:00
parent 999984d15a
commit 2af2b34d84
No known key found for this signature in database
GPG Key ID: 1D8F8FAF2294D6EA
2 changed files with 26 additions and 5 deletions

View File

@ -8,11 +8,21 @@ pub mod projection;
/// entities /// entities
mod spatial_grid; mod spatial_grid;
pub const GIT_VERSION: &str = include_str!(concat!(env!("OUT_DIR"), "/githash")); pub const GIT_VERSION_BUILD: &str = include_str!(concat!(env!("OUT_DIR"), "/githash"));
pub const GIT_TAG: &str = include_str!(concat!(env!("OUT_DIR"), "/gittag")); pub const GIT_TAG_BUILD: &str = include_str!(concat!(env!("OUT_DIR"), "/gittag"));
pub const VELOREN_VERSION_STAGE: &str = "Pre-Alpha"; pub const VELOREN_VERSION_STAGE: &str = "Pre-Alpha";
lazy_static::lazy_static! { lazy_static::lazy_static! {
pub static ref GIT_VERSION: String = if GIT_VERSION_BUILD.is_empty() {
std::env::var("VELOREN_GIT_VERSION").expect("failed to get git version")
} else {
GIT_VERSION_BUILD.to_string()
};
pub static ref GIT_TAG: String = if GIT_TAG_BUILD.is_empty() {
std::env::var("VELOREN_GIT_TAG").expect("failed to get git tag")
} else {
GIT_TAG_BUILD.to_string()
};
pub static ref GIT_HASH: &'static str = GIT_VERSION.split('/').next().expect("failed to retrieve git_hash!"); pub static ref GIT_HASH: &'static str = GIT_VERSION.split('/').next().expect("failed to retrieve git_hash!");
static ref GIT_DATETIME: &'static str = GIT_VERSION.split('/').nth(1).expect("failed to retrieve git_datetime!"); static ref GIT_DATETIME: &'static str = GIT_VERSION.split('/').nth(1).expect("failed to retrieve git_datetime!");
pub static ref GIT_DATE: String = GIT_DATETIME.split('-').take(3).collect::<Vec<&str>>().join("-"); pub static ref GIT_DATE: String = GIT_DATETIME.split('-').take(3).collect::<Vec<&str>>().join("-");

View File

@ -5,6 +5,15 @@
outputs = inputs: let outputs = inputs: let
lib = inputs.nci.inputs.nixpkgs.lib; lib = inputs.nci.inputs.nixpkgs.lib;
git = let
sourceInfo = inputs.self.sourceInfo;
dateTimeFormat = import ./nix/dateTimeFormat.nix;
dateTime = dateTimeFormat sourceInfo.lastModified;
rev = sourceInfo.rev or "dirty";
in {
prettyRev = (builtins.substring 0 8 rev) + "/" + dateTime;
tag = "";
};
outputs = inputs.nci.lib.makeOutputs { outputs = inputs.nci.lib.makeOutputs {
root = ./.; root = ./.;
defaultOutputs = { defaultOutputs = {
@ -68,8 +77,8 @@
# We have to include the command output here, otherwise Nix won't run it # We have to include the command output here, otherwise Nix won't run it
DISABLE_GIT_LFS_CHECK = true; DISABLE_GIT_LFS_CHECK = true;
# We don't add in any information here because otherwise anything # We don't add in any information here because otherwise anything
# that depends on common will be recompiled. Ideally we should have # that depends on common will be recompiled. We will set these in
# a way to pass these in a wrapper, at runtime, rather than build time. # our wrapper instead.
NIX_GIT_HASH = ""; NIX_GIT_HASH = "";
NIX_GIT_TAG = ""; NIX_GIT_TAG = "";
}; };
@ -192,7 +201,9 @@
ln -sf ${old}/bin/* $out/bin/ ln -sf ${old}/bin/* $out/bin/
wrapProgram $out/bin/* \ wrapProgram $out/bin/* \
${lib.optionalString (old.pname == "veloren-voxygen") "--prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath runtimeLibs}"} \ ${lib.optionalString (old.pname == "veloren-voxygen") "--prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath runtimeLibs}"} \
--set VELOREN_ASSETS ${assets} --set VELOREN_ASSETS ${assets} \
--set VELOREN_GIT_VERSION "${git.prettyRev}" \
--set VELOREN_GIT_TAG "${git.tag}"
''; '';
in in
wrapped; wrapped;