2014-12-16 22:32:02 +00:00
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
use std::slice;
|
|
|
|
|
2015-01-28 13:34:18 +00:00
|
|
|
#[derive(Clone, Debug)]
|
2014-12-16 22:32:02 +00:00
|
|
|
pub struct SearchPaths {
|
|
|
|
paths: Vec<(PathKind, Path)>,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Iter<'a> {
|
|
|
|
kind: PathKind,
|
|
|
|
iter: slice::Iter<'a, (PathKind, Path)>,
|
|
|
|
}
|
|
|
|
|
2015-01-28 13:34:18 +00:00
|
|
|
#[derive(Eq, PartialEq, Clone, Copy, Debug)]
|
2014-12-16 22:32:02 +00:00
|
|
|
pub enum PathKind {
|
|
|
|
Native,
|
|
|
|
Crate,
|
|
|
|
Dependency,
|
2015-01-06 16:46:07 +00:00
|
|
|
ExternFlag,
|
2014-12-16 22:32:02 +00:00
|
|
|
All,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SearchPaths {
|
|
|
|
pub fn new() -> SearchPaths {
|
|
|
|
SearchPaths { paths: Vec::new() }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn add_path(&mut self, path: &str) {
|
2014-12-31 23:10:45 +00:00
|
|
|
let (kind, path) = if path.starts_with("native=") {
|
2015-01-18 00:15:52 +00:00
|
|
|
(PathKind::Native, &path["native=".len()..])
|
2014-12-31 23:10:45 +00:00
|
|
|
} else if path.starts_with("crate=") {
|
2015-01-18 00:15:52 +00:00
|
|
|
(PathKind::Crate, &path["crate=".len()..])
|
2014-12-31 23:10:45 +00:00
|
|
|
} else if path.starts_with("dependency=") {
|
2015-01-18 00:15:52 +00:00
|
|
|
(PathKind::Dependency, &path["dependency=".len()..])
|
2014-12-31 23:10:45 +00:00
|
|
|
} else if path.starts_with("all=") {
|
2015-01-18 00:15:52 +00:00
|
|
|
(PathKind::All, &path["all=".len()..])
|
2014-12-16 22:32:02 +00:00
|
|
|
} else {
|
|
|
|
(PathKind::All, path)
|
|
|
|
};
|
|
|
|
self.paths.push((kind, Path::new(path)));
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn iter(&self, kind: PathKind) -> Iter {
|
|
|
|
Iter { kind: kind, iter: self.paths.iter() }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-02 04:26:38 +00:00
|
|
|
impl<'a> Iterator for Iter<'a> {
|
2015-01-06 16:46:07 +00:00
|
|
|
type Item = (&'a Path, PathKind);
|
2015-01-02 04:26:38 +00:00
|
|
|
|
2015-01-06 16:46:07 +00:00
|
|
|
fn next(&mut self) -> Option<(&'a Path, PathKind)> {
|
2014-12-16 22:32:02 +00:00
|
|
|
loop {
|
|
|
|
match self.iter.next() {
|
|
|
|
Some(&(kind, ref p)) if self.kind == PathKind::All ||
|
|
|
|
kind == PathKind::All ||
|
2015-01-06 16:46:07 +00:00
|
|
|
kind == self.kind => {
|
|
|
|
return Some((p, kind))
|
|
|
|
}
|
2014-12-16 22:32:02 +00:00
|
|
|
Some(..) => {}
|
|
|
|
None => return None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|