@@ -25,132 +25,117 @@ pub enum FileMatch { FileMatches, FileDoesntMatch }
25
25
/// a file found in that directory.
26
26
pub type pick< ' a > = ' a |path : & Path | -> FileMatch ;
27
27
28
- pub fn pick_file ( file : Path , path : & Path ) -> Option < Path > {
29
- if path. filename ( ) == Some ( file. as_vec ( ) ) {
30
- Some ( path. clone ( ) )
31
- } else {
32
- None
33
- }
34
- }
35
-
36
- pub trait FileSearch {
37
- fn sysroot ( & self ) -> @Path ;
38
- fn for_each_lib_search_path ( & self , f: |& Path | -> FileMatch ) ;
39
- fn get_target_lib_path ( & self ) -> Path ;
40
- fn get_target_lib_file_path ( & self , file : & Path ) -> Path ;
28
+ pub struct FileSearch {
29
+ sysroot : @Path ,
30
+ addl_lib_search_paths : @RefCell < HashSet < Path > > ,
31
+ target_triple : ~str
41
32
}
42
33
43
- pub fn mk_filesearch ( maybe_sysroot : & Option < @Path > ,
44
- target_triple : & str ,
45
- addl_lib_search_paths : @RefCell < HashSet < Path > > )
46
- -> @FileSearch {
47
- struct FileSearchImpl {
48
- sysroot : @Path ,
49
- addl_lib_search_paths : @RefCell < HashSet < Path > > ,
50
- target_triple : ~str
51
- }
52
- impl FileSearch for FileSearchImpl {
53
- fn sysroot ( & self ) -> @Path { self . sysroot }
54
-
55
- fn for_each_lib_search_path ( & self , f: |& Path | -> FileMatch ) {
56
- let mut visited_dirs = HashSet :: new ( ) ;
57
- let mut found = false ;
58
-
59
- let addl_lib_search_paths = self . addl_lib_search_paths . borrow ( ) ;
60
- debug ! ( "filesearch: searching additional lib search paths [{:?}]" ,
61
- addl_lib_search_paths. get( ) . len( ) ) ;
62
- for path in addl_lib_search_paths. get ( ) . iter ( ) {
63
- match f ( path) {
64
- FileMatches => found = true ,
65
- FileDoesntMatch => ( )
66
- }
67
- visited_dirs. insert ( path. as_vec ( ) . to_owned ( ) ) ;
34
+ impl FileSearch {
35
+ pub fn for_each_lib_search_path ( & self , f: |& Path | -> FileMatch ) {
36
+ let mut visited_dirs = HashSet :: new ( ) ;
37
+ let mut found = false ;
38
+
39
+ let addl_lib_search_paths = self . addl_lib_search_paths . borrow ( ) ;
40
+ debug ! ( "filesearch: searching additional lib search paths [{:?}]" ,
41
+ addl_lib_search_paths. get( ) . len( ) ) ;
42
+ for path in addl_lib_search_paths. get ( ) . iter ( ) {
43
+ match f ( path) {
44
+ FileMatches => found = true ,
45
+ FileDoesntMatch => ( )
68
46
}
47
+ visited_dirs. insert ( path. as_vec ( ) . to_owned ( ) ) ;
48
+ }
69
49
70
- debug ! ( "filesearch: searching target lib path" ) ;
71
- let tlib_path = make_target_lib_path ( self . sysroot ,
72
- self . target_triple ) ;
73
- if !visited_dirs. contains_equiv ( & tlib_path. as_vec ( ) ) {
74
- match f ( & tlib_path) {
75
- FileMatches => found = true ,
76
- FileDoesntMatch => ( )
77
- }
50
+ debug ! ( "filesearch: searching target lib path" ) ;
51
+ let tlib_path = make_target_lib_path ( self . sysroot ,
52
+ self . target_triple ) ;
53
+ if !visited_dirs. contains_equiv ( & tlib_path. as_vec ( ) ) {
54
+ match f ( & tlib_path) {
55
+ FileMatches => found = true ,
56
+ FileDoesntMatch => ( )
78
57
}
79
- visited_dirs . insert ( tlib_path . as_vec ( ) . to_owned ( ) ) ;
80
- // Try RUST_PATH
81
- if !found {
82
- let rustpath = rust_path ( ) ;
83
- for path in rustpath . iter ( ) {
84
- let tlib_path = make_rustpkg_target_lib_path ( path, self . target_triple ) ;
85
- debug ! ( "is {} in visited_dirs? {:?}" , tlib_path . display ( ) ,
86
- visited_dirs . contains_equiv ( & tlib_path. as_vec ( ) . to_owned ( ) ) ) ;
87
-
88
- if !visited_dirs . contains_equiv ( & tlib_path . as_vec ( ) ) {
89
- visited_dirs. insert ( tlib_path. as_vec ( ) . to_owned ( ) ) ;
90
- // Don't keep searching the RUST_PATH if one match turns up --
91
- // if we did, we'd get a "multiple matching crates" error
92
- match f ( & tlib_path ) {
93
- FileMatches => {
94
- break ;
95
- }
96
- FileDoesntMatch => ( )
97
- }
58
+ }
59
+ visited_dirs . insert ( tlib_path . as_vec ( ) . to_owned ( ) ) ;
60
+ // Try RUST_PATH
61
+ if !found {
62
+ let rustpath = rust_path ( ) ;
63
+ for path in rustpath . iter ( ) {
64
+ let tlib_path = make_rustpkg_target_lib_path ( path , self . target_triple ) ;
65
+ debug ! ( "is {} in visited_dirs? {:?}" , tlib_path. display ( ) ,
66
+ visited_dirs . contains_equiv ( & tlib_path . as_vec ( ) . to_owned ( ) ) ) ;
67
+
68
+ if ! visited_dirs. contains_equiv ( & tlib_path. as_vec ( ) ) {
69
+ visited_dirs . insert ( tlib_path . as_vec ( ) . to_owned ( ) ) ;
70
+ // Don't keep searching the RUST_PATH if one match turns up --
71
+ // if we did, we'd get a "multiple matching crates" error
72
+ match f ( & tlib_path ) {
73
+ FileMatches => {
74
+ break ;
75
+ }
76
+ FileDoesntMatch => ( )
98
77
}
99
78
}
100
79
}
101
80
}
102
- fn get_target_lib_path ( & self ) -> Path {
103
- make_target_lib_path ( self . sysroot , self . target_triple )
104
- }
105
- fn get_target_lib_file_path ( & self , file : & Path ) -> Path {
106
- let mut p = self . get_target_lib_path ( ) ;
107
- p. push ( file) ;
108
- p
109
- }
110
81
}
111
82
112
- let sysroot = get_sysroot ( maybe_sysroot) ;
113
- debug ! ( "using sysroot = {}" , sysroot. display( ) ) ;
114
- @FileSearchImpl {
115
- sysroot : sysroot,
116
- addl_lib_search_paths : addl_lib_search_paths,
117
- target_triple : target_triple. to_owned ( )
118
- } as @FileSearch
119
- }
83
+ pub fn get_target_lib_path ( & self ) -> Path {
84
+ make_target_lib_path ( self . sysroot , self . target_triple )
85
+ }
120
86
121
- pub fn search ( filesearch : @FileSearch , pick : pick ) {
122
- filesearch. for_each_lib_search_path ( |lib_search_path| {
123
- debug ! ( "searching {}" , lib_search_path. display( ) ) ;
124
- match io:: result ( || fs:: readdir ( lib_search_path) ) {
125
- Ok ( files) => {
126
- let mut rslt = FileDoesntMatch ;
127
- let is_rlib = |p : & & Path | {
128
- p. extension_str ( ) == Some ( "rlib" )
129
- } ;
130
- // Reading metadata out of rlibs is faster, and if we find both
131
- // an rlib and a dylib we only read one of the files of
132
- // metadata, so in the name of speed, bring all rlib files to
133
- // the front of the search list.
134
- let files1 = files. iter ( ) . filter ( |p| is_rlib ( p) ) ;
135
- let files2 = files. iter ( ) . filter ( |p| !is_rlib ( p) ) ;
136
- for path in files1. chain ( files2) {
137
- debug ! ( "testing {}" , path. display( ) ) ;
138
- let maybe_picked = pick ( path) ;
139
- match maybe_picked {
140
- FileMatches => {
141
- debug ! ( "picked {}" , path. display( ) ) ;
142
- rslt = FileMatches ;
143
- }
144
- FileDoesntMatch => {
145
- debug ! ( "rejected {}" , path. display( ) ) ;
87
+ pub fn get_target_lib_file_path ( & self , file : & Path ) -> Path {
88
+ let mut p = self . get_target_lib_path ( ) ;
89
+ p. push ( file) ;
90
+ p
91
+ }
92
+
93
+ pub fn search ( & self , pick : pick ) {
94
+ self . for_each_lib_search_path ( |lib_search_path| {
95
+ debug ! ( "searching {}" , lib_search_path. display( ) ) ;
96
+ match io:: result ( || fs:: readdir ( lib_search_path) ) {
97
+ Ok ( files) => {
98
+ let mut rslt = FileDoesntMatch ;
99
+ let is_rlib = |p : & & Path | {
100
+ p. extension_str ( ) == Some ( "rlib" )
101
+ } ;
102
+ // Reading metadata out of rlibs is faster, and if we find both
103
+ // an rlib and a dylib we only read one of the files of
104
+ // metadata, so in the name of speed, bring all rlib files to
105
+ // the front of the search list.
106
+ let files1 = files. iter ( ) . filter ( |p| is_rlib ( p) ) ;
107
+ let files2 = files. iter ( ) . filter ( |p| !is_rlib ( p) ) ;
108
+ for path in files1. chain ( files2) {
109
+ debug ! ( "testing {}" , path. display( ) ) ;
110
+ let maybe_picked = pick ( path) ;
111
+ match maybe_picked {
112
+ FileMatches => {
113
+ debug ! ( "picked {}" , path. display( ) ) ;
114
+ rslt = FileMatches ;
115
+ }
116
+ FileDoesntMatch => {
117
+ debug ! ( "rejected {}" , path. display( ) ) ;
118
+ }
146
119
}
147
120
}
121
+ rslt
148
122
}
149
- rslt
123
+ Err ( .. ) => FileDoesntMatch ,
150
124
}
151
- Err ( ..) => FileDoesntMatch ,
125
+ } ) ;
126
+ }
127
+
128
+ pub fn new ( maybe_sysroot : & Option < @Path > ,
129
+ target_triple : & str ,
130
+ addl_lib_search_paths : @RefCell < HashSet < Path > > ) -> FileSearch {
131
+ let sysroot = get_sysroot ( maybe_sysroot) ;
132
+ debug ! ( "using sysroot = {}" , sysroot. display( ) ) ;
133
+ FileSearch {
134
+ sysroot : sysroot,
135
+ addl_lib_search_paths : addl_lib_search_paths,
136
+ target_triple : target_triple. to_owned ( )
152
137
}
153
- } ) ;
138
+ }
154
139
}
155
140
156
141
pub fn relative_target_lib_path ( target_triple : & str ) -> Path {
0 commit comments