Skip to content

Commit 37f0dcd

Browse files
committed
---
yaml --- r: 145386 b: refs/heads/try2 c: 6a8169d h: refs/heads/master v: v3
1 parent 245c7cf commit 37f0dcd

File tree

3 files changed

+62
-38
lines changed

3 files changed

+62
-38
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: d126be068b0daab3b5abd9b1f365a4c98f2121b7
8+
refs/heads/try2: 6a8169db0a201b9fc2fbf581f507e143f0482aae
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/librustpkg/util.rs

Lines changed: 61 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ use extra::getopts::groups::getopts;
1616
use syntax::ast_util::*;
1717
use syntax::codemap::{dummy_sp, Spanned};
1818
use syntax::ext::base::ExtCtxt;
19-
use syntax::{ast, attr, codemap, diagnostic, fold};
19+
use syntax::{ast, attr, codemap, diagnostic, fold, visit};
2020
use syntax::attr::AttrMetaMethods;
2121
use syntax::fold::ast_fold;
22+
use syntax::visit::Visitor;
2223
use rustc::back::link::output_type_exe;
2324
use rustc::back::link;
2425
use rustc::driver::session::{lib_crate, bin_crate};
@@ -28,6 +29,7 @@ use package_source::PkgSrc;
2829
use workspace::pkg_parent_workspaces;
2930
use path_util::{installed_library_in_workspace, U_RWX, rust_path, system_library, target_build_dir};
3031
use messages::error;
32+
use conditions::nonexistent_package::cond;
3133

3234
pub use target::{OutputType, Main, Lib, Bench, Test, JustOne, lib_name_of, lib_crate_filename};
3335
use workcache_support::{digest_file_with_date, digest_only_date};
@@ -395,31 +397,28 @@ pub fn compile_crate(ctxt: &BuildContext,
395397
compile_input(ctxt, exec, pkg_id, crate, workspace, flags, cfgs, opt, what)
396398
}
397399

400+
struct ViewItemVisitor<'self> {
401+
context: &'self BuildContext,
402+
parent: &'self PkgId,
403+
sess: session::Session,
404+
exec: &'self mut workcache::Exec,
405+
c: &'self ast::Crate,
406+
save: @fn(Path),
407+
}
398408

