Skip to content

Commit 91e64d0

Browse files
committed
rustpkg: Search RUST_PATH properly for dependencies, and add a test for recursive dependencies
Closes #8524
1 parent 761ae00 commit 91e64d0

File tree

4 files changed

+48
-10
lines changed

4 files changed

+48
-10
lines changed

src/librustpkg/path_util.rs

+4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ pub fn workspace_contains_package_id(pkgid: &PkgId, workspace: &Path) -> bool {
5555
pub fn workspace_contains_package_id_(pkgid: &PkgId, workspace: &Path,
5656
// Returns the directory it was actually found in
5757
workspace_to_src_dir: &fn(&Path) -> Path) -> Option<Path> {
58+
if !os::path_is_dir(workspace) {
59+
return None;
60+
}
61+
5862
let src_dir = workspace_to_src_dir(workspace);
5963

6064
let mut found = None;

src/librustpkg/rustpkg.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use rustc::metadata::filesearch::rust_path;
3333
use extra::{getopts};
3434
use syntax::{ast, diagnostic};
3535
use util::*;
36-
use messages::*;
36+
use messages::{error, warn, note};
3737
use path_util::build_pkg_id_in_workspace;
3838
use path_util::{U_RWX, in_rust_path};
3939
use path_util::{built_executable_in_workspace, built_library_in_workspace, default_workspace};

src/librustpkg/tests.rs

+22
Original file line numberDiff line numberDiff line change
@@ -1581,6 +1581,28 @@ fn pkgid_pointing_to_subdir() {
15811581
assert_executable_exists(&workspace, "testpkg");
15821582
}
15831583
1584+
fn test_recursive_deps() {
1585+
let a_id = PkgId::new("a");
1586+
let b_id = PkgId::new("b");
1587+
let c_id = PkgId::new("c");
1588+
let b_workspace = create_local_package_with_dep(&b_id, &c_id);
1589+
writeFile(&b_workspace.push("src").push("c-0.1").push("lib.rs"),
1590+
"pub fn g() {}");
1591+
let a_workspace = create_local_package(&a_id);
1592+
writeFile(&a_workspace.push("src").push("a-0.1").push("main.rs"),
1593+
"extern mod b; use b::f; fn main() { f(); }");
1594+
writeFile(&b_workspace.push("src").push("b-0.1").push("lib.rs"),
1595+
"extern mod c; use c::g; pub fn f() { g(); }");
1596+
let environment = Some(~[(~"RUST_PATH", b_workspace.to_str())]);
1597+
debug!("RUST_PATH=%s", b_workspace.to_str());
1598+
command_line_test_with_env([~"install", ~"a"],
1599+
&a_workspace,
1600+
environment);
1601+
assert_lib_exists(&a_workspace, &Path("a"), NoVersion);
1602+
assert_lib_exists(&b_workspace, &Path("b"), NoVersion);
1603+
assert_lib_exists(&b_workspace, &Path("c"), NoVersion);
1604+
}
1605+
15841606
/// Returns true if p exists and is executable
15851607
fn is_executable(p: &Path) -> bool {
15861608
use std::libc::consts::os::posix88::{S_IXUSR};

src/librustpkg/util.rs

+21-9
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ use rustc::driver::session::{lib_crate, bin_crate};
2222
use context::{in_target, StopBefore, Link, Assemble, BuildContext};
2323
use package_id::PkgId;
2424
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;
2628

2729
pub use target::{OutputType, Main, Lib, Bench, Test};
2830
use 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

Comments
 (0)