File tree Expand file tree Collapse file tree 3 files changed +30
-1
lines changed Expand file tree Collapse file tree 3 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -6,17 +6,22 @@ fn main() {
6
6
"cargo:rustc-env=RUSTPYTHON_GIT_TIMESTAMP={}" ,
7
7
git_timestamp( )
8
8
) ;
9
+ println ! ( "cargo:rustc-env=RUSTPYTHON_GIT_TAG={}" , git_tag( ) ) ;
9
10
println ! ( "cargo:rustc-env=RUSTPYTHON_GIT_BRANCH={}" , git_branch( ) ) ;
10
11
}
11
12
12
13
fn git_hash ( ) -> String {
13
- git ( & [ "rev-parse" , "HEAD" ] )
14
+ git ( & [ "rev-parse" , "--short" , " HEAD"] )
14
15
}
15
16
16
17
fn git_timestamp ( ) -> String {
17
18
git ( & [ "log" , "-1" , "--format=%cd" ] )
18
19
}
19
20
21
+ fn git_tag ( ) -> String {
22
+ git ( & [ "describe" , "--all" , "--always" , "--dirty" ] )
23
+ }
24
+
20
25
fn git_branch ( ) -> String {
21
26
git ( & [ "rev-parse" , "--abbrev-ref" , "HEAD" ] )
22
27
}
Original file line number Diff line number Diff line change @@ -163,6 +163,14 @@ fn sys_exc_info(vm: &VirtualMachine) -> PyResult {
163
163
} ) )
164
164
}
165
165
166
+ fn sys_git_info ( vm : & VirtualMachine ) -> PyObjectRef {
167
+ vm. ctx . new_tuple ( vec ! [
168
+ vm. ctx. new_str( "RustPython" . to_string( ) ) ,
169
+ vm. ctx. new_str( version:: get_git_identifier( ) ) ,
170
+ vm. ctx. new_str( version:: get_git_revision( ) ) ,
171
+ ] )
172
+ }
173
+
166
174
// TODO: raise a SystemExit here
167
175
fn sys_exit ( code : OptionalArg < i32 > , _vm : & VirtualMachine ) -> PyResult < ( ) > {
168
176
let code = code. unwrap_or ( 0 ) ;
@@ -360,6 +368,7 @@ settrace() -- set the global debug tracing function
360
368
"settrace" => ctx. new_rustfunc( sys_settrace) ,
361
369
"version" => vm. new_str( version:: get_version( ) ) ,
362
370
"version_info" => version_info,
371
+ "_git" => sys_git_info( vm) ,
363
372
"exc_info" => ctx. new_rustfunc( sys_exc_info) ,
364
373
"prefix" => ctx. new_str( prefix. to_string( ) ) ,
365
374
"base_prefix" => ctx. new_str( base_prefix. to_string( ) ) ,
Original file line number Diff line number Diff line change @@ -38,8 +38,23 @@ pub fn get_git_revision() -> String {
38
38
option_env ! ( "RUSTPYTHON_GIT_HASH" ) . unwrap_or ( "" ) . to_string ( )
39
39
}
40
40
41
+ pub fn get_git_tag ( ) -> String {
42
+ option_env ! ( "RUSTPYTHON_GIT_TAG" ) . unwrap_or ( "" ) . to_string ( )
43
+ }
44
+
41
45
pub fn get_git_branch ( ) -> String {
42
46
option_env ! ( "RUSTPYTHON_GIT_BRANCH" )
43
47
. unwrap_or ( "" )
44
48
. to_string ( )
45
49
}
50
+
51
+ pub fn get_git_identifier ( ) -> String {
52
+ let git_tag = get_git_tag ( ) ;
53
+ let git_branch = get_git_branch ( ) ;
54
+
55
+ if git_tag. is_empty ( ) || git_tag == "undefined" {
56
+ git_branch
57
+ } else {
58
+ git_tag
59
+ }
60
+ }
You can’t perform that action at this time.
0 commit comments