1111// rustpkg utilities having to do with paths and directories
1212
1313use core:: prelude:: * ;
14- pub use package_path:: { RemotePath , LocalPath } ;
14+ pub use package_path:: { RemotePath , LocalPath , normalize } ;
1515pub use package_id:: PkgId ;
1616pub use target:: { OutputType , Main , Lib , Test , Bench , Target , Build , Install } ;
17+ pub use version:: { Version , NoVersion , split_version_general} ;
1718use core:: libc:: consts:: os:: posix88:: { S_IRUSR , S_IWUSR , S_IXUSR } ;
1819use core:: os:: mkdir_recursive;
1920use core:: os;
21+ use core:: iterator:: IteratorUtil ;
22+ use messages:: * ;
23+ use package_id:: * ;
2024
2125/// Returns the value of RUST_PATH, as a list
2226/// 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) }
3842/// True if there's a directory in <workspace> with
3943/// pkgid's short name
4044pub 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
4378}
4479
4580/// Returns a list of possible directories
@@ -114,31 +149,34 @@ fn output_in_workspace(pkgid: &PkgId, workspace: &Path, what: OutputType) -> Opt
114149/// Figure out what the library name for <pkgid> in <workspace>'s build
115150 /// directory is, and if the file exists, return it.
116151pub 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" )
120154}
121155
122156/// Does the actual searching stuff
123157pub 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" )
125160}
126161
127162
128163/// This doesn't take a PkgId, so we can use it for `extern mod` inference, where we
129164 /// 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.
131166 /// `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 ,
133168 workspace: & Path , prefix: & str) -> Option < Path > {
134169 debug ! ( "library_in_workspace: checking whether a library named %s exists" ,
135170 short_name) ;
136171
137172 // We don't know what the hash is, so we have to search through the directory
138173 // contents
139174
175+ debug ! ( "short_name = %s where = %? workspace = %s \
176+ prefix = %s", short_name, where , workspace. to_str( ) , prefix) ;
177+
140178 let dir_to_search = match where {
141- Build => workspace. push ( prefix) . push ( full_name ) ,
179+ Build => workspace. push( prefix) . push_rel ( & * * path ) ,
142180 Install => workspace. push( prefix)
143181 } ;
144182 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,
193231 // Return the filename that matches, which we now know exists
194232 // (if result_filename != None)
195233 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+ }
197239 Some ( result_filename) => {
198240 let absolute_path = dir_to_search. push_rel( & result_filename) ;
199241 debug ! ( "result_filename = %s" , absolute_path. to_str( ) ) ;
@@ -210,17 +252,17 @@ pub fn target_executable_in_workspace(pkgid: &PkgId, workspace: &Path) -> Path {
210252}
211253
212254
213- /// Returns the installed path for <built_library> in <workspace>
255+ /// Returns the executable that would be installed for <pkgid>
256+ /// in <workspace>
214257/// 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 {
217259 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( ) ) ) ) ;
221264 }
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 )
224266}
225267
226268/// Returns the test executable that would be installed for <pkgid>
@@ -249,7 +291,9 @@ fn target_file_in_workspace(pkgid: &PkgId, workspace: &Path,
249291 } ;
250292 let result = workspace. push( subdir) ;
251293 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 ) ) ) ;
253297 }
254298 mk_output_path( what, where, pkgid, & result)
255299}
@@ -275,7 +319,8 @@ pub fn build_pkg_id_in_workspace(pkgid: &PkgId, workspace: &Path) -> Path {
275319 /// given whether we' re building a library and whether we' re building tests
276320pub fn mk_output_path( what: OutputType , where: Target ,
277321 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( ) ) ;
279324 // Not local_path.dir_path()! For package foo/bar/blat/, we want
280325 // the executable blat-0.5 to live under blat/
281326 let dir = match where {
@@ -291,7 +336,7 @@ pub fn mk_output_path(what: OutputType, where: Target,
291336 // this code is duplicated from elsewhere; fix this
292337 Lib => dir. push( os:: dll_filename( short_name_with_version) ) ,
293338 // 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,
295340 match what {
296341 Test => "test" ,
297342 Bench => "bench" ,
0 commit comments