Skip to content

Commit 4e2d732

Browse files
committed
---
yaml --- r: 144437 b: refs/heads/try2 c: 87d9d37 h: refs/heads/master i: 144435: 411183c v: v3
1 parent 9985d8b commit 4e2d732

File tree

29 files changed

+124
-644
lines changed

29 files changed

+124
-644
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: 1ac7d809af161abc7fb73d76bae4fd0fb2a4826d
8+
refs/heads/try2: 87d9d37c07c96ed2fe816e9cda6e3d1e14cda2fc
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

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

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,13 @@ use std::option;
1313
use std::os;
1414
use std::hashmap::HashSet;
1515

16-
pub enum FileMatch { FileMatches, FileDoesntMatch }
17-
1816
// A module for searching for libraries
1917
// FIXME (#2658): I'm not happy how this module turned out. Should
2018
// probably just be folded into cstore.
2119

2220
/// Functions with type `pick` take a parent directory as well as
2321
/// a file found in that directory.
24-
pub type pick<'self> = &'self fn(path: &Path) -> FileMatch;
22+
pub type pick<'self, T> = &'self fn(path: &Path) -> Option<T>;
2523

2624
pub fn pick_file(file: Path, path: &Path) -> Option<Path> {
2725
if path.file_path() == file {
@@ -33,7 +31,7 @@ pub fn pick_file(file: Path, path: &Path) -> Option<Path> {
3331

3432
pub trait FileSearch {
3533
fn sysroot(&self) -> @Path;
36-
fn for_each_lib_search_path(&self, f: &fn(&Path) -> FileMatch);
34+
fn for_each_lib_search_path(&self, f: &fn(&Path) -> bool) -> bool;
3735
fn get_target_lib_path(&self) -> Path;
3836
fn get_target_lib_file_path(&self, file: &Path) -> Path;
3937
}
@@ -49,51 +47,34 @@ pub fn mk_filesearch(maybe_sysroot: &Option<@Path>,
4947
}
5048
impl FileSearch for FileSearchImpl {
5149
fn sysroot(&self) -> @Path { self.sysroot }
52-
fn for_each_lib_search_path(&self, f: &fn(&Path) -> FileMatch) {
50+
fn for_each_lib_search_path(&self, f: &fn(&Path) -> bool) -> bool {
5351
let mut visited_dirs = HashSet::new();
54-
let mut found = false;
5552

5653
debug!("filesearch: searching additional lib search paths [%?]",
5754
self.addl_lib_search_paths.len());
5855
for path in self.addl_lib_search_paths.iter() {
59-
match f(path) {
60-
FileMatches => found = true,
61-
FileDoesntMatch => ()
62-
}
56+
f(path);
6357
visited_dirs.insert(path.to_str());
6458
}
6559

6660
debug!("filesearch: searching target lib path");
6761
let tlib_path = make_target_lib_path(self.sysroot,
6862
self.target_triple);
6963
if !visited_dirs.contains(&tlib_path.to_str()) {
70-
match f(&tlib_path) {
71-
FileMatches => found = true,
72-
FileDoesntMatch => ()
64+
if !f(&tlib_path) {
65+
return false;
7366
}
7467
}
7568
visited_dirs.insert(tlib_path.to_str());
7669
// Try RUST_PATH
77-
if !found {
78-
let rustpath = rust_path();
79-
for path in rustpath.iter() {
80-
debug!("is %s in visited_dirs? %?",
81-
path.push("lib").to_str(),
82-
visited_dirs.contains(&path.push("lib").to_str()));
83-
70+
let rustpath = rust_path();
71+
for path in rustpath.iter() {
8472
if !visited_dirs.contains(&path.push("lib").to_str()) {
73+
f(&path.push("lib"));
8574
visited_dirs.insert(path.push("lib").to_str());
86-
// Don't keep searching the RUST_PATH if one match turns up --
87-
// if we did, we'd get a "multiple matching crates" error
88-
match f(&path.push("lib")) {
89-
FileMatches => {
90-
break;
91-
}
92-
FileDoesntMatch => ()
93-
}
9475
}
95-
}
9676
}
77+
true
9778
}
9879
fn get_target_lib_path(&self) -> Path {
9980
make_target_lib_path(self.sysroot, self.target_triple)
@@ -112,26 +93,28 @@ pub fn mk_filesearch(maybe_sysroot: &Option<@Path>,
11293
} as @FileSearch
11394
}
11495

115-
pub fn search(filesearch: @FileSearch, pick: pick) {
96+
pub fn search<T>(filesearch: @FileSearch, pick: pick<T>) -> Option<T> {
97+
let mut rslt = None;
11698
do filesearch.for_each_lib_search_path() |lib_search_path| {
11799
debug!("searching %s", lib_search_path.to_str());
118100
let r = os::list_dir_path(lib_search_path);
119-
let mut rslt = FileDoesntMatch;
120101
for path in r.iter() {
121102
debug!("testing %s", path.to_str());
122103
let maybe_picked = pick(path);
123104
match maybe_picked {
124-
FileMatches => {
105+
Some(_) => {
125106
debug!("picked %s", path.to_str());
126-
rslt = FileMatches;
107+
rslt = maybe_picked;
108+
break;
127109
}
128-
FileDoesntMatch => {
110+
None => {
129111
debug!("rejected %s", path.to_str());
130112
}
131113
}
132114
}
133-
rslt
115+
rslt.is_none()
134116
};
117+
return rslt;
135118
}
136119

137120
pub fn relative_target_lib_path(target_triple: &str) -> Path {

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use lib::llvm::{False, llvm, mk_object_file, mk_section_iter};
1515
use metadata::decoder;
1616
use metadata::encoder;
17-
use metadata::filesearch::{FileSearch, FileMatch, FileMatches, FileDoesntMatch};
17+
use metadata::filesearch::FileSearch;
1818
use metadata::filesearch;
1919
use syntax::codemap::span;
2020
use syntax::diagnostic::span_handler;
@@ -92,10 +92,10 @@ fn find_library_crate_aux(
9292
// want: crate_name.dir_part() + prefix + crate_name.file_part + "-"
9393
let prefix = fmt!("%s%s-", prefix, crate_name);
9494
let mut matches = ~[];
95-
filesearch::search(filesearch, |path| -> FileMatch {
95+
filesearch::search(filesearch, |path| -> Option<()> {
9696
let path_str = path.filename();
9797
match path_str {
98-
None => FileDoesntMatch,
98+
None => None,
9999
Some(path_str) =>
100100
if path_str.starts_with(prefix) && path_str.ends_with(suffix) {
101101
debug!("%s is a candidate", path.to_str());
@@ -104,20 +104,20 @@ fn find_library_crate_aux(
104104
if !crate_matches(cvec, cx.metas, cx.hash) {
105105
debug!("skipping %s, metadata doesn't match",
106106
path.to_str());
107-
FileDoesntMatch
107+
None
108108
} else {
109109
debug!("found %s with matching metadata", path.to_str());
110110
matches.push((path.to_str(), cvec));
111-
FileMatches
111+
None
112112
},
113113
_ => {
114114
debug!("could not load metadata for %s", path.to_str());
115-
FileDoesntMatch
115+
None
116116
}
117117
}
118118
}
119119
else {
120-
FileDoesntMatch
120+
None
121121
}
122122
}
123123
});

branches/try2/src/librustc/middle/trans/base.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2370,12 +2370,7 @@ pub fn create_entry_wrapper(ccx: @mut CrateContext,
23702370
decl_cdecl_fn(ccx.llmod, "amain", llfty)
23712371
} else {
23722372
let main_name = match ccx.sess.targ_cfg.os {
2373-
session::os_win32 => {
2374-
match ccx.sess.targ_cfg.arch {
2375-
X86 => ~"WinMain@16",
2376-
_ => ~"WinMain",
2377-
}
2378-
},
2373+
session::os_win32 => ~"WinMain@16",
23792374
_ => ~"main",
23802375
};
23812376
decl_cdecl_fn(ccx.llmod, main_name, llfty)

branches/try2/src/librustpkg/path_util.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ pub fn make_dir_rwx(p: &Path) -> bool { os::make_dir(p, U_RWX) }
4949
/// True if there's a directory in <workspace> with
5050
/// pkgid's short name
5151
pub fn workspace_contains_package_id(pkgid: &PkgId, workspace: &Path) -> bool {
52-
debug!("Checking in src dir of %s for %s",
53-
workspace.to_str(), pkgid.to_str());
54-
5552
let src_dir = workspace.push("src");
5653

5754
let mut found = false;
@@ -84,9 +81,6 @@ pub fn workspace_contains_package_id(pkgid: &PkgId, workspace: &Path) -> bool {
8481
}
8582
true
8683
};
87-
88-
debug!(if found { fmt!("Found %s in %s", pkgid.to_str(), workspace.to_str()) }
89-
else { fmt!("Didn't find %s in %s", pkgid.to_str(), workspace.to_str()) });
9084
found
9185
}
9286

branches/try2/src/librustpkg/rustpkg.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,6 @@ impl CtxMethods for Ctx {
250250
// argument
251251
let pkgid = PkgId::new(args[0]);
252252
let workspaces = pkg_parent_workspaces(&pkgid);
253-
debug!("package ID = %s, found it in %? workspaces",
254-
pkgid.to_str(), workspaces.len());
255253
if workspaces.is_empty() {
256254
let rp = rust_path();
257255
assert!(!rp.is_empty());

branches/try2/src/librustpkg/search.rs

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

11-
use path_util::{installed_library_in_workspace, rust_path};
12-
use version::Version;
11+
use path_util::installed_library_in_workspace;
1312

1413
/// If a library with path `p` matching pkg_id's name exists under sroot_opt,
1514
/// return Some(p). Return None if there's no such path or if sroot_opt is None.
@@ -20,18 +19,3 @@ pub fn find_library_in_search_path(sroot_opt: Option<@Path>, short_name: &str) -
2019
installed_library_in_workspace(short_name, sroot)
2120
}
2221
}
23-
24-
/// If some workspace `p` in the RUST_PATH contains a package matching short_name,
25-
/// return Some(p) (returns the first one of there are multiple matches.) Return
26-
/// None if there's no such path.
27-
/// FIXME #8711: This ignores the desired version.
28-
pub fn find_installed_library_in_rust_path(short_name: &str, _version: &Version) -> Option<Path> {
29-
let rp = rust_path();
30-
for p in rp.iter() {
31-
match installed_library_in_workspace(short_name, p) {
32-
Some(path) => return Some(path),
33-
None => ()
34-
}
35-
}
36-
None
37-
}

branches/try2/src/librustpkg/tests.rs

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ fn package_script_with_default_build() {
686686
push("testsuite").push("pass").push("src").push("fancy-lib").push("pkg.rs");
687687
debug!("package_script_with_default_build: %s", source.to_str());
688688
if !os::copy_file(&source,
689-
&dir.push("src").push("fancy-lib-0.1").push("pkg.rs")) {
689+
& dir.push("src").push("fancy-lib-0.1").push("pkg.rs")) {
690690
fail!("Couldn't copy file");
691691
}
692692
command_line_test([~"install", ~"fancy-lib"], &dir);
@@ -890,28 +890,20 @@ fn no_rebuilding_dep() {
890890
assert!(bar_date < foo_date);
891891
}
892892
893-
// n.b. The following two tests are ignored; they worked "accidentally" before,
894-
// when the behavior was "always rebuild libraries" (now it's "never rebuild
895-
// libraries if they already exist"). They can be un-ignored once #7075 is done.
896893
#[test]
897-
#[ignore(reason = "Workcache not yet implemented -- see #7075")]
898894
fn do_rebuild_dep_dates_change() {
899895
let p_id = PkgId::new("foo");
900896
let dep_id = PkgId::new("bar");
901897
let workspace = create_local_package_with_dep(&p_id, &dep_id);
902898
command_line_test([~"build", ~"foo"], &workspace);
903-
let bar_lib_name = lib_output_file_name(&workspace, "build", "bar");
904-
let bar_date = datestamp(&bar_lib_name);
905-
debug!("Datestamp on %s is %?", bar_lib_name.to_str(), bar_date);
899+
let bar_date = datestamp(&lib_output_file_name(&workspace, "build", "bar"));
906900
touch_source_file(&workspace, &dep_id);
907901
command_line_test([~"build", ~"foo"], &workspace);
908-
let new_bar_date = datestamp(&bar_lib_name);
909-
debug!("Datestamp on %s is %?", bar_lib_name.to_str(), new_bar_date);
902+
let new_bar_date = datestamp(&lib_output_file_name(&workspace, "build", "bar"));
910903
assert!(new_bar_date > bar_date);
911904
}
912905
913906
#[test]
914-
#[ignore(reason = "Workcache not yet implemented -- see #7075")]
915907
fn do_rebuild_dep_only_contents_change() {
916908
let p_id = PkgId::new("foo");
917909
let dep_id = PkgId::new("bar");
@@ -1068,23 +1060,6 @@ fn test_macro_pkg_script() {
10681060
os::EXE_SUFFIX))));
10691061
}
10701062

1071-
#[test]
1072-
fn multiple_workspaces() {
1073-
// Make a package foo; build/install in directory A
1074-
// Copy the exact same package into directory B and install it
1075-
// Set the RUST_PATH to A:B
1076-
// Make a third package that uses foo, make sure we can build/install it
1077-
let a_loc = mk_temp_workspace(&Path("foo"), &NoVersion).pop().pop();
1078-
let b_loc = mk_temp_workspace(&Path("foo"), &NoVersion).pop().pop();
1079-
debug!("Trying to install foo in %s", a_loc.to_str());
1080-
command_line_test([~"install", ~"foo"], &a_loc);
1081-
debug!("Trying to install foo in %s", b_loc.to_str());
1082-
command_line_test([~"install", ~"foo"], &b_loc);
1083-
let env = Some(~[(~"RUST_PATH", fmt!("%s:%s", a_loc.to_str(), b_loc.to_str()))]);
1084-
let c_loc = create_local_package_with_dep(&PkgId::new("bar"), &PkgId::new("foo"));
1085-
command_line_test_with_env([~"install", ~"bar"], &c_loc, env);
1086-
}
1087-
10881063
/// Returns true if p exists and is executable
10891064
fn is_executable(p: &Path) -> bool {
10901065
use std::libc::consts::os::posix88::{S_IXUSR};

branches/try2/src/librustpkg/util.rs

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ use rustc::back::link::output_type_exe;
2020
use rustc::driver::session::{lib_crate, bin_crate};
2121
use context::{Ctx, in_target};
2222
use package_id::PkgId;
23-
use search::{find_library_in_search_path, find_installed_library_in_rust_path};
23+
use search::find_library_in_search_path;
2424
use path_util::{target_library_in_workspace, U_RWX};
2525
pub use target::{OutputType, Main, Lib, Bench, Test};
26-
use version::NoVersion;
2726

2827
// It would be nice to have the list of commands in just one place -- for example,
2928
// you could update the match in rustpkg.rc but forget to update this list. I think
@@ -361,32 +360,18 @@ pub fn find_and_install_dependencies(ctxt: &Ctx,
361360
debug!("It exists: %s", installed_path.to_str());
362361
}
363362
None => {
364-
// FIXME #8711: need to parse version out of path_opt
365-
match find_installed_library_in_rust_path(lib_name, &NoVersion) {
366-
Some(installed_path) => {
367-
debug!("Found library %s, not rebuilding it",
368-
installed_path.to_str());
369-
// Once workcache is implemented, we'll actually check
370-
// whether or not the library at installed_path is fresh
371-
save(installed_path.pop());
372-
}
373-
None => {
374-
debug!("Trying to install library %s, rebuilding it",
375-
lib_name.to_str());
376-
// Try to install it
377-
let pkg_id = PkgId::new(lib_name);
378-
my_ctxt.install(&my_workspace, &pkg_id);
379-
// Also, add an additional search path
380-
debug!("let installed_path...")
381-
let installed_path = target_library_in_workspace(&pkg_id,
363+
// Try to install it
364+
let pkg_id = PkgId::new(lib_name);
365+
my_ctxt.install(&my_workspace, &pkg_id);
366+
// Also, add an additional search path
367+
debug!("let installed_path...")
368+
let installed_path = target_library_in_workspace(&pkg_id,
382369
&my_workspace).pop();
383-
debug!("Great, I installed %s, and it's in %s",
384-
lib_name, installed_path.to_str());
385-
save(installed_path);
386-
}
370+
debug!("Great, I installed %s, and it's in %s",
371+
lib_name, installed_path.to_str());
372+
save(installed_path);
387373
}
388374
}
389-
}
390375
}
391376
// Ignore `use`s
392377
_ => ()

branches/try2/src/librustpkg/version.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,11 @@ fn is_url_like(p: &Path) -> bool {
213213
pub fn split_version<'a>(s: &'a str) -> Option<(&'a str, Version)> {
214214
// Check for extra '#' characters separately
215215
if s.split_iter('#').len() > 2 {
216-
return None;
216+
None
217+
}
218+
else {
219+
split_version_general(s, '#')
217220
}
218-
split_version_general(s, '#')
219221
}
220222

221223
pub fn split_version_general<'a>(s: &'a str, sep: char) -> Option<(&'a str, Version)> {

branches/try2/src/libstd/default.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
//! The Default trait
12+
13+
/// A trait that types which have a useful default value should implement.
14+
pub trait Default {
15+
/// Return the "default value" for a type.
16+
fn default() -> Self;
17+
}

0 commit comments

Comments
 (0)