@@ -8,7 +8,7 @@ macro_rules! get_version_info {
88 let patch = env!( "CARGO_PKG_VERSION_PATCH" ) . parse:: <u16 >( ) . unwrap( ) ;
99 let crate_name = String :: from( env!( "CARGO_PKG_NAME" ) ) ;
1010
11- let host_compiler = $crate :: get_channel ( ) ;
11+ let host_compiler = option_env! ( "RUSTC_RELEASE_CHANNEL" ) . map ( str :: to_string ) ;
1212 let commit_hash = option_env!( "GIT_HASH" ) . map( str :: to_string) ;
1313 let commit_date = option_env!( "COMMIT_DATE" ) . map( str :: to_string) ;
1414
@@ -79,15 +79,6 @@ impl std::fmt::Debug for VersionInfo {
7979 }
8080}
8181
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-
9182pub fn get_commit_hash ( ) -> Option < String > {
9283 std:: process:: Command :: new ( "git" )
9384 . args ( & [ "rev-parse" , "--short" , "HEAD" ] )
@@ -104,6 +95,34 @@ pub fn get_commit_date() -> Option<String> {
10495 . and_then ( |r| String :: from_utf8 ( r. stdout ) . ok ( ) )
10596}
10697
98+ pub fn get_channel ( ) -> Option < String > {
99+ match env:: var ( "CFG_RELEASE_CHANNEL" ) {
100+ Ok ( channel) => Some ( channel) ,
101+ Err ( _) => {
102+ // if that failed, try to ask rustc -V, do some parsing and find out
103+ match std:: process:: Command :: new ( "rustc" )
104+ . arg ( "-V" )
105+ . output ( )
106+ . ok ( )
107+ . and_then ( |r| String :: from_utf8 ( r. stdout ) . ok ( ) )
108+ {
109+ Some ( rustc_output) => {
110+ if rustc_output. contains ( "beta" ) {
111+ Some ( String :: from ( "beta" ) )
112+ } else if rustc_output. contains ( "stable" ) {
113+ Some ( String :: from ( "stable" ) )
114+ } else {
115+ // default to nightly if we fail to parse
116+ Some ( String :: from ( "nightly" ) )
117+ }
118+ } ,
119+ // default to nightly
120+ None => Some ( String :: from ( "nightly" ) ) ,
121+ }
122+ } ,
123+ }
124+ }
125+
107126#[ cfg( test) ]
108127mod test {
109128 use super :: * ;
0 commit comments