Stabilize version output for rustc and rustdoc

This commit is contained in:
Robert Buonpastore 2014-05-18 23:37:07 -04:00 committed by Alex Crichton
parent fb296b8011
commit d6a4c431f4
5 changed files with 47 additions and 15 deletions

View File

@ -42,9 +42,9 @@ SPACE :=
SPACE +=
ifneq ($(wildcard $(subst $(SPACE),\$(SPACE),$(CFG_GIT))),)
ifneq ($(wildcard $(subst $(SPACE),\$(SPACE),$(CFG_GIT_DIR))),)
CFG_VERSION += $(shell git --git-dir='$(CFG_GIT_DIR)' log -1 \
--pretty=format:'(%h %ci)')
CFG_VER_DATE = $(shell git --git-dir='$(CFG_GIT_DIR)' log -1 --pretty=format:'%ci')
CFG_VER_HASH = $(shell git --git-dir='$(CFG_GIT_DIR)' rev-parse HEAD)
CFG_VERSION += ($(CFG_VER_HASH) $(CFG_VER_DATE))
endif
endif
@ -272,6 +272,12 @@ $(foreach host,$(CFG_HOST), \
export CFG_SRC_DIR
export CFG_BUILD_DIR
ifdef CFG_VER_DATE
export CFG_VER_DATE
endif
ifdef CFG_VER_HASH
export CFG_VER_HASH
endif
export CFG_VERSION
export CFG_VERSION_WIN
export CFG_RELEASE

View File

@ -544,7 +544,7 @@ pub fn optgroups() -> Vec<getopts::OptGroup> {
optmulti("F", "forbid", "Set lint forbidden", "OPT"),
optmulti("C", "codegen", "Set a codegen option", "OPT[=VALUE]"),
optmulti("Z", "", "Set internal debugging options", "FLAG"),
optflag("v", "version", "Print version info and exit"),
optflagopt("v", "version", "Print version info and exit", "verbose"),
optopt("", "color", "Configure coloring of output:
auto = colorize, if output goes to a tty (default);
always = always colorize output;

View File

@ -112,13 +112,24 @@ fn run_compiler(args: &[String]) {
driver::compile_input(sess, cfg, &input, &odir, &ofile);
}
pub fn version(command: &str) {
let vers = match option_env!("CFG_VERSION") {
Some(vers) => vers,
None => "unknown version"
/// Prints version information and returns None on success or an error
/// message on failure.
pub fn version(binary: &str, matches: &getopts::Matches) -> Option<String> {
let verbose = match matches.opt_str("version").as_ref().map(|s| s.as_slice()) {
None => false,
Some("verbose") => true,
Some(s) => return Some(format!("Unrecognized argument: {}", s))
};
println!("{} {}", command, vers);
println!("host: {}", driver::host_triple());
println!("{} {}", binary, env!("CFG_VERSION"));
if verbose {
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!("host: {}", driver::host_triple());
println!("release: {}", env!("CFG_RELEASE"));
}
None
}
fn usage() {
@ -268,9 +279,11 @@ pub fn handle_options(mut args: Vec<String>) -> Option<getopts::Matches> {
return None;
}
if matches.opt_present("v") || matches.opt_present("version") {
version("rustc");
return None;
if matches.opt_present("version") {
match version("rustc", &matches) {
Some(err) => early_error(err.as_slice()),
None => return None
}
}
Some(matches)

View File

@ -95,7 +95,7 @@ pub fn opts() -> Vec<getopts::OptGroup> {
use getopts::*;
vec!(
optflag("h", "help", "show this help message"),
optflag("", "version", "print rustdoc's version"),
optflagopt("", "version", "print rustdoc's version", "verbose"),
optopt("r", "input-format", "the input type of the specified file",
"[rust|json]"),
optopt("w", "output-format", "the output type to write",
@ -150,8 +150,13 @@ pub fn main_args(args: &[String]) -> int {
usage(args[0].as_slice());
return 0;
} else if matches.opt_present("version") {
rustc::driver::version("rustdoc");
return 0;
match rustc::driver::version("rustdoc", &matches) {
Some(err) => {
println!("{}", err);
return 1
},
None => return 0
}
}
if matches.free.len() == 0 {

View File

@ -0,0 +1,8 @@
-include ../tools.mk
all:
$(RUSTC) -v
$(RUSTC) -v verbose
$(RUSTC) -v bad_arg && exit 1 || exit 0
$(RUSTC) --version verbose
$(RUSTC) --version bad_arg && exit 1 || exit 0