Skip to content

Commit

Permalink
Auto merge of #3468 - nrc:metadata-emit, r=alexcrichton
Browse files Browse the repository at this point in the history
cargo check: use --emit=metadata rather than --crate-type=metadata

Requires rust-lang/rust#38571 (don't land before that does)

r? @alexcrichton
  • Loading branch information
bors committed Jan 5, 2017
2 parents 71e996e + 844d7ae commit 154a30b
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 98 deletions.
70 changes: 29 additions & 41 deletions src/cargo/ops/cargo_rustc/context.rs
Expand Up @@ -146,9 +146,6 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
unit: &Unit<'a>,
crate_types: &mut BTreeSet<String>)
-> CargoResult<()> {
if unit.profile.check {
crate_types.insert("metadata".to_string());
}
for target in unit.pkg.manifest().targets() {
crate_types.extend(target.rustc_crate_types().iter().map(|s| {
if *s == "lib" {
Expand Down Expand Up @@ -180,11 +177,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
.env_remove("RUST_LOG");

for crate_type in crate_types {
// Here and below we'll skip the metadata crate-type because it is
// not supported by older compilers. We'll do this one manually.
if crate_type != "metadata" {
process.arg("--crate-type").arg(crate_type);
}
process.arg("--crate-type").arg(crate_type);
}
if kind == Kind::Target {
process.arg("--target").arg(&self.target_triple());
Expand Down Expand Up @@ -216,9 +209,6 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
map.insert(crate_type.to_string(), None);
continue;
}
if crate_type == "metadata" {
continue;
}
let line = match lines.next() {
Some(line) => line,
None => bail!("malformed output when learning about \
Expand All @@ -235,12 +225,6 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
map.insert(crate_type.to_string(), Some((prefix.to_string(), suffix.to_string())));
}

// Manually handle the metadata case. If it is not supported by the
// compiler we'll error out elsewhere.
if crate_types.contains("metadata") {
map.insert("metadata".to_string(), Some(("lib".to_owned(), ".rmeta".to_owned())));
}

let cfg = if has_cfg {
Some(try!(lines.map(Cfg::from_str).collect()))
} else {
Expand Down Expand Up @@ -502,32 +486,36 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
let mut ret = Vec::new();
let mut unsupported = Vec::new();
{
let mut add = |crate_type: &str, linkable: bool| -> CargoResult<()> {
let crate_type = if crate_type == "lib" {"rlib"} else {crate_type};
match info.crate_types.get(crate_type) {
Some(&Some((ref prefix, ref suffix))) => {
let filename = out_dir.join(format!("{}{}{}", prefix, stem, suffix));
let link_dst = link_stem.clone().map(|(ld, ls)| {
ld.join(format!("{}{}{}", prefix, ls, suffix))
});
ret.push((filename, link_dst, linkable));
Ok(())
}
// not supported, don't worry about it
Some(&None) => {
unsupported.push(crate_type.to_string());
Ok(())
}
None => {
bail!("failed to learn about crate-type `{}` early on",
crate_type)
}
}
};

if unit.profile.check {
add("metadata", true)?;
let filename = out_dir.join(format!("lib{}.rmeta", stem));
let link_dst = link_stem.clone().map(|(ld, ls)| {
ld.join(format!("lib{}.rmeta", ls))
});
ret.push((filename, link_dst, true));
} else {
let mut add = |crate_type: &str, linkable: bool| -> CargoResult<()> {
let crate_type = if crate_type == "lib" {"rlib"} else {crate_type};
match info.crate_types.get(crate_type) {
Some(&Some((ref prefix, ref suffix))) => {
let filename = out_dir.join(format!("{}{}{}", prefix, stem, suffix));
let link_dst = link_stem.clone().map(|(ld, ls)| {
ld.join(format!("{}{}{}", prefix, ls, suffix))
});
ret.push((filename, link_dst, linkable));
Ok(())
}
// not supported, don't worry about it
Some(&None) => {
unsupported.push(crate_type.to_string());
Ok(())
}
None => {
bail!("failed to learn about crate-type `{}` early on",
crate_type)
}
}
};

match *unit.target.kind() {
TargetKind::Example |
TargetKind::Bin |
Expand Down
18 changes: 9 additions & 9 deletions src/cargo/ops/cargo_rustc/mod.rs
Expand Up @@ -460,7 +460,6 @@ fn prepare_rustc(cx: &mut Context,
unit: &Unit) -> CargoResult<ProcessBuilder> {
let mut base = cx.compilation.rustc_process(unit.pkg)?;
build_base_args(cx, &mut base, unit, &crate_types);
build_plugin_args(&mut base, cx, unit);
build_deps_args(&mut base, cx, unit)?;
Ok(base)
}
Expand Down Expand Up @@ -566,14 +565,18 @@ fn build_base_args(cx: &mut Context,
cmd.arg("--error-format").arg("json");
}

if check {
cmd.arg("--crate-type").arg("metadata");
} else if !test {
if !test {
for crate_type in crate_types.iter() {
cmd.arg("--crate-type").arg(crate_type);
}
}

if check {
cmd.arg("--emit=dep-info,metadata");
} else {
cmd.arg("--emit=dep-info,link");
}

let prefer_dynamic = (unit.target.for_host() &&
!unit.target.is_custom_build()) ||
(crate_types.contains(&"dylib") &&
Expand Down Expand Up @@ -653,10 +656,9 @@ fn build_base_args(cx: &mut Context,
if rpath {
cmd.arg("-C").arg("rpath");
}
}

cmd.arg("--out-dir").arg(&cx.out_dir(unit));

fn build_plugin_args(cmd: &mut ProcessBuilder, cx: &mut Context, unit: &Unit) {
fn opt(cmd: &mut ProcessBuilder, key: &str, prefix: &str,
val: Option<&OsStr>) {
if let Some(val) = val {
Expand All @@ -666,9 +668,6 @@ fn build_plugin_args(cmd: &mut ProcessBuilder, cx: &mut Context, unit: &Unit) {
}
}

cmd.arg("--out-dir").arg(&cx.out_dir(unit));
cmd.arg("--emit=dep-info,link");

if unit.kind == Kind::Target {
opt(cmd, "--target", "", cx.requested_target().map(|s| s.as_ref()));
}
Expand All @@ -677,6 +676,7 @@ fn build_plugin_args(cmd: &mut ProcessBuilder, cx: &mut Context, unit: &Unit) {
opt(cmd, "-C", "linker=", cx.linker(unit.kind).map(|s| s.as_ref()));
}


fn build_deps_args(cmd: &mut ProcessBuilder, cx: &mut Context, unit: &Unit)
-> CargoResult<()> {
cmd.arg("-L").arg(&{
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/util/cfg.rs
Expand Up @@ -44,7 +44,7 @@ impl FromStr for Cfg {
let mut p = Parser::new(s);
let e = p.cfg()?;
if p.t.next().is_some() {
bail!("malformed cfg value or key/value pair")
bail!("malformed cfg value or key/value pair: `{}`", s)
}
Ok(e)
}
Expand Down
4 changes: 2 additions & 2 deletions tests/build-lib.rs
Expand Up @@ -7,10 +7,10 @@ use hamcrest::{assert_that};
fn verbose_output_for_lib(p: &ProjectBuilder) -> String {
format!("\
[COMPILING] {name} v{version} ({url})
[RUNNING] `rustc --crate-name {name} src[/]lib.rs --crate-type lib -g \
[RUNNING] `rustc --crate-name {name} src[/]lib.rs --crate-type lib \
--emit=dep-info,link -g \
-C metadata=[..] \
--out-dir [..] \
--emit=dep-info,link \
-L dependency={dir}[/]target[/]debug[/]deps`
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
",
Expand Down
13 changes: 8 additions & 5 deletions tests/build-script.rs
Expand Up @@ -765,19 +765,22 @@ fn build_cmd_with_a_build_cmd() {
[COMPILING] a v0.5.0 (file://[..])
[RUNNING] `rustc [..] a[/]build.rs [..] --extern b=[..]`
[RUNNING] `[..][/]a-[..][/]build-script-build`
[RUNNING] `rustc --crate-name a [..]lib.rs --crate-type lib -g \
[RUNNING] `rustc --crate-name a [..]lib.rs --crate-type lib \
--emit=dep-info,link -g \
-C metadata=[..] \
--out-dir [..]target[/]debug[/]deps --emit=dep-info,link \
--out-dir [..]target[/]debug[/]deps \
-L [..]target[/]debug[/]deps`
[COMPILING] foo v0.5.0 (file://[..])
[RUNNING] `rustc --crate-name build_script_build build.rs --crate-type bin \
-g -C metadata=[..] --out-dir [..] --emit=dep-info,link \
--emit=dep-info,link \
-g -C metadata=[..] --out-dir [..] \
-L [..]target[/]debug[/]deps \
--extern a=[..]liba[..].rlib`
[RUNNING] `[..][/]foo-[..][/]build-script-build`
[RUNNING] `rustc --crate-name foo [..]lib.rs --crate-type lib -g \
[RUNNING] `rustc --crate-name foo [..]lib.rs --crate-type lib \
--emit=dep-info,link -g \
-C metadata=[..] \
--out-dir [..] --emit=dep-info,link \
--out-dir [..] \
-L [..]target[/]debug[/]deps`
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
"));
Expand Down
30 changes: 15 additions & 15 deletions tests/build.rs
Expand Up @@ -794,21 +794,20 @@ fn cargo_default_env_metadata_env_var() {
execs().with_status(0).with_stderr(&format!("\
[COMPILING] bar v0.0.1 ({url}/bar)
[RUNNING] `rustc --crate-name bar bar[/]src[/]lib.rs --crate-type dylib \
--emit=dep-info,link \
-C prefer-dynamic -g \
-C metadata=[..] \
--out-dir [..] \
--emit=dep-info,link \
-L dependency={dir}[/]target[/]debug[/]deps`
[COMPILING] foo v0.0.1 ({url})
[RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib -g \
[RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib \
--emit=dep-info,link -g \
-C metadata=[..] \
-C extra-filename=[..] \
--out-dir [..] \
--emit=dep-info,link \
-L dependency={dir}[/]target[/]debug[/]deps \
--extern bar={dir}[/]target[/]debug[/]deps[/]{prefix}bar{suffix}`
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
",
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]",
dir = p.root().display(),
url = p.url(),
prefix = env::consts::DLL_PREFIX,
Expand All @@ -822,17 +821,17 @@ suffix = env::consts::DLL_SUFFIX,
execs().with_status(0).with_stderr(&format!("\
[COMPILING] bar v0.0.1 ({url}/bar)
[RUNNING] `rustc --crate-name bar bar[/]src[/]lib.rs --crate-type dylib \
--emit=dep-info,link \
-C prefer-dynamic -g \
-C metadata=[..] \
--out-dir [..] \
--emit=dep-info,link \
-L dependency={dir}[/]target[/]debug[/]deps`
[COMPILING] foo v0.0.1 ({url})
[RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib -g \
[RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib \
--emit=dep-info,link -g \
-C metadata=[..] \
-C extra-filename=[..] \
--out-dir [..] \
--emit=dep-info,link \
-L dependency={dir}[/]target[/]debug[/]deps \
--extern bar={dir}[/]target[/]debug[/]deps[/]{prefix}bar-[..]{suffix}`
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
Expand Down Expand Up @@ -1142,11 +1141,11 @@ fn lto_build() {
execs().with_status(0).with_stderr(&format!("\
[COMPILING] test v0.0.0 ({url})
[RUNNING] `rustc --crate-name test src[/]main.rs --crate-type bin \
--emit=dep-info,link \
-C opt-level=3 \
-C lto \
-C metadata=[..] \
--out-dir {dir}[/]target[/]release[/]deps \
--emit=dep-info,link \
-L dependency={dir}[/]target[/]release[/]deps`
[FINISHED] release [optimized] target(s) in [..]
",
Expand All @@ -1170,10 +1169,10 @@ fn verbose_build() {
assert_that(p.cargo_process("build").arg("-v"),
execs().with_status(0).with_stderr(&format!("\
[COMPILING] test v0.0.0 ({url})
[RUNNING] `rustc --crate-name test src[/]lib.rs --crate-type lib -g \
[RUNNING] `rustc --crate-name test src[/]lib.rs --crate-type lib \
--emit=dep-info,link -g \
-C metadata=[..] \
--out-dir [..] \
--emit=dep-info,link \
-L dependency={dir}[/]target[/]debug[/]deps`
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
",
Expand All @@ -1198,10 +1197,10 @@ fn verbose_release_build() {
execs().with_status(0).with_stderr(&format!("\
[COMPILING] test v0.0.0 ({url})
[RUNNING] `rustc --crate-name test src[/]lib.rs --crate-type lib \
--emit=dep-info,link \
-C opt-level=3 \
-C metadata=[..] \
--out-dir [..] \
--emit=dep-info,link \
-L dependency={dir}[/]target[/]release[/]deps`
[FINISHED] release [optimized] target(s) in [..]
",
Expand Down Expand Up @@ -1241,18 +1240,19 @@ fn verbose_release_build_deps() {
execs().with_status(0).with_stderr(&format!("\
[COMPILING] foo v0.0.0 ({url}/foo)
[RUNNING] `rustc --crate-name foo foo[/]src[/]lib.rs \
--crate-type dylib --crate-type rlib -C prefer-dynamic \
--crate-type dylib --crate-type rlib \
--emit=dep-info,link \
-C prefer-dynamic \
-C opt-level=3 \
-C metadata=[..] \
--out-dir [..] \
--emit=dep-info,link \
-L dependency={dir}[/]target[/]release[/]deps`
[COMPILING] test v0.0.0 ({url})
[RUNNING] `rustc --crate-name test src[/]lib.rs --crate-type lib \
--emit=dep-info,link \
-C opt-level=3 \
-C metadata=[..] \
--out-dir [..] \
--emit=dep-info,link \
-L dependency={dir}[/]target[/]release[/]deps \
--extern foo={dir}[/]target[/]release[/]deps[/]{prefix}foo{suffix} \
--extern foo={dir}[/]target[/]release[/]deps[/]libfoo.rlib`
Expand Down
2 changes: 1 addition & 1 deletion tests/check.rs
Expand Up @@ -244,7 +244,7 @@ fn issue_3418() {

assert_that(foo.cargo_process("check").arg("-v"),
execs().with_status(0)
.with_stderr_does_not_contain("--crate-type lib"));
.with_stderr_contains("[..] --emit=dep-info,metadata [..]"));
}

// Some weirdness that seems to be caused by a crate being built as well as
Expand Down
4 changes: 2 additions & 2 deletions tests/cross-compile.rs
Expand Up @@ -357,10 +357,10 @@ fn linker_and_ar() {
execs().with_status(101)
.with_stderr_contains(&format!("\
[COMPILING] foo v0.5.0 ({url})
[RUNNING] `rustc --crate-name foo src[/]foo.rs --crate-type bin -g \
[RUNNING] `rustc --crate-name foo src[/]foo.rs --crate-type bin \
--emit=dep-info,link -g \
-C metadata=[..] \
--out-dir {dir}[/]target[/]{target}[/]debug[/]deps \
--emit=dep-info,link \
--target {target} \
-C ar=my-ar-tool -C linker=my-linker-tool \
-L dependency={dir}[/]target[/]{target}[/]debug[/]deps \
Expand Down

0 comments on commit 154a30b

Please sign in to comment.