]> git.lizzy.rs Git - rust.git/commitdiff
rollup merge of #17682 : nodakai/librustc-handy-version
authorAlex Crichton <alex@alexcrichton.com>
Thu, 2 Oct 2014 21:50:18 +0000 (14:50 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Thu, 2 Oct 2014 21:50:18 +0000 (14:50 -0700)
1  2 
src/librustc/driver/mod.rs

index 88059dc814fbb4890d892b4e9b6330bb204c1a0d,95ff2703be8b2cdaa570f65d39ef9edc42525b12..cb671d6e85f6147a0f937140167e34f873937db1
@@@ -29,13 -29,16 +29,13 @@@ use syntax::diagnostics
  
  use getopts;
  
 -
  pub mod driver;
  pub mod session;
  pub mod config;
  pub mod pretty;
  
 -
 -pub fn main_args(args: &[String]) -> int {
 -    let owned_args = args.to_vec();
 -    monitor(proc() run_compiler(owned_args.as_slice()));
 +pub fn run(args: Vec<String>) -> int {
 +    monitor(proc() run_compiler(args.as_slice()));
      0
  }
  
@@@ -125,6 -128,21 +125,21 @@@ fn run_compiler(args: &[String]) 
      driver::compile_input(sess, cfg, &input, &odir, &ofile, None);
  }
  
+ /// Returns a version string such as "0.12.0-dev".
+ pub fn release_str() -> Option<&'static str> {
+     option_env!("CFG_RELEASE")
+ }
+ /// Returns the full SHA1 hash of HEAD of the Git repo from which rustc was built.
+ pub fn commit_hash_str() -> Option<&'static str> {
+     option_env!("CFG_VER_HASH")
+ }
+ /// Returns the "commit date" of HEAD of the Git repo from which rustc was built as a static string.
+ pub fn commit_date_str() -> Option<&'static str> {
+     option_env!("CFG_VER_DATE")
+ }
  /// Prints version information and returns None on success or an error
  /// message on failure.
  pub fn version(binary: &str, matches: &getopts::Matches) -> Option<String> {
          Some(s) => return Some(format!("Unrecognized argument: {}", s))
      };
  
-     println!("{} {}", binary, env!("CFG_VERSION"));
+     println!("{} {}", binary, option_env!("CFG_VERSION").unwrap_or("unknown version"));
      if verbose {
+         fn unw(x: Option<&str>) -> &str { x.unwrap_or("unknown") }
          println!("binary: {}", binary);
-         println!("commit-hash: {}", option_env!("CFG_VER_HASH").unwrap_or("unknown"));
-         println!("commit-date: {}", option_env!("CFG_VER_DATE").unwrap_or("unknown"));
+         println!("commit-hash: {}", unw(commit_hash_str()));
+         println!("commit-date: {}", unw(commit_date_str()));
          println!("host: {}", driver::host_triple());
-         println!("release: {}", env!("CFG_RELEASE"));
+         println!("release: {}", unw(release_str()));
      }
      None
  }