mirror of
https://github.com/rust-lang/cargo
synced 2024-10-03 22:43:59 +00:00
Pass the arg_opts
from the command line further on to the CompileOptions.
- The new tests verifies that the extra arguments gets appended to the command. One is for lib and one is for main - Currently the arguments gets passed on to *every* target that gets built, so the tests only contain one file each
This commit is contained in:
parent
77bb01ece2
commit
b177d2ab56
|
@ -85,7 +85,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
|
|||
&options.flag_test,
|
||||
&options.flag_example,
|
||||
&options.flag_bench),
|
||||
target_rustc_args: None,
|
||||
target_rustc_args: options.arg_opts.as_ref().map(|a| &a[..]),
|
||||
};
|
||||
|
||||
ops::compile(&root, &opts).map(|_| None).map_err(|err| {
|
||||
|
|
|
@ -665,6 +665,10 @@ fn build_base_args(cx: &Context,
|
|||
cmd.arg("-g");
|
||||
}
|
||||
|
||||
if let Some(ref args) = cx.build_config.target_rustc_args {
|
||||
cmd.args(args);
|
||||
}
|
||||
|
||||
if debug_assertions && opt_level > 0 {
|
||||
cmd.args(&["-C", "debug-assertions=on"]);
|
||||
} else if !debug_assertions && opt_level == 0 {
|
||||
|
|
|
@ -6,10 +6,14 @@ use hamcrest::{assert_that};
|
|||
fn setup() {
|
||||
}
|
||||
|
||||
fn verbose_output_for_lib(p: &ProjectBuilder) -> String {
|
||||
fn verbose_output_for_target(lib: bool, p: &ProjectBuilder) -> String {
|
||||
let (target, kind) = match lib {
|
||||
true => ("lib", "lib"),
|
||||
false => ("main", "bin"),
|
||||
};
|
||||
format!("\
|
||||
{compiling} {name} v{version} ({url})
|
||||
{running} `rustc src{sep}lib.rs --crate-name {name} --crate-type lib -g \
|
||||
{running} `rustc src{sep}{target}.rs --crate-name {name} --crate-type {kind} -g \
|
||||
--out-dir {dir}{sep}target{sep}debug \
|
||||
--emit=dep-info,link \
|
||||
-L dependency={dir}{sep}target{sep}debug \
|
||||
|
@ -17,9 +21,14 @@ fn verbose_output_for_lib(p: &ProjectBuilder) -> String {
|
|||
",
|
||||
running = RUNNING, compiling = COMPILING, sep = SEP,
|
||||
dir = p.root().display(), url = p.url(),
|
||||
target = target, kind = kind,
|
||||
name = "foo", version = "0.0.1")
|
||||
}
|
||||
|
||||
fn verbose_output_for_target_with_args(lib: bool, p: &ProjectBuilder, args: &str) -> String {
|
||||
verbose_output_for_target(lib, p).replace(" -g ", &format!(" -g {} ", args))
|
||||
}
|
||||
|
||||
test!(build_lib_for_foo {
|
||||
let p = project("foo")
|
||||
.file("Cargo.toml", r#"
|
||||
|
@ -37,5 +46,48 @@ test!(build_lib_for_foo {
|
|||
assert_that(p.cargo_process("rustc").arg("--lib").arg("-v").arg("foo"),
|
||||
execs()
|
||||
.with_status(0)
|
||||
.with_stdout(verbose_output_for_lib(&p)));
|
||||
.with_stdout(verbose_output_for_target(true, &p)));
|
||||
});
|
||||
|
||||
test!(build_lib_and_allow_unstable_options {
|
||||
let p = project("foo")
|
||||
.file("Cargo.toml", r#"
|
||||
[package]
|
||||
|
||||
name = "foo"
|
||||
version = "0.0.1"
|
||||
authors = ["wycats@example.com"]
|
||||
"#)
|
||||
.file("src/main.rs", r#"
|
||||
fn main() {}
|
||||
"#)
|
||||
.file("src/lib.rs", r#" "#);
|
||||
|
||||
assert_that(p.cargo_process("rustc").arg("--lib").arg("-v").arg("foo")
|
||||
.arg("--").arg("-Z").arg("unstable-options"),
|
||||
execs()
|
||||
.with_status(0)
|
||||
.with_stdout(verbose_output_for_target_with_args(true, &p,
|
||||
"-Z unstable-options")));
|
||||
});
|
||||
|
||||
test!(build_main_and_allow_unstable_options {
|
||||
let p = project("foo")
|
||||
.file("Cargo.toml", r#"
|
||||
[package]
|
||||
|
||||
name = "foo"
|
||||
version = "0.0.1"
|
||||
authors = ["wycats@example.com"]
|
||||
"#)
|
||||
.file("src/main.rs", r#"
|
||||
fn main() {}
|
||||
"#);
|
||||
|
||||
assert_that(p.cargo_process("rustc").arg("-v").arg("foo")
|
||||
.arg("--").arg("-Z").arg("unstable-options"),
|
||||
execs()
|
||||
.with_status(0)
|
||||
.with_stdout(verbose_output_for_target_with_args(false, &p,
|
||||
"-Z unstable-options")));
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue