auto merge of #212 : fhahn/cargo/version, r=alexcrichton

This PR adds a rustc style version command
This commit is contained in:
bors 2014-07-18 14:53:17 +00:00
commit 7a2aa75414
5 changed files with 70 additions and 2 deletions

View File

@ -12,6 +12,16 @@ export LD_LIBRARY_PATH := $(CURDIR)/rustc/lib:$(LD_LIBRARY_PATH)
export DYLD_LIBRARY_PATH := $(CURDIR)/rustc/lib:$(DYLD_LIBRARY_PATH)
endif
CFG_RELEASE=0.1.0-pre
CFG_VER_DATE = $(shell git log -1 --pretty=format:'%ai')
CFG_VER_HASH = $(shell git rev-parse --short HEAD)
CFG_VERSION = $(PKG_NAME) $(CFG_RELEASE) ($(CFG_VER_HASH) $(CFG_VER_DATE))
export CFG_RELEASE
export CFG_VER_DATE
export CFG_VER_HASH
export CFG_VERSION
export PATH := $(CURDIR)/rustc/bin:$(PATH)
# Link flags to pull in dependencies
@ -23,7 +33,8 @@ BINS = cargo \
cargo-verify-project \
cargo-git-checkout \
cargo-test \
cargo-run
cargo-run \
cargo-version
SRC = $(shell find src -name '*.rs' -not -path 'src/bin*')

35
src/bin/cargo-version.rs Normal file
View File

@ -0,0 +1,35 @@
#![crate_name="cargo-version"]
#![feature(phase)]
extern crate cargo;
#[phase(plugin, link)]
extern crate hammer;
#[phase(plugin, link)]
extern crate log;
extern crate serialize;
use std::os;
use cargo::execute_main_without_stdin;
use cargo::core::MultiShell;
use cargo::util::CliResult;
#[deriving(Decodable,Encodable)]
pub struct Options;
hammer_config!(Options)
fn main() {
execute_main_without_stdin(execute);
}
fn execute(_: Options, _: &mut MultiShell) -> CliResult<Option<()>> {
debug!("executing; cmd=cargo-version; args={}", os::args());
println!("{}", env!("CFG_VERSION"));
Ok(None)
}

View File

@ -1,8 +1,11 @@
#![feature(phase)]
extern crate cargo;
#[phase(plugin, link)]
extern crate hammer;
extern crate serialize;
#[phase(plugin, link)]
extern crate log;
@ -31,7 +34,6 @@ struct ProjectLocation {
*/
fn execute() {
debug!("executing; cmd=cargo; args={}", os::args());
let (cmd, args) = process(os::args());
match cmd.as_slice() {
@ -53,6 +55,7 @@ fn execute() {
println!(" test # run the tests");
println!(" clean # remove the target directory");
println!(" run # build and execute src/main.rs");
println!(" version # displays the version of cargo");
println!("");
@ -60,6 +63,12 @@ fn execute() {
println!("Options (for all commands):\n\n{}", options);
},
_ => {
// `cargo --version` and `cargo -v` are aliases for `cargo version`
let cmd = if cmd.as_slice() == "--version" || cmd.as_slice() == "-V" {
"version".into_string()
} else {
cmd
};
let command = format!("cargo-{}{}", cmd, os::consts::EXE_SUFFIX);
let mut command = match os::self_exe_path() {
Some(path) => {

View File

@ -0,0 +1,12 @@
use support::{project, execs};
use hamcrest::assert_that;
fn setup() {}
test!(simple {
let p = project("foo");
assert_that(p.cargo_process("cargo-version"),
execs().with_status(0).with_stdout(format!("{}\n",
env!("CFG_VERSION")).as_slice()));
})

View File

@ -28,3 +28,4 @@ mod test_cargo_test;
mod test_shell;
mod test_cargo_cross_compile;
mod test_cargo_run;
mod test_cargo_version;