@@ -22,7 +22,9 @@ use rustc::driver::session::{lib_crate, bin_crate};
22
22
use context:: { in_target, StopBefore , Link , Assemble , BuildContext } ;
23
23
use package_id:: PkgId ;
24
24
use 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;
26
28
27
29
pub use target:: { OutputType , Main , Lib , Bench , Test } ;
28
30
use workcache_support:: { digest_file_with_date, digest_only_date} ;
@@ -243,9 +245,7 @@ pub fn compile_input(context: &BuildContext,
243
245
let mut crate = driver:: phase_1_parse_input ( sess, cfg. clone ( ) , & input) ;
244
246
crate = driver:: phase_2_configure_and_expand ( sess, cfg. clone ( ) , crate ) ;
245
247
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 ,
249
249
|p| {
250
250
debug ! ( "a dependency: %s" , p. to_str( ) ) ;
251
251
// Pass the directory containing a dependency
@@ -362,13 +362,15 @@ pub fn compile_crate(ctxt: &BuildContext,
362
362
/// Collect all `extern mod` directives in `c`, then
363
363
/// try to install their targets, failing if any target
364
364
/// 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 ,
366
367
sess : session:: Session ,
367
368
exec : & mut workcache:: Exec ,
368
- workspace : & Path ,
369
369
c : & ast:: Crate ,
370
370
save : @fn ( Path )
371
371
) {
372
+ use conditions:: nonexistent_package:: cond;
373
+
372
374
do c. each_view_item ( ) |vi: & ast:: view_item| {
373
375
debug ! ( "A view item!" ) ;
374
376
match vi. node {
@@ -379,7 +381,7 @@ pub fn find_and_install_dependencies(ctxt: &BuildContext,
379
381
None => sess. str_of ( lib_ident)
380
382
} ;
381
383
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 ( ) ) {
383
385
Some ( ref installed_path) => {
384
386
debug ! ( "It exists: %s" , installed_path. to_str( ) ) ;
385
387
// Say that [path for c] has a discovered dependency on
@@ -397,8 +399,18 @@ pub fn find_and_install_dependencies(ctxt: &BuildContext,
397
399
lib_name. to_str( ) ) ;
398
400
// Try to install it
399
401
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
+ } ;
400
412
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) ) ;
402
414
debug ! ( "Installed %s, returned %? dependencies and \
403
415
%? transitive dependencies",
404
416
lib_name, outputs_disc. len( ) , inputs_disc. len( ) ) ;
@@ -423,7 +435,7 @@ pub fn find_and_install_dependencies(ctxt: &BuildContext,
423
435
// Also, add an additional search path
424
436
debug ! ( "Adding additional search path: %s" , lib_name) ;
425
437
let installed_library =
426
- installed_library_in_workspace ( & Path ( lib_name) , workspace )
438
+ installed_library_in_workspace ( & Path ( lib_name) , & dep_workspace )
427
439
. expect ( fmt ! ( "rustpkg failed to install dependency %s" ,
428
440
lib_name) ) ;
429
441
let install_dir = installed_library. pop ( ) ;
0 commit comments