diff --git a/src/bin/rustc.rs b/src/bin/rustc.rs index 14f9e120b65..391e5f41f5f 100644 --- a/src/bin/rustc.rs +++ b/src/bin/rustc.rs @@ -1,9 +1,9 @@ use std::env; -use cargo::ops::CompileOptions; +use cargo::ops::{CompileOptions, CompileMode}; use cargo::ops; use cargo::util::important_paths::{find_root_manifest_for_wd}; -use cargo::util::{CliResult, Config}; +use cargo::util::{CliResult, CliError, Config}; #[derive(RustcDecodable)] struct Options { @@ -23,6 +23,7 @@ struct Options { flag_example: Vec, flag_test: Vec, flag_bench: Vec, + flag_profile: Option, } pub const USAGE: &'static str = " @@ -41,6 +42,7 @@ Options: --test NAME Build only the specified test target --bench NAME Build only the specified benchmark target --release Build artifacts in release mode, with optimizations + --profile PROFILE Profile to build the selected target for --features FEATURES Features to compile for the package --no-default-features Do not compile default features for the package --target TRIPLE Target triple which compiles will be for @@ -69,6 +71,15 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())); + let mode = match options.flag_profile.as_ref().map(|t| &t[..]) { + Some("dev") | None => CompileMode::Build, + Some("test") => CompileMode::Test, + Some("bench") => CompileMode::Bench, + Some(mode) => { + return Err(CliError::new(&format!("unknown profile: `{}`, use dev, + test, or bench", mode), 101)) + } + }; let opts = CompileOptions { config: config, @@ -78,7 +89,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { no_default_features: options.flag_no_default_features, spec: &options.flag_package.map_or(Vec::new(), |s| vec![s]), exec_engine: None, - mode: ops::CompileMode::Build, + mode: mode, release: options.flag_release, filter: ops::CompileFilter::new(options.flag_lib, &options.flag_bin, diff --git a/tests/test_cargo_rustc.rs b/tests/test_cargo_rustc.rs index 559a5f722cc..d79ccd9b6bd 100644 --- a/tests/test_cargo_rustc.rs +++ b/tests/test_cargo_rustc.rs @@ -1,8 +1,9 @@ use std::path::MAIN_SEPARATOR as SEP; + use support::{execs, project}; use support::{COMPILING, RUNNING}; -use hamcrest::{assert_that}; +use hamcrest::{assert_that, existing_file}; fn setup() { } @@ -353,3 +354,33 @@ Invalid arguments. Usage: cargo rustc [options] [--] [...]".to_string())); }); + +test!(rustc_with_other_profile { + let foo = project("foo") + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [dev-dependencies] + a = { path = "a" } + "#) + .file("src/main.rs", r#" + #[cfg(test)] extern crate a; + + #[test] + fn foo() {} + "#) + .file("a/Cargo.toml", r#" + [package] + name = "a" + version = "0.1.0" + authors = [] + "#) + .file("a/src/lib.rs", ""); + foo.build(); + + assert_that(foo.cargo("rustc").arg("--profile").arg("test"), + execs().with_status(0)); +});