Skip to content

rustpkg install #6124

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

Merged
merged 4 commits into from
May 4, 2013
Merged
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
37 changes: 37 additions & 0 deletions src/libcore/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,28 @@ pub fn list_dir_path(p: &Path) -> ~[~Path] {
list_dir(p).map(|f| ~p.push(*f))
}

/// Removes a directory at the specified path, after removing
/// all its contents. Use carefully!
pub fn remove_dir_recursive(p: &Path) -> bool {
let mut error_happened = false;
for walk_dir(p) |inner| {
if !error_happened {
if path_is_dir(inner) {
if !remove_dir_recursive(inner) {
error_happened = true;
}
}
else {
if !remove_file(inner) {
error_happened = true;
}
}
}
};
// Directory should now be empty
!error_happened && remove_dir(p)
}

/// Removes a directory at the specified path
pub fn remove_dir(p: &Path) -> bool {
return rmdir(p);
Expand Down Expand Up @@ -877,6 +899,10 @@ pub fn copy_file(from: &Path, to: &Path) -> bool {
if istream as uint == 0u {
return false;
}
// Preserve permissions
let from_mode = from.get_mode().expect("copy_file: couldn't get permissions \
for source file");

let ostream = do as_c_charp(to.to_str()) |top| {
do as_c_charp("w+b") |modebuf| {
libc::fopen(top, modebuf)
Expand Down Expand Up @@ -908,6 +934,15 @@ pub fn copy_file(from: &Path, to: &Path) -> bool {
}
fclose(istream);
fclose(ostream);

// Give the new file the old file's permissions
unsafe {
if do str::as_c_str(to.to_str()) |to_buf| {
libc::chmod(to_buf, from_mode as mode_t)
} != 0 {
return false; // should be a condition...
}
}
return ok;
}
}
Expand Down Expand Up @@ -1594,13 +1629,15 @@ mod tests {
== buf.len() as size_t))
}
assert!((libc::fclose(ostream) == (0u as c_int)));
let in_mode = in.get_mode();
let rs = os::copy_file(&in, &out);
if (!os::path_exists(&in)) {
fail!(fmt!("%s doesn't exist", in.to_str()));
}
assert!((rs));
let rslt = run::run_program(~"diff", ~[in.to_str(), out.to_str()]);
assert!((rslt == 0));
assert!(out.get_mode() == in_mode);
assert!((remove_file(&in)));
assert!((remove_file(&out)));
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/back/rpath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn get_rpath_flags(sess: session::Session, out_filename: &Path)
// where rustrt is and we know every rust program needs it
let libs = vec::append_one(libs, get_sysroot_absolute_rt_lib(sess));

