@@ -16,9 +16,10 @@ use extra::getopts::groups::getopts;
1616use syntax:: ast_util:: * ;
1717use syntax:: codemap:: { dummy_sp, Spanned } ;
1818use syntax:: ext:: base:: ExtCtxt ;
19- use syntax:: { ast, attr, codemap, diagnostic, fold} ;
19+ use syntax:: { ast, attr, codemap, diagnostic, fold, visit } ;
2020use syntax:: attr:: AttrMetaMethods ;
2121use syntax:: fold:: ast_fold;
22+ use syntax:: visit:: Visitor ;
2223use rustc:: back:: link:: output_type_exe;
2324use rustc:: back:: link;
2425use rustc:: driver:: session:: { lib_crate, bin_crate} ;
@@ -28,6 +29,7 @@ use package_source::PkgSrc;
2829use workspace:: pkg_parent_workspaces;
2930use path_util:: { installed_library_in_workspace, U_RWX , rust_path, system_library, target_build_dir} ;
3031use messages:: error;
32+ use conditions:: nonexistent_package:: cond;
3133
3234pub use target:: { OutputType , Main , Lib , Bench , Test , JustOne , lib_name_of, lib_crate_filename} ;
3335use 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
493524pub fn mk_string_lit ( s : @str ) -> ast:: lit {
0 commit comments