@@ -412,10 +412,18 @@ impl Dependency {
412
412
table. insert ( "version" , src. version . as_str ( ) . into ( ) ) ;
413
413
}
414
414
Some ( Source :: Path ( src) ) => {
415
- let relpath = path_field ( crate_root, & src. path ) ;
416
415
if let Some ( r) = src. version . as_deref ( ) {
417
416
table. insert ( "version" , r. into ( ) ) ;
418
417
}
418
+ let relative_to = if let Some ( ( base_name, base_value) ) =
419
+ src. base_name_and_value . as_ref ( )
420
+ {
421
+ table. insert ( "base" , base_name. into ( ) ) ;
422
+ base_value
423
+ } else {
424
+ crate_root
425
+ } ;
426
+ let relpath = path_field ( relative_to, & src. path ) ;
419
427
table. insert ( "path" , relpath. into ( ) ) ;
420
428
}
421
429
Some ( Source :: Git ( src) ) => {
@@ -493,12 +501,20 @@ impl Dependency {
493
501
Some ( Source :: Registry ( src) ) => {
494
502
overwrite_value ( table, "version" , src. version . as_str ( ) ) ;
495
503
496
- for key in [ "path" , "git" , "branch" , "tag" , "rev" , "workspace" ] {
504
+ for key in [ "path" , "git" , "branch" , "tag" , "rev" , "workspace" , "base" ] {
497
505
table. remove ( key) ;
498
506
}
499
507
}
500
508
Some ( Source :: Path ( src) ) => {
501
- let relpath = path_field ( crate_root, & src. path ) ;
509
+ let relative_to =
510
+ if let Some ( ( base_name, base_value) ) = src. base_name_and_value . as_ref ( ) {
511
+ overwrite_value ( table, "base" , base_name) ;
512
+ base_value
513
+ } else {
514
+ table. remove ( "base" ) ;
515
+ crate_root
516
+ } ;
517
+ let relpath = path_field ( relative_to, & src. path ) ;
502
518
overwrite_value ( table, "path" , relpath) ;
503
519
if let Some ( r) = src. version . as_deref ( ) {
504
520
overwrite_value ( table, "version" , r) ;
@@ -533,7 +549,7 @@ impl Dependency {
533
549
table. remove ( "version" ) ;
534
550
}
535
551
536
- for key in [ "path" , "workspace" ] {
552
+ for key in [ "path" , "workspace" , "base" ] {
537
553
table. remove ( key) ;
538
554
}
539
555
}
@@ -552,6 +568,7 @@ impl Dependency {
552
568
"rev" ,
553
569
"package" ,
554
570
"default-features" ,
571
+ "base" ,
555
572
] {
556
573
table. remove ( key) ;
557
574
}
@@ -812,6 +829,8 @@ impl std::fmt::Display for RegistrySource {
812
829
pub struct PathSource {
813
830
/// Local, absolute path.
814
831
pub path : PathBuf ,
832
+ /// If using a named base, the base and relative path.
833
+ pub base_name_and_value : Option < ( String , PathBuf ) > ,
815
834
/// Version requirement for when published.
816
835
pub version : Option < String > ,
817
836
}
@@ -821,6 +840,7 @@ impl PathSource {
821
840
pub fn new ( path : impl Into < PathBuf > ) -> Self {
822
841
Self {
823
842
path : path. into ( ) ,
843
+ base_name_and_value : None ,
824
844
version : None ,
825
845
}
826
846
}
@@ -843,7 +863,11 @@ impl PathSource {
843
863
844
864
impl std:: fmt:: Display for PathSource {
845
865
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
846
- self . path . display ( ) . fmt ( f)
866
+ if let Some ( ( base_name, _) ) = & self . base_name_and_value {
867
+ write ! ( f, "[{base_name}]/{}" , self . path. display( ) )
868
+ } else {
869
+ self . path . display ( ) . fmt ( f)
870
+ }
847
871
}
848
872
}
849
873
0 commit comments