399-
/// Collect all `extern mod` directives in `c`, then
400-
/// try to install their targets, failing if any target
401-
/// can't be found.
402-
pub fn find_and_install_dependencies(context: &BuildContext,
403-
parent: &PkgId,
404-
sess: session::Session,
405-
exec: &mut workcache::Exec,
406-
c: &ast::Crate,
407-
save: @fn(Path)
408-
) {
409-
use conditions::nonexistent_package::cond;
410-
411-
do c.each_view_item() |vi: &ast::view_item| {
409+
impl<'self> Visitor<()> for ViewItemVisitor<'self> {
410+
fn visit_view_item(&mut self, vi: &ast::view_item, env: ()) {
412411
debug!("A view item!");
413412
match vi.node {
414413
// ignore metadata, I guess
415414
ast::view_item_extern_mod(lib_ident, path_opt, _, _) => {
416415
let lib_name = match path_opt {
417416
Some(p) => p,
418-
None => sess.str_of(lib_ident)
417+
None => self.sess.str_of(lib_ident)
419418
};
420419
debug!("Finding and installing... %s", lib_name);
421420
// Check standard Rust library path first
422-
match system_library(&context.sysroot(), lib_name) {
421+
match system_library(&self.context.sysroot(), lib_name) {
423422
Some(ref installed_path) => {
424423
debug!("It exists: %s", installed_path.to_str());
425424
// Say that [path for c] has a discovered dependency on
@@ -428,44 +427,54 @@ pub fn find_and_install_dependencies(context: &BuildContext,
428427
// I'm not sure what the right thing is.
429428
// Now we know that this crate has a discovered dependency on
430429
// installed_path
431-
exec.discover_input("binary", installed_path.to_str(),
432-
digest_only_date(installed_path));
430+
self.exec.discover_input("binary",
431+
installed_path.to_str(),
432+
digest_only_date(installed_path));
433433
}
434434
None => {
435435
// FIXME #8711: need to parse version out of path_opt
436436
debug!("Trying to install library %s, rebuilding it",
437437
lib_name.to_str());
438438
// Try to install it
439439
let pkg_id = PkgId::new(lib_name);
440-
let workspaces = pkg_parent_workspaces(&context.context, &pkg_id);
440+
let workspaces = pkg_parent_workspaces(&self.context.context,
441+
&pkg_id);
441442
let dep_workspace = if workspaces.is_empty() {
442443
error(fmt!("Couldn't find package %s, which is needed by %s, \
443444
in any of the workspaces in the RUST_PATH (%?)",
444-
lib_name, parent.to_str(), rust_path()));
445+
lib_name,
446+
self.parent.to_str(),
447+
rust_path()));
445448
cond.raise((pkg_id.clone(), ~"Dependency not found"))
446449
}
447450
else {
448451
workspaces[0]
449452
};
450453
let (outputs_disc, inputs_disc) =
451-
context.install(PkgSrc::new(dep_workspace.clone(),
452-
false, pkg_id), &JustOne(Path(lib_crate_filename)));
454+
self.context.install(PkgSrc::new(dep_workspace.clone(),
455+
false,
456+
pkg_id),
457+
&JustOne(Path(
458+
lib_crate_filename)));
453459
debug!("Installed %s, returned %? dependencies and \
454460
%? transitive dependencies",
455461
lib_name, outputs_disc.len(), inputs_disc.len());
456462
for dep in outputs_disc.iter() {
457463
debug!("Discovering a binary input: %s", dep.to_str());
458-
exec.discover_input("binary", dep.to_str(),
459-
digest_only_date(dep));
464+
self.exec.discover_input("binary",
465+
dep.to_str(),
466+
digest_only_date(dep));
460467
}
461468
for &(ref what, ref dep) in inputs_disc.iter() {
462469
if *what == ~"file" {
463-
exec.discover_input(*what, *dep,
464-
digest_file_with_date(&Path(*dep)));
470+
self.exec.discover_input(*what,
471+
*dep,
472+
digest_file_with_date(&Path(*dep)));
465473
}
466474
else if *what == ~"binary" {
467-
exec.discover_input(*what, *dep,
468-
digest_only_date(&Path(*dep)));
475+
self.exec.discover_input(*what,
476+
*dep,
477+
digest_only_date(&Path(*dep)));
469478
}
470479
else {
471480
fail!("Bad kind: %s", *what);
@@ -480,14 +489,36 @@ pub fn find_and_install_dependencies(context: &BuildContext,
480489
let install_dir = installed_library.pop();
481490
debug!("Installed %s into %s [%?]", lib_name, install_dir.to_str(),
482491
datestamp(&installed_library));
483-
save(install_dir);
492+
(self.save)(install_dir);
484493
}
485494
}}
486495
// Ignore `use`s
487496
_ => ()
488497
}
489-
true
498+
499+
visit::walk_view_item(self, vi, env)
500+
}
501+
}
502+
503+
/// Collect all `extern mod` directives in `c`, then
504+
/// try to install their targets, failing if any target
505+
/// can't be found.
506+
pub fn find_and_install_dependencies(context: &BuildContext,
507+
parent: &PkgId,
508+
sess: session::Session,
509+
exec: &mut workcache::Exec,
510+
c: &ast::Crate,
511+
save: @fn(Path)) {
512+
debug!("In find_and_install_dependencies...");
513+
let mut visitor = ViewItemVisitor {
514+
context: context,
515+
parent: parent,
516+
sess: sess,
517+
exec: exec,
518+
c: c,
519+
save: save,
490520
};
521+
visit::walk_crate(&mut visitor, c, ())
491522
}
492523

493524
pub fn mk_string_lit(s: @str) -> ast::lit {

branches/try2/src/libsyntax/diagnostic.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,6 @@ fn print_diagnostic(topic: &str, lvl: level, msg: &str) {
236236
print_maybe_styled(fmt!("%s\n", msg), term::attr::Bold);
237237
}
238238

239-
pub fn collect(messages: @mut ~[~str])
240-
-> @fn(Option<(@codemap::CodeMap, Span)>, &str, level) {
241-
let f: @fn(Option<(@codemap::CodeMap, Span)>, &str, level) =
242-
|_o, msg: &str, _l| { messages.push(msg.to_str()); };
243-
f
244-
}
245-
246239
pub struct DefaultEmitter;
247240

248241
impl Emitter for DefaultEmitter {

0 commit comments

Comments
 (0)