@@ -14,6 +14,7 @@ pub use package_id::PkgId;
1414pub use target:: { OutputType , Main , Lib , Test , Bench , Target , Build , Install } ;
1515pub use version:: { Version , NoVersion , split_version_general, try_parsing_version} ;
1616pub use rustc:: metadata:: filesearch:: rust_path;
17+ use rustc:: driver:: driver:: host_triple;
1718
1819use std:: libc:: consts:: os:: posix88:: { S_IRUSR , S_IWUSR , S_IXUSR } ;
1920use std:: os:: mkdir_recursive;
@@ -94,10 +95,29 @@ pub fn workspace_contains_package_id_(pkgid: &PkgId, workspace: &Path,
9495 found
9596}
9697
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+
97117/// Figure out what the executable name for <pkgid> in <workspace>'s build
98118/// directory is, and if the file exists, return it.
99119pub 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 ) ;
101121 // should use a target-specific subdirectory
102122 result = mk_output_path ( Main , Build , pkgid, result) ;
103123 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>
124144}
125145
126146fn 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 ) ;
128148 // should use a target-specific subdirectory
129149 result = mk_output_path ( what, Build , pkgid, result) ;
130150 debug ! ( "output_in_workspace: checking whether %s exists" ,
@@ -172,11 +192,21 @@ pub fn library_in_workspace(path: &Path, short_name: &str, where: Target,
172192 prefix = %s", short_name, where , workspace. to_str( ) , prefix) ;
173193
174194 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 )
177197 } ;
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 > {
178208 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) ;
180210 debug ! ( "dir has %? entries" , dir_contents. len( ) ) ;
181211
182212 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,
298328 } ;
299329 // Artifacts in the build directory live in a package-ID-specific subdirectory,
300330 // 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)
304335 } ;
305336 if !os:: path_exists ( & result) && !mkdir_recursive ( & result, U_RWX ) {
306337 cond. raise ( ( result. clone ( ) , fmt ! ( "target_file_in_workspace couldn't \
@@ -315,10 +346,10 @@ fn target_file_in_workspace(pkgid: &PkgId, workspace: &Path,
315346pub fn build_pkg_id_in_workspace ( pkgid : & PkgId , workspace : & Path ) -> Path {
316347 use conditions:: bad_path:: cond;
317348
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) ;
321350 result = result. push_rel ( & pkgid. path ) ;
351+ debug ! ( "Creating build dir %s for package id %s" , result. to_str( ) ,
352+ pkgid. to_str( ) ) ;
322353 if os:: path_exists ( & result) || os:: mkdir_recursive ( & result, U_RWX ) {
323354 result
324355 }
0 commit comments