11
11
// rustpkg utilities having to do with paths and directories
12
12
13
13
use core:: prelude:: * ;
14
- pub use package_path:: { RemotePath , LocalPath } ;
14
+ pub use package_path:: { RemotePath , LocalPath , normalize } ;
15
15
pub use package_id:: PkgId ;
16
16
pub use target:: { OutputType , Main , Lib , Test , Bench , Target , Build , Install } ;
17
+ pub use version:: { Version , NoVersion , split_version_general} ;
17
18
use core:: libc:: consts:: os:: posix88:: { S_IRUSR , S_IWUSR , S_IXUSR } ;
18
19
use core:: os:: mkdir_recursive;
19
20
use core:: os;
21
+ use core:: iterator:: IteratorUtil ;
22
+ use messages:: * ;
23
+ use package_id:: * ;
20
24
21
25
/// Returns the value of RUST_PATH, as a list
22
26
/// of Paths. In general this should be read from the
@@ -38,8 +42,39 @@ pub fn make_dir_rwx(p: &Path) -> bool { os::make_dir(p, u_rwx) }
38
42
/// True if there's a directory in <workspace> with
39
43
/// pkgid's short name
40
44
pub fn workspace_contains_package_id( pkgid : & PkgId , workspace : & Path ) -> bool {
41
- let pkgpath = workspace. push ( "src" ) . push ( pkgid. remote_path . to_str ( ) ) ;
42
- os:: path_is_dir ( & pkgpath)
45
+ let src_dir = workspace. push ( "src" ) ;
46
+ for os:: list_dir( & src_dir) . each |& p| {
47
+ let p = Path ( p) ;
48
+ debug ! ( "=> p = %s" , p. to_str( ) ) ;
49
+ if !os:: path_is_dir ( & src_dir. push_rel ( & p) ) {
50
+ loop ;
51
+ }
52
+ debug ! ( "p = %s, remote_path = %s" , p. to_str( ) , pkgid. remote_path. to_str( ) ) ;
53
+
54
+ if p == * pkgid. remote_path {
55
+ return true ;
56
+ }
57
+ else {
58
+ let pf = p. filename ( ) ;
59
+ for pf. iter( ) . advance |& pf| {
60
+ let f_ = copy pf;
61
+ let g = f_. to_str( ) ;
62
+ match split_version_general( g, '-' ) {
63
+ Some ( ( ref might_match, ref vers) ) => {
64
+ debug ! ( "might_match = %s, vers = %s" , * might_match,
65
+ vers. to_str( ) ) ;
66
+ if * might_match == pkgid. short_name
67
+ && ( * vers == pkgid. version || pkgid. version == NoVersion )
68
+ {
69
+ return true ;
70
+ }
71
+ }
72
+ None => ( )
73
+ }
74
+ }
75
+ }
76
+ }
77
+ false
43
78
}
44
79
45
80
/// Returns a list of possible directories
@@ -114,31 +149,34 @@ fn output_in_workspace(pkgid: &PkgId, workspace: &Path, what: OutputType) -> Opt
114
149
/// Figure out what the library name for <pkgid> in <workspace>'s build
115
150
/// directory is, and if the file exists, return it.
116
151
pub fn built_library_in_workspace( pkgid: & PkgId , workspace: & Path ) -> Option < Path > {
117
- // passing in local_path here sounds fishy
118
- library_in_workspace ( pkgid. local_path . to_str ( ) , pkgid. short_name , Build ,
119
- workspace, "build" )
152
+ library_in_workspace( & pkgid. local_path, pkgid. short_name,
153
+ Build , workspace, "build" )
120
154
}
121
155
122
156
/// Does the actual searching stuff
123
157
pub fn installed_library_in_workspace( short_name: & str, workspace: & Path ) -> Option < Path > {
124
- library_in_workspace ( short_name, short_name, Install , workspace, "lib" )
158
+ library_in_workspace( & normalize( RemotePath ( Path ( short_name) ) ) ,
159
+ short_name, Install , workspace, "lib" )
125
160
}
126
161
127
162
128
163
/// This doesn't take a PkgId, so we can use it for `extern mod` inference, where we
129
164
/// don' t know the entire package ID .
130
- /// `full_name ` is used to figure out the directory to search.
165
+ /// `workspace ` is used to figure out the directory to search.
131
166
/// `short_name` is taken as the link name of the library.
132
- fn library_in_workspace( full_name : & str , short_name : & str , where : Target ,
167
+ pub fn library_in_workspace( path : & LocalPath , short_name: & str, where: Target ,
133
168
workspace: & Path , prefix: & str) -> Option < Path > {
134
169
debug ! ( "library_in_workspace: checking whether a library named %s exists" ,
135
170
short_name) ;
136
171
137
172
// We don't know what the hash is, so we have to search through the directory
138
173
// contents
139
174
175
+ debug ! ( "short_name = %s where = %? workspace = %s \
176
+ prefix = %s", short_name, where , workspace. to_str( ) , prefix) ;
177
+
140
178
let dir_to_search = match where {
141
- Build => workspace. push ( prefix) . push ( full_name ) ,
179
+ Build => workspace. push( prefix) . push_rel ( & * * path ) ,
142
180
Install => workspace. push( prefix)
143
181
} ;
144
182
debug ! ( "Listing directory %s" , dir_to_search. to_str( ) ) ;
@@ -193,7 +231,11 @@ fn library_in_workspace(full_name: &str, short_name: &str, where: Target,
193
231
// Return the filename that matches, which we now know exists
194
232
// (if result_filename != None)
195
233
match result_filename {
196
- None => None,
234
+ None => {
235
+ warn( fmt ! ( "library_in_workspace didn't find a library in %s for %s" ,
236
+ dir_to_search. to_str( ) , short_name) ) ;
237
+ None
238
+ }
197
239
Some ( result_filename) => {
198
240
let absolute_path = dir_to_search. push_rel( & result_filename) ;
199
241
debug ! ( "result_filename = %s" , absolute_path. to_str( ) ) ;
@@ -210,17 +252,17 @@ pub fn target_executable_in_workspace(pkgid: &PkgId, workspace: &Path) -> Path {
210
252
}
211
253
212
254
213
- /// Returns the installed path for <built_library> in <workspace>
255
+ /// Returns the executable that would be installed for <pkgid>
256
+ /// in <workspace>
214
257
/// As a side effect, creates the lib-dir if it doesn't exist
215
- pub fn target_library_in_workspace( workspace : & Path ,
216
- built_library : & Path ) -> Path {
258
+ pub fn target_library_in_workspace( pkgid: & PkgId , workspace: & Path ) -> Path {
217
259
use conditions:: bad_path:: cond;
218
- let result = workspace. push ( "lib" ) ;
219
- if !os:: path_exists ( & result) && !mkdir_recursive ( & result, u_rwx) {
220
- cond. raise ( ( copy result, ~"I couldn' t create the library directory") ) ;
260
+ if !os:: path_is_dir( workspace) {
261
+ cond. raise( ( copy * workspace,
262
+ fmt ! ( "Workspace supplied to target_library_in_workspace \
263
+ is not a directory! %s", workspace. to_str( ) ) ) ) ;
221
264
}
222
- result. push ( built_library. filename ( ) . expect ( fmt ! ( "I don't know how to treat %s as a library" ,
223
- built_library. to_str( ) ) ) )
265
+ target_file_in_workspace( pkgid, workspace, Lib , Install )
224
266
}
225
267
226
268
/// Returns the test executable that would be installed for <pkgid>
@@ -249,7 +291,9 @@ fn target_file_in_workspace(pkgid: &PkgId, workspace: &Path,
249
291
} ;
250
292
let result = workspace. push( subdir) ;
251
293
if !os:: path_exists( & result) && !mkdir_recursive( & result, u_rwx) {
252
- cond. raise ( ( copy result, fmt ! ( "I couldn't create the %s dir" , subdir) ) ) ;
294
+ cond. raise( ( copy result, fmt ! ( "target_file_in_workspace couldn't \
295
+ create the %s dir (pkgid=%s, workspace=%s, what=%?, where=%?",
296
+ subdir, pkgid. to_str( ) , workspace. to_str( ) , what, where ) ) ) ;
253
297
}
254
298
mk_output_path( what, where, pkgid, & result)
255
299
}
@@ -275,7 +319,8 @@ pub fn build_pkg_id_in_workspace(pkgid: &PkgId, workspace: &Path) -> Path {
275
319
/// given whether we' re building a library and whether we' re building tests
276
320
pub fn mk_output_path( what: OutputType , where: Target ,
277
321
pkg_id: & PkgId , workspace: & Path ) -> Path {
278
- let short_name_with_version = pkg_id. short_name_with_version ( ) ;
322
+ let short_name_with_version = fmt!( "%s-%s" , pkg_id. short_name,
323
+ pkg_id. version. to_str( ) ) ;
279
324
// Not local_path.dir_path()! For package foo/bar/blat/, we want
280
325
// the executable blat-0.5 to live under blat/
281
326
let dir = match where {
@@ -291,7 +336,7 @@ pub fn mk_output_path(what: OutputType, where: Target,
291
336
// this code is duplicated from elsewhere; fix this
292
337
Lib => dir. push( os:: dll_filename( short_name_with_version) ) ,
293
338
// executable names *aren't* versioned
294
- _ => dir. push ( fmt ! ( "%s%s%s" , copy pkg_id. short_name,
339
+ _ => dir. push( fmt ! ( "%s%s%s" , pkg_id. short_name,
295
340
match what {
296
341
Test => "test" ,
297
342
Bench => "bench" ,
0 commit comments