@@ -16,6 +16,7 @@ use std::process::{self, Command};
16
16
17
17
use rustc_version:: VersionMeta ;
18
18
use serde:: { Deserialize , Serialize } ;
19
+ use cargo_metadata:: { MetadataCommand , Metadata } ;
19
20
20
21
use version:: * ;
21
22
@@ -582,41 +583,29 @@ path = "lib.rs"
582
583
}
583
584
}
584
585
585
- #[ derive( Deserialize ) ]
586
- struct Metadata {
587
- target_directory : PathBuf ,
588
- workspace_members : Vec < String > ,
589
- }
590
-
591
586
fn get_cargo_metadata ( ) -> Metadata {
592
- let mut cmd = cargo ( ) ;
593
- // `-Zunstable-options` is required by `--config`.
594
- cmd. args ( [ "metadata" , "--no-deps" , "--format-version=1" , "-Zunstable-options" ] ) ;
595
587
// The `build.target-dir` config can be passed by `--config` flags, so forward them to
596
588
// `cargo metadata`.
589
+ let mut additional_options = Vec :: new ( ) ;
590
+ // `-Zunstable-options` is required by `--config`.
591
+ additional_options. push ( "-Zunstable-options" . to_string ( ) ) ;
592
+
597
593
let config_flag = "--config" ;
598
594
for arg in ArgSplitFlagValue :: new (
599
595
env:: args ( ) . skip ( 3 ) , // skip the program name, "miri" and "run" / "test"
600
596
config_flag,
601
- )
602
- // Only look at `Ok`
603
- . flatten ( )
604
- {
605
- cmd. arg ( config_flag) . arg ( arg) ;
606
- }
607
- let mut child = cmd
608
- . stdin ( process:: Stdio :: null ( ) )
609
- . stdout ( process:: Stdio :: piped ( ) )
610
- . spawn ( )
611
- . expect ( "failed ro run `cargo metadata`" ) ;
612
- // Check this `Result` after `status.success()` is checked, so we don't print the error
613
- // to stderr if `cargo metadata` is also printing to stderr.
614
- let metadata: Result < Metadata , _ > = serde_json:: from_reader ( child. stdout . take ( ) . unwrap ( ) ) ;
615
- let status = child. wait ( ) . expect ( "failed to wait for `cargo metadata` to exit" ) ;
616
- if !status. success ( ) {
617
- std:: process:: exit ( status. code ( ) . unwrap_or ( -1 ) ) ;
597
+ ) . flatten ( ) { // Only look at `Ok`
598
+ additional_options. push ( config_flag. to_string ( ) ) ;
599
+ additional_options. push ( arg) ;
618
600
}
619
- metadata. unwrap_or_else ( |e| show_error ( format ! ( "invalid `cargo metadata` output: {}" , e) ) )
601
+
602
+ let metadata = MetadataCommand :: new ( )
603
+ . no_deps ( )
604
+ . other_options ( additional_options)
605
+ . exec ( )
606
+ . unwrap ( ) ;
607
+
608
+ metadata
620
609
}
621
610
622
611
/// Pulls all the crates in this workspace from the cargo metadata.
@@ -627,7 +616,7 @@ fn local_crates(metadata: &Metadata) -> String {
627
616
assert ! ( !metadata. workspace_members. is_empty( ) ) ;
628
617
let mut local_crates = String :: new ( ) ;
629
618
for member in & metadata. workspace_members {
630
- let name = member. split ( ' ' ) . next ( ) . unwrap ( ) ;
619
+ let name = member. repr . split ( ' ' ) . next ( ) . unwrap ( ) ;
631
620
let name = name. replace ( '-' , "_" ) ;
632
621
local_crates. push_str ( & name) ;
633
622
local_crates. push ( ',' ) ;
0 commit comments