1 use crate::filesearch::make_target_lib_path;
2 use crate::{config, early_error};
3 use std::path::{Path, PathBuf};
5 #[derive(Clone, Debug)]
6 pub struct SearchPath {
9 pub files: Vec<PathBuf>,
12 #[derive(PartialEq, Clone, Copy, Debug, Hash, Eq, RustcEncodable, RustcDecodable)]
22 rustc_data_structures::impl_stable_hash_via_hash!(PathKind);
25 pub fn matches(&self, kind: PathKind) -> bool {
27 (PathKind::All, _) | (_, PathKind::All) => true,
34 pub fn from_cli_opt(path: &str, output: config::ErrorOutputType) -> Self {
35 let (kind, path) = if path.starts_with("native=") {
36 (PathKind::Native, &path["native=".len()..])
37 } else if path.starts_with("crate=") {
38 (PathKind::Crate, &path["crate=".len()..])
39 } else if path.starts_with("dependency=") {
40 (PathKind::Dependency, &path["dependency=".len()..])
41 } else if path.starts_with("framework=") {
42 (PathKind::Framework, &path["framework=".len()..])
43 } else if path.starts_with("all=") {
44 (PathKind::All, &path["all=".len()..])
49 early_error(output, "empty search path given via `-L`");
52 let dir = PathBuf::from(path);
56 pub fn from_sysroot_and_triple(sysroot: &Path, triple: &str) -> Self {
57 Self::new(PathKind::All, make_target_lib_path(sysroot, triple))
60 fn new(kind: PathKind, dir: PathBuf) -> Self {
61 // Get the files within the directory.
62 let files = match std::fs::read_dir(&dir) {
63 Ok(files) => files.filter_map(|p| p.ok().map(|s| s.path())).collect::<Vec<_>>(),
67 SearchPath { kind, dir, files }