Skip to content

Commit 902abab

Browse files
committed
rollup merge of rust-lang#21787: alexcrichton/std-env
Conflicts: src/libstd/sys/unix/backtrace.rs src/libstd/sys/unix/os.rs
2 parents 7b185f9 + 70ed3a4 commit 902abab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+2175
-783
lines changed

src/compiletest/compiletest.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#![feature(std_misc)]
2323
#![feature(test)]
2424
#![feature(unicode)]
25+
#![feature(env)]
2526

2627
#![deny(warnings)]
2728

@@ -31,7 +32,7 @@ extern crate getopts;
3132
#[macro_use]
3233
extern crate log;
3334

34-
use std::os;
35+
use std::env;
3536
use std::old_io;
3637
use std::old_io::fs;
3738
use std::thunk::Thunk;
@@ -48,7 +49,7 @@ pub mod common;
4849
pub mod errors;
4950

5051
pub fn main() {
51-
let args = os::args();
52+
let args = env::args().map(|s| s.into_string().unwrap()).collect();;
5253
let config = parse_config(args);
5354

5455
if config.valgrind_path.is_none() && config.force_valgrind {
@@ -224,15 +225,15 @@ pub fn run_tests(config: &Config) {
224225
//arm-linux-androideabi debug-info test uses remote debugger
225226
//so, we test 1 task at once.
226227
// also trying to isolate problems with adb_run_wrapper.sh ilooping
227-
os::setenv("RUST_TEST_TASKS","1");
228+
env::set_var("RUST_TEST_TASKS","1");
228229
}
229230

230231
match config.mode {
231232
DebugInfoLldb => {
232233
// Some older versions of LLDB seem to have problems with multiple
233234
// instances running in parallel, so only run one test task at a
234235
// time.
235-
os::setenv("RUST_TEST_TASKS", "1");
236+
env::set_var("RUST_TEST_TASKS", "1");
236237
}
237238
_ => { /* proceed */ }
238239
}
@@ -245,7 +246,7 @@ pub fn run_tests(config: &Config) {
245246
old_io::test::raise_fd_limit();
246247
// Prevent issue #21352 UAC blocking .exe containing 'patch' etc. on Windows
247248
// If #11207 is resolved (adding manifest to .exe) this becomes unnecessary
248-
os::setenv("__COMPAT_LAYER", "RunAsInvoker");
249+
env::set_var("__COMPAT_LAYER", "RunAsInvoker");
249250
let res = test::run_tests_console(&opts, tests.into_iter().collect());
250251
match res {
251252
Ok(true) => {}

src/compiletest/runtest.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use std::old_io::process::ProcessExit;
3131
use std::old_io::process;
3232
use std::old_io::timer;
3333
use std::old_io;
34-
use std::os;
34+
use std::env;
3535
use std::iter::repeat;
3636
use std::str;
3737
use std::string::String;
@@ -1298,9 +1298,9 @@ fn make_lib_name(config: &Config, auxfile: &Path, testfile: &Path) -> Path {
12981298

12991299
fn make_exe_name(config: &Config, testfile: &Path) -> Path {
13001300
let mut f = output_base_name(config, testfile);
1301-
if !os::consts::EXE_SUFFIX.is_empty() {
1301+
if !env::consts::EXE_SUFFIX.is_empty() {
13021302
let mut fname = f.filename().unwrap().to_vec();
1303-
fname.extend(os::consts::EXE_SUFFIX.bytes());
1303+
fname.extend(env::consts::EXE_SUFFIX.bytes());
13041304
f.set_filename(fname);
13051305
}
13061306
f

src/etc/make-win-dist.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ def make_win_dist(rust_root, gcc_root, target_triple):
8787
"libsetupapi.a",
8888
"libshell32.a",
8989
"libuser32.a",
90+
"libuserenv.a",
9091
"libuuid.a",
9192
"libwinhttp.a",
9293
"libwinmm.a",

src/liblog/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,15 @@
173173
#![feature(int_uint)]
174174
#![feature(core)]
175175
#![feature(io)]
176-
#![feature(os)]
177176
#![feature(std_misc)]
177+
#![feature(env)]
178178

179179
use std::cell::RefCell;
180180
use std::fmt;
181181
use std::old_io::LineBufferedWriter;
182182
use std::old_io;
183183
use std::mem;
184-
use std::os;
184+
use std::env;
185185
use std::ptr;
186186
use std::rt;
187187
use std::slice;
@@ -397,9 +397,9 @@ fn enabled(level: u32,
397397
/// This is not threadsafe at all, so initialization is performed through a
398398
/// `Once` primitive (and this function is called from that primitive).
399399
fn init() {
400-
let (mut directives, filter) = match os::getenv("RUST_LOG") {
401-
Some(spec) => directive::parse_logging_spec(&spec[]),
402-
None => (Vec::new(), None),
400+
let (mut directives, filter) = match env::var_string("RUST_LOG") {
401+
Ok(spec) => directive::parse_logging_spec(&spec[]),
402+
Err(..) => (Vec::new(), None),
403403
};
404404

405405
// Sort the provided directives by length of their name, this allows a

src/librustc/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#![feature(int_uint)]
3333
#![feature(io)]
3434
#![feature(libc)]
35-
#![feature(os)]
35+
#![feature(env)]
3636
#![feature(path)]
3737
#![feature(quote)]
3838
#![feature(rustc_diagnostic_macros)]

src/librustc/metadata/filesearch.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
pub use self::FileMatch::*;
1414

1515
use std::collections::HashSet;
16+
use std::env;
1617
use std::old_io::fs::PathExtensions;
1718
use std::old_io::fs;
18-
use std::os;
1919

2020
use util::fs as myfs;
2121
use session::search_paths::{SearchPaths, PathKind};
@@ -194,7 +194,7 @@ pub fn get_or_default_sysroot() -> Path {
194194
})
195195
}
196196

197-
match canonicalize(os::self_exe_name()) {
197+
match canonicalize(env::current_exe().ok()) {
198198
Some(mut p) => { p.pop(); p.pop(); p }
199199
None => panic!("can't determine value for sysroot")
200200
}
@@ -207,7 +207,7 @@ static PATH_ENTRY_SEPARATOR: &'static str = ":";
207207

208208
/// Returns RUST_PATH as a string, without default paths added
209209
pub fn get_rust_path() -> Option<String> {
210-
os::getenv("RUST_PATH").map(|x| x.to_string())
210+
env::var_string("RUST_PATH").ok()
211211
}
212212

213213
/// Returns the value of RUST_PATH, as a list
@@ -224,7 +224,7 @@ pub fn rust_path() -> Vec<Path> {
224224
}
225225
None => Vec::new()
226226
};
227-
let mut cwd = os::getcwd().unwrap();
227+
let mut cwd = env::current_dir().unwrap();
228228
// now add in default entries
229229
let cwd_dot_rust = cwd.join(".rust");
230230
if !env_rust_path.contains(&cwd_dot_rust) {
@@ -243,7 +243,7 @@ pub fn rust_path() -> Vec<Path> {
243243
}
244244
cwd.pop();
245245
}
246-
let h = os::homedir();
246+
let h = env::home_dir();
247247
for h in h.iter() {
248248
let p = h.join(".rust");
249249
if !env_rust_path.contains(&p) && p.exists() {

src/librustc/middle/infer/region_inference/graphviz.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use util::ppaux::Repr;
2727

2828
use std::collections::hash_map::Entry::Vacant;
2929
use std::old_io::{self, File};
30-
use std::os;
30+
use std::env;
3131
use std::sync::atomic::{AtomicBool, Ordering, ATOMIC_BOOL_INIT};
3232
use syntax::ast;
3333

@@ -59,13 +59,13 @@ pub fn maybe_print_constraints_for<'a, 'tcx>(region_vars: &RegionVarBindings<'a,
5959
}
6060

6161
let requested_node : Option<ast::NodeId> =
62-
os::getenv("RUST_REGION_GRAPH_NODE").and_then(|s| s.parse().ok());
62+
env::var_string("RUST_REGION_GRAPH_NODE").ok().and_then(|s| s.parse().ok());
6363

6464
if requested_node.is_some() && requested_node != Some(subject_node) {
6565
return;
6666
}
6767

68-
let requested_output = os::getenv("RUST_REGION_GRAPH");
68+
let requested_output = env::var_string("RUST_REGION_GRAPH").ok();
6969
debug!("requested_output: {:?} requested_node: {:?}",
7070
requested_output, requested_node);
7171

src/librustc/plugin/load.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use metadata::creader::{CrateOrString, CrateReader};
1515
use plugin::registry::Registry;
1616

1717
use std::mem;
18-
use std::os;
18+
use std::env;
1919
use std::dynamic_lib::DynamicLibrary;
2020
use std::collections::HashSet;
2121
use syntax::ast;
@@ -233,7 +233,7 @@ impl<'a> PluginLoader<'a> {
233233
path: Path,
234234
symbol: String) -> PluginRegistrarFun {
235235
// Make sure the path contains a / or the linker will search for it.
236-
let path = os::make_absolute(&path).unwrap();
236+
let path = env::current_dir().unwrap().join(&path);
237237

238238
let lib = match DynamicLibrary::open(Some(&path)) {
239239
Ok(lib) => lib,

src/librustc/session/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use syntax::{ast, codemap};
2727

2828
use rustc_back::target::Target;
2929

30-
use std::os;
30+
use std::env;
3131
use std::cell::{Cell, RefCell};
3232

3333
pub mod config;
@@ -347,7 +347,7 @@ pub fn build_session_(sopts: config::Options,
347347
if path.is_absolute() {
348348
path.clone()
349349
} else {
350-
os::getcwd().unwrap().join(&path)
350+
env::current_dir().unwrap().join(&path)
351351
}
352352
);
353353

@@ -370,7 +370,7 @@ pub fn build_session_(sopts: config::Options,
370370
plugin_registrar_fn: Cell::new(None),
371371
default_sysroot: default_sysroot,
372372
local_crate_source_file: local_crate_source_file,
373-
working_dir: os::getcwd().unwrap(),
373+
working_dir: env::current_dir().unwrap(),
374374
lint_store: RefCell::new(lint::LintStore::new()),
375375
lints: RefCell::new(NodeMap()),
376376
crate_types: RefCell::new(Vec::new()),

src/librustc_back/archive.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::old_io::fs::PathExtensions;
1414
use std::old_io::process::{Command, ProcessOutput};
1515
use std::old_io::{fs, TempDir};
1616
use std::old_io;
17-
use std::os;
17+
use std::env;
1818
use std::str;
1919
use syntax::diagnostic::Handler as ErrorHandler;
2020

@@ -224,7 +224,7 @@ impl<'a> ArchiveBuilder<'a> {
224224
pub fn build(self) -> Archive<'a> {
225225
// Get an absolute path to the destination, so `ar` will work even
226226
// though we run it from `self.work_dir`.
227-
let abs_dst = os::getcwd().unwrap().join(&self.archive.dst);
227+
let abs_dst = env::current_dir().unwrap().join(&self.archive.dst);
228228
assert!(!abs_dst.is_relative());
229229
let mut args = vec![&abs_dst];
230230
let mut total_len = abs_dst.as_vec().len();
@@ -283,7 +283,7 @@ impl<'a> ArchiveBuilder<'a> {
283283
// First, extract the contents of the archive to a temporary directory.
284284
// We don't unpack directly into `self.work_dir` due to the possibility
285285
// of filename collisions.
286-
let archive = os::make_absolute(archive).unwrap();
286+
let archive = env::current_dir().unwrap().join(archive);
287287
run_ar(self.archive.handler, &self.archive.maybe_ar_prog,
288288
"x", Some(loc.path()), &[&archive]);
289289

src/librustc_back/fs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010

1111
use std::old_io;
1212
use std::old_io::fs;
13-
use std::os;
13+
use std::env;
1414

1515
/// Returns an absolute path in the filesystem that `path` points to. The
1616
/// returned path does not contain any symlinks in its hierarchy.
1717
pub fn realpath(original: &Path) -> old_io::IoResult<Path> {
1818
static MAX_LINKS_FOLLOWED: uint = 256;
19-
let original = os::make_absolute(original).unwrap();
19+
let original = try!(env::current_dir()).join(original);
2020

2121
// Right now lstat on windows doesn't work quite well
2222
if cfg!(windows) {

src/librustc_back/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#![feature(path)]
4141
#![feature(rustc_private)]
4242
#![feature(staged_api)]
43+
#![feature(env)]
4344

4445
extern crate syntax;
4546
extern crate serialize;

src/librustc_back/rpath.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
use std::collections::HashSet;
13-
use std::os;
13+
use std::env;
1414
use std::old_io::IoError;
1515
use syntax::ast;
1616

@@ -105,18 +105,17 @@ fn get_rpath_relative_to_output<F, G>(config: &mut RPathConfig<F, G>, lib: &Path
105105
F: FnOnce() -> Path,
106106
G: FnMut(&Path) -> Result<Path, IoError>,
107107
{
108-
use std::os;
109-
110108
// Mac doesn't appear to support $ORIGIN
111109
let prefix = if config.is_like_osx {
112110
"@loader_path"
113111
} else {
114112
"$ORIGIN"
115113
};
116114

117-
let mut lib = (config.realpath)(&os::make_absolute(lib).unwrap()).unwrap();
115+
let cwd = env::current_dir().unwrap();
116+
let mut lib = (config.realpath)(&cwd.join(lib)).unwrap();
118117
lib.pop();
119-
let mut output = (config.realpath)(&os::make_absolute(&config.out_filename).unwrap()).unwrap();
118+
let mut output = (config.realpath)(&cwd.join(&config.out_filename)).unwrap();
120119
output.pop();
121120
let relative = lib.path_relative_from(&output);
122121
let relative = relative.expect("could not create rpath relative to output");
@@ -131,7 +130,7 @@ fn get_install_prefix_rpath<F, G>(config: RPathConfig<F, G>) -> String where
131130
G: FnMut(&Path) -> Result<Path, IoError>,
132131
{
133132
let path = (config.get_install_prefix_lib_path)();
134-
let path = os::make_absolute(&path).unwrap();
133+
let path = env::current_dir().unwrap().join(&path);
135134
// FIXME (#9639): This needs to handle non-utf8 paths
136135
path.as_str().expect("non-utf8 component in rpath").to_string()
137136
}

src/librustc_back/target/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ impl Target {
303303
/// The error string could come from any of the APIs called, including filesystem access and
304304
/// JSON decoding.
305305
pub fn search(target: &str) -> Result<Target, String> {
306-
use std::os;
306+
use std::env;
307+
use std::ffi::OsString;
307308
use std::old_io::File;
308309
use std::path::Path;
309310
use serialize::json;
@@ -383,12 +384,12 @@ impl Target {
383384
Path::new(target)
384385
};
385386

386-
let target_path = os::getenv("RUST_TARGET_PATH").unwrap_or(String::new());
387+
let target_path = env::var("RUST_TARGET_PATH")
388+
.unwrap_or(OsString::from_str(""));
387389

388-
let paths = os::split_paths(&target_path[]);
389390
// FIXME 16351: add a sane default search path?
390391

391-
for dir in paths.iter() {
392+
for dir in env::split_paths(&target_path) {
392393
let p = dir.join(path.clone());
393394
if p.is_file() {
394395
return load_file(&p);

0 commit comments

Comments
 (0)