@@ -2,6 +2,7 @@ use rustc_data_structures::fx::FxHashSet;
22use std:: env;
33use std:: fs;
44use std:: path:: { Path , PathBuf } ;
5+ use pathdiff:: diff_paths;
56
67use rustc_hir:: def_id:: CrateNum ;
78use rustc_middle:: middle:: cstore:: LibSource ;
@@ -109,37 +110,7 @@ fn get_rpath_relative_to_output(config: &mut RPathConfig<'_>, lib: &Path) -> Str
109110// In particular, this handles the case on unix where both paths are
110111// absolute but with only the root as the common directory.
111112fn path_relative_from ( path : & Path , base : & Path ) -> Option < PathBuf > {
112- use std:: path:: Component ;
113-
114- if path. is_absolute ( ) != base. is_absolute ( ) {
115- path. is_absolute ( ) . then ( || PathBuf :: from ( path) )
116- } else {
117- let mut ita = path. components ( ) ;
118- let mut itb = base. components ( ) ;
119- let mut comps: Vec < Component < ' _ > > = vec ! [ ] ;
120- loop {
121- match ( ita. next ( ) , itb. next ( ) ) {
122- ( None , None ) => break ,
123- ( Some ( a) , None ) => {
124- comps. push ( a) ;
125- comps. extend ( ita. by_ref ( ) ) ;
126- break ;
127- }
128- ( None , _) => comps. push ( Component :: ParentDir ) ,
129- ( Some ( a) , Some ( b) ) if comps. is_empty ( ) && a == b => ( ) ,
130- ( Some ( a) , Some ( b) ) if b == Component :: CurDir => comps. push ( a) ,
131- ( Some ( _) , Some ( b) ) if b == Component :: ParentDir => return None ,
132- ( Some ( a) , Some ( _) ) => {
133- comps. push ( Component :: ParentDir ) ;
134- comps. extend ( itb. map ( |_| Component :: ParentDir ) ) ;
135- comps. push ( a) ;
136- comps. extend ( ita. by_ref ( ) ) ;
137- break ;
138- }
139- }
140- }
141- Some ( comps. iter ( ) . map ( |c| c. as_os_str ( ) ) . collect ( ) )
142- }
113+ diff_paths ( path, base)
143114}
144115
145116fn get_install_prefix_rpath ( config : & mut RPathConfig < ' _ > ) -> String {
0 commit comments