std: Deprecate std::old_io::fs

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.
This commit is contained in:
Alex Crichton 2015-02-26 21:00:43 -08:00
parent 3b3bb0e682
commit 95d904625b
80 changed files with 1430 additions and 1209 deletions

View file

@ -39,6 +39,9 @@
#![feature(staged_api)]
#![feature(std_misc)]
#![feature(os)]
#![feature(path)]
#![feature(fs)]
#![feature(io)]
#![cfg_attr(test, feature(test))]
extern crate arena;

View file

@ -21,6 +21,7 @@ use metadata::decoder;
use metadata::loader;
use metadata::loader::CratePaths;
use std::path::{Path, PathBuf};
use std::rc::Rc;
use syntax::ast;
use syntax::abi;
@ -126,7 +127,7 @@ fn register_native_lib(sess: &Session,
// Extra info about a crate loaded for plugins or exported macros.
struct ExtensionCrate {
metadata: PMDSource,
dylib: Option<Path>,
dylib: Option<PathBuf>,
target_only: bool,
}
@ -551,7 +552,8 @@ impl<'a> CrateReader<'a> {
}
/// Look for a plugin registrar. Returns library path and symbol name.
pub fn find_plugin_registrar(&mut self, span: Span, name: &str) -> Option<(Path, String)> {
pub fn find_plugin_registrar(&mut self, span: Span, name: &str)
-> Option<(PathBuf, String)> {
let ekrate = self.read_extension_crate(span, &CrateInfo {
name: name.to_string(),
ident: name.to_string(),
@ -574,7 +576,7 @@ impl<'a> CrateReader<'a> {
.map(|id| decoder::get_symbol(ekrate.metadata.as_slice(), id));
match (ekrate.dylib.as_ref(), registrar) {
(Some(dylib), Some(reg)) => Some((dylib.clone(), reg)),
(Some(dylib), Some(reg)) => Some((dylib.to_path_buf(), reg)),
(None, Some(_)) => {
let message = format!("plugin `{}` only found in rlib format, \
but must be available in dylib format",

View file

@ -25,6 +25,7 @@ use util::nodemap::{FnvHashMap, NodeMap};
use std::cell::RefCell;
use std::rc::Rc;
use std::path::PathBuf;
use flate::Bytes;
use syntax::ast;
use syntax::codemap;
@ -78,8 +79,8 @@ pub enum NativeLibraryKind {
// must be non-None.
#[derive(PartialEq, Clone)]
pub struct CrateSource {
pub dylib: Option<(Path, PathKind)>,
pub rlib: Option<(Path, PathKind)>,
pub dylib: Option<(PathBuf, PathKind)>,
pub rlib: Option<(PathBuf, PathKind)>,
pub cnum: ast::CrateNum,
}
@ -172,7 +173,7 @@ impl CStore {
// topological sort of all crates putting the leaves at the right-most
// positions.
pub fn get_used_crates(&self, prefer: LinkagePreference)
-> Vec<(ast::CrateNum, Option<Path>)> {
-> Vec<(ast::CrateNum, Option<PathBuf>)> {
let mut ordering = Vec::new();
fn visit(cstore: &CStore, cnum: ast::CrateNum,
ordering: &mut Vec<ast::CrateNum>) {

View file

@ -34,9 +34,9 @@ use middle::astencode::vtable_decoder_helpers;
use std::collections::HashMap;
use std::hash::{self, Hash, SipHasher};
use std::num::FromPrimitive;
use std::num::Int;
use std::old_io;
use std::io::prelude::*;
use std::io;
use std::num::{FromPrimitive, Int};
use std::rc::Rc;
use std::slice::bytes;
use std::str;
@ -1191,7 +1191,7 @@ fn get_attributes(md: rbml::Doc) -> Vec<ast::Attribute> {
}
fn list_crate_attributes(md: rbml::Doc, hash: &Svh,
out: &mut old_io::Writer) -> old_io::IoResult<()> {
out: &mut io::Write) -> io::Result<()> {
try!(write!(out, "=Crate Attributes ({})=\n", *hash));
let r = get_attributes(md);
@ -1236,7 +1236,7 @@ pub fn get_crate_deps(data: &[u8]) -> Vec<CrateDep> {
return deps;
}
fn list_crate_deps(data: &[u8], out: &mut old_io::Writer) -> old_io::IoResult<()> {
fn list_crate_deps(data: &[u8], out: &mut io::Write) -> io::Result<()> {
try!(write!(out, "=External Dependencies=\n"));
for dep in &get_crate_deps(data) {
try!(write!(out, "{} {}-{}\n", dep.cnum, dep.name, dep.hash));
@ -1275,7 +1275,7 @@ pub fn get_crate_name(data: &[u8]) -> String {
maybe_get_crate_name(data).expect("no crate name in crate")
}
pub fn list_crate_metadata(bytes: &[u8], out: &mut old_io::Writer) -> old_io::IoResult<()> {
pub fn list_crate_metadata(bytes: &[u8], out: &mut io::Write) -> io::Result<()> {
let hash = get_crate_hash(bytes);
let md = rbml::Doc::new(bytes);
try!(list_crate_attributes(md, &hash, out));

View file

@ -14,9 +14,9 @@ pub use self::FileMatch::*;
use std::collections::HashSet;
use std::env;
use std::os;
use std::old_io::fs::PathExtensions;
use std::old_io::fs;
use std::fs;
use std::io::prelude::*;
use std::path::{Path, PathBuf};
use util::fs as myfs;
use session::search_paths::{SearchPaths, PathKind};
@ -50,20 +50,20 @@ impl<'a> FileSearch<'a> {
FileMatches => found = true,
FileDoesntMatch => ()
}
visited_dirs.insert(path.as_vec().to_vec());
visited_dirs.insert(path.to_path_buf());
}
debug!("filesearch: searching lib path");
let tlib_path = make_target_lib_path(self.sysroot,
self.triple);
if !visited_dirs.contains(tlib_path.as_vec()) {
if !visited_dirs.contains(&tlib_path) {
match f(&tlib_path, PathKind::All) {
FileMatches => found = true,
FileDoesntMatch => ()
}
}
visited_dirs.insert(tlib_path.as_vec().to_vec());
visited_dirs.insert(tlib_path);
// Try RUST_PATH
if !found {
let rustpath = rust_path();
@ -71,10 +71,10 @@ impl<'a> FileSearch<'a> {
let tlib_path = make_rustpkg_lib_path(
self.sysroot, path, self.triple);
debug!("is {} in visited_dirs? {}", tlib_path.display(),
visited_dirs.contains(&tlib_path.as_vec().to_vec()));
visited_dirs.contains(&tlib_path));
if !visited_dirs.contains(tlib_path.as_vec()) {
visited_dirs.insert(tlib_path.as_vec().to_vec());
if !visited_dirs.contains(&tlib_path) {
visited_dirs.insert(tlib_path.clone());
// Don't keep searching the RUST_PATH if one match turns up --
// if we did, we'd get a "multiple matching crates" error
match f(&tlib_path, PathKind::All) {
@ -88,7 +88,7 @@ impl<'a> FileSearch<'a> {
}
}
pub fn get_lib_path(&self) -> Path {
pub fn get_lib_path(&self) -> PathBuf {
make_target_lib_path(self.sysroot, self.triple)
}
@ -97,11 +97,13 @@ impl<'a> FileSearch<'a> {
{
self.for_each_lib_search_path(|lib_search_path, kind| {
debug!("searching {}", lib_search_path.display());
match fs::readdir(lib_search_path) {
match fs::read_dir(lib_search_path) {
Ok(files) => {
let files = files.filter_map(|p| p.ok().map(|s| s.path()))
.collect::<Vec<_>>();
let mut rslt = FileDoesntMatch;
fn is_rlib(p: & &Path) -> bool {
p.extension_str() == Some("rlib")
fn is_rlib(p: &Path) -> bool {
p.extension().and_then(|s| s.to_str()) == Some("rlib")
}
// Reading metadata out of rlibs is faster, and if we find both
// an rlib and a dylib we only read one of the files of
@ -143,59 +145,60 @@ impl<'a> FileSearch<'a> {
}
// Returns a list of directories where target-specific dylibs might be located.
pub fn get_dylib_search_paths(&self) -> Vec<Path> {
pub fn get_dylib_search_paths(&self) -> Vec<PathBuf> {
let mut paths = Vec::new();
self.for_each_lib_search_path(|lib_search_path, _| {
paths.push(lib_search_path.clone());
paths.push(lib_search_path.to_path_buf());
FileDoesntMatch
});
paths
}
// Returns a list of directories where target-specific tool binaries are located.
pub fn get_tools_search_paths(&self) -> Vec<Path> {
let mut p = Path::new(self.sysroot);
p.push(find_libdir(self.sysroot));
p.push(rustlibdir());
p.push(self.triple);
pub fn get_tools_search_paths(&self) -> Vec<PathBuf> {
let mut p = PathBuf::new(self.sysroot);
p.push(&find_libdir(self.sysroot));
p.push(&rustlibdir());
p.push(&self.triple);
p.push("bin");
vec![p]
}
}
pub fn relative_target_lib_path(sysroot: &Path, target_triple: &str) -> Path {
let mut p = Path::new(find_libdir(sysroot));
pub fn relative_target_lib_path(sysroot: &Path, target_triple: &str) -> PathBuf {
let mut p = PathBuf::new(&find_libdir(sysroot));
assert!(p.is_relative());
p.push(rustlibdir());
p.push(&rustlibdir());
p.push(target_triple);
p.push("lib");
p
}
fn make_target_lib_path(sysroot: &Path,
target_triple: &str) -> Path {
target_triple: &str) -> PathBuf {
sysroot.join(&relative_target_lib_path(sysroot, target_triple))
}
fn make_rustpkg_lib_path(sysroot: &Path,
dir: &Path,
triple: &str) -> Path {
let mut p = dir.join(find_libdir(sysroot));
triple: &str) -> PathBuf {
let mut p = dir.join(&find_libdir(sysroot));
p.push(triple);
p
}
pub fn get_or_default_sysroot() -> Path {
pub fn get_or_default_sysroot() -> PathBuf {
// Follow symlinks. If the resolved path is relative, make it absolute.
fn canonicalize(path: Option<Path>) -> Option<Path> {
path.and_then(|path|
fn canonicalize(path: Option<PathBuf>) -> Option<PathBuf> {
path.and_then(|path| {
match myfs::realpath(&path) {
Ok(canon) => Some(canon),
Err(e) => panic!("failed to get realpath: {}", e),
})
}
})
}
match canonicalize(os::self_exe_name()) {
match canonicalize(env::current_exe().ok()) {
Some(mut p) => { p.pop(); p.pop(); p }
None => panic!("can't determine value for sysroot")
}
@ -216,16 +219,16 @@ pub fn get_rust_path() -> Option<String> {
/// $HOME/.rust
/// DIR/.rust for any DIR that's the current working directory
/// or an ancestor of it
pub fn rust_path() -> Vec<Path> {
let mut env_rust_path: Vec<Path> = match get_rust_path() {
pub fn rust_path() -> Vec<PathBuf> {
let mut env_rust_path: Vec<PathBuf> = match get_rust_path() {
Some(env_path) => {
let env_path_components =
env_path.split(PATH_ENTRY_SEPARATOR);
env_path_components.map(|s| Path::new(s)).collect()
env_path_components.map(|s| PathBuf::new(s)).collect()
}
None => Vec::new()
};
let mut cwd = os::getcwd().unwrap();
let cwd = env::current_dir().unwrap();
// now add in default entries
let cwd_dot_rust = cwd.join(".rust");
if !env_rust_path.contains(&cwd_dot_rust) {
@ -234,17 +237,15 @@ pub fn rust_path() -> Vec<Path> {
if !env_rust_path.contains(&cwd) {
env_rust_path.push(cwd.clone());
}
loop {
if { let f = cwd.filename(); f.is_none() || f.unwrap() == b".." } {
break
let mut cur = &*cwd;
while let Some(parent) = cur.parent() {
let candidate = parent.join(".rust");
if !env_rust_path.contains(&candidate) && candidate.exists() {
env_rust_path.push(candidate.clone());
}
cwd.set_filename(".rust");
if !env_rust_path.contains(&cwd) && cwd.exists() {
env_rust_path.push(cwd.clone());
}
cwd.pop();
cur = parent;
}
if let Some(h) = os::homedir() {
if let Some(h) = env::home_dir() {
let p = h.join(".rust");
if !env_rust_path.contains(&p) && p.exists() {
env_rust_path.push(p);
@ -267,7 +268,7 @@ fn find_libdir(sysroot: &Path) -> String {
match option_env!("CFG_LIBDIR_RELATIVE") {
Some(libdir) if libdir != "lib" => return libdir.to_string(),
_ => if sysroot.join(primary_libdir_name()).join(rustlibdir()).exists() {
_ => if sysroot.join(&primary_libdir_name()).join(&rustlibdir()).exists() {
return primary_libdir_name();
} else {
return secondary_libdir_name();

View file

@ -226,13 +226,14 @@ use metadata::filesearch::{FileSearch, FileMatches, FileDoesntMatch};
use syntax::codemap::Span;
use syntax::diagnostic::SpanHandler;
use util::fs;
use util::common;
use rustc_back::target::Target;
use std::ffi::CString;
use std::cmp;
use std::collections::HashMap;
use std::old_io::fs::PathExtensions;
use std::old_io;
use std::io::prelude::*;
use std::io;
use std::path::{Path, PathBuf};
use std::ptr;
use std::slice;
use std::time::Duration;
@ -240,7 +241,7 @@ use std::time::Duration;
use flate;
pub struct CrateMismatch {
path: Path,
path: PathBuf,
got: String,
}
@ -262,8 +263,8 @@ pub struct Context<'a> {
}
pub struct Library {
pub dylib: Option<(Path, PathKind)>,
pub rlib: Option<(Path, PathKind)>,
pub dylib: Option<(PathBuf, PathKind)>,
pub rlib: Option<(PathBuf, PathKind)>,
pub metadata: MetadataBlob,
}
@ -275,12 +276,12 @@ pub struct ArchiveMetadata {
pub struct CratePaths {
pub ident: String,
pub dylib: Option<Path>,
pub rlib: Option<Path>
pub dylib: Option<PathBuf>,
pub rlib: Option<PathBuf>
}
impl CratePaths {
fn paths(&self) -> Vec<Path> {
fn paths(&self) -> Vec<PathBuf> {
match (&self.dylib, &self.rlib) {
(&None, &None) => vec!(),
(&Some(ref p), &None) |
@ -400,7 +401,7 @@ impl<'a> Context<'a> {
//
// The goal of this step is to look at as little metadata as possible.
self.filesearch.search(|path, kind| {
let file = match path.filename_str() {
let file = match path.file_name().and_then(|s| s.to_str()) {
None => return FileDoesntMatch,
Some(file) => file,
};
@ -416,7 +417,7 @@ impl<'a> Context<'a> {
if file.starts_with(&staticlib_prefix[..]) &&
file.ends_with(".a") {
staticlibs.push(CrateMismatch {
path: path.clone(),
path: path.to_path_buf(),
got: "static".to_string()
});
}
@ -506,9 +507,9 @@ impl<'a> Context<'a> {
// read the metadata from it if `*slot` is `None`. If the metadata couldn't
// be read, it is assumed that the file isn't a valid rust library (no
// errors are emitted).
fn extract_one(&mut self, m: HashMap<Path, PathKind>, flavor: &str,
slot: &mut Option<MetadataBlob>) -> Option<(Path, PathKind)> {
let mut ret = None::<(Path, PathKind)>;
fn extract_one(&mut self, m: HashMap<PathBuf, PathKind>, flavor: &str,
slot: &mut Option<MetadataBlob>) -> Option<(PathBuf, PathKind)> {
let mut ret = None::<(PathBuf, PathKind)>;
let mut error = 0;
if slot.is_some() {
@ -587,7 +588,7 @@ impl<'a> Context<'a> {
if triple != self.triple {
info!("Rejecting via crate triple: expected {} got {}", self.triple, triple);
self.rejected_via_triple.push(CrateMismatch {
path: libpath.clone(),
path: libpath.to_path_buf(),
got: triple.to_string()
});
return false;
@ -599,7 +600,7 @@ impl<'a> Context<'a> {
if *myhash != hash {
info!("Rejecting via hash: expected {} got {}", *myhash, hash);
self.rejected_via_hash.push(CrateMismatch {
path: libpath.clone(),
path: libpath.to_path_buf(),
got: myhash.as_str().to_string()
});
false
@ -627,13 +628,13 @@ impl<'a> Context<'a> {
let mut rlibs = HashMap::new();
let mut dylibs = HashMap::new();
{
let locs = locs.iter().map(|l| Path::new(&l[..])).filter(|loc| {
let locs = locs.iter().map(|l| PathBuf::new(&l[..])).filter(|loc| {
if !loc.exists() {
sess.err(&format!("extern location for {} does not exist: {}",
self.crate_name, loc.display()));
return false;
}
let file = match loc.filename_str() {
let file = match loc.file_name().and_then(|s| s.to_str()) {
Some(file) => file,
None => {
sess.err(&format!("extern location for {} is not a file: {}",
@ -658,7 +659,7 @@ impl<'a> Context<'a> {
// Now that we have an iterator of good candidates, make sure
// there's at most one rlib and at most one dylib.
for loc in locs {
if loc.filename_str().unwrap().ends_with(".rlib") {
if loc.file_name().unwrap().to_str().unwrap().ends_with(".rlib") {
rlibs.insert(fs::realpath(&loc).unwrap(),
PathKind::ExternFlag);
} else {
@ -714,7 +715,7 @@ fn get_metadata_section(is_osx: bool, filename: &Path) -> Result<MetadataBlob, S
let dur = Duration::span(|| {
ret = Some(get_metadata_section_imp(is_osx, filename));
});
info!("reading {} => {}ms", filename.filename_display(),
info!("reading {:?} => {}ms", filename.file_name().unwrap(),
dur.num_milliseconds());
return ret.unwrap();;
}
@ -723,7 +724,7 @@ fn get_metadata_section_imp(is_osx: bool, filename: &Path) -> Result<MetadataBlo
if !filename.exists() {
return Err(format!("no such file: '{}'", filename.display()));
}
if filename.filename_str().unwrap().ends_with(".rlib") {
if filename.file_name().unwrap().to_str().unwrap().ends_with(".rlib") {
// Use ArchiveRO for speed here, it's backed by LLVM and uses mmap
// internally to read the file. We also avoid even using a memcpy by
// just keeping the archive along while the metadata is in use.
@ -742,7 +743,7 @@ fn get_metadata_section_imp(is_osx: bool, filename: &Path) -> Result<MetadataBlo
};
}
unsafe {
let buf = CString::new(filename.as_vec()).unwrap();
let buf = common::path2cstr(filename);
let mb = llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf.as_ptr());
if mb as int == 0 {
return Err(format!("error reading library: '{}'",
@ -811,7 +812,7 @@ pub fn read_meta_section_name(is_osx: bool) -> &'static str {
// A diagnostic function for dumping crate metadata to an output stream
pub fn list_file_metadata(is_osx: bool, path: &Path,
out: &mut old_io::Writer) -> old_io::IoResult<()> {
out: &mut io::Write) -> io::Result<()> {
match get_metadata_section(is_osx, path) {
Ok(bytes) => decoder::list_crate_metadata(bytes.as_slice(), out),
Err(msg) => {

View file

@ -19,7 +19,7 @@ pub use self::EntryOrExit::*;
use middle::cfg;
use middle::cfg::CFGIndex;
use middle::ty;
use std::old_io;
use std::io;
use std::usize;
use std::iter::repeat;
use syntax::ast;
@ -103,7 +103,7 @@ impl<'a, 'tcx, O:DataFlowOperator> DataFlowContext<'a, 'tcx, O> {
impl<'a, 'tcx, O:DataFlowOperator> pprust::PpAnn for DataFlowContext<'a, 'tcx, O> {
fn pre(&self,
ps: &mut pprust::State,
node: pprust::AnnNode) -> old_io::IoResult<()> {
node: pprust::AnnNode) -> io::Result<()> {
let id = match node {
pprust::NodeIdent(_) | pprust::NodeName(_) => 0,
pprust::NodeExpr(expr) => expr.id,
@ -485,13 +485,15 @@ impl<'a, 'tcx, O:DataFlowOperator+Clone+'static> DataFlowContext<'a, 'tcx, O> {
debug!("Dataflow result for {}:", self.analysis_name);
debug!("{}", {
self.pretty_print_to(box old_io::stderr(), blk).unwrap();
let mut v = Vec::new();
self.pretty_print_to(box &mut v, blk).unwrap();
println!("{}", String::from_utf8(v).unwrap());
""
});
}
fn pretty_print_to(&self, wr: Box<old_io::Writer+'static>,
blk: &ast::Block) -> old_io::IoResult<()> {
fn pretty_print_to<'b>(&self, wr: Box<io::Write + 'b>,
blk: &ast::Block) -> io::Result<()> {
let mut ps = pprust::rust_printer_annotated(wr, self);
try!(ps.cbox(pprust::indent_unit));
try!(ps.ibox(0));

View file

@ -28,8 +28,10 @@ use util::ppaux::Repr;
use std::borrow::Cow;
use std::collections::hash_map::Entry::Vacant;
use std::old_io::{self, File};
use std::env;
use std::fs::File;
use std::io;
use std::io::prelude::*;
use std::sync::atomic::{AtomicBool, Ordering, ATOMIC_BOOL_INIT};
use syntax::ast;
@ -256,10 +258,11 @@ pub type ConstraintMap<'tcx> = FnvHashMap<Constraint, SubregionOrigin<'tcx>>;
fn dump_region_constraints_to<'a, 'tcx:'a >(tcx: &'a ty::ctxt<'tcx>,
map: &ConstraintMap<'tcx>,
path: &str) -> old_io::IoResult<()> {
path: &str) -> io::Result<()> {
debug!("dump_region_constraints map (len: {}) path: {}", map.len(), path);
let g = ConstraintGraph::new(tcx, format!("region_constraints"), map);
let mut f = File::create(&Path::new(path));
debug!("dump_region_constraints calling render");
dot::render(&g, &mut f)
let mut v = Vec::new();
dot::render(&g, &mut v).unwrap();
File::create(path).and_then(|mut f| f.write_all(&v))
}

View file

@ -14,10 +14,12 @@ use session::Session;
use metadata::creader::CrateReader;
use plugin::registry::Registry;
use std::mem;
use std::os;
use std::dynamic_lib::DynamicLibrary;
use std::borrow::ToOwned;
use std::dynamic_lib::DynamicLibrary;
use std::env;
use std::mem;
use std::old_path;
use std::path::PathBuf;
use syntax::ast;
use syntax::codemap::{Span, COMMAND_LINE_SP};
use syntax::ptr::P;
@ -100,10 +102,11 @@ impl<'a> PluginLoader<'a> {
// Dynamically link a registrar function into the compiler process.
fn dylink_registrar(&mut self,
span: Span,
path: Path,
path: PathBuf,
symbol: String) -> PluginRegistrarFun {
// Make sure the path contains a / or the linker will search for it.
let path = os::getcwd().unwrap().join(&path);
let path = env::current_dir().unwrap().join(&path);
let path = old_path::Path::new(path.to_str().unwrap());
let lib = match DynamicLibrary::open(Some(&path)) {
Ok(lib) => lib,

View file

@ -38,6 +38,7 @@ use std::collections::HashMap;
use std::collections::hash_map::Entry::{Occupied, Vacant};
use std::env;
use std::fmt;
use std::path::PathBuf;
use llvm;
@ -89,7 +90,7 @@ pub struct Options {
// this.
pub search_paths: SearchPaths,
pub libs: Vec<(String, cstore::NativeLibraryKind)>,
pub maybe_sysroot: Option<Path>,
pub maybe_sysroot: Option<PathBuf>,
pub target_triple: String,
// User-specified cfg meta items. The compiler itself will add additional
// items to the crate config, and during parsing the entire crate config
@ -103,7 +104,7 @@ pub struct Options {
pub no_analysis: bool,
pub debugging_opts: DebuggingOptions,
/// Whether to write dependency files. It's (enabled, optional filename).
pub write_dependency_info: (bool, Option<Path>),
pub write_dependency_info: (bool, Option<PathBuf>),
pub prints: Vec<PrintRequest>,
pub cg: CodegenOptions,
pub color: ColorConfig,
@ -142,7 +143,7 @@ pub enum PrintRequest {
pub enum Input {
/// Load source from file
File(Path),
File(PathBuf),
/// The string is the source
Str(String)
}
@ -150,7 +151,8 @@ pub enum Input {
impl Input {
pub fn filestem(&self) -> String {
match *self {
Input::File(ref ifile) => ifile.filestem_str().unwrap().to_string(),
Input::File(ref ifile) => ifile.file_stem().unwrap()
.to_str().unwrap().to_string(),
Input::Str(_) => "rust_out".to_string(),
}
}
@ -158,14 +160,14 @@ impl Input {
#[derive(Clone)]
pub struct OutputFilenames {
pub out_directory: Path,
pub out_directory: PathBuf,
pub out_filestem: String,
pub single_output_file: Option<Path>,
pub single_output_file: Option<PathBuf>,
pub extra: String,
}
impl OutputFilenames {
pub fn path(&self, flavor: OutputType) -> Path {
pub fn path(&self, flavor: OutputType) -> PathBuf {
match self.single_output_file {
Some(ref path) => return path.clone(),
None => {}
@ -173,8 +175,8 @@ impl OutputFilenames {
self.temp_path(flavor)
}
pub fn temp_path(&self, flavor: OutputType) -> Path {
let base = self.out_directory.join(self.filestem());
pub fn temp_path(&self, flavor: OutputType) -> PathBuf {
let base = self.out_directory.join(&self.filestem());
match flavor {
OutputTypeBitcode => base.with_extension("bc"),
OutputTypeAssembly => base.with_extension("s"),
@ -185,8 +187,8 @@ impl OutputFilenames {
}
}
pub fn with_extension(&self, extension: &str) -> Path {
self.out_directory.join(self.filestem()).with_extension(extension)
pub fn with_extension(&self, extension: &str) -> PathBuf {
self.out_directory.join(&self.filestem()).with_extension(extension)
}
pub fn filestem(&self) -> String {
@ -897,7 +899,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
let cg = build_codegen_options(matches);
let sysroot_opt = matches.opt_str("sysroot").map(|m| Path::new(m));
let sysroot_opt = matches.opt_str("sysroot").map(|m| PathBuf::new(&m));
let target = matches.opt_str("target").unwrap_or(
host_triple().to_string());
let opt_level = {

View file

@ -26,8 +26,9 @@ use syntax::{ast, codemap};
use rustc_back::target::Target;
use std::path::{Path, PathBuf};
use std::cell::{Cell, RefCell};
use std::os;
use std::env;
pub mod config;
pub mod search_paths;
@ -44,11 +45,11 @@ pub struct Session {
pub entry_fn: RefCell<Option<(NodeId, codemap::Span)>>,
pub entry_type: Cell<Option<config::EntryFnType>>,
pub plugin_registrar_fn: Cell<Option<ast::NodeId>>,
pub default_sysroot: Option<Path>,
pub default_sysroot: Option<PathBuf>,
// The name of the root source file of the crate, in the local file system. The path is always
// expected to be absolute. `None` means that there is no source file.
pub local_crate_source_file: Option<Path>,
pub working_dir: Path,
pub local_crate_source_file: Option<PathBuf>,
pub working_dir: PathBuf,
pub lint_store: RefCell<lint::LintStore>,
pub lints: RefCell<NodeMap<Vec<(lint::LintId, codemap::Span, String)>>>,
pub crate_types: RefCell<Vec<config::CrateType>>,
@ -310,7 +311,7 @@ fn split_msg_into_multilines(msg: &str) -> Option<String> {
}
pub fn build_session(sopts: config::Options,
local_crate_source_file: Option<Path>,
local_crate_source_file: Option<PathBuf>,
registry: diagnostics::registry::Registry)
-> Session {
// FIXME: This is not general enough to make the warning lint completely override
@ -333,7 +334,7 @@ pub fn build_session(sopts: config::Options,
}
pub fn build_session_(sopts: config::Options,
local_crate_source_file: Option<Path>,
local_crate_source_file: Option<PathBuf>,
span_diagnostic: diagnostic::SpanHandler)
-> Session {
let host = match Target::search(config::host_triple()) {
@ -355,7 +356,7 @@ pub fn build_session_(sopts: config::Options,
if path.is_absolute() {
path.clone()
} else {
os::getcwd().unwrap().join(&path)
env::current_dir().unwrap().join(&path)
}
);
@ -378,7 +379,7 @@ pub fn build_session_(sopts: config::Options,
plugin_registrar_fn: Cell::new(None),
default_sysroot: default_sysroot,
local_crate_source_file: local_crate_source_file,
working_dir: os::getcwd().unwrap(),
working_dir: env::current_dir().unwrap(),
lint_store: RefCell::new(lint::LintStore::new()),
lints: RefCell::new(NodeMap()),
crate_types: RefCell::new(Vec::new()),

View file

@ -9,15 +9,16 @@
// except according to those terms.
use std::slice;
use std::path::{Path, PathBuf};
#[derive(Clone, Debug)]
pub struct SearchPaths {
paths: Vec<(PathKind, Path)>,
paths: Vec<(PathKind, PathBuf)>,
}
pub struct Iter<'a> {
kind: PathKind,
iter: slice::Iter<'a, (PathKind, Path)>,
iter: slice::Iter<'a, (PathKind, PathBuf)>,
}
#[derive(Eq, PartialEq, Clone, Copy, Debug)]
@ -49,7 +50,7 @@ impl SearchPaths {
} else {
(PathKind::All, path)
};
self.paths.push((kind, Path::new(path)));
self.paths.push((kind, PathBuf::new(path)));
}
pub fn iter(&self, kind: PathKind) -> Iter {

View file

@ -12,11 +12,13 @@
use std::cell::{RefCell, Cell};
use std::collections::HashMap;
use std::collections::hash_state::HashState;
use std::ffi::CString;
use std::fmt::Debug;
use std::hash::Hash;
use std::iter::repeat;
use std::path::Path;
use std::time::Duration;
use std::collections::hash_state::HashState;
use syntax::ast;
use syntax::visit;
@ -222,3 +224,14 @@ pub fn memoized<T, U, S, F>(cache: &RefCell<HashMap<T, U, S>>, arg: T, f: F) ->
}
}
}
#[cfg(unix)]
pub fn path2cstr(p: &Path) -> CString {
use std::os::unix::prelude::*;
use std::ffi::AsOsStr;
CString::new(p.as_os_str().as_bytes()).unwrap()
}
#[cfg(windows)]
pub fn path2cstr(p: &Path) -> CString {
CString::new(p.to_str().unwrap()).unwrap()
}