@@ -22,7 +22,9 @@ use rustc::driver::session::{lib_crate, bin_crate};
2222use context:: { in_target, StopBefore , Link , Assemble , BuildContext } ;
2323use package_id:: PkgId ;
2424use package_source:: PkgSrc ;
25- use path_util:: { installed_library_in_workspace, U_RWX } ;
25+ use workspace:: pkg_parent_workspaces;
26+ use path_util:: { installed_library_in_workspace, U_RWX , rust_path} ;
27+ use messages:: error;
2628
2729pub use target:: { OutputType , Main , Lib , Bench , Test } ;
2830use workcache_support:: { digest_file_with_date, digest_only_date} ;
@@ -243,9 +245,7 @@ pub fn compile_input(context: &BuildContext,
243245 let mut crate = driver:: phase_1_parse_input ( sess, cfg. clone ( ) , & input) ;
244246 crate = driver:: phase_2_configure_and_expand ( sess, cfg. clone ( ) , crate ) ;
245247
246- // Not really right. Should search other workspaces too, and the installed
247- // database (which doesn't exist yet)
248- find_and_install_dependencies ( context, sess, exec, workspace, crate ,
248+ find_and_install_dependencies ( context, pkg_id, sess, exec, crate ,
249249 |p| {
250250 debug ! ( "a dependency: %s" , p. to_str( ) ) ;
251251 // Pass the directory containing a dependency
@@ -362,13 +362,15 @@ pub fn compile_crate(ctxt: &BuildContext,
362362/// Collect all `extern mod` directives in `c`, then
363363/// try to install their targets, failing if any target
364364/// can't be found.
365- pub fn find_and_install_dependencies ( ctxt : & BuildContext ,
365+ pub fn find_and_install_dependencies ( context : & BuildContext ,
366+ parent : & PkgId ,
366367 sess : session:: Session ,
367368 exec : & mut workcache:: Exec ,
368- workspace : & Path ,
369369 c : & ast:: Crate ,
370370 save : @fn ( Path )
371371 ) {
372+ use conditions:: nonexistent_package:: cond;
373+
372374 do c. each_view_item ( ) |vi: & ast:: view_item| {
373375 debug ! ( "A view item!" ) ;
374376 match vi. node {
@@ -379,7 +381,7 @@ pub fn find_and_install_dependencies(ctxt: &BuildContext,
379381 None => sess. str_of ( lib_ident)
380382 } ;
381383 debug ! ( "Finding and installing... %s" , lib_name) ;
382- match installed_library_in_workspace ( & Path ( lib_name) , & ctxt . sysroot ( ) ) {
384+ match installed_library_in_workspace ( & Path ( lib_name) , & context . sysroot ( ) ) {
383385 Some ( ref installed_path) => {
384386 debug ! ( "It exists: %s" , installed_path. to_str( ) ) ;
385387 // Say that [path for c] has a discovered dependency on
@@ -397,8 +399,18 @@ pub fn find_and_install_dependencies(ctxt: &BuildContext,
397399 lib_name. to_str( ) ) ;
398400 // Try to install it
399401 let pkg_id = PkgId :: new ( lib_name) ;
402+ let workspaces = pkg_parent_workspaces ( & context. context , & pkg_id) ;
403+ let dep_workspace = if workspaces. is_empty ( ) {
404+ error ( fmt ! ( "Couldn't find package %s, which is needed by %s, \
405+ in any of the workspaces in the RUST_PATH (%?)",
406+ lib_name, parent. to_str( ) , rust_path( ) ) ) ;
407+ cond. raise ( ( pkg_id. clone ( ) , ~"Dependency not found") )
408+ }
409+ else {
410+ workspaces[ 0 ]
411+ } ;
400412 let ( outputs_disc, inputs_disc) =
401- ctxt . install ( PkgSrc :: new ( workspace . clone ( ) , false , pkg_id) ) ;
413+ context . install ( PkgSrc :: new ( dep_workspace . clone ( ) , false , pkg_id) ) ;
402414 debug ! ( "Installed %s, returned %? dependencies and \
403415 %? transitive dependencies",
404416 lib_name, outputs_disc. len( ) , inputs_disc. len( ) ) ;
@@ -423,7 +435,7 @@ pub fn find_and_install_dependencies(ctxt: &BuildContext,
423435 // Also, add an additional search path
424436 debug ! ( "Adding additional search path: %s" , lib_name) ;
425437 let installed_library =
426- installed_library_in_workspace ( & Path ( lib_name) , workspace )
438+ installed_library_in_workspace ( & Path ( lib_name) , & dep_workspace )
427439 . expect ( fmt ! ( "rustpkg failed to install dependency %s" ,
428440 lib_name) ) ;
429441 let install_dir = installed_library. pop ( ) ;
0 commit comments