@@ -14,6 +14,7 @@ pub use package_id::PkgId;
14
14
pub use target:: { OutputType , Main , Lib , Test , Bench , Target , Build , Install } ;
15
15
pub use version:: { Version , NoVersion , split_version_general, try_parsing_version} ;
16
16
pub use rustc:: metadata:: filesearch:: rust_path;
17
+ use rustc:: driver:: driver:: host_triple;
17
18
18
19
use std:: libc:: consts:: os:: posix88:: { S_IRUSR , S_IWUSR , S_IXUSR } ;
19
20
use std:: os:: mkdir_recursive;
@@ -94,10 +95,29 @@ pub fn workspace_contains_package_id_(pkgid: &PkgId, workspace: &Path,
94
95
found
95
96
}
96
97
98
+ /// Return the target-specific build subdirectory, pushed onto `base`;
99
+ /// doesn't check that it exists or create it
100
+ pub fn target_build_dir ( workspace : & Path ) -> Path {
101
+ workspace. push ( "build" ) . push ( host_triple ( ) )
102
+ }
103
+
104
+ /// Return the target-specific lib subdirectory, pushed onto `base`;
105
+ /// doesn't check that it exists or create it
106
+ fn target_lib_dir ( workspace : & Path ) -> Path {
107
+ workspace. push ( "lib" ) . push ( host_triple ( ) )
108
+ }
109
+
110
+ /// Return the bin subdirectory, pushed onto `base`;
111
+ /// doesn't check that it exists or create it
112
+ /// note: this isn't target-specific
113
+ fn target_bin_dir ( workspace : & Path ) -> Path {
114
+ workspace. push ( "bin" )
115
+ }
116
+
97
117
/// Figure out what the executable name for <pkgid> in <workspace>'s build
98
118
/// directory is, and if the file exists, return it.
99
119
pub fn built_executable_in_workspace ( pkgid : & PkgId , workspace : & Path ) -> Option < Path > {
100
- let mut result = workspace . push ( "build" ) ;
120
+ let mut result = target_build_dir ( workspace ) ;
101
121
// should use a target-specific subdirectory
102
122
result = mk_output_path ( Main , Build , pkgid, result) ;
103
123
debug ! ( "built_executable_in_workspace: checking whether %s exists" ,
@@ -124,7 +144,7 @@ pub fn built_bench_in_workspace(pkgid: &PkgId, workspace: &Path) -> Option<Path>
124
144
}
125
145
126
146
fn output_in_workspace ( pkgid : & PkgId , workspace : & Path , what : OutputType ) -> Option < Path > {
127
- let mut result = workspace . push ( "build" ) ;
147
+ let mut result = target_build_dir ( workspace ) ;
128
148
// should use a target-specific subdirectory
129
149
result = mk_output_path ( what, Build , pkgid, result) ;
130
150
debug ! ( "output_in_workspace: checking whether %s exists" ,
@@ -172,11 +192,21 @@ pub fn library_in_workspace(path: &Path, short_name: &str, where: Target,
172
192
prefix = %s", short_name, where , workspace. to_str( ) , prefix) ;
173
193
174
194
let dir_to_search = match where {
175
- Build => workspace . push ( prefix ) . push_rel ( path) ,
176
- Install => workspace . push ( prefix )
195
+ Build => target_build_dir ( workspace ) . push_rel ( path) ,
196
+ Install => target_lib_dir ( workspace )
177
197
} ;
198
+
199
+ library_in ( short_name, version, & dir_to_search)
200
+ }
201
+
202
+ // rustc doesn't use target-specific subdirectories
203
+ pub fn system_library ( sysroot : & Path , lib_name : & str ) -> Option < Path > {
204
+ library_in ( lib_name, & NoVersion , & sysroot. push ( "lib" ) )
205
+ }
206
+
207
+ fn library_in ( short_name : & str , version : & Version , dir_to_search : & Path ) -> Option < Path > {
178
208
debug ! ( "Listing directory %s" , dir_to_search. to_str( ) ) ;
179
- let dir_contents = os:: list_dir ( & dir_to_search) ;
209
+ let dir_contents = os:: list_dir ( dir_to_search) ;
180
210
debug ! ( "dir has %? entries" , dir_contents. len( ) ) ;
181
211
182
212
let lib_prefix = fmt ! ( "%s%s" , os:: consts:: DLL_PREFIX , short_name) ;
@@ -298,9 +328,10 @@ fn target_file_in_workspace(pkgid: &PkgId, workspace: &Path,
298
328
} ;
299
329
// Artifacts in the build directory live in a package-ID-specific subdirectory,
300
330
// but installed ones don't.
301
- let result = match where {
302
- Build => workspace. push ( subdir) . push_rel ( & pkgid. path ) ,
303
- _ => workspace. push ( subdir)
331
+ let result = match ( where, what) {
332
+ ( Build , _) => target_build_dir ( workspace) . push_rel ( & pkgid. path ) ,
333
+ ( Install , Lib ) => target_lib_dir ( workspace) ,
334
+ ( Install , _) => target_bin_dir ( workspace)
304
335
} ;
305
336
if !os:: path_exists ( & result) && !mkdir_recursive ( & result, U_RWX ) {
306
337
cond. raise ( ( result. clone ( ) , fmt ! ( "target_file_in_workspace couldn't \
@@ -315,10 +346,10 @@ fn target_file_in_workspace(pkgid: &PkgId, workspace: &Path,
315
346
pub fn build_pkg_id_in_workspace ( pkgid : & PkgId , workspace : & Path ) -> Path {
316
347
use conditions:: bad_path:: cond;
317
348
318
- let mut result = workspace. push ( "build" ) ;
319
- // n.b. Should actually use a target-specific
320
- // subdirectory of build/
349
+ let mut result = target_build_dir ( workspace) ;
321
350
result = result. push_rel ( & pkgid. path ) ;
351
+ debug ! ( "Creating build dir %s for package id %s" , result. to_str( ) ,
352
+ pkgid. to_str( ) ) ;
322
353
if os:: path_exists ( & result) || os:: mkdir_recursive ( & result, U_RWX ) {
323
354
result
324
355
}
0 commit comments