10
10
11
11
// rustpkg utilities having to do with paths and directories
12
12
13
- use util:: PkgId ;
13
+ pub use util:: { PkgId , RemotePath , LocalPath } ;
14
14
use core:: libc:: consts:: os:: posix88:: { S_IRUSR , S_IWUSR , S_IXUSR } ;
15
15
use core:: os:: mkdir_recursive;
16
-
17
- #[ deriving( Eq ) ]
18
- pub enum OutputType { Main , Lib , Bench , Test }
16
+ pub use util:: { normalize, OutputType , Main , Lib , Bench , Test } ;
19
17
20
18
/// Returns the value of RUST_PATH, as a list
21
19
/// of Paths. In general this should be read from the
@@ -31,67 +29,73 @@ pub static u_rwx: i32 = (S_IRUSR | S_IWUSR | S_IXUSR) as i32;
31
29
/// succeeded.
32
30
pub fn make_dir_rwx ( p : & Path ) -> bool { os:: make_dir ( p, u_rwx) }
33
31
34
- /// Replace all occurrences of '-' in the stem part of path with '_'
35
- /// This is because we treat rust-foo-bar-quux and rust_foo_bar_quux
36
- /// as the same name
37
- pub fn normalize ( p : ~Path ) -> ~Path {
38
- match p. filestem ( ) {
39
- None => p,
40
- Some ( st) => {
41
- let replaced = str:: replace ( st, "-" , "_" ) ;
42
- if replaced != st {
43
- ~p. with_filestem ( replaced)
44
- }
45
- else {
46
- p
47
- }
48
- }
49
- }
50
- }
51
-
52
32
// n.b. So far this only handles local workspaces
53
33
// n.b. The next three functions ignore the package version right
54
34
// now. Should fix that.
55
35
56
36
/// True if there's a directory in <workspace> with
57
37
/// pkgid's short name
58
38
pub fn workspace_contains_package_id ( pkgid : & PkgId , workspace : & Path ) -> bool {
59
- let pkgpath = workspace. push ( "src" ) . push ( pkgid. path . to_str ( ) ) ;
39
+ let pkgpath = workspace. push ( "src" ) . push ( pkgid. local_path . to_str ( ) ) ;
60
40
os:: path_is_dir ( & pkgpath)
61
41
}
62
42
63
43
/// Return the directory for <pkgid>'s source files in <workspace>.
64
44
/// Doesn't check that it exists.
65
45
pub fn pkgid_src_in_workspace ( pkgid : & PkgId , workspace : & Path ) -> Path {
66
46
let result = workspace. push ( "src" ) ;
67
- result. push ( pkgid. path . to_str ( ) )
47
+ result. push ( pkgid. local_path . to_str ( ) )
68
48
}
69
49
70
50
/// Figure out what the executable name for <pkgid> in <workspace>'s build
71
51
/// directory is, and if the file exists, return it.
72
52
pub fn built_executable_in_workspace ( pkgid : & PkgId , workspace : & Path ) -> Option < Path > {
73
53
let mut result = workspace. push ( "build" ) ;
74
- result = result. push_rel ( & pkgid. path ) ;
75
54
// should use a target-specific subdirectory
76
- result = mk_output_path ( Main , fmt ! ( "%s-%s" , pkgid. path. to_str( ) , pkgid. version. to_str( ) ) ,
77
- result) ;
55
+ result = mk_output_path ( Main , pkgid, & result) ;
78
56
debug ! ( "built_executable_in_workspace: checking whether %s exists" ,
79
57
result. to_str( ) ) ;
80
58
if os:: path_exists ( & result) {
81
59
Some ( result)
82
60
}
83
61
else {
62
+ // This is not an error, but it's worth logging it
63
+ error ! ( fmt!( "built_executable_in_workspace: %s does not exist" , result. to_str( ) ) ) ;
84
64
None
85
65
}
86
66
}
87
67
88
- /// Figure out what the library name for <pkgid> in <workspace>'s build
68
+ /// Figure out what the test name for <pkgid> in <workspace>'s build
89
69
/// directory is, and if the file exists, return it.
90
- pub fn built_library_in_workspace ( pkgid : & PkgId , workspace : & Path ) -> Option < Path > {
70
+ pub fn built_test_in_workspace ( pkgid : & PkgId , workspace : & Path ) -> Option < Path > {
71
+ output_in_workspace ( pkgid, workspace, Test )
72
+ }
73
+
74
+ /// Figure out what the test name for <pkgid> in <workspace>'s build
75
+ /// directory is, and if the file exists, return it.
76
+ pub fn built_bench_in_workspace ( pkgid : & PkgId , workspace : & Path ) -> Option < Path > {
77
+ output_in_workspace ( pkgid, workspace, Bench )
78
+ }
79
+
80
+ fn output_in_workspace ( pkgid : & PkgId , workspace : & Path , what : OutputType ) -> Option < Path > {
91
81
let mut result = workspace. push ( "build" ) ;
92
- result = result. push_rel ( & pkgid. path ) ;
93
82
// should use a target-specific subdirectory
94
- result = mk_output_path ( Lib , pkgid. path . to_str ( ) , result) ;
83
+ result = mk_output_path ( what, pkgid, & result) ;
84
+ debug ! ( "output_in_workspace: checking whether %s exists" ,
85
+ result. to_str( ) ) ;
86
+ if os:: path_exists ( & result) {
87
+ Some ( result)
88
+ }
89
+ else {
90
+ error ! ( fmt!( "output_in_workspace: %s does not exist" , result. to_str( ) ) ) ;
91
+ None
92
+ }
93
+ }
94
+
95
+ /// Figure out what the library name for <pkgid> in <workspace>'s build
96
+ /// directory is, and if the file exists, return it.
97
+ pub fn built_library_in_workspace ( pkgid : & PkgId , workspace : & Path ) -> Option < Path > {
98
+ let result = mk_output_path ( Lib , pkgid, & workspace. push ( "build" ) ) ;
95
99
debug ! ( "built_library_in_workspace: checking whether %s exists" ,
96
100
result. to_str( ) ) ;
97
101
@@ -100,8 +104,7 @@ pub fn built_library_in_workspace(pkgid: &PkgId, workspace: &Path) -> Option<Pat
100
104
let dir_contents = os:: list_dir ( & result. pop ( ) ) ;
101
105
debug ! ( "dir has %? entries" , dir_contents. len( ) ) ;
102
106
103
- // n.b. This code assumes the pkgid's path only has one element
104
- let lib_prefix = fmt ! ( "%s%s" , os:: consts:: DLL_PREFIX , pkgid. path. to_str( ) ) ;
107
+ let lib_prefix = fmt ! ( "%s%s" , os:: consts:: DLL_PREFIX , pkgid. short_name) ;
105
108
let lib_filetype = fmt ! ( "%s%s" , pkgid. version. to_str( ) , os:: consts:: DLL_SUFFIX ) ;
106
109
107
110
debug ! ( "lib_prefix = %s and lib_filetype = %s" , lib_prefix, lib_filetype) ;
@@ -173,12 +176,14 @@ pub fn target_library_in_workspace(pkgid: &PkgId, workspace: &Path) -> Path {
173
176
174
177
/// Returns the test executable that would be installed for <pkgid>
175
178
/// in <workspace>
179
+ /// note that we *don't* install test executables, so this is just for unit testing
176
180
pub fn target_test_in_workspace ( pkgid: & PkgId , workspace: & Path ) -> Path {
177
181
target_file_in_workspace( pkgid, workspace, Test )
178
182
}
179
183
180
184
/// Returns the bench executable that would be installed for <pkgid>
181
185
/// in <workspace>
186
+ /// note that we *don't* install bench executables, so this is just for unit testing
182
187
pub fn target_bench_in_workspace ( pkgid: & PkgId , workspace: & Path ) -> Path {
183
188
target_file_in_workspace( pkgid, workspace, Bench )
184
189
}
@@ -187,18 +192,14 @@ fn target_file_in_workspace(pkgid: &PkgId, workspace: &Path,
187
192
what : OutputType ) -> Path {
188
193
use conditions:: bad_path:: cond;
189
194
190
- let ( subdir, create_dir ) = match what {
191
- Main => ( "bin" , true ) , Lib => ( "lib" , true ) , Test | Bench => ( "build" , false )
195
+ let subdir = match what {
196
+ Lib => "lib" , Main | Test | Bench => "bin"
192
197
} ;
193
198
let result = workspace. push ( subdir) ;
194
- if create_dir {
195
- if !os:: path_exists ( & result) && !mkdir_recursive ( & result, u_rwx) {
196
- cond. raise ( ( copy result,
197
- fmt ! ( "I couldn't create the %s dir" , subdir) ) ) ;
198
- }
199
+ if !os:: path_exists ( & result) && !mkdir_recursive ( & result, u_rwx) {
200
+ cond. raise ( ( copy result, fmt ! ( "I couldn't create the %s dir" , subdir) ) ) ;
199
201
}
200
- mk_output_path ( what, pkgid. path . to_str ( ) , result)
201
-
202
+ mk_output_path ( what, pkgid, & result)
202
203
}
203
204
204
205
/// Return the directory for <pkgid>'s build artifacts in <workspace>.
@@ -209,7 +210,7 @@ pub fn build_pkg_id_in_workspace(pkgid: &PkgId, workspace: &Path) -> Path {
209
210
let mut result = workspace. push ( "build" ) ;
210
211
// n.b. Should actually use a target-specific
211
212
// subdirectory of build/
212
- result = result. push ( normalize ( ~copy pkgid. path ) . to_str ( ) ) ;
213
+ result = result. push_rel ( & * pkgid. local_path ) ;
213
214
if os:: path_exists ( & result) || os:: mkdir_recursive ( & result, u_rwx) {
214
215
result
215
216
}
@@ -220,15 +221,26 @@ pub fn build_pkg_id_in_workspace(pkgid: &PkgId, workspace: &Path) -> Path {
220
221
221
222
/// Return the output file for a given directory name,
222
223
/// given whether we're building a library and whether we're building tests
223
- pub fn mk_output_path ( what : OutputType , short_name : ~str , dir : Path ) -> Path {
224
- match what {
225
- Lib => dir. push ( os:: dll_filename ( short_name) ) ,
226
- _ => dir. push ( fmt ! ( "%s%s%s" , short_name,
224
+ pub fn mk_output_path ( what : OutputType , pkg_id : & PkgId , workspace : & Path ) -> Path {
225
+ let short_name_with_version = pkg_id. short_name_with_version ( ) ;
226
+ // Not local_path.dir_path()! For package foo/bar/blat/, we want
227
+ // the executable blat-0.5 to live under blat/
228
+ let dir = workspace. push_rel ( & * pkg_id. local_path ) ;
229
+ debug ! ( "mk_output_path: short_name = %s, path = %s" ,
230
+ if what == Lib { copy short_name_with_version } else { copy pkg_id. short_name } ,
231
+ dir. to_str( ) ) ;
232
+ let output_path = match what {
233
+ // this code is duplicated from elsewhere; fix this
234
+ Lib => dir. push ( os:: dll_filename ( short_name_with_version) ) ,
235
+ // executable names *aren't* versioned
236
+ _ => dir. push ( fmt ! ( "%s%s%s" , copy pkg_id. short_name,
227
237
match what {
228
238
Test => "test" ,
229
239
Bench => "bench" ,
230
240
_ => ""
231
241
}
232
242
os:: EXE_SUFFIX ) )
233
- }
243
+ } ;
244
+ debug ! ( "mk_output_path: returning %s" , output_path. to_str( ) ) ;
245
+ output_path
234
246
}
0 commit comments