@@ -228,11 +228,11 @@ struct PackageMetadata {
228228}
229229
230230impl CargoWorkspace {
231- pub fn from_cargo_metadata (
231+ pub fn fetch_metadata (
232232 cargo_toml : & AbsPath ,
233233 config : & CargoConfig ,
234234 progress : & dyn Fn ( String ) ,
235- ) -> Result < CargoWorkspace > {
235+ ) -> Result < cargo_metadata :: Metadata > {
236236 let mut meta = MetadataCommand :: new ( ) ;
237237 meta. cargo_path ( toolchain:: cargo ( ) ) ;
238238 meta. manifest_path ( cargo_toml. to_path_buf ( ) ) ;
@@ -262,10 +262,12 @@ impl CargoWorkspace {
262262 meta. other_options ( vec ! [ String :: from( "--filter-platform" ) , target] ) ;
263263 }
264264
265- // FIXME: Currently MetadataCommand is not based on parse_stream,
266- // So we just report it as a whole
265+ // FIXME: Fetching metadata is a slow process, as it might require
266+ // calling crates.io. We should be reporting progress here, but it's
267+ // unclear whether cargo itself supports it.
267268 progress ( "metadata" . to_string ( ) ) ;
268- let mut meta = meta. exec ( ) . with_context ( || {
269+
270+ let meta = meta. exec ( ) . with_context ( || {
269271 let cwd: Option < AbsPathBuf > =
270272 std:: env:: current_dir ( ) . ok ( ) . and_then ( |p| p. try_into ( ) . ok ( ) ) ;
271273
@@ -283,6 +285,14 @@ impl CargoWorkspace {
283285 )
284286 } ) ?;
285287
288+ Ok ( meta)
289+ }
290+
291+ pub fn new (
292+ cargo_toml : & AbsPath ,
293+ config : & CargoConfig ,
294+ mut meta : cargo_metadata:: Metadata ,
295+ ) -> CargoWorkspace {
286296 let mut pkg_by_id = FxHashMap :: default ( ) ;
287297 let mut packages = Arena :: default ( ) ;
288298 let mut targets = Arena :: default ( ) ;
@@ -296,9 +306,10 @@ impl CargoWorkspace {
296306 } = meta_pkg;
297307 let meta = from_value :: < PackageMetadata > ( metadata. clone ( ) ) . unwrap_or_default ( ) ;
298308 let is_member = ws_members. contains ( id) ;
299- let edition = edition
300- . parse :: < Edition > ( )
301- . with_context ( || format ! ( "Failed to parse edition {}" , edition) ) ?;
309+ let edition = edition. parse :: < Edition > ( ) . unwrap_or_else ( |err| {
310+ log:: error!( "Failed to parse edition {}" , err) ;
311+ Edition :: CURRENT
312+ } ) ;
302313
303314 let pkg = packages. alloc ( PackageData {
304315 id : id. repr . clone ( ) ,
@@ -366,7 +377,16 @@ impl CargoWorkspace {
366377 let build_data_config =
367378 BuildDataConfig :: new ( cargo_toml. to_path_buf ( ) , config. clone ( ) , Arc :: new ( meta. packages ) ) ;
368379
369- Ok ( CargoWorkspace { packages, targets, workspace_root, build_data_config } )
380+ CargoWorkspace { packages, targets, workspace_root, build_data_config }
381+ }
382+
383+ pub fn from_cargo_metadata3 (
384+ cargo_toml : & AbsPath ,
385+ config : & CargoConfig ,
386+ progress : & dyn Fn ( String ) ,
387+ ) -> Result < CargoWorkspace > {
388+ let meta = CargoWorkspace :: fetch_metadata ( cargo_toml, config, progress) ?;
389+ Ok ( CargoWorkspace :: new ( cargo_toml, config, meta) )
370390 }
371391
372392 pub fn packages < ' a > ( & ' a self ) -> impl Iterator < Item = Package > + ExactSizeIterator + ' a {
0 commit comments