Skip to content

Commit 2470f89

Browse files
committed
---
yaml --- r: 140446 b: refs/heads/try2 c: c3ab74b h: refs/heads/master v: v3
1 parent 926391b commit 2470f89

File tree

22 files changed

+544
-186
lines changed

22 files changed

+544
-186
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: c15fa3a02aa3e7e5111f0410abf7321387a7a97f
8+
refs/heads/try2: c3ab74b8b933a1bc2c5f207ae5c023cf3e7aeb58
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libcore/os.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,28 @@ pub fn list_dir_path(p: &Path) -> ~[~Path] {
772772
list_dir(p).map(|f| ~p.push(*f))
773773
}
774774
775+
/// Removes a directory at the specified path, after removing
776+
/// all its contents. Use carefully!
777+
pub fn remove_dir_recursive(p: &Path) -> bool {
778+
let mut error_happened = false;
779+
for walk_dir(p) |inner| {
780+
if !error_happened {
781+
if path_is_dir(inner) {
782+
if !remove_dir_recursive(inner) {
783+
error_happened = true;
784+
}
785+
}
786+
else {
787+
if !remove_file(inner) {
788+
error_happened = true;
789+
}
790+
}
791+
}
792+
};
793+
// Directory should now be empty
794+
!error_happened && remove_dir(p)
795+
}
796+
775797
/// Removes a directory at the specified path
776798
pub fn remove_dir(p: &Path) -> bool {
777799
return rmdir(p);
@@ -877,6 +899,10 @@ pub fn copy_file(from: &Path, to: &Path) -> bool {
877899
if istream as uint == 0u {
878900
return false;
879901
}
902+
// Preserve permissions
903+
let from_mode = from.get_mode().expect("copy_file: couldn't get permissions \
904+
for source file");
905+
880906
let ostream = do as_c_charp(to.to_str()) |top| {
881907
do as_c_charp("w+b") |modebuf| {
882908
libc::fopen(top, modebuf)
@@ -908,6 +934,15 @@ pub fn copy_file(from: &Path, to: &Path) -> bool {
908934
}
909935
fclose(istream);
910936
fclose(ostream);
937+
938+
// Give the new file the old file's permissions
939+
unsafe {
940+
if do str::as_c_str(to.to_str()) |to_buf| {
941+
libc::chmod(to_buf, from_mode as mode_t)
942+
} != 0 {
943+
return false; // should be a condition...
944+
}
945+
}
911946
return ok;
912947
}
913948
}
@@ -1594,13 +1629,15 @@ mod tests {
15941629
== buf.len() as size_t))
15951630
}
15961631
assert!((libc::fclose(ostream) == (0u as c_int)));
1632+
let in_mode = in.get_mode();
15971633
let rs = os::copy_file(&in, &out);
15981634
if (!os::path_exists(&in)) {
15991635
fail!(fmt!("%s doesn't exist", in.to_str()));
16001636
}
16011637
assert!((rs));
16021638
let rslt = run::run_program(~"diff", ~[in.to_str(), out.to_str()]);
16031639
assert!((rslt == 0));
1640+
assert!(out.get_mode() == in_mode);
16041641
assert!((remove_file(&in)));
16051642
assert!((remove_file(&out)));
16061643
}

branches/try2/src/libcore/prelude.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub use io::{print, println};
3131
/* Reexported types and traits */
3232

3333
pub use clone::Clone;
34-
pub use cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater};
34+
pub use cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater, Equiv};
3535
pub use container::{Container, Mutable, Map, Set};
3636
pub use hash::Hash;
3737
pub use old_iter::{BaseIter, ReverseIter, MutableIter, ExtendedIter, EqIter};

branches/try2/src/libcore/str/ascii.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
//! Operations on ASCII strings and characters.
12+
1113
use to_str::{ToStr,ToStrConsume};
1214
use str;
1315
use cast;

branches/try2/src/libcore/to_bytes.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,7 @@ impl<A> IterBytes for *const A {
419419
}
420420
}
421421

