@@ -125,6 +125,21 @@ fn run_compiler(args: &[String]) {
125125 driver:: compile_input ( sess, cfg, & input, & odir, & ofile, None ) ;
126126}
127127
128+ /// Returns a version string such as "0.12.0-dev".
129+ pub fn release_str ( ) -> Option < & ' static str > {
130+ option_env ! ( "CFG_RELEASE" )
131+ }
132+
133+ /// Returns the full SHA1 hash of HEAD of the Git repo from which rustc was built.
134+ pub fn commit_hash_str ( ) -> Option < & ' static str > {
135+ option_env ! ( "CFG_VER_HASH" )
136+ }
137+
138+ /// Returns the "commit date" of HEAD of the Git repo from which rustc was built as a static string.
139+ pub fn commit_date_str ( ) -> Option < & ' static str > {
140+ option_env ! ( "CFG_VER_DATE" )
141+ }
142+
128143/// Prints version information and returns None on success or an error
129144/// message on failure.
130145pub fn version ( binary : & str , matches : & getopts:: Matches ) -> Option < String > {
@@ -134,13 +149,14 @@ pub fn version(binary: &str, matches: &getopts::Matches) -> Option<String> {
134149 Some ( s) => return Some ( format ! ( "Unrecognized argument: {}" , s) )
135150 } ;
136151
137- println ! ( "{} {}" , binary, env !( "CFG_VERSION" ) ) ;
152+ println ! ( "{} {}" , binary, option_env !( "CFG_VERSION" ) . unwrap_or ( "unknown version ") ) ;
138153 if verbose {
154+ fn unw ( x : Option < & str > ) -> & str { x. unwrap_or ( "unknown" ) }
139155 println ! ( "binary: {}" , binary) ;
140- println ! ( "commit-hash: {}" , option_env! ( "CFG_VER_HASH" ) . unwrap_or ( "unknown" ) ) ;
141- println ! ( "commit-date: {}" , option_env! ( "CFG_VER_DATE" ) . unwrap_or ( "unknown" ) ) ;
156+ println ! ( "commit-hash: {}" , unw ( commit_hash_str ( ) ) ) ;
157+ println ! ( "commit-date: {}" , unw ( commit_date_str ( ) ) ) ;
142158 println ! ( "host: {}" , driver:: host_triple( ) ) ;
143- println ! ( "release: {}" , env! ( "CFG_RELEASE" ) ) ;
159+ println ! ( "release: {}" , unw ( release_str ( ) ) ) ;
144160 }
145161 None
146162}
0 commit comments