Skip to content

Commit 154a30b

Browse files
committed
Auto merge of #3468 - nrc:metadata-emit, r=alexcrichton
cargo check: use --emit=metadata rather than --crate-type=metadata Requires rust-lang/rust#38571 (don't land before that does) r? @alexcrichton
2 parents 71e996e + 844d7ae commit 154a30b

File tree

11 files changed

+90
-98
lines changed

11 files changed

+90
-98
lines changed

src/cargo/ops/cargo_rustc/context.rs

Lines changed: 29 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,6 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
146146
unit: &Unit<'a>,
147147
crate_types: &mut BTreeSet<String>)
148148
-> CargoResult<()> {
149-
if unit.profile.check {
150-
crate_types.insert("metadata".to_string());
151-
}
152149
for target in unit.pkg.manifest().targets() {
153150
crate_types.extend(target.rustc_crate_types().iter().map(|s| {
154151
if *s == "lib" {
@@ -180,11 +177,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
180177
.env_remove("RUST_LOG");
181178

182179
for crate_type in crate_types {
183-
// Here and below we'll skip the metadata crate-type because it is
184-
// not supported by older compilers. We'll do this one manually.
185-
if crate_type != "metadata" {
186-
process.arg("--crate-type").arg(crate_type);
187-
}
180+
process.arg("--crate-type").arg(crate_type);
188181
}
189182
if kind == Kind::Target {
190183
process.arg("--target").arg(&self.target_triple());
@@ -216,9 +209,6 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
216209
map.insert(crate_type.to_string(), None);
217210
continue;
218211
}
219-
if crate_type == "metadata" {
220-
continue;
221-
}
222212
let line = match lines.next() {
223213
Some(line) => line,
224214
None => bail!("malformed output when learning about \
@@ -235,12 +225,6 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
235225
map.insert(crate_type.to_string(), Some((prefix.to_string(), suffix.to_string())));
236226
}
237227

238-
// Manually handle the metadata case. If it is not supported by the
239-
// compiler we'll error out elsewhere.
240-
if crate_types.contains("metadata") {
241-
map.insert("metadata".to_string(), Some(("lib".to_owned(), ".rmeta".to_owned())));
242-
}
243-
244228
let cfg = if has_cfg {
245229
Some(try!(lines.map(Cfg::from_str).collect()))
246230
} else {
@@ -502,32 +486,36 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
502486
let mut ret = Vec::new();
503487
let mut unsupported = Vec::new();
504488
{
505-
let mut add = |crate_type: &str, linkable: bool| -> CargoResult<()> {
506-
let crate_type = if crate_type == "lib" {"rlib"} else {crate_type};
507-
match info.crate_types.get(crate_type) {
508-
Some(&Some((ref prefix, ref suffix))) => {
509-
let filename = out_dir.join(format!("{}{}{}", prefix, stem, suffix));
510-
let link_dst = link_stem.clone().map(|(ld, ls)| {
511-
ld.join(format!("{}{}{}", prefix, ls, suffix))
512-
});
513-
ret.push((filename, link_dst, linkable));
514-
Ok(())
515-
}
516-
// not supported, don't worry about it
517-
Some(&None) => {
518-
unsupported.push(crate_type.to_string());
519-
Ok(())
520-
}
521-
None => {
522-
bail!("failed to learn about crate-type `{}` early on",
523-
crate_type)
524-
}
525-
}
526-
};
527-
528489
if unit.profile.check {
529-
add("metadata", true)?;
490+
let filename = out_dir.join(format!("lib{}.rmeta", stem));
491+
let link_dst = link_stem.clone().map(|(ld, ls)| {
492+
ld.join(format!("lib{}.rmeta", ls))
493+
});
494+
ret.push((filename, link_dst, true));
530495
} else {
496+
let mut add = |crate_type: &str, linkable: bool| -> CargoResult<()> {
497+
let crate_type = if crate_type == "lib" {"rlib"} else {crate_type};
498+
match info.crate_types.get(crate_type) {
499+
Some(&Some((ref prefix, ref suffix))) => {
500+
let filename = out_dir.join(format!("{}{}{}", prefix, stem, suffix));
501+
let link_dst = link_stem.clone().map(|(ld, ls)| {
502+
ld.join(format!("{}{}{}", prefix, ls, suffix))
503+
});
504+
ret.push((filename, link_dst, linkable));
505+
Ok(())
506+
}
507+
// not supported, don't worry about it
508+
Some(&None) => {
509+
unsupported.push(crate_type.to_string());
510+
Ok(())
511+
}
512+
None => {
513+
bail!("failed to learn about crate-type `{}` early on",
514+
crate_type)
515+
}
516+
}
517+
};
518+
531519
match *unit.target.kind() {
532520
TargetKind::Example |
533521
TargetKind::Bin |

src/cargo/ops/cargo_rustc/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,6 @@ fn prepare_rustc(cx: &mut Context,
460460
unit: &Unit) -> CargoResult<ProcessBuilder> {
461461
let mut base = cx.compilation.rustc_process(unit.pkg)?;
462462
build_base_args(cx, &mut base, unit, &crate_types);
463-
build_plugin_args(&mut base, cx, unit);
464463
build_deps_args(&mut base, cx, unit)?;
465464
Ok(base)
466465
}
@@ -566,14 +565,18 @@ fn build_base_args(cx: &mut Context,
566565
cmd.arg("--error-format").arg("json");
567566
}
568567

569-
if check {
570-
cmd.arg("--crate-type").arg("metadata");
571-
} else if !test {
568+
if !test {
572569
for crate_type in crate_types.iter() {
573570
cmd.arg("--crate-type").arg(crate_type);
574571
}
575572
}
576573

574+
if check {
575+
cmd.arg("--emit=dep-info,metadata");
576+
} else {
577+
cmd.arg("--emit=dep-info,link");
578+
}
579+
577580
let prefer_dynamic = (unit.target.for_host() &&
578581
!unit.target.is_custom_build()) ||
579582
(crate_types.contains(&"dylib") &&
@@ -653,10 +656,9 @@ fn build_base_args(cx: &mut Context,
653656
if rpath {
654657
cmd.arg("-C").arg("rpath");
655658
}
656-
}
657659

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

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

669-
cmd.arg("--out-dir").arg(&cx.out_dir(unit));
670-
cmd.arg("--emit=dep-info,link");
671-
672671
if unit.kind == Kind::Target {
673672
opt(cmd, "--target", "", cx.requested_target().map(|s| s.as_ref()));
674673
}
@@ -677,6 +676,7 @@ fn build_plugin_args(cmd: &mut ProcessBuilder, cx: &mut Context, unit: &Unit) {
677676
opt(cmd, "-C", "linker=", cx.linker(unit.kind).map(|s| s.as_ref()));
678677
}
679678

679+
680680
fn build_deps_args(cmd: &mut ProcessBuilder, cx: &mut Context, unit: &Unit)
681681
-> CargoResult<()> {
682682
cmd.arg("-L").arg(&{

src/cargo/util/cfg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl FromStr for Cfg {
4444
let mut p = Parser::new(s);
4545
let e = p.cfg()?;
4646
if p.t.next().is_some() {
47-
bail!("malformed cfg value or key/value pair")
47+
bail!("malformed cfg value or key/value pair: `{}`", s)
4848
}
4949
Ok(e)
5050
}

tests/build-lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ use hamcrest::{assert_that};
77
fn verbose_output_for_lib(p: &ProjectBuilder) -> String {
88
format!("\
99
[COMPILING] {name} v{version} ({url})
10-
[RUNNING] `rustc --crate-name {name} src[/]lib.rs --crate-type lib -g \
10+
[RUNNING] `rustc --crate-name {name} src[/]lib.rs --crate-type lib \
11+
--emit=dep-info,link -g \
1112
-C metadata=[..] \
1213
--out-dir [..] \
13-
--emit=dep-info,link \
1414
-L dependency={dir}[/]target[/]debug[/]deps`
1515
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
1616
",

tests/build-script.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -765,19 +765,22 @@ fn build_cmd_with_a_build_cmd() {
765765
[COMPILING] a v0.5.0 (file://[..])
766766
[RUNNING] `rustc [..] a[/]build.rs [..] --extern b=[..]`
767767
[RUNNING] `[..][/]a-[..][/]build-script-build`
768-
[RUNNING] `rustc --crate-name a [..]lib.rs --crate-type lib -g \
768+
[RUNNING] `rustc --crate-name a [..]lib.rs --crate-type lib \
769+
--emit=dep-info,link -g \
769770
-C metadata=[..] \
770-
--out-dir [..]target[/]debug[/]deps --emit=dep-info,link \
771+
--out-dir [..]target[/]debug[/]deps \
771772
-L [..]target[/]debug[/]deps`
772773
[COMPILING] foo v0.5.0 (file://[..])
773774
[RUNNING] `rustc --crate-name build_script_build build.rs --crate-type bin \
774-
-g -C metadata=[..] --out-dir [..] --emit=dep-info,link \
775+
--emit=dep-info,link \
776+
-g -C metadata=[..] --out-dir [..] \
775777
-L [..]target[/]debug[/]deps \
776778
--extern a=[..]liba[..].rlib`
777779
[RUNNING] `[..][/]foo-[..][/]build-script-build`
778-
[RUNNING] `rustc --crate-name foo [..]lib.rs --crate-type lib -g \
780+
[RUNNING] `rustc --crate-name foo [..]lib.rs --crate-type lib \
781+
--emit=dep-info,link -g \
779782
-C metadata=[..] \
780-
--out-dir [..] --emit=dep-info,link \
783+
--out-dir [..] \
781784
-L [..]target[/]debug[/]deps`
782785
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
783786
"));

tests/build.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -794,21 +794,20 @@ fn cargo_default_env_metadata_env_var() {
794794
execs().with_status(0).with_stderr(&format!("\
795795
[COMPILING] bar v0.0.1 ({url}/bar)
796796
[RUNNING] `rustc --crate-name bar bar[/]src[/]lib.rs --crate-type dylib \
797+
--emit=dep-info,link \
797798
-C prefer-dynamic -g \
798799
-C metadata=[..] \
799800
--out-dir [..] \
800-
--emit=dep-info,link \
801801
-L dependency={dir}[/]target[/]debug[/]deps`
802802
[COMPILING] foo v0.0.1 ({url})
803-
[RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib -g \
803+
[RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib \
804+
--emit=dep-info,link -g \
804805
-C metadata=[..] \
805806
-C extra-filename=[..] \
806807
--out-dir [..] \
807-
--emit=dep-info,link \
808808
-L dependency={dir}[/]target[/]debug[/]deps \
809809
--extern bar={dir}[/]target[/]debug[/]deps[/]{prefix}bar{suffix}`
810-
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
811-
",
810+
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]",
812811
dir = p.root().display(),
813812
url = p.url(),
814813
prefix = env::consts::DLL_PREFIX,
@@ -822,17 +821,17 @@ suffix = env::consts::DLL_SUFFIX,
822821
execs().with_status(0).with_stderr(&format!("\
823822
[COMPILING] bar v0.0.1 ({url}/bar)
824823
[RUNNING] `rustc --crate-name bar bar[/]src[/]lib.rs --crate-type dylib \
824+
--emit=dep-info,link \
825825
-C prefer-dynamic -g \
826826
-C metadata=[..] \
827827
--out-dir [..] \
828-
--emit=dep-info,link \
829828
-L dependency={dir}[/]target[/]debug[/]deps`
830829
[COMPILING] foo v0.0.1 ({url})
831-
[RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib -g \
830+
[RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib \
831+
--emit=dep-info,link -g \
832832
-C metadata=[..] \
833833
-C extra-filename=[..] \
834834
--out-dir [..] \
835-
--emit=dep-info,link \
836835
-L dependency={dir}[/]target[/]debug[/]deps \
837836
--extern bar={dir}[/]target[/]debug[/]deps[/]{prefix}bar-[..]{suffix}`
838837
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
@@ -1142,11 +1141,11 @@ fn lto_build() {
11421141
execs().with_status(0).with_stderr(&format!("\
11431142
[COMPILING] test v0.0.0 ({url})
11441143
[RUNNING] `rustc --crate-name test src[/]main.rs --crate-type bin \
1144+
--emit=dep-info,link \
11451145
-C opt-level=3 \
11461146
-C lto \
11471147
-C metadata=[..] \
11481148
--out-dir {dir}[/]target[/]release[/]deps \
1149-
--emit=dep-info,link \
11501149
-L dependency={dir}[/]target[/]release[/]deps`
11511150
[FINISHED] release [optimized] target(s) in [..]
11521151
",
@@ -1170,10 +1169,10 @@ fn verbose_build() {
11701169
assert_that(p.cargo_process("build").arg("-v"),
11711170
execs().with_status(0).with_stderr(&format!("\
11721171
[COMPILING] test v0.0.0 ({url})
1173-
[RUNNING] `rustc --crate-name test src[/]lib.rs --crate-type lib -g \
1172+
[RUNNING] `rustc --crate-name test src[/]lib.rs --crate-type lib \
1173+
--emit=dep-info,link -g \
11741174
-C metadata=[..] \
11751175
--out-dir [..] \
1176-
--emit=dep-info,link \
11771176
-L dependency={dir}[/]target[/]debug[/]deps`
11781177
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
11791178
",
@@ -1198,10 +1197,10 @@ fn verbose_release_build() {
11981197
execs().with_status(0).with_stderr(&format!("\
11991198
[COMPILING] test v0.0.0 ({url})
12001199
[RUNNING] `rustc --crate-name test src[/]lib.rs --crate-type lib \
1200+
--emit=dep-info,link \
12011201
-C opt-level=3 \
12021202
-C metadata=[..] \
12031203
--out-dir [..] \
1204-
--emit=dep-info,link \
12051204
-L dependency={dir}[/]target[/]release[/]deps`
12061205
[FINISHED] release [optimized] target(s) in [..]
12071206
",
@@ -1241,18 +1240,19 @@ fn verbose_release_build_deps() {
12411240
execs().with_status(0).with_stderr(&format!("\
12421241
[COMPILING] foo v0.0.0 ({url}/foo)
12431242
[RUNNING] `rustc --crate-name foo foo[/]src[/]lib.rs \
1244-
--crate-type dylib --crate-type rlib -C prefer-dynamic \
1243+
--crate-type dylib --crate-type rlib \
1244+
--emit=dep-info,link \
1245+
-C prefer-dynamic \
12451246
-C opt-level=3 \
12461247
-C metadata=[..] \
12471248
--out-dir [..] \
1248-
--emit=dep-info,link \
12491249
-L dependency={dir}[/]target[/]release[/]deps`
12501250
[COMPILING] test v0.0.0 ({url})
12511251
[RUNNING] `rustc --crate-name test src[/]lib.rs --crate-type lib \
1252+
--emit=dep-info,link \
12521253
-C opt-level=3 \
12531254
-C metadata=[..] \
12541255
--out-dir [..] \
1255-
--emit=dep-info,link \
12561256
-L dependency={dir}[/]target[/]release[/]deps \
12571257
--extern foo={dir}[/]target[/]release[/]deps[/]{prefix}foo{suffix} \
12581258
--extern foo={dir}[/]target[/]release[/]deps[/]libfoo.rlib`

tests/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ fn issue_3418() {
244244

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

250250
// Some weirdness that seems to be caused by a crate being built as well as

tests/cross-compile.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,10 @@ fn linker_and_ar() {
357357
execs().with_status(101)
358358
.with_stderr_contains(&format!("\
359359
[COMPILING] foo v0.5.0 ({url})
360-
[RUNNING] `rustc --crate-name foo src[/]foo.rs --crate-type bin -g \
360+
[RUNNING] `rustc --crate-name foo src[/]foo.rs --crate-type bin \
361+
--emit=dep-info,link -g \
361362
-C metadata=[..] \
362363
--out-dir {dir}[/]target[/]{target}[/]debug[/]deps \
363-
--emit=dep-info,link \
364364
--target {target} \
365365
-C ar=my-ar-tool -C linker=my-linker-tool \
366366
-L dependency={dir}[/]target[/]{target}[/]debug[/]deps \

0 commit comments

Comments
 (0)