422-
423-
trait ToBytes {
422+
pub trait ToBytes {
424423
fn to_bytes(&self, lsb0: bool) -> ~[u8];
425424
}
426425

branches/try2/src/librustc/back/link.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -752,18 +752,26 @@ pub fn link_binary(sess: Session,
752752
// instead of hard-coded gcc.
753753
// For win32, there is no cc command,
754754
// so we add a condition to make it use gcc.
755-
let cc_prog: ~str = if sess.targ_cfg.os == session::os_android {
756-
match &sess.opts.android_cross_path {
757-
&Some(copy path) => {
758-
fmt!("%s/bin/arm-linux-androideabi-gcc", path)
759-
}
760-
&None => {
761-
sess.fatal(~"need Android NDK path for linking \
762-
(--android-cross-path)")
755+
let cc_prog: ~str = match sess.opts.linker {
756+
Some(copy linker) => linker,
757+
None => {
758+
if sess.targ_cfg.os == session::os_android {
759+
match &sess.opts.android_cross_path {
760+
&Some(copy path) => {
761+
fmt!("%s/bin/arm-linux-androideabi-gcc", path)
762+
}
763+
&None => {
764+
sess.fatal(~"need Android NDK path for linking \
765+
(--android-cross-path)")
766+
}
767+
}
768+
} else if sess.targ_cfg.os == session::os_win32 {
769+
~"gcc"
770+
} else {
771+
~"cc"
763772
}
764773
}
765-
} else if sess.targ_cfg.os == session::os_win32 { ~"gcc" }
766-
else { ~"cc" };
774+
};
767775
// The invocations of cc share some flags across platforms
768776
769777

branches/try2/src/librustc/back/rpath.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub fn get_rpath_flags(sess: session::Session, out_filename: &Path)
4040
// where rustrt is and we know every rust program needs it
4141
let libs = vec::append_one(libs, get_sysroot_absolute_rt_lib(sess));
4242

43-
let rpaths = get_rpaths(os, &sysroot, output, libs,
43+
let rpaths = get_rpaths(os, sysroot, output, libs,
4444
sess.opts.target_triple);
4545
rpaths_to_flags(rpaths)
4646
}

branches/try2/src/librustc/driver/driver.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ pub fn build_session_options(binary: @~str,
603603
link::output_type_bitcode
604604
} else { link::output_type_exe };
605605
let sysroot_opt = getopts::opt_maybe_str(matches, ~"sysroot");
606-
let sysroot_opt = sysroot_opt.map(|m| Path(*m));
606+
let sysroot_opt = sysroot_opt.map(|m| @Path(*m));
607607
let target_opt = getopts::opt_maybe_str(matches, ~"target");
608608
let target_feature_opt = getopts::opt_maybe_str(matches, ~"target-feature");
609609
let save_temps = getopts::opt_present(matches, ~"save-temps");
@@ -650,7 +650,7 @@ pub fn build_session_options(binary: @~str,
650650
};
651651
652652
let addl_lib_search_paths = getopts::opt_strs(matches, ~"L").map(|s| Path(*s));
653-
653+
let linker = getopts::opt_maybe_str(matches, ~"linker");
654654
let linker_args = getopts::opt_strs(matches, ~"link-args").flat_map( |a| {
655655
let mut args = ~[];
656656
for str::each_split_char(*a, ' ') |arg| {
@@ -676,6 +676,7 @@ pub fn build_session_options(binary: @~str,
676676
jit: jit,
677677
output_type: output_type,
678678
addl_lib_search_paths: addl_lib_search_paths,
679+
linker: linker,
679680
linker_args: linker_args,
680681
maybe_sysroot: sysroot_opt,
681682
target_triple: target,
@@ -760,6 +761,7 @@ pub fn optgroups() -> ~[getopts::groups::OptGroup] {
760761
optmulti("L", "", "Add a directory to the library search path",
761762
"PATH"),
762763
optflag("", "lib", "Compile a library crate"),
764+
optopt("", "linker", "Program to use for linking instead of the default.", "LINKER"),
763765
optmulti("", "link-args", "FLAGS is a space-separated list of flags
764766
passed to the linker", "FLAGS"),
765767
optflag("", "ls", "List the symbols defined by a library crate"),

branches/try2/src/librustc/driver/session.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,9 @@ pub struct options {
124124
jit: bool,
125125
output_type: back::link::output_type,
126126
addl_lib_search_paths: ~[Path],
127+
linker: Option<~str>,
127128
linker_args: ~[~str],
128-
maybe_sysroot: Option<Path>,
129+
maybe_sysroot: Option<@Path>,
129130
target_triple: ~str,
130131
target_feature: ~str,
131132
// User-specified cfg meta items. The compiler itself will add additional
@@ -302,7 +303,8 @@ pub fn basic_options() -> @options {
302303
jit: false,
303304
output_type: link::output_type_exe,
304305
addl_lib_search_paths: ~[],
305-
linker_args:~[],
306+
linker: None,
307+
linker_args: ~[],
306308
maybe_sysroot: None,
307309
target_triple: host_triple(),
308310
target_feature: ~"",

branches/try2/src/librustc/metadata/filesearch.rs

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,41 +20,48 @@ pub fn pick_file(file: Path, path: &Path) -> Option<Path> {
2020
}
2121

2222
pub trait FileSearch {
23-
fn sysroot(&self) -> Path;
24-
fn lib_search_paths(&self) -> ~[Path];
23+
fn sysroot(&self) -> @Path;
24+
fn for_each_lib_search_path(&self, f: &fn(&Path) -> bool);
2525
fn get_target_lib_path(&self) -> Path;
2626
fn get_target_lib_file_path(&self, file: &Path) -> Path;
2727
}
2828

29-
pub fn mk_filesearch(maybe_sysroot: &Option<Path>,
29+
pub fn mk_filesearch(maybe_sysroot: &Option<@Path>,
3030
target_triple: &str,
3131
addl_lib_search_paths: ~[Path])
3232
-> @FileSearch {
3333
struct FileSearchImpl {
34-
sysroot: Path,
34+
sysroot: @Path,
3535
addl_lib_search_paths: ~[Path],
3636
target_triple: ~str
3737
}
3838
impl FileSearch for FileSearchImpl {
39-
fn sysroot(&self) -> Path { /*bad*/copy self.sysroot }
40-
fn lib_search_paths(&self) -> ~[Path] {
41-
let mut paths = /*bad*/copy self.addl_lib_search_paths;
42-
43-
paths.push(
44-
make_target_lib_path(&self.sysroot,
45-
self.target_triple));
46-
match get_rustpkg_lib_path_nearest() {
47-
result::Ok(ref p) => paths.push((/*bad*/copy *p)),
48-
result::Err(_) => ()
39+
fn sysroot(&self) -> @Path { self.sysroot }
40+
fn for_each_lib_search_path(&self, f: &fn(&Path) -> bool) {
41+
debug!("filesearch: searching additional lib search paths");
42+
// a little weird
43+
self.addl_lib_search_paths.each(f);
44+
45+
debug!("filesearch: searching target lib path");
46+
if !f(&make_target_lib_path(self.sysroot,
47+
self.target_triple)) {
48+
return;
4949
}
50-
match get_rustpkg_lib_path() {
51-
result::Ok(ref p) => paths.push((/*bad*/copy *p)),
52-
result::Err(_) => ()
53-
}
54-
paths
50+
debug!("filesearch: searching rustpkg lib path nearest");
51+
if match get_rustpkg_lib_path_nearest() {
52+
result::Ok(ref p) => f(p),
53+
result::Err(_) => true
54+
} {
55+
return;
56+
}
57+
debug!("filesearch: searching rustpkg lib path");
58+
match get_rustpkg_lib_path() {
59+
result::Ok(ref p) => f(p),
60+
result::Err(_) => true
61+
};
5562
}
5663
fn get_target_lib_path(&self) -> Path {
57-
make_target_lib_path(&self.sysroot, self.target_triple)
64+
make_target_lib_path(self.sysroot, self.target_triple)
5865
}
5966
fn get_target_lib_file_path(&self, file: &Path) -> Path {
6067
self.get_target_lib_path().push_rel(file)
@@ -72,7 +79,7 @@ pub fn mk_filesearch(maybe_sysroot: &Option<Path>,
7279

7380
pub fn search<T:Copy>(filesearch: @FileSearch, pick: pick<T>) -> Option<T> {
7481
let mut rslt = None;
75-
for filesearch.lib_search_paths().each |lib_search_path| {
82+
for filesearch.for_each_lib_search_path() |lib_search_path| {
7683
debug!("searching %s", lib_search_path.to_str());
7784
for os::list_dir_path(lib_search_path).each |path| {
7885
debug!("testing %s", path.to_str());
@@ -108,10 +115,10 @@ fn get_or_default_sysroot() -> Path {
108115
}
109116
}
110117
111-
fn get_sysroot(maybe_sysroot: &Option<Path>) -> Path {
118+
fn get_sysroot(maybe_sysroot: &Option<@Path>) -> @Path {
112119
match *maybe_sysroot {
113-
option::Some(ref sr) => (/*bad*/copy *sr),
114-
option::None => get_or_default_sysroot()
120+
option::Some(sr) => sr,
121+
option::None => @get_or_default_sysroot()
115122
}
116123
}
117124

branches/try2/src/librustc/middle/typeck/check/_match.rs

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -114,37 +114,53 @@ pub fn check_pat_variant(pcx: &pat_ctxt, pat: @ast::pat, path: @ast::Path,
114114
ty::ty_enum(_, ref expected_substs) => {
115115
// Lookup the enum and variant def ids:
116116
let v_def = lookup_def(pcx.fcx, pat.span, pat.id);
117-
let (enm, var) = ast_util::variant_def_ids(v_def);
118-
119-
// Assign the pattern the type of the *enum*, not the variant.
120-
let enum_tpt = ty::lookup_item_type(tcx, enm);
121-
instantiate_path(pcx.fcx, path, enum_tpt, pat.span, pat.id,
122-
pcx.block_region);
123-
124-
// check that the type of the value being matched is a subtype
125-
// of the type of the pattern:
126-
let pat_ty = fcx.node_ty(pat.id);
127-
demand::subtype(fcx, pat.span, expected, pat_ty);
128-
129-
// Get the expected types of the arguments.
130-
arg_types = {
131-
let vinfo =
132-
ty::enum_variant_with_id(tcx, enm, var);
133-
let var_tpt = ty::lookup_item_type(tcx, var);
134-
vinfo.args.map(|t| {
135-
if var_tpt.generics.type_param_defs.len() ==
136-
expected_substs.tps.len()
137-
{
138-
ty::subst(tcx, expected_substs, *t)
139-
}
140-
else {
141-
*t // In this case, an error was already signaled
142-
// anyway
143-
}
144-
})
145-
};
146-
147-
kind_name = "variant";
117+
match ast_util::variant_def_ids(v_def) {
118+
Some((enm, var)) => {
119+
// Assign the pattern the type of the *enum*, not the variant.
120+
let enum_tpt = ty::lookup_item_type(tcx, enm);
121+
instantiate_path(pcx.fcx, path, enum_tpt, pat.span, pat.id,
122+
pcx.block_region);
123+
124+
// check that the type of the value being matched is a subtype
125+
// of the type of the pattern:
126+
let pat_ty = fcx.node_ty(pat.id);
127+
demand::subtype(fcx, pat.span, expected, pat_ty);
128+
129+
// Get the expected types of the arguments.
130+
arg_types = {
131+
let vinfo =
132+
ty::enum_variant_with_id(tcx, enm, var);
133+
let var_tpt = ty::lookup_item_type(tcx, var);
134+
vinfo.args.map(|t| {
135+
if var_tpt.generics.type_param_defs.len() ==
136+
expected_substs.tps.len()
137+
{
138+
ty::subst(tcx, expected_substs, *t)
139+
}
140+
else {
141+
*t // In this case, an error was already signaled
142+
// anyway
143+
}
144+
})
145+
};
146+
147+
kind_name = "variant";
148+
}
149+
None => {
150+
let resolved_expected =
151+
fcx.infcx().ty_to_str(fcx.infcx().resolve_type_vars_if_possible(expected));
152+
fcx.infcx().type_error_message_str(pat.span,
153+
|actual| {
154+
fmt!("mismatched types: expected `%s` but found %s",
155+
resolved_expected, actual)},
156+
~"a structure pattern",
157+
None);
158+
fcx.write_error(pat.id);
159+
kind_name = "[error]";
160+
arg_types = (copy subpats).get_or_default(~[]).map(|_|
161+
ty::mk_err());
162+
}
163+
}
148164
}
149165
ty::ty_struct(struct_def_id, ref expected_substs) => {
150166
// Lookup the struct ctor def id

0 commit comments

Comments
 (0)