@@ -259,6 +259,18 @@ impl CargoWorkspace {
259
259
sysroot : & Sysroot ,
260
260
locked : bool ,
261
261
progress : & dyn Fn ( String ) ,
262
+ ) -> anyhow:: Result < cargo_metadata:: Metadata > {
263
+ Self :: fetch_metadata_ ( cargo_toml, current_dir, config, sysroot, locked, false , progress)
264
+ }
265
+
266
+ fn fetch_metadata_ (
267
+ cargo_toml : & ManifestPath ,
268
+ current_dir : & AbsPath ,
269
+ config : & CargoConfig ,
270
+ sysroot : & Sysroot ,
271
+ locked : bool ,
272
+ no_deps : bool ,
273
+ progress : & dyn Fn ( String ) ,
262
274
) -> anyhow:: Result < cargo_metadata:: Metadata > {
263
275
let targets = find_list_of_build_targets ( config, cargo_toml, sysroot) ;
264
276
@@ -314,6 +326,9 @@ impl CargoWorkspace {
314
326
if locked {
315
327
other_options. push ( "--locked" . to_owned ( ) ) ;
316
328
}
329
+ if no_deps {
330
+ other_options. push ( "--no-deps" . to_owned ( ) ) ;
331
+ }
317
332
meta. other_options ( other_options) ;
318
333
319
334
// FIXME: Fetching metadata is a slow process, as it might require
@@ -324,6 +339,22 @@ impl CargoWorkspace {
324
339
( || -> Result < cargo_metadata:: Metadata , cargo_metadata:: Error > {
325
340
let output = meta. cargo_command ( ) . output ( ) ?;
326
341
if !output. status . success ( ) {
342
+ if !no_deps {
343
+ // If we failed to fetch metadata with deps, try again without them.
344
+ // This makes r-a still work partially when offline.
345
+ if let Ok ( metadata) = Self :: fetch_metadata_ (
346
+ cargo_toml,
347
+ current_dir,
348
+ config,
349
+ sysroot,
350
+ locked,
351
+ true ,
352
+ progress,
353
+ ) {
354
+ return Ok ( metadata) ;
355
+ }
356
+ }
357
+
327
358
return Err ( cargo_metadata:: Error :: CargoMetadata {
328
359
stderr : String :: from_utf8 ( output. stderr ) ?,
329
360
} ) ;
@@ -431,8 +462,8 @@ impl CargoWorkspace {
431
462
pkg_data. targets . push ( tgt) ;
432
463
}
433
464
}
434
- let resolve = meta. resolve . expect ( "metadata executed with deps" ) ;
435
- for mut node in resolve . nodes {
465
+ let nodes = meta. resolve . map_or_else ( Vec :: new , |it| it . nodes ) ;
466
+ for mut node in nodes {
436
467
let & source = pkg_by_id. get ( & node. id ) . unwrap ( ) ;
437
468
node. deps . sort_by ( |a, b| a. pkg . cmp ( & b. pkg ) ) ;
438
469
let dependencies = node
0 commit comments