Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying profiles to cargo rustc #2224

Merged
merged 1 commit into from
Dec 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
});