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