@@ -35,12 +35,10 @@ use cargo::core::{PackageId, Target, TargetKind};
35
35
use cargo:: util:: ProcessBuilder ;
36
36
use cargo_metadata;
37
37
use log:: { error, trace} ;
38
- use url:: Url ;
39
38
40
- use crate :: build:: PackageArg ;
41
- use crate :: build:: plan:: { BuildKey , BuildGraph , JobQueue , WorkStatus } ;
39
+ use crate :: build:: plan:: { BuildGraph , BuildKey , JobQueue , WorkStatus } ;
42
40
use crate :: build:: rustc:: src_path;
43
- use crate :: lsp_data :: parse_file_path ;
41
+ use crate :: build :: PackageArg ;
44
42
45
43
/// Main key type by which `Unit`s will be distinguished in the build plan.
46
44
/// In Target we're mostly interested in TargetKind (Lib, Bin, ...) and name
@@ -455,19 +453,16 @@ impl PackageMap {
455
453
// Find each package in the workspace and record the root directory and package name.
456
454
fn discover_package_paths ( manifest_path : & Path ) -> HashMap < PathBuf , String > {
457
455
trace ! ( "read metadata {:?}" , manifest_path) ;
458
- let metadata = match cargo_metadata:: metadata ( Some ( manifest_path) ) {
459
- Ok ( metadata) => metadata,
460
- Err ( _) => return HashMap :: new ( ) ,
461
- } ;
462
- metadata
463
- . workspace_members
464
- . into_iter ( )
465
- . map ( |wm| {
466
- assert ! ( wm. url( ) . starts_with( "path+" ) ) ;
467
- let url = Url :: parse ( & wm. url ( ) [ 5 ..] ) . expect ( "Bad URL" ) ;
468
- let path = parse_file_path ( & url) . expect ( "URL not a path" ) ;
469
- ( path, wm. name ( ) . into ( ) )
470
- } ) . collect ( )
456
+ cargo_metadata:: MetadataCommand :: new ( )
457
+ . manifest_path ( manifest_path)
458
+ . exec ( )
459
+ . iter ( )
460
+ . flat_map ( |meta| meta. workspace_members . iter ( ) . map ( move |id| & meta[ id] ) )
461
+ . filter_map ( |pkg| {
462
+ let dir = pkg. manifest_path . parent ( ) ?. to_path_buf ( ) ;
463
+ Some ( ( dir, pkg. name . clone ( ) ) )
464
+ } )
465
+ . collect ( )
471
466
}
472
467
473
468
/// Given modified set of files, returns a set of corresponding dirty packages.
0 commit comments