@@ -32,11 +32,15 @@ pub fn vendor(ws: &Workspace<'_>, opts: &VendorOptions<'_>) -> CargoResult<()> {
32
32
let vendor_config = sync ( config, & workspaces, opts) . with_context ( || "failed to sync" ) ?;
33
33
34
34
if config. shell ( ) . verbosity ( ) != Verbosity :: Quiet {
35
- crate :: drop_eprint!(
36
- config,
37
- "To use vendored sources, add this to your .cargo/config.toml for this project:\n \n "
38
- ) ;
39
- crate :: drop_print!( config, "{}" , & toml:: to_string( & vendor_config) . unwrap( ) ) ;
35
+ if vendor_config. source . is_empty ( ) {
36
+ crate :: drop_eprintln!( config, "There is no dependency to vendor in this project." ) ;
37
+ } else {
38
+ crate :: drop_eprint!(
39
+ config,
40
+ "To use vendored sources, add this to your .cargo/config.toml for this project:\n \n "
41
+ ) ;
42
+ crate :: drop_print!( config, "{}" , & toml:: to_string( & vendor_config) . unwrap( ) ) ;
43
+ }
40
44
}
41
45
42
46
Ok ( ( ) )
@@ -75,6 +79,7 @@ fn sync(
75
79
) -> CargoResult < VendorConfig > {
76
80
let canonical_destination = opts. destination . canonicalize ( ) ;
77
81
let canonical_destination = canonical_destination. as_deref ( ) . unwrap_or ( opts. destination ) ;
82
+ let dest_dir_already_exists = canonical_destination. exists ( ) ;
78
83
79
84
paths:: create_dir_all ( & canonical_destination) ?;
80
85
let mut to_remove = HashSet :: new ( ) ;
@@ -239,12 +244,6 @@ fn sync(
239
244
let mut config = BTreeMap :: new ( ) ;
240
245
241
246
let merged_source_name = "vendored-sources" ;
242
- config. insert (
243
- merged_source_name. to_string ( ) ,
244
- VendorSource :: Directory {
245
- directory : opts. destination . to_path_buf ( ) ,
246
- } ,
247
- ) ;
248
247
249
248
// replace original sources with vendor
250
249
for source_id in sources {
@@ -290,6 +289,18 @@ fn sync(
290
289
config. insert ( name, source) ;
291
290
}
292
291
292
+ if !config. is_empty ( ) {
293
+ config. insert (
294
+ merged_source_name. to_string ( ) ,
295
+ VendorSource :: Directory {
296
+ directory : opts. destination . to_path_buf ( ) ,
297
+ } ,
298
+ ) ;
299
+ } else if !dest_dir_already_exists {
300
+ // Nothing to vendor. Remove the destination dir we've just created.
301
+ paths:: remove_dir ( canonical_destination) ?;
302
+ }
303
+
293
304
Ok ( VendorConfig { source : config } )
294
305
}
295
306
0 commit comments