@@ -8,7 +8,7 @@ macro_rules! get_version_info {
8
8
let patch = env!( "CARGO_PKG_VERSION_PATCH" ) . parse:: <u16 >( ) . unwrap( ) ;
9
9
let crate_name = String :: from( env!( "CARGO_PKG_NAME" ) ) ;
10
10
11
- let host_compiler = $crate :: get_channel ( ) ;
11
+ let host_compiler = option_env! ( "RUSTC_RELEASE_CHANNEL" ) . map ( str :: to_string ) ;
12
12
let commit_hash = option_env!( "GIT_HASH" ) . map( str :: to_string) ;
13
13
let commit_date = option_env!( "COMMIT_DATE" ) . map( str :: to_string) ;
14
14
@@ -79,14 +79,6 @@ impl std::fmt::Debug for VersionInfo {
79
79
}
80
80
}
81
81
82
- pub fn get_channel ( ) -> Option < String > {
83
- if let Ok ( channel) = env:: var ( "CFG_RELEASE_CHANNEL" ) {
84
- Some ( channel)
85
- } else {
86
- // we could ask ${RUSTC} -Vv and do some parsing and find out
87
- Some ( String :: from ( "nightly" ) )
88
- }
89
- }
90
82
91
83
pub fn get_commit_hash ( ) -> Option < String > {
92
84
std:: process:: Command :: new ( "git" )
@@ -104,6 +96,34 @@ pub fn get_commit_date() -> Option<String> {
104
96
. and_then ( |r| String :: from_utf8 ( r. stdout ) . ok ( ) )
105
97
}
106
98
99
+ pub fn get_channel ( ) -> Option < String > {
100
+ match env:: var ( "CFG_RELEASE_CHANNEL" ) {
101
+ Ok ( channel) => Some ( channel) ,
102
+ Err ( _) => {
103
+ // if that failed, try to ask rustc -V, do some parsing and find out
104
+ match std:: process:: Command :: new ( "rustc" )
105
+ . arg ( "-V" )
106
+ . output ( )
107
+ . ok ( )
108
+ . and_then ( |r| String :: from_utf8 ( r. stdout ) . ok ( ) )
109
+ {
110
+ Some ( rustc_output) => {
111
+ if rustc_output. contains ( "beta" ) {
112
+ Some ( String :: from ( "beta" ) )
113
+ } else if rustc_output. contains ( "stable" ) {
114
+ Some ( String :: from ( "stable" ) )
115
+ } else {
116
+ // default to nightly if we fail to parse
117
+ Some ( String :: from ( "nightly" ) )
118
+ }
119
+ } ,
120
+ // default to nightly
121
+ None => Some ( String :: from ( "nightly" ) ) ,
122
+ }
123
+ } ,
124
+ }
125
+ }
126
+
107
127
#[ cfg( test) ]
108
128
mod test {
109
129
use super :: * ;
0 commit comments