@@ -125,6 +125,21 @@ fn run_compiler(args: &[String]) {
125
125
driver:: compile_input ( sess, cfg, & input, & odir, & ofile, None ) ;
126
126
}
127
127
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
+
128
143
/// Prints version information and returns None on success or an error
129
144
/// message on failure.
130
145
pub fn version ( binary : & str , matches : & getopts:: Matches ) -> Option < String > {
@@ -134,13 +149,14 @@ pub fn version(binary: &str, matches: &getopts::Matches) -> Option<String> {
134
149
Some ( s) => return Some ( format ! ( "Unrecognized argument: {}" , s) )
135
150
} ;
136
151
137
- println ! ( "{} {}" , binary, env !( "CFG_VERSION" ) ) ;
152
+ println ! ( "{} {}" , binary, option_env !( "CFG_VERSION" ) . unwrap_or ( "unknown version ") ) ;
138
153
if verbose {
154
+ fn unw ( x : Option < & str > ) -> & str { x. unwrap_or ( "unknown" ) }
139
155
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 ( ) ) ) ;
142
158
println ! ( "host: {}" , driver:: host_triple( ) ) ;
143
- println ! ( "release: {}" , env! ( "CFG_RELEASE" ) ) ;
159
+ println ! ( "release: {}" , unw ( release_str ( ) ) ) ;
144
160
}
145
161
None
146
162
}
0 commit comments