File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,14 +14,22 @@ include!("src/utils/cli.rs");
1414include ! ( "src/utils/denylist_default.rs" ) ;
1515
1616fn get_git_version ( ) {
17- let output = Command :: new ( "git" )
17+ let version = Command :: new ( "git" )
1818 . args ( [ "describe" , "--tags" , "--always" , "--dirty" ] )
1919 . output ( )
20- . expect ( "Failed to execute git" ) ;
21-
22- let git_version = String :: from_utf8 ( output. stdout ) . expect ( "Cannot get git version" ) ;
23- println ! ( "cargo:rustc-env=GIT_VERSION={}" , git_version. trim( ) ) ;
24-
20+ . ok ( )
21+ . filter ( |o| o. status . success ( ) )
22+ . and_then ( |o| String :: from_utf8 ( o. stdout ) . ok ( ) )
23+ . map ( |s| s. trim ( ) . to_owned ( ) )
24+ . filter ( |s| !s. is_empty ( ) )
25+ . unwrap_or_else ( || {
26+ format ! (
27+ "v{}" ,
28+ std:: env:: var( "CARGO_PKG_VERSION" ) . unwrap_or_default( )
29+ )
30+ } ) ;
31+
32+ println ! ( "cargo:rustc-env=GIT_VERSION={version}" ) ;
2533 println ! ( "cargo:rerun-if-changed=.git/HEAD" ) ;
2634 println ! ( "cargo:rerun-if-changed=.git/refs/" ) ;
2735}
You can’t perform that action at this time.
0 commit comments