@@ -16,9 +16,10 @@ use extra::getopts::groups::getopts;
16
16
use syntax:: ast_util:: * ;
17
17
use syntax:: codemap:: { dummy_sp, Spanned } ;
18
18
use syntax:: ext:: base:: ExtCtxt ;
19
- use syntax:: { ast, attr, codemap, diagnostic, fold} ;
19
+ use syntax:: { ast, attr, codemap, diagnostic, fold, visit } ;
20
20
use syntax:: attr:: AttrMetaMethods ;
21
21
use syntax:: fold:: ast_fold;
22
+ use syntax:: visit:: Visitor ;
22
23
use rustc:: back:: link:: output_type_exe;
23
24
use rustc:: back:: link;
24
25
use rustc:: driver:: session:: { lib_crate, bin_crate} ;
@@ -28,6 +29,7 @@ use package_source::PkgSrc;
28
29
use workspace:: pkg_parent_workspaces;
29
30
use path_util:: { installed_library_in_workspace, U_RWX , rust_path, system_library, target_build_dir} ;
30
31
use messages:: error;
32
+ use conditions:: nonexistent_package:: cond;
31
33
32
34
pub use target:: { OutputType , Main , Lib , Bench , Test , JustOne , lib_name_of, lib_crate_filename} ;
33
35
use workcache_support:: { digest_file_with_date, digest_only_date} ;
@@ -395,31 +397,28 @@ pub fn compile_crate(ctxt: &BuildContext,
395
397
compile_input ( ctxt, exec, pkg_id, crate , workspace, flags, cfgs, opt, what)
396
398
}
397
399
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
+ }
398
408
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 : ( ) ) {
412
411
debug ! ( "A view item!" ) ;
413
412
match vi. node {
414
413
// ignore metadata, I guess
415
414
ast:: view_item_extern_mod( lib_ident, path_opt, _, _) => {
416
415
let lib_name = match path_opt {
417
416
Some ( p) => p,
418
- None => sess. str_of ( lib_ident)
417
+ None => self . sess . str_of ( lib_ident)
419
418
} ;
420
419
debug ! ( "Finding and installing... %s" , lib_name) ;
421
420
// Check standard Rust library path first
422
- match system_library ( & context. sysroot ( ) , lib_name) {
421
+ match system_library ( & self . context . sysroot ( ) , lib_name) {
423
422
Some ( ref installed_path) => {
424
423
debug ! ( "It exists: %s" , installed_path. to_str( ) ) ;
425
424
// Say that [path for c] has a discovered dependency on
@@ -428,44 +427,54 @@ pub fn find_and_install_dependencies(context: &BuildContext,
428
427
// I'm not sure what the right thing is.
429
428
// Now we know that this crate has a discovered dependency on
430
429
// 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) ) ;
433
433
}
434
434
None => {
435
435
// FIXME #8711: need to parse version out of path_opt
436
436
debug ! ( "Trying to install library %s, rebuilding it" ,
437
437
lib_name. to_str( ) ) ;
438
438
// Try to install it
439
439
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) ;
441
442
let dep_workspace = if workspaces. is_empty ( ) {
442
443
error ( fmt ! ( "Couldn't find package %s, which is needed by %s, \
443
444
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( ) ) ) ;
445
448
cond. raise ( ( pkg_id. clone ( ) , ~"Dependency not found") )
446
449
}
447
450
else {
448
451
workspaces[ 0 ]
449
452
} ;
450
453
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) ) ) ;
453
459
debug ! ( "Installed %s, returned %? dependencies and \
454
460
%? transitive dependencies",
455
461
lib_name, outputs_disc. len( ) , inputs_disc. len( ) ) ;
456
462
for dep in outputs_disc. iter ( ) {
457
463
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) ) ;
460
467
}
461
468
for & ( ref what, ref dep) in inputs_disc. iter ( ) {
462
469
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) ) ) ;
465
473
}
466
474
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) ) ) ;
469
478
}
470
479
else {
471
480
fail ! ( "Bad kind: %s" , * what) ;
@@ -480,14 +489,36 @@ pub fn find_and_install_dependencies(context: &BuildContext,
480
489
let install_dir = installed_library. pop ( ) ;
481
490
debug ! ( "Installed %s into %s [%?]" , lib_name, install_dir. to_str( ) ,
482
491
datestamp( & installed_library) ) ;
483
- save ( install_dir) ;
492
+ ( self . save ) ( install_dir) ;
484
493
}
485
494
} }
486
495
// Ignore `use`s
487
496
_ => ( )
488
497
}
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,
490
520
} ;
521
+ visit:: walk_crate ( & mut visitor, c, ( ) )
491
522
}
492
523
493
524
pub fn mk_string_lit ( s : @str ) -> ast:: lit {
0 commit comments