Skip to content

std::os: Add get_path_env() #11324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions src/librustc/metadata/filesearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,30 +189,15 @@ fn get_sysroot(maybe_sysroot: &Option<@Path>) -> @Path {
}
}

#[cfg(windows)]
static PATH_ENTRY_SEPARATOR: &'static str = ";";
#[cfg(not(windows))]
static PATH_ENTRY_SEPARATOR: &'static str = ":";

/// Returns RUST_PATH as a string, without default paths added
pub fn get_rust_path() -> Option<~str> {
os::getenv("RUST_PATH")
}
pub static RUST_PATH: &'static str = "RUST_PATH";

/// Returns the value of RUST_PATH, as a list
/// of Paths. Includes default entries for, if they exist:
/// $HOME/.rust
/// DIR/.rust for any DIR that's the current working directory
/// or an ancestor of it
pub fn rust_path() -> ~[Path] {
let mut env_rust_path: ~[Path] = match get_rust_path() {
Some(env_path) => {
let env_path_components: ~[&str] =
env_path.split_str(PATH_ENTRY_SEPARATOR).collect();
env_path_components.map(|&s| Path::new(s))
}
None => ~[]
};
let mut env_rust_path: ~[Path] = os::get_path_env(RUST_PATH);
let mut cwd = os::getcwd();
// now add in default entries
let cwd_dot_rust = cwd.join(".rust");
Expand Down
18 changes: 18 additions & 0 deletions src/libstd/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,24 @@ pub fn getenv(n: &str) -> Option<~str> {
}
}

#[cfg(windows)]
static PATH_ENTRY_SEPARATOR: &'static str = ";";
#[cfg(not(windows))]
static PATH_ENTRY_SEPARATOR: &'static str = ":";

/// Fetches the environment variable `n` from the current process and
/// splits into strings.
///
/// On Unix, the list is separated by character ':'.
/// On Windows, the list is separated by character ';'.
pub fn get_path_env(n: &str) -> ~[Path] {
match getenv(n) {
Some(s) => {
s.split_str(PATH_ENTRY_SEPARATOR).map(|s| Path::new(s)).to_owned_vec()
}
None => ~[],
}
}

#[cfg(unix)]
/// Sets the environment variable `n` to the value `v` for the currently running
Expand Down