@@ -13,20 +13,17 @@ export get_rpath_flags, test;
13
13
14
14
#[ cfg( target_os="linux" ) ]
15
15
#[ cfg( target_os="macos" ) ]
16
- fn get_rpath_flags ( _sess : session:: session , _out_filename : str ) -> [ str ] {
16
+ fn get_rpath_flags ( sess : session:: session , out_filename : str ) -> [ str ] {
17
17
log "preparing the RPATH!" ;
18
18
19
- // FIXME
20
- /*
21
19
let cwd = os:: getcwd ( ) ;
22
20
let sysroot = sess. filesearch ( ) . sysroot ( ) ;
23
21
let output = out_filename;
24
22
let libs = cstore:: get_used_crate_files ( sess. get_cstore ( ) ) ;
25
23
let target_triple = sess. get_opts ( ) . target_triple ;
26
24
let rpaths = get_rpaths ( cwd, sysroot, output, libs, target_triple) ;
27
- */
28
- let rpaths = [ ] ;
29
- rpaths_to_flags ( rpaths)
25
+ rpaths_to_flags ( rpaths) ;
26
+ [ ] // FIXME: activate RPATH!
30
27
}
31
28
32
29
#[ cfg( target_os="win32" ) ]
@@ -53,14 +50,27 @@ fn get_rpaths(cwd: fs::path, sysroot: fs::path,
53
50
// Use relative paths to the libraries. Binaries can be moved
54
51
// as long as they maintain the relative relationship to the
55
52
// crates they depend on.
56
- let rpaths = get_rpaths_relative_to_output ( cwd, output, libs) ;
53
+ let rel_rpaths = get_rpaths_relative_to_output ( cwd, output, libs) ;
57
54
58
55
// Make backup absolute paths to the libraries. Binaries can
59
56
// be moved as long as the crates they link against don't move.
60
- rpaths + = get_absolute_rpaths ( cwd, libs) ;
57
+ let abs_rpaths = get_absolute_rpaths ( cwd, libs) ;
61
58
62
59
// And a final backup rpath to the global library location.
63
- rpaths += [ get_install_prefix_rpath ( target_triple) ] ;
60
+ let fallback_rpaths = [ get_install_prefix_rpath ( target_triple) ] ;
61
+
62
+ fn log_rpaths ( desc : str , rpaths : [ str ] ) {
63
+ log #fmt( "%s rpaths:" , desc) ;
64
+ for rpath in rpaths {
65
+ log #fmt( " %s" , rpath) ;
66
+ }
67
+ }
68
+
69
+ log_rpaths ( "relative" , rel_rpaths) ;
70
+ log_rpaths ( "absolute" , abs_rpaths) ;
71
+ log_rpaths ( "fallback" , fallback_rpaths) ;
72
+
73
+ let rpaths = rel_rpaths + abs_rpaths + fallback_rpaths;
64
74
65
75
// Remove duplicates
66
76
let rpaths = minimize_rpaths ( rpaths) ;
@@ -85,6 +95,8 @@ fn get_rpath_relative_to_output(cwd: fs::path,
85
95
fn get_relative_to ( abs1 : fs:: path , abs2 : fs:: path ) -> fs:: path {
86
96
assert fs:: path_is_absolute ( abs1) ;
87
97
assert fs:: path_is_absolute ( abs2) ;
98
+ log #fmt( "finding relative path from %s to %s" ,
99
+ abs1, abs2) ;
88
100
let normal1 = fs:: normalize ( abs1) ;
89
101
let normal2 = fs:: normalize ( abs2) ;
90
102
let split1 = str:: split ( normal1, os_fs:: path_sep as u8 ) ;
@@ -109,16 +121,19 @@ fn get_relative_to(abs1: fs::path, abs2: fs::path) -> fs::path {
109
121
110
122
path += vec:: slice ( split2, start_idx, len2 - 1 u) ;
111
123
112
- check vec:: is_not_empty ( path) ;
113
- ret fs:: connect_many ( path) ;
124
+ if check vec:: is_not_empty ( path) {
125
+ ret fs:: connect_many ( path) ;
126
+ } else {
127
+ ret "." ;
128
+ }
114
129
}
115
130
116
131
fn get_absolute_rpaths ( cwd : fs:: path , libs : [ fs:: path ] ) -> [ str ] {
117
132
vec:: map ( bind get_absolute_rpath ( cwd, _) , libs)
118
133
}
119
134
120
135
fn get_absolute_rpath ( cwd : fs:: path , lib : fs:: path ) -> str {
121
- get_absolute ( cwd, lib)
136
+ fs :: dirname ( get_absolute ( cwd, lib) )
122
137
}
123
138
124
139
fn get_absolute ( cwd : fs:: path , lib : fs:: path ) -> fs:: path {
@@ -144,9 +159,13 @@ fn get_install_prefix_rpath(target_triple: str) -> str {
144
159
145
160
fn minimize_rpaths ( rpaths : [ str ] ) -> [ str ] {
146
161
let set = map:: new_str_hash :: < ( ) > ( ) ;
147
- for rpath in rpaths { set. insert ( rpath, ( ) ) ; }
148
162
let minimized = [ ] ;
149
- for each rpath in set. keys ( ) { minimized += [ rpath] ; }
163
+ for rpath in rpaths {
164
+ if !set. contains_key ( rpath) {
165
+ minimized += [ rpath] ;
166
+ set. insert ( rpath, ( ) ) ;
167
+ }
168
+ }
150
169
ret minimized;
151
170
}
152
171
@@ -182,11 +201,18 @@ mod test {
182
201
}
183
202
184
203
#[ test]
185
- fn test_minimize ( ) {
204
+ fn test_minimize1 ( ) {
186
205
let res = minimize_rpaths ( [ "rpath1" , "rpath2" , "rpath1" ] ) ;
187
206
assert res == [ "rpath1" , "rpath2" ] ;
188
207
}
189
208
209
+ #[ test]
210
+ fn test_minimize2 ( ) {
211
+ let res = minimize_rpaths ( [ "1a" , "2" , "2" , "1a" , "4a" ,
212
+ "1a" , "2" , "3" , "4a" , "3" ] ) ;
213
+ assert res == [ "1a" , "2" , "4a" , "3" ] ;
214
+ }
215
+
190
216
#[ test]
191
217
fn test_relative_to1 ( ) {
192
218
let p1 = "/usr/bin/rustc" ;
@@ -243,10 +269,26 @@ mod test {
243
269
assert res == ".." ;
244
270
}
245
271
272
+ #[ test]
273
+ fn test_relative_to8 ( ) {
274
+ let p1 = "/home/brian/Dev/rust/build/"
275
+ + "stage2/lib/rustc/i686-unknown-linux-gnu/lib/librustc.so" ;
276
+ let p2 = "/home/brian/Dev/rust/build/stage2/bin/.."
277
+ + "/lib/rustc/i686-unknown-linux-gnu/lib/libstd.so" ;
278
+ let res = get_relative_to ( p1, p2) ;
279
+ assert res == "." ;
280
+ }
281
+
246
282
#[ test]
247
283
fn test_rpath_relative ( ) {
248
284
let res = get_rpath_relative_to_output (
249
285
"/usr" , "bin/rustc" , "lib/libstd.so" ) ;
250
286
assert res == "$ORIGIN/../lib" ;
251
287
}
288
+
289
+ #[ test]
290
+ fn test_get_absolute_rpath ( ) {
291
+ let res = get_absolute_rpath ( "/usr" , "lib/libstd.so" ) ;
292
+ assert res == "/usr/lib" ;
293
+ }
252
294
}
0 commit comments