Skip to content

Commit

Permalink
std: Deprecate std::old_io::fs
Browse files Browse the repository at this point in the history
This commit deprecates the majority of std::old_io::fs in favor of std::fs and
its new functionality. Some functions remain non-deprecated but are now behind a
feature gate called `old_fs`. These functions will be deprecated once
suitable replacements have been implemented.

The compiler has been migrated to new `std::fs` and `std::path` APIs where
appropriate as part of this change.
  • Loading branch information
alexcrichton committed Mar 4, 2015
1 parent 3b3bb0e commit 95d9046
Show file tree
Hide file tree
Showing 80 changed files with 1,430 additions and 1,209 deletions.
2 changes: 2 additions & 0 deletions mk/docs.mk
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,13 @@ compiler-docs: $(COMPILER_DOC_TARGETS)
trpl: doc/book/index.html

doc/book/index.html: $(RUSTBOOK_EXE) $(wildcard $(S)/src/doc/trpl/*.md) | doc/
@$(call E, rustbook: $@)
$(Q)rm -rf doc/book
$(Q)$(RUSTBOOK) build $(S)src/doc/trpl doc/book

style: doc/style/index.html

doc/style/index.html: $(RUSTBOOK_EXE) $(wildcard $(S)/src/doc/style/*.md) | doc/
@$(call E, rustbook: $@)
$(Q)rm -rf doc/style
$(Q)$(RUSTBOOK) build $(S)src/doc/style doc/style
17 changes: 9 additions & 8 deletions src/compiletest/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub use self::Mode::*;

use std::fmt;
use std::str::FromStr;
use std::path::PathBuf;

#[derive(Clone, Copy, PartialEq, Debug)]
pub enum Mode {
Expand Down Expand Up @@ -68,13 +69,13 @@ pub struct Config {
pub run_lib_path: String,

// The rustc executable
pub rustc_path: Path,
pub rustc_path: PathBuf,

// The clang executable
pub clang_path: Option<Path>,
pub clang_path: Option<PathBuf>,

// The llvm binaries path
pub llvm_bin_path: Option<Path>,
pub llvm_bin_path: Option<PathBuf>,

// The valgrind path
pub valgrind_path: Option<String>,
Expand All @@ -84,13 +85,13 @@ pub struct Config {
pub force_valgrind: bool,

// The directory containing the tests to run
pub src_base: Path,
pub src_base: PathBuf,

// The directory where programs should be built
pub build_base: Path,
pub build_base: PathBuf,

// Directory for auxiliary libraries
pub aux_base: Path,
pub aux_base: PathBuf,

// The name of the stage being built (stage1, etc)
pub stage_id: String,
Expand All @@ -105,7 +106,7 @@ pub struct Config {
pub filter: Option<String>,

// Write out a parseable log of tests that were run
pub logfile: Option<Path>,
pub logfile: Option<PathBuf>,

// A command line to prefix program execution with,
// for running under valgrind
Expand Down Expand Up @@ -133,7 +134,7 @@ pub struct Config {
pub lldb_version: Option<String>,

// Path to the android tools
pub android_cross_path: Path,
pub android_cross_path: PathBuf,

// Extra parameter to run adb on arm-linux-androideabi
pub adb_path: String,
Expand Down
42 changes: 23 additions & 19 deletions src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
#![feature(test)]
#![feature(unicode)]
#![feature(core)]
#![feature(path)]
#![feature(os)]
#![feature(io)]
#![feature(fs)]
#![feature(net)]

#![deny(warnings)]

Expand All @@ -31,8 +36,9 @@ extern crate getopts;
extern crate log;

use std::env;
use std::fs;
use std::old_io;
use std::old_io::fs;
use std::path::{Path, PathBuf};
use std::thunk::Thunk;
use getopts::{optopt, optflag, reqopt};
use common::Config;
Expand Down Expand Up @@ -114,9 +120,9 @@ pub fn parse_config(args: Vec<String> ) -> Config {
panic!()
}

fn opt_path(m: &getopts::Matches, nm: &str) -> Path {
fn opt_path(m: &getopts::Matches, nm: &str) -> PathBuf {
match m.opt_str(nm) {
Some(s) => Path::new(s),
Some(s) => PathBuf::new(&s),
None => panic!("no option (=path) found for {}", nm),
}
}
Expand All @@ -131,18 +137,18 @@ pub fn parse_config(args: Vec<String> ) -> Config {
compile_lib_path: matches.opt_str("compile-lib-path").unwrap(),
run_lib_path: matches.opt_str("run-lib-path").unwrap(),
rustc_path: opt_path(matches, "rustc-path"),
clang_path: matches.opt_str("clang-path").map(|s| Path::new(s)),
clang_path: matches.opt_str("clang-path").map(|s| PathBuf::new(&s)),
valgrind_path: matches.opt_str("valgrind-path"),
force_valgrind: matches.opt_present("force-valgrind"),
llvm_bin_path: matches.opt_str("llvm-bin-path").map(|s| Path::new(s)),
llvm_bin_path: matches.opt_str("llvm-bin-path").map(|s| PathBuf::new(&s)),
src_base: opt_path(matches, "src-base"),
build_base: opt_path(matches, "build-base"),
aux_base: opt_path(matches, "aux-base"),
stage_id: matches.opt_str("stage-id").unwrap(),
mode: matches.opt_str("mode").unwrap().parse().ok().expect("invalid mode"),
run_ignored: matches.opt_present("ignored"),
filter: filter,
logfile: matches.opt_str("logfile").map(|s| Path::new(s)),
logfile: matches.opt_str("logfile").map(|s| PathBuf::new(&s)),
runtool: matches.opt_str("runtool"),
host_rustcflags: matches.opt_str("host-rustcflags"),
target_rustcflags: matches.opt_str("target-rustcflags"),
Expand Down Expand Up @@ -276,9 +282,9 @@ pub fn make_tests(config: &Config) -> Vec<test::TestDescAndFn> {
debug!("making tests from {:?}",
config.src_base.display());
let mut tests = Vec::new();
let dirs = fs::readdir(&config.src_base).unwrap();
for file in &dirs {
let file = file.clone();
let dirs = fs::read_dir(&config.src_base).unwrap();
for file in dirs {
let file = file.unwrap().path();
debug!("inspecting file {:?}", file.display());
if is_test(config, &file) {
let t = make_test(config, &file, || {
Expand All @@ -301,7 +307,7 @@ pub fn is_test(config: &Config, testfile: &Path) -> bool {
_ => vec!(".rc".to_string(), ".rs".to_string())
};
let invalid_prefixes = vec!(".".to_string(), "#".to_string(), "~".to_string());
let name = testfile.filename_str().unwrap();
let name = testfile.file_name().unwrap().to_str().unwrap();

let mut valid = false;

Expand Down Expand Up @@ -337,9 +343,9 @@ pub fn make_test_name(config: &Config, testfile: &Path) -> test::TestName {

// Try to elide redundant long paths
fn shorten(path: &Path) -> String {
let filename = path.filename_str();
let p = path.dir_path();
let dir = p.filename_str();
let filename = path.file_name().unwrap().to_str();
let p = path.parent().unwrap();
let dir = p.file_name().unwrap().to_str();
format!("{}/{}", dir.unwrap_or(""), filename.unwrap_or(""))
}

Expand All @@ -348,19 +354,17 @@ pub fn make_test_name(config: &Config, testfile: &Path) -> test::TestName {

pub fn make_test_closure(config: &Config, testfile: &Path) -> test::TestFn {
let config = (*config).clone();
// FIXME (#9639): This needs to handle non-utf8 paths
let testfile = testfile.as_str().unwrap().to_string();
let testfile = testfile.to_path_buf();
test::DynTestFn(Thunk::new(move || {
runtest::run(config, testfile)
runtest::run(config, &testfile)
}))
}

pub fn make_metrics_test_closure(config: &Config, testfile: &Path) -> test::TestFn {
let config = (*config).clone();
// FIXME (#9639): This needs to handle non-utf8 paths
let testfile = testfile.as_str().unwrap().to_string();
let testfile = testfile.to_path_buf();
test::DynMetricFn(box move |mm: &mut test::MetricMap| {
runtest::run_metrics(config, testfile, mm)
runtest::run_metrics(config, &testfile, mm)
})
}

Expand Down
7 changes: 5 additions & 2 deletions src/compiletest/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
// except according to those terms.
use self::WhichLine::*;

use std::old_io::{BufferedReader, File};
use std::fs::File;
use std::io::BufReader;
use std::io::prelude::*;
use std::path::Path;

pub struct ExpectedError {
pub line: uint,
Expand All @@ -29,7 +32,7 @@ enum WhichLine { ThisLine, FollowPrevious(uint), AdjustBackward(uint) }
/// //~| ERROR message two for that same line.
// Load any test directives embedded in the file
pub fn load_errors(testfile: &Path) -> Vec<ExpectedError> {
let mut rdr = BufferedReader::new(File::open(testfile).unwrap());
let rdr = BufReader::new(File::open(testfile).unwrap());

// `last_nonfollow_error` tracks the most recently seen
// line with an error template that did not use the
Expand Down
24 changes: 12 additions & 12 deletions src/compiletest/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
// except according to those terms.

use std::env;
use std::fs::File;
use std::io::BufReader;
use std::io::prelude::*;
use std::path::{Path, PathBuf};

use common::Config;
use common;
Expand All @@ -23,7 +27,7 @@ pub struct TestProps {
pub run_flags: Option<String>,
// If present, the name of a file that this test should match when
// pretty-printed
pub pp_exact: Option<Path>,
pub pp_exact: Option<PathBuf>,
// Modules from aux directory that should be compiled
pub aux_builds: Vec<String> ,
// Environment settings to use during execution
Expand Down Expand Up @@ -62,7 +66,7 @@ pub fn load_props(testfile: &Path) -> TestProps {
let mut pretty_mode = None;
let mut pretty_compare_only = false;
let mut forbid_output = Vec::new();
iter_header(testfile, |ln| {
iter_header(testfile, &mut |ln| {
match parse_error_pattern(ln) {
Some(ep) => error_patterns.push(ep),
None => ()
Expand Down Expand Up @@ -219,7 +223,7 @@ pub fn is_test_ignored(config: &Config, testfile: &Path) -> bool {
}
}

let val = iter_header(testfile, |ln| {
let val = iter_header(testfile, &mut |ln| {
!parse_name_directive(ln, "ignore-test") &&
!parse_name_directive(ln, &ignore_target(config)) &&
!parse_name_directive(ln, &ignore_stage(config)) &&
Expand All @@ -232,12 +236,8 @@ pub fn is_test_ignored(config: &Config, testfile: &Path) -> bool {
!val
}

fn iter_header<F>(testfile: &Path, mut it: F) -> bool where
F: FnMut(&str) -> bool,
{
use std::old_io::{BufferedReader, File};

let mut rdr = BufferedReader::new(File::open(testfile).unwrap());
fn iter_header(testfile: &Path, it: &mut FnMut(&str) -> bool) -> bool {
let rdr = BufReader::new(File::open(testfile).unwrap());
for ln in rdr.lines() {
// Assume that any directives will be found before the first
// module or function. This doesn't seem to be an optimization
Expand Down Expand Up @@ -322,12 +322,12 @@ fn parse_exec_env(line: &str) -> Option<(String, String)> {
})
}

fn parse_pp_exact(line: &str, testfile: &Path) -> Option<Path> {
fn parse_pp_exact(line: &str, testfile: &Path) -> Option<PathBuf> {
match parse_name_value_directive(line, "pp-exact") {
Some(s) => Some(Path::new(s)),
Some(s) => Some(PathBuf::new(&s)),
None => {
if parse_name_directive(line, "pp-exact") {
testfile.filename().map(|s| Path::new(s))
testfile.file_name().map(|s| PathBuf::new(s))
} else {
None
}
Expand Down
29 changes: 18 additions & 11 deletions src/compiletest/procsrv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::old_io::process::{ProcessExit, Command, Process, ProcessOutput};
use std::process::{ExitStatus, Command, Child, Output, Stdio};
use std::io::prelude::*;
use std::dynamic_lib::DynamicLibrary;

fn add_target_env(cmd: &mut Command, lib_path: &str, aux_path: Option<&str>) {
Expand All @@ -25,10 +26,10 @@ fn add_target_env(cmd: &mut Command, lib_path: &str, aux_path: Option<&str>) {
let var = DynamicLibrary::envvar();
let newpath = DynamicLibrary::create_path(&path);
let newpath = String::from_utf8(newpath).unwrap();
cmd.env(var.to_string(), newpath);
cmd.env(var, &newpath);
}

pub struct Result {pub status: ProcessExit, pub out: String, pub err: String}
pub struct Result {pub status: ExitStatus, pub out: String, pub err: String}

pub fn run(lib_path: &str,
prog: &str,
Expand All @@ -38,24 +39,27 @@ pub fn run(lib_path: &str,
input: Option<String>) -> Option<Result> {

let mut cmd = Command::new(prog);
cmd.args(args);
cmd.args(args)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped());
add_target_env(&mut cmd, lib_path, aux_path);
for (key, val) in env {
cmd.env(key, val);
cmd.env(&key, &val);
}

match cmd.spawn() {
Ok(mut process) => {
if let Some(input) = input {
process.stdin.as_mut().unwrap().write_all(input.as_bytes()).unwrap();
}
let ProcessOutput { status, output, error } =
let Output { status, stdout, stderr } =
process.wait_with_output().unwrap();

Some(Result {
status: status,
out: String::from_utf8(output).unwrap(),
err: String::from_utf8(error).unwrap()
out: String::from_utf8(stdout).unwrap(),
err: String::from_utf8(stderr).unwrap()
})
},
Err(..) => None
Expand All @@ -67,13 +71,16 @@ pub fn run_background(lib_path: &str,
aux_path: Option<&str>,
args: &[String],
env: Vec<(String, String)> ,
input: Option<String>) -> Option<Process> {
input: Option<String>) -> Option<Child> {

let mut cmd = Command::new(prog);
cmd.args(args);
cmd.args(args)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped());
add_target_env(&mut cmd, lib_path, aux_path);
for (key, val) in env {
cmd.env(key, val);
cmd.env(&key, &val);
}

match cmd.spawn() {
Expand Down
Loading

0 comments on commit 95d9046

Please sign in to comment.