@@ -14,10 +14,7 @@ use metadata::cstore;
1414use metadata:: filesearch;
1515
1616use std:: hashmap:: HashSet ;
17- use std:: num;
18- use std:: os;
19- use std:: util;
20- use std:: vec;
17+ use std:: { num, os, path, uint, util, vec} ;
2118
2219fn not_win32 ( os : session:: os ) -> bool {
2320 os != session:: os_win32
@@ -122,44 +119,10 @@ pub fn get_rpath_relative_to_output(os: session::os,
122119 session:: os_win32 => util:: unreachable ( )
123120 } ;
124121
125- Path ( prefix) . push_rel ( & get_relative_to ( & os:: make_absolute ( output) ,
122+ Path ( prefix) . push_rel ( & path :: get_relative_to ( & os:: make_absolute ( output) ,
126123 & os:: make_absolute ( lib) ) )
127124}
128125
129- // Find the relative path from one file to another
130- pub fn get_relative_to ( abs1 : & Path , abs2 : & Path ) -> Path {
131- assert ! ( abs1. is_absolute) ;
132- assert ! ( abs2. is_absolute) ;
133- let abs1 = abs1. normalize ( ) ;
134- let abs2 = abs2. normalize ( ) ;
135- debug ! ( "finding relative path from %s to %s" ,
136- abs1. to_str( ) , abs2. to_str( ) ) ;
137- let split1: & [ ~str ] = abs1. components ;
138- let split2: & [ ~str ] = abs2. components ;
139- let len1 = split1. len ( ) ;
140- let len2 = split2. len ( ) ;
141- assert ! ( len1 > 0 ) ;
142- assert ! ( len2 > 0 ) ;
143-
144- let max_common_path = num:: min ( len1, len2) - 1 ;
145- let mut start_idx = 0 ;
146- while start_idx < max_common_path
147- && split1[ start_idx] == split2[ start_idx] {
148- start_idx += 1 ;
149- }
150-
151- let mut path = ~[ ] ;
152- foreach _ in range( start_idx, len1 - 1 ) { path. push ( ~".."); };
153-
154- path.push_all(split2.slice(start_idx, len2 - 1));
155-
156- return if !path.is_empty() {
157- Path(" ") . push_many ( path)
158- } else {
159- Path ( "." )
160- }
161- }
162-
163126fn get_absolute_rpaths ( libs : & [ Path ] ) -> ~[ Path ] {
164127 libs. iter ( ) . transform ( |a| get_absolute_rpath ( a) ) . collect ( )
165128}
@@ -199,7 +162,6 @@ mod test {
199162 #[ cfg( test) ]
200163 #[ cfg( test) ]
201164 use back:: rpath:: { get_absolute_rpath, get_install_prefix_rpath} ;
202- use back:: rpath:: { get_relative_to, get_rpath_relative_to_output} ;
203165 use back:: rpath:: { minimize_rpaths, rpaths_to_flags} ;
204166 use driver:: session;
205167
@@ -244,78 +206,9 @@ mod test {
244206 assert_eq!(res, ~[Path(" 1 a"), Path(" 2 "), Path(" 4 a"), Path(" 3 ")]);
245207 }
246208
247- #[test]
248- fn test_relative_to1() {
249- let p1 = Path(" /usr/bin/rustc");
250- let p2 = Path(" /usr/lib/mylib");
251- let res = get_relative_to(&p1, &p2);
252- assert_eq!(res, Path(" ../lib"));
253- }
254-
255- #[test]
256- fn test_relative_to2() {
257- let p1 = Path(" /usr/bin/rustc");
258- let p2 = Path(" /usr/bin/../lib/mylib");
259- let res = get_relative_to(&p1, &p2);
260- assert_eq!(res, Path(" ../lib"));
261- }
262-
263- #[test]
264- fn test_relative_to3() {
265- let p1 = Path(" /usr/bin/whatever/rustc");
266- let p2 = Path(" /usr/lib/whatever/mylib");
267- let res = get_relative_to(&p1, &p2);
268- assert_eq!(res, Path(" ../../lib/whatever"));
269- }
270-
271- #[test]
272- fn test_relative_to4() {
273- let p1 = Path(" /usr/bin/whatever/../rustc");
274- let p2 = Path(" /usr/lib/whatever/mylib");
275- let res = get_relative_to(&p1, &p2);
276- assert_eq!(res, Path(" ../lib/whatever"));
277- }
278-
279- #[test]
280- fn test_relative_to5() {
281- let p1 = Path(" /usr/bin/whatever/../rustc");
282- let p2 = Path(" /usr/lib/whatever/../mylib");
283- let res = get_relative_to(&p1, &p2);
284- assert_eq!(res, Path(" ../lib"));
285- }
286-
287- #[test]
288- fn test_relative_to6() {
289- let p1 = Path(" /1 ");
290- let p2 = Path(" /2 /3 ");
291- let res = get_relative_to(&p1, &p2);
292- assert_eq!(res, Path(" 2 "));
293- }
294-
295- #[test]
296- fn test_relative_to7() {
297- let p1 = Path(" /1 /2 ");
298- let p2 = Path(" /3 ");
299- let res = get_relative_to(&p1, &p2);
300- assert_eq!(res, Path(" .."));
301- }
302-
303- #[test]
304- fn test_relative_to8() {
305- let p1 = Path(" /home/brian/Dev /rust/build/").push_rel(
306- &Path(" stage2/lib/rustc/i686-unknown-linux-gnu/lib/librustc. so"));
307- let p2 = Path(" /home/brian/Dev /rust/build/stage2/bin/..").push_rel(
308- &Path(" lib/rustc/i686-unknown-linux-gnu/lib/libstd. so"));
309- let res = get_relative_to(&p1, &p2);
310- debug!(" test_relative_tu8: %s vs. %s",
311- res.to_str(),
312- Path(" . ").to_str());
313- assert_eq!(res, Path(" . "));
314- }
315-
316209 #[test]
317210 #[cfg(target_os = " linux")]
318- #[cfg(target_os = " andorid ")]
211+ #[cfg(target_os = " android ")]
319212 fn test_rpath_relative() {
320213 let o = session::os_linux;
321214 let res = get_rpath_relative_to_output(o,
0 commit comments