File tree 1 file changed +14
-13
lines changed 1 file changed +14
-13
lines changed Original file line number Diff line number Diff line change 1
1
use anyhow:: Result ;
2
2
3
+ fn describe_git ( ) -> Result < String > {
4
+ let dir = std:: env:: current_dir ( ) ?;
5
+ let repo = git2:: Repository :: discover ( dir) ?;
6
+ let mut desc_opts = git2:: DescribeOptions :: new ( ) ;
7
+ desc_opts. describe_tags ( ) ;
8
+ let desc = repo. describe ( & desc_opts) ?;
9
+ let mut fmt_opts = git2:: DescribeFormatOptions :: new ( ) ;
10
+ fmt_opts. dirty_suffix ( "-dirty" ) ;
11
+ Ok ( desc. format ( Some ( & fmt_opts) ) ?)
12
+ }
13
+
3
14
fn main ( ) -> Result < ( ) > {
4
15
println ! ( "cargo:rerun-if-env-changed=TOOL_VERSION" ) ;
5
16
6
- let version = match dbg ! ( std:: env:: var( "TOOL_VERSION" ) ) {
7
- Ok ( value) => value,
8
- _ => {
9
- let dir = std:: env:: current_dir ( ) ?;
10
- let repo = git2:: Repository :: discover ( dir) ?;
11
- let mut desc_opts = git2:: DescribeOptions :: new ( ) ;
12
- desc_opts. describe_tags ( ) ;
13
- let desc = repo. describe ( & desc_opts) ?;
14
- let mut fmt_opts = git2:: DescribeFormatOptions :: new ( ) ;
15
- fmt_opts. dirty_suffix ( "-dirty" ) ;
16
- desc. format ( Some ( & fmt_opts) ) ?
17
- }
18
- } ;
17
+ let version = std:: env:: var ( "TOOL_VERSION" )
18
+ . or_else ( |_| describe_git ( ) )
19
+ . unwrap_or_else ( |_| "unknown" . into ( ) ) ;
19
20
20
21
println ! ( "cargo:rustc-env=TOOL_VERSION={version}" ) ;
21
22
You can’t perform that action at this time.
0 commit comments