Convert std::fs to istrs. Issue #855
This commit is contained in:
parent
051f1ff562
commit
c2eafd268b
@ -40,7 +40,9 @@ fn llvm_err(sess: session::session, msg: str) {
|
||||
}
|
||||
|
||||
fn link_intrinsics(sess: session::session, llmod: ModuleRef) {
|
||||
let path = fs::connect(sess.get_opts().sysroot, "lib/intrinsics.bc");
|
||||
let path = istr::to_estr(
|
||||
fs::connect(istr::from_estr(sess.get_opts().sysroot),
|
||||
~"lib/intrinsics.bc"));
|
||||
let membuf =
|
||||
llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(str::buf(path));
|
||||
if membuf as uint == 0u {
|
||||
@ -360,10 +362,12 @@ fn build_link_meta(sess: &session::session, c: &ast::crate, output: &str,
|
||||
none. {
|
||||
let name =
|
||||
{
|
||||
let os = str::split(fs::basename(output), '.' as u8);
|
||||
let os = istr::split(
|
||||
fs::basename(istr::from_estr(output)),
|
||||
'.' as u8);
|
||||
assert (vec::len(os) >= 2u);
|
||||
vec::pop(os);
|
||||
str::connect(os, ".")
|
||||
istr::to_estr(istr::connect(os, ~"."))
|
||||
};
|
||||
warn_missing(sess, "name", name);
|
||||
name
|
||||
|
@ -312,7 +312,8 @@ fn get_arch(triple: str) -> session::arch {
|
||||
}
|
||||
|
||||
fn get_default_sysroot(binary: str) -> str {
|
||||
let dirname = fs::dirname(binary);
|
||||
let dirname = istr::to_estr(
|
||||
fs::dirname(istr::from_estr(binary)));
|
||||
if str::eq(dirname, binary) { ret "."; }
|
||||
ret dirname;
|
||||
}
|
||||
@ -443,7 +444,8 @@ fn opts() -> [getopts::opt] {
|
||||
|
||||
fn main(args: [str]) {
|
||||
let binary = vec::shift(args);
|
||||
let binary_dir = fs::dirname(binary);
|
||||
let binary_dir = istr::to_estr(
|
||||
fs::dirname(istr::from_estr(binary)));
|
||||
let match =
|
||||
alt getopts::getopts(args, opts()) {
|
||||
getopts::success(m) { m }
|
||||
@ -557,20 +559,20 @@ fn main(args: [str]) {
|
||||
} else { lib_cmd = "-shared"; }
|
||||
|
||||
// Converts a library file name into a gcc -l argument
|
||||
fn unlib(config: @session::config, filename: str) -> str {
|
||||
fn unlib(config: @session::config, filename: &istr) -> istr {
|
||||
let rmlib =
|
||||
bind fn (config: @session::config, filename: str) -> str {
|
||||
if config.os == session::os_macos ||
|
||||
config.os == session::os_linux &&
|
||||
str::find(filename, "lib") == 0 {
|
||||
ret str::slice(filename, 3u,
|
||||
str::byte_len(filename));
|
||||
} else { ret filename; }
|
||||
}(config, _);
|
||||
fn rmext(filename: str) -> str {
|
||||
let parts = str::split(filename, '.' as u8);
|
||||
bind fn (config: @session::config, filename: &istr) -> istr {
|
||||
if config.os == session::os_macos ||
|
||||
config.os == session::os_linux &&
|
||||
istr::find(filename, ~"lib") == 0 {
|
||||
ret istr::slice(filename, 3u,
|
||||
istr::byte_len(filename));
|
||||
} else { ret filename; }
|
||||
}(config, _);
|
||||
fn rmext(filename: &istr) -> istr {
|
||||
let parts = istr::split(filename, '.' as u8);
|
||||
vec::pop(parts);
|
||||
ret str::connect(parts, ".");
|
||||
ret istr::connect(parts, ~".");
|
||||
}
|
||||
ret alt config.os {
|
||||
session::os_macos. { rmext(rmlib(filename)) }
|
||||
@ -585,10 +587,11 @@ fn main(args: [str]) {
|
||||
gcc_args += [cratepath];
|
||||
cont;
|
||||
}
|
||||
let cratepath = istr::from_estr(cratepath);
|
||||
let dir = fs::dirname(cratepath);
|
||||
if dir != "" { gcc_args += ["-L" + dir]; }
|
||||
if dir != ~"" { gcc_args += ["-L" + istr::to_estr(dir)]; }
|
||||
let libarg = unlib(sess.get_targ_cfg(), fs::basename(cratepath));
|
||||
gcc_args += ["-l" + libarg];
|
||||
gcc_args += ["-l" + istr::to_estr(libarg)];
|
||||
}
|
||||
|
||||
let ula = cstore::get_used_link_args(cstore);
|
||||
|
@ -15,6 +15,7 @@ import back::x86;
|
||||
import util::common;
|
||||
import std::vec;
|
||||
import std::str;
|
||||
import std::istr;
|
||||
import std::fs;
|
||||
import std::io;
|
||||
import std::option;
|
||||
@ -150,7 +151,8 @@ fn find_library_crate_aux(nn: &{prefix: str, suffix: str}, crate_name: str,
|
||||
metas: &[@ast::meta_item],
|
||||
library_search_paths: &[str]) ->
|
||||
option::t<{ident: str, data: @[u8]}> {
|
||||
let prefix: str = nn.prefix + crate_name;
|
||||
let prefix: istr = istr::from_estr(nn.prefix + crate_name);
|
||||
let suffix: istr = istr::from_estr(nn.suffix);
|
||||
// FIXME: we could probably use a 'glob' function in std::fs but it will
|
||||
// be much easier to write once the unsafe module knows more about FFI
|
||||
// tricks. Currently the glob(3) interface is a bit more than we can
|
||||
@ -159,13 +161,17 @@ fn find_library_crate_aux(nn: &{prefix: str, suffix: str}, crate_name: str,
|
||||
|
||||
for library_search_path: str in library_search_paths {
|
||||
log #fmt["searching %s", library_search_path];
|
||||
for path: str in fs::list_dir(library_search_path) {
|
||||
log #fmt["searching %s", path];
|
||||
let f: str = fs::basename(path);
|
||||
if !(str::starts_with(f, prefix) && str::ends_with(f, nn.suffix))
|
||||
let library_search_path = istr::from_estr(library_search_path);
|
||||
for path: istr in fs::list_dir(library_search_path) {
|
||||
log #fmt["searching %s", istr::to_estr(path)];
|
||||
let f: istr = fs::basename(path);
|
||||
let path = istr::to_estr(path);
|
||||
if !(istr::starts_with(f, prefix) && istr::ends_with(f, suffix))
|
||||
{
|
||||
log #fmt["skipping %s, doesn't look like %s*%s", path, prefix,
|
||||
nn.suffix];
|
||||
log #fmt["skipping %s, doesn't look like %s*%s",
|
||||
path,
|
||||
istr::to_estr(prefix),
|
||||
istr::to_estr(suffix)];
|
||||
cont;
|
||||
}
|
||||
alt get_metadata_section(path) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
|
||||
import std::str;
|
||||
import std::istr;
|
||||
import std::option;
|
||||
import std::option::some;
|
||||
import std::option::none;
|
||||
@ -48,10 +49,12 @@ fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: str,
|
||||
ast::cdir_src_mod(id, file_opt, attrs) {
|
||||
let file_path = id + ".rs";
|
||||
alt file_opt { some(f) { file_path = f; } none. { } }
|
||||
let full_path =
|
||||
if std::fs::path_is_absolute(file_path) {
|
||||
file_path
|
||||
} else { prefix + std::fs::path_sep() + file_path };
|
||||
let full_path = if std::fs::path_is_absolute(
|
||||
istr::from_estr(file_path)) {
|
||||
file_path
|
||||
} else {
|
||||
prefix + istr::to_estr(std::fs::path_sep()) + file_path
|
||||
};
|
||||
if cx.mode == mode_depend { cx.deps += [full_path]; ret; }
|
||||
let p0 =
|
||||
new_parser_from_file(cx.sess, cx.cfg, full_path, cx.chpos,
|
||||
@ -73,9 +76,9 @@ fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: str,
|
||||
let path = id;
|
||||
alt dir_opt { some(d) { path = d; } none. { } }
|
||||
let full_path =
|
||||
if std::fs::path_is_absolute(path) {
|
||||
if std::fs::path_is_absolute(istr::from_estr(path)) {
|
||||
path
|
||||
} else { prefix + std::fs::path_sep() + path };
|
||||
} else { prefix + istr::to_estr(std::fs::path_sep()) + path };
|
||||
let m0 = eval_crate_directives_to_mod(cx, cdirs, full_path);
|
||||
let i =
|
||||
@{ident: id,
|
||||
|
@ -2,6 +2,7 @@
|
||||
import std::io;
|
||||
import std::vec;
|
||||
import std::str;
|
||||
import std::istr;
|
||||
import std::option;
|
||||
import std::option::some;
|
||||
import std::option::none;
|
||||
@ -2525,7 +2526,8 @@ fn parse_crate_from_crate_file(input: &str, cfg: &ast::crate_cfg,
|
||||
sess: &parse_sess) -> @ast::crate {
|
||||
let p = new_parser_from_file(sess, cfg, input, 0u, 0u, CRATE_FILE);
|
||||
let lo = p.get_lo_pos();
|
||||
let prefix = std::fs::dirname(p.get_filemap().name);
|
||||
let prefix = istr::to_estr(
|
||||
std::fs::dirname(istr::from_estr(p.get_filemap().name)));
|
||||
let leading_attrs = parse_inner_attrs_and_next(p);
|
||||
let crate_attrs = leading_attrs.inner;
|
||||
let first_cdir_attr = leading_attrs.next;
|
||||
|
@ -10,6 +10,7 @@ import std::io;
|
||||
import std::io::stdout;
|
||||
import std::vec;
|
||||
import std::str;
|
||||
import std::istr;
|
||||
import std::uint;
|
||||
import std::option;
|
||||
|
||||
@ -40,8 +41,11 @@ fn find_rust_files(files: &mutable [str], path: str) {
|
||||
if file_contains(path, "xfail-stage1") {
|
||||
//log_err "Skipping " + path + " because it is marked as xfail-stage1";
|
||||
} else { files += [path]; }
|
||||
} else if fs::file_is_dir(path) && str::find(path, "compile-fail") == -1 {
|
||||
for p in fs::list_dir(path) { find_rust_files(files, p); }
|
||||
} else if fs::file_is_dir(istr::from_estr(path))
|
||||
&& str::find(path, "compile-fail") == -1 {
|
||||
for p in fs::list_dir(istr::from_estr(path)) {
|
||||
find_rust_files(files, istr::to_estr(p));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,34 +7,34 @@ native "rust" mod rustrt {
|
||||
fn rust_file_is_dir(path: str) -> int;
|
||||
}
|
||||
|
||||
fn path_sep() -> str { ret str::from_char(os_fs::path_sep); }
|
||||
fn path_sep() -> istr { ret istr::from_char(os_fs::path_sep); }
|
||||
|
||||
type path = str;
|
||||
type path = istr;
|
||||
|
||||
fn dirname(p: path) -> path {
|
||||
let i: int = str::rindex(p, os_fs::path_sep as u8);
|
||||
fn dirname(p: &path) -> path {
|
||||
let i: int = istr::rindex(p, os_fs::path_sep as u8);
|
||||
if i == -1 {
|
||||
i = str::rindex(p, os_fs::alt_path_sep as u8);
|
||||
if i == -1 { ret "."; }
|
||||
i = istr::rindex(p, os_fs::alt_path_sep as u8);
|
||||
if i == -1 { ret ~"."; }
|
||||
}
|
||||
ret str::substr(p, 0u, i as uint);
|
||||
ret istr::substr(p, 0u, i as uint);
|
||||
}
|
||||
|
||||
fn basename(p: path) -> path {
|
||||
let i: int = str::rindex(p, os_fs::path_sep as u8);
|
||||
fn basename(p: &path) -> path {
|
||||
let i: int = istr::rindex(p, os_fs::path_sep as u8);
|
||||
if i == -1 {
|
||||
i = str::rindex(p, os_fs::alt_path_sep as u8);
|
||||
i = istr::rindex(p, os_fs::alt_path_sep as u8);
|
||||
if i == -1 { ret p; }
|
||||
}
|
||||
let len = str::byte_len(p);
|
||||
let len = istr::byte_len(p);
|
||||
if i + 1 as uint >= len { ret p; }
|
||||
ret str::slice(p, i + 1 as uint, len);
|
||||
ret istr::slice(p, i + 1 as uint, len);
|
||||
}
|
||||
|
||||
|
||||
// FIXME: Need some typestate to avoid bounds check when len(pre) == 0
|
||||
fn connect(pre: path, post: path) -> path {
|
||||
let len = str::byte_len(pre);
|
||||
fn connect(pre: &path, post: &path) -> path {
|
||||
let len = istr::byte_len(pre);
|
||||
ret if pre[len - 1u] == os_fs::path_sep as u8 {
|
||||
|
||||
// Trailing '/'?
|
||||
@ -42,26 +42,36 @@ fn connect(pre: path, post: path) -> path {
|
||||
} else { pre + path_sep() + post };
|
||||
}
|
||||
|
||||
fn file_is_dir(p: path) -> bool { ret rustrt::rust_file_is_dir(p) != 0; }
|
||||
fn file_is_dir(p: &path) -> bool {
|
||||
ret rustrt::rust_file_is_dir(istr::to_estr(p)) != 0;
|
||||
}
|
||||
|
||||
fn list_dir(p: path) -> [str] {
|
||||
let pl = str::byte_len(p);
|
||||
fn list_dir(p: &path) -> [istr] {
|
||||
let p = p;
|
||||
let pl = istr::byte_len(p);
|
||||
if pl == 0u || p[pl - 1u] as char != os_fs::path_sep { p += path_sep(); }
|
||||
let full_paths: [str] = [];
|
||||
for filename: str in os_fs::list_dir(p) {
|
||||
if !str::eq(filename, ".") {
|
||||
if !str::eq(filename, "..") { full_paths += [p + filename]; }
|
||||
let full_paths: [istr] = [];
|
||||
for filename: str in os_fs::list_dir(istr::to_estr(p)) {
|
||||
let filename = istr::from_estr(filename);
|
||||
if !istr::eq(filename, ~".") {
|
||||
if !istr::eq(filename, ~"..") { full_paths += [p + filename]; }
|
||||
}
|
||||
}
|
||||
ret full_paths;
|
||||
}
|
||||
|
||||
fn path_is_absolute(p: path) -> bool { ret os_fs::path_is_absolute(p); }
|
||||
fn path_is_absolute(p: &path) -> bool {
|
||||
ret os_fs::path_is_absolute(istr::to_estr(p));
|
||||
}
|
||||
|
||||
// FIXME: under Windows, we should prepend the current drive letter to paths
|
||||
// that start with a slash.
|
||||
fn make_absolute(p: path) -> path {
|
||||
if path_is_absolute(p) { ret p; } else { ret connect(getcwd(), p); }
|
||||
fn make_absolute(p: &path) -> path {
|
||||
if path_is_absolute(p) {
|
||||
ret p;
|
||||
} else {
|
||||
ret connect(istr::from_estr(getcwd()), p);
|
||||
}
|
||||
}
|
||||
|
||||
// Local Variables:
|
||||
|
@ -3,7 +3,7 @@ index, rindex, find, starts_with, ends_with, substr, slice, split,
|
||||
concat, connect, to_upper, replace, char_slice, trim_left, trim_right, trim,
|
||||
unshift_char, shift_char, pop_char, push_char, is_utf8, from_chars, to_chars,
|
||||
char_len, char_at, bytes, is_ascii, shift_byte, pop_byte, unsafe_from_byte,
|
||||
unsafe_from_bytes;
|
||||
unsafe_from_bytes, from_char;
|
||||
|
||||
export from_estr, to_estr;
|
||||
|
||||
|
@ -3,6 +3,7 @@ import std::getopts;
|
||||
import std::test;
|
||||
import std::fs;
|
||||
import std::str;
|
||||
import std::istr;
|
||||
import std::vec;
|
||||
import std::task;
|
||||
|
||||
@ -126,7 +127,8 @@ fn make_tests(cx: &cx) -> tests_and_conv_fn {
|
||||
log #fmt["making tests from %s", cx.config.src_base];
|
||||
let configport = port::<[u8]>();
|
||||
let tests = [];
|
||||
for file: str in fs::list_dir(cx.config.src_base) {
|
||||
for file: istr in fs::list_dir(istr::from_estr(cx.config.src_base)) {
|
||||
let file = istr::to_estr(file);
|
||||
log #fmt["inspecting file %s", file];
|
||||
if is_test(cx.config, file) {
|
||||
tests += [make_test(cx, file, configport)];
|
||||
@ -137,19 +139,21 @@ fn make_tests(cx: &cx) -> tests_and_conv_fn {
|
||||
|
||||
fn is_test(config: &config, testfile: &str) -> bool {
|
||||
// Pretty-printer does not work with .rc files yet
|
||||
let valid_extensions =
|
||||
alt config.mode { mode_pretty. { [".rs"] } _ { [".rc", ".rs"] } };
|
||||
let invalid_prefixes = [".", "#", "~"];
|
||||
let name = fs::basename(testfile);
|
||||
let valid_extensions = alt config.mode {
|
||||
mode_pretty. { [~".rs"] }
|
||||
_ { [~".rc", ~".rs"] }
|
||||
};
|
||||
let invalid_prefixes = [~".", ~"#", ~"~"];
|
||||
let name = fs::basename(istr::from_estr(testfile));
|
||||
|
||||
let valid = false;
|
||||
|
||||
for ext in valid_extensions {
|
||||
if str::ends_with(name, ext) { valid = true }
|
||||
if istr::ends_with(name, ext) { valid = true }
|
||||
}
|
||||
|
||||
for pre in invalid_prefixes {
|
||||
if str::starts_with(name, pre) { valid = false }
|
||||
if istr::starts_with(name, pre) { valid = false }
|
||||
}
|
||||
|
||||
ret valid;
|
||||
|
@ -1,5 +1,6 @@
|
||||
import std::option;
|
||||
import std::str;
|
||||
import std::istr;
|
||||
import std::io;
|
||||
import std::fs;
|
||||
|
||||
@ -95,7 +96,8 @@ fn parse_pp_exact(line: &str, testfile: &str) -> option::t<str> {
|
||||
option::some(s) { option::some(s) }
|
||||
option::none. {
|
||||
if parse_name_directive(line, "pp-exact") {
|
||||
option::some(fs::basename(testfile))
|
||||
option::some(istr::to_estr(
|
||||
fs::basename(istr::from_estr(testfile))))
|
||||
} else {
|
||||
option::none
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
import std::io;
|
||||
import std::str;
|
||||
import std::istr;
|
||||
import std::option;
|
||||
import std::fs;
|
||||
import std::os;
|
||||
@ -105,8 +106,9 @@ fn run_pretty_test(cx: &cx, props: &test_props, testfile: &str) {
|
||||
let expected =
|
||||
alt props.pp_exact {
|
||||
option::some(file) {
|
||||
let filepath = fs::connect(fs::dirname(testfile), file);
|
||||
io::read_whole_file_str(filepath)
|
||||
let filepath = fs::connect(fs::dirname(
|
||||
istr::from_estr(testfile)), istr::from_estr(file));
|
||||
io::read_whole_file_str(istr::to_estr(filepath))
|
||||
}
|
||||
option::none. { srcs[vec::len(srcs) - 2u] }
|
||||
};
|
||||
@ -338,11 +340,12 @@ fn output_base_name(config: &config, testfile: &str) -> str {
|
||||
let base = config.build_base;
|
||||
let filename =
|
||||
{
|
||||
let parts = str::split(fs::basename(testfile), '.' as u8);
|
||||
let parts = istr::split(fs::basename(istr::from_estr(testfile)),
|
||||
'.' as u8);
|
||||
parts = vec::slice(parts, 0u, vec::len(parts) - 1u);
|
||||
str::connect(parts, ".")
|
||||
istr::connect(parts, ~".")
|
||||
};
|
||||
#fmt["%s%s.%s", base, filename, config.stage_id]
|
||||
#fmt["%s%s.%s", base, istr::to_estr(filename), config.stage_id]
|
||||
}
|
||||
|
||||
fn maybe_dump_to_stdout(config: &config, out: &str, err: &str) {
|
||||
|
@ -5,12 +5,12 @@ import std::fs;
|
||||
#[test]
|
||||
fn test_connect() {
|
||||
let slash = fs::path_sep();
|
||||
log_err fs::connect("a", "b");
|
||||
assert (fs::connect("a", "b") == "a" + slash + "b");
|
||||
assert (fs::connect("a" + slash, "b") == "a" + slash + "b");
|
||||
log_err fs::connect(~"a", ~"b");
|
||||
assert (fs::connect(~"a", ~"b") == ~"a" + slash + ~"b");
|
||||
assert (fs::connect(~"a" + slash, ~"b") == ~"a" + slash + ~"b");
|
||||
}
|
||||
|
||||
// Issue #712
|
||||
#[test]
|
||||
fn test_list_dir_no_invalid_memory_access() { fs::list_dir("."); }
|
||||
fn test_list_dir_no_invalid_memory_access() { fs::list_dir(~"."); }
|
||||
|
||||
|
@ -8,10 +8,10 @@ import std::os;
|
||||
|
||||
#[test]
|
||||
fn test() {
|
||||
assert (!fs::path_is_absolute("test-path"));
|
||||
assert (!fs::path_is_absolute(~"test-path"));
|
||||
|
||||
log "Current working directory: " + os::getcwd();
|
||||
|
||||
log fs::make_absolute("test-path");
|
||||
log fs::make_absolute("/usr/bin");
|
||||
log fs::make_absolute(~"test-path");
|
||||
log fs::make_absolute(~"/usr/bin");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user