@@ -19,7 +19,6 @@ use std::libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR};
19
19
use std:: os:: mkdir_recursive;
20
20
use std:: os;
21
21
use messages:: * ;
22
- use package_id:: * ;
23
22
24
23
pub fn default_workspace ( ) -> Path {
25
24
let p = rust_path ( ) ;
@@ -51,35 +50,34 @@ pub fn make_dir_rwx(p: &Path) -> bool { os::make_dir(p, U_RWX) }
51
50
/// pkgid's short name
52
51
pub fn workspace_contains_package_id ( pkgid : & PkgId , workspace : & Path ) -> bool {
53
52
let src_dir = workspace. push ( "src" ) ;
53
+
54
54
let mut found = false ;
55
55
do os:: walk_dir ( & src_dir) |p| {
56
56
debug ! ( "=> p = %s" , p. to_str( ) ) ;
57
- if os:: path_is_dir ( p) {
57
+
58
+ let was_found = os:: path_is_dir ( p) && {
58
59
debug ! ( "p = %s, path = %s [%s]" , p. to_str( ) , pkgid. path. to_str( ) ,
59
- src_dir. push_rel( & pkgid. path) . to_str( ) ) ;
60
+ src_dir. push_rel( & pkgid. path) . to_str( ) ) ;
60
61
61
- if * p == src_dir. push_rel ( & pkgid. path ) {
62
- found = true ;
63
- }
64
- else {
62
+ * p == src_dir. push_rel ( & pkgid. path ) || {
65
63
let pf = p. filename ( ) ;
66
- for pf in pf. iter ( ) {
67
- let f_ = ( * pf) . clone ( ) ;
68
- let g = f_. to_str ( ) ;
64
+ do pf. iter ( ) . any |pf| {
65
+ let g = pf. to_str ( ) ;
69
66
match split_version_general ( g, '-' ) {
67
+ None => false ,
70
68
Some ( ( ref might_match, ref vers) ) => {
71
69
debug ! ( "might_match = %s, vers = %s" , * might_match,
72
- vers. to_str( ) ) ;
73
- if * might_match == pkgid. short_name
74
- && ( * vers == pkgid. version || pkgid. version == NoVersion )
75
- {
76
- found = true ;
77
- }
70
+ vers. to_str( ) ) ;
71
+ * might_match == pkgid. short_name
72
+ && ( pkgid. version == * vers || pkgid. version == NoVersion )
78
73
}
79
- None => ( )
80
- }
74
+ }
81
75
}
82
76
}
77
+ } ;
78
+
79
+ if was_found {
80
+ found = true
83
81
}
84
82
true
85
83
} ;
@@ -102,12 +100,9 @@ pub fn pkgid_src_in_workspace(pkgid: &PkgId, workspace: &Path) -> ~[Path] {
102
100
/// Returns a src for pkgid that does exist -- None if none of them do
103
101
pub fn first_pkgid_src_in_workspace ( pkgid : & PkgId , workspace : & Path ) -> Option < Path > {
104
102
let rs = pkgid_src_in_workspace ( pkgid, workspace) ;
105
- for p in rs. iter ( ) {
106
- if os:: path_exists ( p) {
107
- return Some ( ( * p) . clone ( ) ) ;
108
- }
109
- }
110
- None
103
+ do rs. iter ( ) . find |& p| {
104
+ os:: path_exists ( p)
105
+ } . map ( |p| ( * * p) . clone ( ) )
111
106
}
112
107
113
108
/// Figure out what the executable name for <pkgid> in <workspace>'s build
@@ -195,22 +190,31 @@ pub fn library_in_workspace(path: &Path, short_name: &str, where: Target,
195
190
196
191
debug ! ( "lib_prefix = %s and lib_filetype = %s" , lib_prefix, lib_filetype) ;
197
192
198
- let mut result_filename = None ;
199
- for p in dir_contents. iter ( ) {
200
- let mut which = 0 ;
201
- let mut hash = None ;
202
- let p_path = Path ( ( * p) . clone ( ) ) ;
203
- let extension = p_path. filetype ( ) ;
193
+ // Find a filename that matches the pattern:
194
+ // (lib_prefix)-hash-(version)(lib_suffix)
195
+ let paths = do dir_contents. iter ( ) . map |p| {
196
+ Path ( ( * p) . clone ( ) )
197
+ } ;
198
+
199
+ let mut libraries = do paths. filter |p| {
200
+ let extension = p. filetype ( ) ;
204
201
debug ! ( "p = %s, p's extension is %?" , p. to_str( ) , extension) ;
205
202
match extension {
206
- Some ( ref s ) if lib_filetype == * s => ( ) ,
207
- _ => loop
203
+ None => false ,
204
+ Some ( ref s ) => lib_filetype == * s
208
205
}
206
+ } ;
207
+
208
+ let mut result_filename = None ;
209
+ for p_path in libraries {
209
210
// Find a filename that matches the pattern: (lib_prefix)-hash-(version)(lib_suffix)
210
211
// and remember what the hash was
211
212
let f_name = match p_path. filename ( ) {
212
213
Some ( s) => s, None => loop
213
214
} ;
215
+
216
+ let mut hash = None ;
217
+ let mut which = 0 ;
214
218
for piece in f_name. split_iter ( '-' ) {
215
219
debug ! ( "a piece = %s" , piece) ;
216
220
if which == 0 && piece != lib_prefix {
@@ -229,26 +233,27 @@ pub fn library_in_workspace(path: &Path, short_name: &str, where: Target,
229
233
break ;
230
234
}
231
235
}
236
+
232
237
if hash. is_some ( ) {
233
238
result_filename = Some ( p_path) ;
234
239
break ;
235
240
}
236
241
}
237
242
243
+ if result_filename. is_none ( ) {
244
+ warn ( fmt ! ( "library_in_workspace didn't find a library in %s for %s" ,
245
+ dir_to_search. to_str( ) , short_name) ) ;
246
+ }
247
+
238
248
// Return the filename that matches, which we now know exists
239
249
// (if result_filename != None)
240
- match result_filename {
241
- None => {
242
- warn( fmt ! ( "library_in_workspace didn't find a library in %s for %s" ,
243
- dir_to_search. to_str( ) , short_name) ) ;
244
- None
245
- }
246
- Some ( result_filename) => {
247
- let absolute_path = dir_to_search. push_rel ( & result_filename) ;
248
- debug ! ( "result_filename = %s" , absolute_path. to_str( ) ) ;
249
- Some ( absolute_path)
250
- }
251
- }
250
+ let abs_path = do result_filename. map |result_filename| {
251
+ let absolute_path = dir_to_search. push_rel ( result_filename) ;
252
+ debug ! ( "result_filename = %s" , absolute_path. to_str( ) ) ;
253
+ absolute_path
254
+ } ;
255
+
256
+ abs_path
252
257
}
253
258
254
259
/// Returns the executable that would be installed for <pkgid>
0 commit comments