mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-25 11:14:46 +00:00
auto merge of #212 : fhahn/cargo/version, r=alexcrichton
This PR adds a rustc style version command
This commit is contained in:
commit
7a2aa75414
13
Makefile
13
Makefile
@ -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
35
src/bin/cargo-version.rs
Normal 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)
|
||||
}
|
@ -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) => {
|
||||
|
12
tests/test_cargo_version.rs
Normal file
12
tests/test_cargo_version.rs
Normal 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()));
|
||||
})
|
@ -28,3 +28,4 @@ mod test_cargo_test;
|
||||
mod test_shell;
|
||||
mod test_cargo_cross_compile;
|
||||
mod test_cargo_run;
|
||||
mod test_cargo_version;
|
||||
|
Loading…
x
Reference in New Issue
Block a user