|
14 | 14 |
|
15 | 15 | pub use crate_id::CrateId; |
16 | 16 | pub use target::{OutputType, Main, Lib, Test, Bench, Target, Build, Install}; |
17 | | -pub use version::{Version, split_version, split_version_general, |
18 | | - try_parsing_version}; |
| 17 | +pub use version::{Version, split_version, split_version_general, try_parsing_version}; |
19 | 18 | pub use rustc::metadata::filesearch::rust_path; |
20 | | -use rustc::metadata::filesearch::{libdir, relative_target_lib_path}; |
21 | | -use rustc::driver::driver::host_triple; |
22 | 19 |
|
23 | 20 | use std::libc; |
24 | 21 | use std::libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR}; |
25 | 22 | use std::os; |
26 | 23 | use std::io; |
27 | 24 | use std::io::fs; |
| 25 | +use rustc::metadata::filesearch::{libdir, relative_target_lib_path}; |
| 26 | +use rustc::driver::driver::host_triple; |
28 | 27 | use messages::*; |
29 | 28 |
|
30 | 29 | pub fn default_workspace() -> Path { |
@@ -173,151 +172,57 @@ fn output_in_workspace(crateid: &CrateId, workspace: &Path, what: OutputType) -> |
173 | 172 | /// Figure out what the library name for <crateid> in <workspace>'s build |
174 | 173 | /// directory is, and if the file exists, return it. |
175 | 174 | pub fn built_library_in_workspace(crateid: &CrateId, workspace: &Path) -> Option<Path> { |
176 | | - library_in_workspace(&crateid.path, crateid.short_name, Build, workspace, "build", |
177 | | - &crateid.version) |
| 175 | + library_in_workspace(crateid, Build, workspace) |
178 | 176 | } |
179 | 177 |
|
180 | 178 | /// Does the actual searching stuff |
181 | | -pub fn installed_library_in_workspace(pkg_path: &Path, workspace: &Path) -> Option<Path> { |
| 179 | +pub fn installed_library_in_workspace(crate_id: &CrateId, workspace: &Path) -> Option<Path> { |
182 | 180 | // This could break once we're handling multiple versions better -- I should add a test for it |
183 | 181 | // FIXME (#9639): This needs to handle non-utf8 paths |
184 | | - match pkg_path.filename_str() { |
| 182 | + match crate_id.path.filename_str() { |
185 | 183 | None => None, |
186 | | - Some(short_name) => library_in_workspace(pkg_path, |
187 | | - short_name, |
188 | | - Install, |
189 | | - workspace, |
190 | | - libdir(), |
191 | | - &None) |
| 184 | + Some(_short_name) => library_in_workspace(crate_id, Install, workspace) |
192 | 185 | } |
193 | 186 | } |
194 | 187 |
|
195 | 188 | /// `workspace` is used to figure out the directory to search. |
196 | 189 | /// `short_name` is taken as the link name of the library. |
197 | | -pub fn library_in_workspace(path: &Path, short_name: &str, where: Target, |
198 | | - workspace: &Path, prefix: &str, version: &Version) -> Option<Path> { |
| 190 | +pub fn library_in_workspace(crate_id: &CrateId, where: Target, workspace: &Path) -> Option<Path> { |
199 | 191 | debug!("library_in_workspace: checking whether a library named {} exists", |
200 | | - short_name); |
201 | | - |
202 | | - // We don't know what the hash is, so we have to search through the directory |
203 | | - // contents |
204 | | - |
205 | | - debug!("short_name = {} where = {:?} workspace = {} \ |
206 | | - prefix = {}", short_name, where, workspace.display(), prefix); |
| 192 | + crate_id.short_name); |
207 | 193 |
|
208 | 194 | let dir_to_search = match where { |
209 | | - Build => target_build_dir(workspace).join(path), |
| 195 | + Build => target_build_dir(workspace).join(&crate_id.path), |
210 | 196 | Install => target_lib_dir(workspace) |
211 | 197 | }; |
212 | 198 |
|
213 | | - library_in(short_name, version, &dir_to_search) |
| 199 | + library_in(crate_id, &dir_to_search) |
214 | 200 | } |
215 | 201 |
|
216 | 202 | pub fn system_library(sysroot: &Path, crate_id: &str) -> Option<Path> { |
217 | | - let (lib_name, version) = split_crate_id(crate_id); |
218 | | - library_in(lib_name, &version, &sysroot.join(relative_target_lib_path(host_triple()))) |
219 | | -} |
220 | | - |
221 | | -fn library_in(short_name: &str, version: &Version, dir_to_search: &Path) -> Option<Path> { |
222 | | - debug!("Listing directory {}", dir_to_search.display()); |
223 | | - let dir_contents = { |
224 | | - let _guard = io::ignore_io_error(); |
225 | | - fs::readdir(dir_to_search) |
226 | | - }; |
227 | | - debug!("dir has {:?} entries", dir_contents.len()); |
228 | | - |
229 | | - let dll_prefix = format!("{}{}", os::consts::DLL_PREFIX, short_name); |
230 | | - let dll_filetype = os::consts::DLL_EXTENSION; |
231 | | - let rlib_prefix = format!("{}{}", "lib", short_name); |
232 | | - let rlib_filetype = "rlib"; |
233 | | - |
234 | | - debug!("dll_prefix = {} and dll_filetype = {}", dll_prefix, dll_filetype); |
235 | | - debug!("rlib_prefix = {} and rlib_filetype = {}", rlib_prefix, rlib_filetype); |
236 | | - |
237 | | - // Find a filename that matches the pattern: |
238 | | - // (lib_prefix)-hash-(version)(lib_suffix) |
239 | | - let mut libraries = dir_contents.iter().filter(|p| { |
240 | | - let extension = p.extension_str(); |
241 | | - debug!("p = {}, p's extension is {:?}", p.display(), extension); |
242 | | - match extension { |
243 | | - None => false, |
244 | | - Some(ref s) => dll_filetype == *s || rlib_filetype == *s, |
| 203 | + library_in(&CrateId::new(crate_id), &sysroot.join(relative_target_lib_path(host_triple()))) |
| 204 | +} |
| 205 | + |
| 206 | +fn library_in(crate_id: &CrateId, dir_to_search: &Path) -> Option<Path> { |
| 207 | + let lib_name = crate_id.to_lib_name(); |
| 208 | + let filenames = [ |
| 209 | + format!("{}{}.{}", "lib", lib_name, "rlib"), |
| 210 | + format!("{}{}{}", os::consts::DLL_PREFIX, lib_name, os::consts::DLL_SUFFIX), |
| 211 | + ]; |
| 212 | + |
| 213 | + for filename in filenames.iter() { |
| 214 | + debug!("filename = {}", filename.as_slice()); |
| 215 | + let path = dir_to_search.join(filename.as_slice()); |
| 216 | + if path.exists() { |
| 217 | + debug!("found: {}", path.display()); |
| 218 | + return Some(path); |
245 | 219 | } |
246 | | - }); |
247 | | - |
248 | | - let mut result_filename = None; |
249 | | - for p_path in libraries { |
250 | | - // Find a filename that matches the pattern: (lib_prefix)-hash-(version)(lib_suffix) |
251 | | - // and remember what the hash was |
252 | | - let mut f_name = match p_path.filestem_str() { |
253 | | - Some(s) => s, None => continue |
254 | | - }; |
255 | | - // Already checked the filetype above |
256 | | - |
257 | | - // This is complicated because library names and versions can both contain dashes |
258 | | - loop { |
259 | | - if f_name.is_empty() { break; } |
260 | | - match f_name.rfind('-') { |
261 | | - Some(i) => { |
262 | | - debug!("Maybe {} is a version", f_name.slice(i + 1, f_name.len())); |
263 | | - match try_parsing_version(f_name.slice(i + 1, f_name.len())) { |
264 | | - Some(ref found_vers) if version == &Some(found_vers.to_owned()) || |
265 | | - version == &None => { |
266 | | - match f_name.slice(0, i).rfind('-') { |
267 | | - Some(j) => { |
268 | | - let lib_prefix = match p_path.extension_str() { |
269 | | - Some(ref s) if dll_filetype == *s => &dll_prefix, |
270 | | - _ => &rlib_prefix, |
271 | | - }; |
272 | | - debug!("Maybe {} equals {}", f_name.slice(0, j), *lib_prefix); |
273 | | - if f_name.slice(0, j) == *lib_prefix { |
274 | | - result_filename = Some(p_path.clone()); |
275 | | - } |
276 | | - break; |
277 | | - } |
278 | | - None => break |
279 | | - } |
280 | | - } |
281 | | - _ => { f_name = f_name.slice(0, i); } |
282 | | - } |
283 | | - } |
284 | | - None => break |
285 | | - } // match |
286 | | - } // loop |
287 | | - } // for |
288 | | - |
289 | | - if result_filename.is_none() { |
290 | | - debug!("warning: library_in_workspace didn't find a library in {} for {}", |
291 | | - dir_to_search.display(), short_name); |
292 | | - } |
293 | | - |
294 | | - // Return the filename that matches, which we now know exists |
295 | | - // (if result_filename != None) |
296 | | - let abs_path = result_filename.map(|result_filename| { |
297 | | - let absolute_path = dir_to_search.join(&result_filename); |
298 | | - debug!("result_filename = {}", absolute_path.display()); |
299 | | - absolute_path |
300 | | - }); |
301 | | - |
302 | | - abs_path |
303 | | -} |
304 | | - |
305 | | -fn split_crate_id<'a>(crate_id: &'a str) -> (&'a str, Version) { |
306 | | - match split_version(crate_id) { |
307 | | - Some((name, vers)) => |
308 | | - match vers { |
309 | | - Some(ref v) => match v.find('-') { |
310 | | - Some(pos) => (name, Some(v.slice(0, pos).to_owned())), |
311 | | - None => (name, Some(v.to_owned())) |
312 | | - }, |
313 | | - _ => (name, vers) |
314 | | - }, |
315 | | - None => (crate_id, None) |
316 | 220 | } |
| 221 | + debug!("warning: library_in_workspace didn't find a library in {} for {}", |
| 222 | + dir_to_search.display(), crate_id.short_name); |
| 223 | + return None; |
317 | 224 | } |
318 | 225 |
|
319 | | - |
320 | | - |
321 | 226 | /// Returns the executable that would be installed for <crateid> |
322 | 227 | /// in <workspace> |
323 | 228 | /// As a side effect, creates the bin-dir if it doesn't exist |
|
0 commit comments