-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: trin cli flag displays wrong version info (#1615)
- Loading branch information
Showing
6 changed files
with
96 additions
and
139 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,15 @@ | ||
use std::{fs::File, io::Write}; | ||
|
||
use shadow_rs::SdResult; | ||
|
||
fn main() -> SdResult<()> { | ||
shadow_rs::new_hook(hook)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn hook(mut file: &File) -> SdResult<()> { | ||
let env_var_git_hash = std::env::var("GIT_HASH").unwrap_or_default(); | ||
writeln!(file, "const ENV_GIT_HASH: &str = \"{}\";", env_var_git_hash)?; | ||
|
||
hook_method(file)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn hook_method(mut file: &File) -> SdResult<()> { | ||
let hook_fn = r#" | ||
pub const fn short_commit() -> &'static str { | ||
if shadow_rs::str_get!(SHORT_COMMIT, 0).is_some() { | ||
return SHORT_COMMIT; | ||
} | ||
if shadow_rs::str_get!(ENV_GIT_HASH, 0).is_some() { | ||
ENV_GIT_HASH | ||
} else { | ||
"unknown" | ||
} | ||
}"#; | ||
|
||
writeln!(file, "{}", hook_fn)?; | ||
use std::error::Error; | ||
|
||
use vergen::EmitBuilder; | ||
|
||
fn main() -> Result<(), Box<dyn Error>> { | ||
EmitBuilder::builder() | ||
.git_sha(true) | ||
.git_describe(false, true, None) | ||
.build_timestamp() | ||
.rustc_semver() | ||
.cargo_features() | ||
.cargo_target_triple() | ||
.emit()?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,31 @@ | ||
/// The latest git commit hash of the build. | ||
pub const TRIN_FULL_COMMIT: &str = env!("VERGEN_GIT_SHA"); | ||
pub const TRIN_SHORT_COMMIT: &str = const_format::str_index!(TRIN_FULL_COMMIT, ..8); | ||
|
||
/// Trin's version is the same as the git tag. | ||
pub const TRIN_VERSION: &str = const_format::str_split!(env!("VERGEN_GIT_DESCRIBE"), '-')[0]; | ||
|
||
/// The operating system of the build, linux, macos, windows etc. | ||
pub const BUILD_OPERATING_SYSTEM: &str = | ||
const_format::str_split!(env!("VERGEN_CARGO_TARGET_TRIPLE"), "-")[2]; | ||
|
||
/// The architecture of the build, x86_64, aarch64, etc. | ||
pub const BUILD_ARCHITECTURE: &str = | ||
const_format::str_split!(env!("VERGEN_CARGO_TARGET_TRIPLE"), "-")[0]; | ||
|
||
// /// The version of the programming language used to build the binary. | ||
pub const PROGRAMMING_LANGUAGE_VERSION: &str = env!("VERGEN_RUSTC_SEMVER"); | ||
|
||
pub const FULL_VERSION: &str = const_format::formatcp!( | ||
"{version}-{hash} {build_os}-{build_arch} rustc{rust_version}", | ||
version = TRIN_VERSION, | ||
hash = TRIN_SHORT_COMMIT, | ||
build_os = BUILD_OPERATING_SYSTEM, | ||
build_arch = BUILD_ARCHITECTURE, | ||
rust_version = PROGRAMMING_LANGUAGE_VERSION | ||
); | ||
|
||
/// Returns the trin version and git revision. | ||
pub const fn get_trin_version() -> &'static str { | ||
crate::build_info::short_commit() | ||
TRIN_SHORT_COMMIT | ||
} |