let rpaths = get_rpaths(os, &sysroot, output, libs,
let rpaths = get_rpaths(os, sysroot, output, libs,
sess.opts.target_triple);
rpaths_to_flags(rpaths)
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ pub fn build_session_options(binary: @~str,
link::output_type_bitcode
} else { link::output_type_exe };
let sysroot_opt = getopts::opt_maybe_str(matches, ~"sysroot");
let sysroot_opt = sysroot_opt.map(|m| Path(*m));
let sysroot_opt = sysroot_opt.map(|m| @Path(*m));
let target_opt = getopts::opt_maybe_str(matches, ~"target");
let target_feature_opt = getopts::opt_maybe_str(matches, ~"target-feature");
let save_temps = getopts::opt_present(matches, ~"save-temps");
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/driver/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub struct options {
output_type: back::link::output_type,
addl_lib_search_paths: ~[Path],
linker_args: ~[~str],
maybe_sysroot: Option<Path>,
maybe_sysroot: Option<@Path>,
target_triple: ~str,
target_feature: ~str,
// User-specified cfg meta items. The compiler itself will add additional
Expand Down
55 changes: 31 additions & 24 deletions src/librustc/metadata/filesearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,48 @@ pub fn pick_file(file: Path, path: &Path) -> Option<Path> {
}

pub trait FileSearch {
fn sysroot(&self) -> Path;
fn lib_search_paths(&self) -> ~[Path];
fn sysroot(&self) -> @Path;
fn for_each_lib_search_path(&self, f: &fn(&Path) -> bool);
fn get_target_lib_path(&self) -> Path;
fn get_target_lib_file_path(&self, file: &Path) -> Path;
}

pub fn mk_filesearch(maybe_sysroot: &Option<Path>,
pub fn mk_filesearch(maybe_sysroot: &Option<@Path>,
target_triple: &str,
addl_lib_search_paths: ~[Path])
-> @FileSearch {
struct FileSearchImpl {
sysroot: Path,
sysroot: @Path,
addl_lib_search_paths: ~[Path],
target_triple: ~str
}
impl FileSearch for FileSearchImpl {
fn sysroot(&self) -> Path { /*bad*/copy self.sysroot }
fn lib_search_paths(&self) -> ~[Path] {
let mut paths = /*bad*/copy self.addl_lib_search_paths;

paths.push(
make_target_lib_path(&self.sysroot,
self.target_triple));
match get_rustpkg_lib_path_nearest() {
result::Ok(ref p) => paths.push((/*bad*/copy *p)),
result::Err(_) => ()
fn sysroot(&self) -> @Path { self.sysroot }
fn for_each_lib_search_path(&self, f: &fn(&Path) -> bool) {
debug!("filesearch: searching additional lib search paths");
// a little weird
self.addl_lib_search_paths.each(f);

debug!("filesearch: searching target lib path");
if !f(&make_target_lib_path(self.sysroot,
self.target_triple)) {
return;
}
match get_rustpkg_lib_path() {
result::Ok(ref p) => paths.push((/*bad*/copy *p)),
result::Err(_) => ()
}
paths
debug!("filesearch: searching rustpkg lib path nearest");
if match get_rustpkg_lib_path_nearest() {
result::Ok(ref p) => f(p),
result::Err(_) => true
} {
return;
}
debug!("filesearch: searching rustpkg lib path");
match get_rustpkg_lib_path() {
result::Ok(ref p) => f(p),
result::Err(_) => true
};
}
fn get_target_lib_path(&self) -> Path {
make_target_lib_path(&self.sysroot, self.target_triple)
make_target_lib_path(self.sysroot, self.target_triple)
}
fn get_target_lib_file_path(&self, file: &Path) -> Path {
self.get_target_lib_path().push_rel(file)
Expand All @@ -72,7 +79,7 @@ pub fn mk_filesearch(maybe_sysroot: &Option<Path>,

pub fn search<T:Copy>(filesearch: @FileSearch, pick: pick<T>) -> Option<T> {
let mut rslt = None;
for filesearch.lib_search_paths().each |lib_search_path| {
for filesearch.for_each_lib_search_path() |lib_search_path| {
debug!("searching %s", lib_search_path.to_str());
for os::list_dir_path(lib_search_path).each |path| {
debug!("testing %s", path.to_str());
Expand Down Expand Up @@ -108,10 +115,10 @@ fn get_or_default_sysroot() -> Path {
}
}

fn get_sysroot(maybe_sysroot: &Option<Path>) -> Path {
fn get_sysroot(maybe_sysroot: &Option<@Path>) -> @Path {
match *maybe_sysroot {
option::Some(ref sr) => (/*bad*/copy *sr),
option::None => get_or_default_sysroot()
option::Some(sr) => sr,
option::None => @get_or_default_sysroot()
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/librustpkg/conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,13 @@ condition! {
}

condition! {
nonexistent_package: (super::PkgId, ~str) -> super::Path;
nonexistent_package: (super::PkgId, ~str) -> ();
}

condition! {
copy_failed: (super::Path, super::Path) -> ();
}

condition! {
missing_pkg_files: (super::PkgId) -> ();
}
3 changes: 3 additions & 0 deletions src/librustpkg/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
use core::hashmap::HashMap;

pub struct Ctx {
// Sysroot -- if this is None, uses rustc filesearch's
// idea of the default
sysroot_opt: Option<@Path>,
// I'm not sure what this is for
json: bool,
// Cache of hashes of things already installed
Expand Down
Loading