Skip to content

Commit

Permalink
Auto merge of #2224 - alexcrichton:rustc-dev, r=brson
Browse files Browse the repository at this point in the history
This should allow compiling the specified target in the various profiles that
are available to it, e.g. bench or test in addition to the standard
dev.

Closes #2120
  • Loading branch information
bors committed Dec 18, 2015
2 parents 5ea67f4 + 71ff274 commit 58cc3a2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
17 changes: 14 additions & 3 deletions src/bin/rustc.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -23,6 +23,7 @@ struct Options {
flag_example: Vec<String>,
flag_test: Vec<String>,
flag_bench: Vec<String>,
flag_profile: Option<String>,
}

pub const USAGE: &'static str = "
Expand All @@ -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
Expand Down Expand Up @@ -69,6 +71,15 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {

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,
Expand All @@ -78,7 +89,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
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,
Expand Down
33 changes: 32 additions & 1 deletion tests/test_cargo_rustc.rs
Original file line number Diff line number Diff line change
@@ -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() {
}
Expand Down Expand Up @@ -353,3 +354,33 @@ Invalid arguments.
Usage:
cargo rustc [options] [--] [<opts>...]".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));
});

0 comments on commit 58cc3a2

Please sign in to comment.