@@ -19,7 +19,6 @@ use std::libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR};
1919use std:: os:: mkdir_recursive;
2020use std:: os;
2121use messages:: * ;
22- use package_id:: * ;
2322
2423pub fn default_workspace ( ) -> Path {
2524 let p = rust_path ( ) ;
@@ -51,35 +50,34 @@ pub fn make_dir_rwx(p: &Path) -> bool { os::make_dir(p, U_RWX) }
5150/// pkgid's short name
5251pub fn workspace_contains_package_id ( pkgid : & PkgId , workspace : & Path ) -> bool {
5352 let src_dir = workspace. push ( "src" ) ;
53+
5454 let mut found = false ;
5555 do os:: walk_dir ( & src_dir) |p| {
5656 debug ! ( "=> p = %s" , p. to_str( ) ) ;
57- if os:: path_is_dir ( p) {
57+
58+ let was_found = os:: path_is_dir ( p) && {
5859 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( ) ) ;
6061
61- if * p == src_dir. push_rel ( & pkgid. path ) {
62- found = true ;
63- }
64- else {
62+ * p == src_dir. push_rel ( & pkgid. path ) || {
6563 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 ( ) ;
6966 match split_version_general ( g, '-' ) {
67+ None => false ,
7068 Some ( ( ref might_match, ref vers) ) => {
7169 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 )
7873 }
79- None => ( )
80- }
74+ }
8175 }
8276 }
77+ } ;
78+
79+ if was_found {
80+ found = true
8381 }
8482 true
8583 } ;
@@ -102,12 +100,9 @@ pub fn pkgid_src_in_workspace(pkgid: &PkgId, workspace: &Path) -> ~[Path] {
102100/// Returns a src for pkgid that does exist -- None if none of them do
103101pub fn first_pkgid_src_in_workspace ( pkgid : & PkgId , workspace : & Path ) -> Option < Path > {
104102 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 ( ) )
111106}
112107
113108/// 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,
195190
196191 debug ! ( "lib_prefix = %s and lib_filetype = %s" , lib_prefix, lib_filetype) ;
197192
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 ( ) ;
204201 debug ! ( "p = %s, p's extension is %?" , p. to_str( ) , extension) ;
205202 match extension {
206- Some ( ref s ) if lib_filetype == * s => ( ) ,
207- _ => loop
203+ None => false ,
204+ Some ( ref s ) => lib_filetype == * s
208205 }
206+ } ;
207+
208+ let mut result_filename = None ;
209+ for p_path in libraries {
209210 // Find a filename that matches the pattern: (lib_prefix)-hash-(version)(lib_suffix)
210211 // and remember what the hash was
211212 let f_name = match p_path. filename ( ) {
212213 Some ( s) => s, None => loop
213214 } ;
215+
216+ let mut hash = None ;
217+ let mut which = 0 ;
214218 for piece in f_name. split_iter ( '-' ) {
215219 debug ! ( "a piece = %s" , piece) ;
216220 if which == 0 && piece != lib_prefix {
@@ -229,26 +233,27 @@ pub fn library_in_workspace(path: &Path, short_name: &str, where: Target,
229233 break ;
230234 }
231235 }
236+
232237 if hash. is_some ( ) {
233238 result_filename = Some ( p_path) ;
234239 break ;
235240 }
236241 }
237242
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+
238248 // Return the filename that matches, which we now know exists
239249 // (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
252257}
253258
254259/// Returns the executable that would be installed for <pkgid>
0 commit comments