@@ -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,42 +119,7 @@ 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) ,
126- & os:: make_absolute ( lib) ) )
127- }
128-
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- for _ 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- }
122+ Path ( prefix) . push_rel ( & os:: make_absolute ( output) . get_relative_to ( & os:: make_absolute ( lib) ) )
161123}
162124
163125fn get_absolute_rpaths ( libs : & [ Path ] ) -> ~[ Path ] {
@@ -208,8 +170,7 @@ mod test {
208170 #[ cfg( test) ]
209171 #[ cfg( test) ]
210172 use back:: rpath:: { get_absolute_rpath, get_install_prefix_rpath} ;
211- use back:: rpath:: { get_relative_to, get_rpath_relative_to_output} ;
212- use back:: rpath:: { minimize_rpaths, rpaths_to_flags} ;
173+ use back:: rpath:: { minimize_rpaths, rpaths_to_flags, get_rpath_relative_to_output} ;
213174 use driver:: session;
214175
215176 #[ test]
@@ -253,78 +214,9 @@ mod test {
253214 assert_eq!(res, ~[Path(" 1 a"), Path(" 2 "), Path(" 4 a"), Path(" 3 ")]);
254215 }
255216
256- #[test]
257- fn test_relative_to1() {
258- let p1 = Path(" /usr/bin/rustc");
259- let p2 = Path(" /usr/lib/mylib");
260- let res = get_relative_to(&p1, &p2);
261- assert_eq!(res, Path(" ../lib"));
262- }
263-
264- #[test]
265- fn test_relative_to2() {
266- let p1 = Path(" /usr/bin/rustc");
267- let p2 = Path(" /usr/bin/../lib/mylib");
268- let res = get_relative_to(&p1, &p2);
269- assert_eq!(res, Path(" ../lib"));
270- }
271-
272- #[test]
273- fn test_relative_to3() {
274- let p1 = Path(" /usr/bin/whatever/rustc");
275- let p2 = Path(" /usr/lib/whatever/mylib");
276- let res = get_relative_to(&p1, &p2);
277- assert_eq!(res, Path(" ../../lib/whatever"));
278- }
279-
280- #[test]
281- fn test_relative_to4() {
282- let p1 = Path(" /usr/bin/whatever/../rustc");
283- let p2 = Path(" /usr/lib/whatever/mylib");
284- let res = get_relative_to(&p1, &p2);
285- assert_eq!(res, Path(" ../lib/whatever"));
286- }
287-
288- #[test]
289- fn test_relative_to5() {
290- let p1 = Path(" /usr/bin/whatever/../rustc");
291- let p2 = Path(" /usr/lib/whatever/../mylib");
292- let res = get_relative_to(&p1, &p2);
293- assert_eq!(res, Path(" ../lib"));
294- }
295-
296- #[test]
297- fn test_relative_to6() {
298- let p1 = Path(" /1 ");
299- let p2 = Path(" /2 /3 ");
300- let res = get_relative_to(&p1, &p2);
301- assert_eq!(res, Path(" 2 "));
302- }
303-
304- #[test]
305- fn test_relative_to7() {
306- let p1 = Path(" /1 /2 ");
307- let p2 = Path(" /3 ");
308- let res = get_relative_to(&p1, &p2);
309- assert_eq!(res, Path(" .."));
310- }
311-
312- #[test]
313- fn test_relative_to8() {
314- let p1 = Path(" /home/brian/Dev /rust/build/").push_rel(
315- &Path(" stage2/lib/rustc/i686-unknown-linux-gnu/lib/librustc. so"));
316- let p2 = Path(" /home/brian/Dev /rust/build/stage2/bin/..").push_rel(
317- &Path(" lib/rustc/i686-unknown-linux-gnu/lib/libstd. so"));
318- let res = get_relative_to(&p1, &p2);
319- debug!(" test_relative_tu8: %s vs. %s",
320- res.to_str(),
321- Path(" . ").to_str());
322- assert_eq!(res, Path(" . "));
323- }
324-
325217 #[test]
326218 #[cfg(target_os = " linux")]
327- #[cfg(target_os = " andorid ")]
219+ #[cfg(target_os = " android ")]
328220 fn test_rpath_relative() {
329221 let o = session::os_linux;
330222 let res = get_rpath_relative_to_output(o,
@@ -344,7 +236,6 @@ mod test {
344236 #[test]
345237 #[cfg(target_os = " macos")]
346238 fn test_rpath_relative() {
347- // this is why refinements would be nice
348239 let o = session::os_macos;
349240 let res = get_rpath_relative_to_output(o,
350241 &Path(" bin/rustc"),
0 commit comments