File tree Expand file tree Collapse file tree 5 files changed +55
-1
lines changed
Expand file tree Collapse file tree 5 files changed +55
-1
lines changed Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ subxt-codegen = { version = "0.25.0", path = "../codegen" }
2121# perform node compatibility
2222subxt-metadata = { version = " 0.25.0" , path = " ../metadata" }
2323# parse command line args
24- clap = { version = " 4.0.8" , features = [" derive" ] }
24+ clap = { version = " 4.0.8" , features = [" derive" , " cargo " ] }
2525# colourful error reports
2626color-eyre = " 0.6.1"
2727# serialize the metadata
Original file line number Diff line number Diff line change 1+ use std:: {
2+ borrow:: Cow ,
3+ process:: Command ,
4+ } ;
5+
6+ fn main ( ) {
7+ // Make git hash available via GIT_HASH build-time env var:
8+ output_git_short_hash ( ) ;
9+ }
10+
11+ fn output_git_short_hash ( ) {
12+ let output = Command :: new ( "git" )
13+ . args ( [ "rev-parse" , "--short=11" , "HEAD" ] )
14+ . output ( ) ;
15+
16+ let git_hash = match output {
17+ Ok ( o) if o. status . success ( ) => {
18+ let sha = String :: from_utf8_lossy ( & o. stdout ) . trim ( ) . to_owned ( ) ;
19+ Cow :: from ( sha)
20+ }
21+ Ok ( o) => {
22+ println ! ( "cargo:warning=Git command failed with status: {}" , o. status) ;
23+ Cow :: from ( "unknown" )
24+ }
25+ Err ( err) => {
26+ println ! ( "cargo:warning=Failed to execute git command: {}" , err) ;
27+ Cow :: from ( "unknown" )
28+ }
29+ } ;
30+
31+ println ! ( "cargo:rustc-env=GIT_HASH={}" , git_hash) ;
32+ println ! ( "cargo:rerun-if-changed=../.git/HEAD" ) ;
33+ println ! ( "cargo:rerun-if-changed=../.git/refs" ) ;
34+ println ! ( "cargo:rerun-if-changed=build.rs" ) ;
35+ }
Original file line number Diff line number Diff line change 55pub mod codegen;
66pub mod compatibility;
77pub mod metadata;
8+ pub mod version;
Original file line number Diff line number Diff line change 1+ use clap:: Parser as ClapParser ;
2+
3+ /// Prints version information
4+ #[ derive( Debug , ClapParser ) ]
5+ pub struct Opts { }
6+
7+ pub fn run ( _opts : Opts ) -> color_eyre:: Result < ( ) > {
8+ let git_hash = env ! ( "GIT_HASH" ) ;
9+ println ! (
10+ "{} {}-{}" ,
11+ clap:: crate_name!( ) ,
12+ clap:: crate_version!( ) ,
13+ git_hash
14+ ) ;
15+ Ok ( ( ) )
16+ }
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ enum Command {
1313 Metadata ( commands:: metadata:: Opts ) ,
1414 Codegen ( commands:: codegen:: Opts ) ,
1515 Compatibility ( commands:: compatibility:: Opts ) ,
16+ Version ( commands:: version:: Opts ) ,
1617}
1718
1819#[ tokio:: main]
@@ -24,5 +25,6 @@ async fn main() -> color_eyre::Result<()> {
2425 Command :: Metadata ( opts) => commands:: metadata:: run ( opts) . await ,
2526 Command :: Codegen ( opts) => commands:: codegen:: run ( opts) . await ,
2627 Command :: Compatibility ( opts) => commands:: compatibility:: run ( opts) . await ,
28+ Command :: Version ( opts) => commands:: version:: run ( opts) ,
2729 }
2830}
You can’t perform that action at this time.
0 commit comments