Skip to content

Commit 0e6a575

Browse files
committed
rustpkg: Build dependencies into the correct workspace when using --rust-path-hack
When invoked with the --rust-path-hack flag, rustpkg was correctly building the package into the default workspace (and not into the build/ subdirectory of the parent directory of the source directory), but not correctly putting the output for any dependencies into the default workspace as well. Spotted by Jack.
1 parent 16b8a41 commit 0e6a575

File tree

4 files changed

+45
-12
lines changed

4 files changed

+45
-12
lines changed

src/librustpkg/package_source.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,8 @@ impl PkgSrc {
422422
fail!("Bad kind in build_crates")
423423
});
424424
}
425+
debug!("Compiling crate {}; its output will be in {}",
426+
subpath.display(), sub_dir.display());
425427
let result = compile_crate(&subcx,
426428
exec,
427429
&id,
@@ -473,8 +475,8 @@ impl PkgSrc {
473475
let tests = self.tests.clone();
474476
let benchs = self.benchs.clone();
475477
debug!("Building libs in {}, destination = {}",
476-
self.destination_workspace.display(),
477-
self.destination_workspace.display());
478+
self.source_workspace.display(),
479+
self.build_workspace().display());
478480
self.build_crates(build_context,
479481
&mut deps,
480482
libs,

src/librustpkg/rustpkg.rs

-2
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,6 @@ impl CtxMethods for BuildContext {
585585
build_inputs,
586586
&pkg_src.destination_workspace,
587587
&id).map(|s| Path::new(s.as_slice()));
588-
debug!("install: id = {}, about to call discover_outputs, {:?}",
589-
id.to_str(), result.map(|p| p.display().to_str()));
590588
installed_files = installed_files + result;
591589
note(format!("Installed package {} to {}",
592590
id.to_str(),

src/librustpkg/tests.rs

+24
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,30 @@ fn rust_path_hack_build_no_arg() {
15121512
assert!(!built_library_exists(&source_dir, "foo"));
15131513
}
15141514

1515+
#[test]
1516+
fn rust_path_hack_build_with_dependency() {
1517+
let foo_id = PkgId::new("foo");
1518+
let dep_id = PkgId::new("dep");
1519+
// Tests that when --rust-path-hack is in effect, dependencies get built
1520+
// into the destination workspace and not the source directory
1521+
let work_dir = create_local_package(&foo_id);
1522+
let work_dir = work_dir.path();
1523+
let dep_workspace = create_local_package(&dep_id);
1524+
let dep_workspace = dep_workspace.path();
1525+
let dest_workspace = mk_emptier_workspace("dep");
1526+
let dest_workspace = dest_workspace.path();
1527+
let source_dir = work_dir.join_many(["src", "foo-0.1"]);
1528+
writeFile(&source_dir.join("lib.rs"), "extern mod dep; pub fn f() { }");
1529+
let dep_dir = dep_workspace.join_many(["src", "dep-0.1"]);
1530+
let rust_path = Some(~[(~"RUST_PATH",
1531+
format!("{}:{}",
1532+
dest_workspace.display(),
1533+
dep_dir.display()))]);
1534+
command_line_test_with_env([~"build", ~"--rust-path-hack", ~"foo"], work_dir, rust_path);
1535+
assert_built_library_exists(dest_workspace, "dep");
1536+
assert!(!built_library_exists(dep_workspace, "dep"));
1537+
}
1538+
15151539
#[test]
15161540
fn rust_path_install_target() {
15171541
let dir_for_path = TempDir::new(

src/librustpkg/util.rs

+17-8
Original file line numberDiff line numberDiff line change
@@ -469,22 +469,31 @@ impl<'self> Visitor<()> for ViewItemVisitor<'self> {
469469
// Find all the workspaces in the RUST_PATH that contain this package.
470470
let workspaces = pkg_parent_workspaces(&self.context.context,
471471
&pkg_id);
472-
// Two cases:
472+
// Three cases:
473473
// (a) `workspaces` is empty. That means there's no local source
474474
// for this package. In that case, we pass the default workspace
475475
// into `PkgSrc::new`, so that if it exists as a remote repository,
476-
// its sources will be fetched into it.
477-
// (b) `workspaces` is non-empty -- we found a local source for this
478-
// package.
479-
let dest_workspace = if workspaces.is_empty() {
480-
default_workspace()
481-
} else { workspaces[0] };
476+
// its sources will be fetched into it. We also put the output in the
477+
// same workspace.
478+
// (b) We're using the Rust path hack. In that case, the output goes
479+
// in the destination workspace.
480+
// (c) `workspaces` is non-empty -- we found a local source for this
481+
// package and will build in that workspace.
482+
let (source_workspace, dest_workspace) = if workspaces.is_empty() {
483+
(default_workspace(), default_workspace())
484+
} else {
485+
if self.context.context.use_rust_path_hack {
486+
(workspaces[0], default_workspace())
487+
} else {
488+
(workspaces[0].clone(), workspaces[0])
489+
}
490+
};
482491
// In this case, the source and destination workspaces are the same:
483492
// Either it's a remote package, so the local sources don't exist
484493
// and the `PkgSrc` constructor will detect that;
485494
// or else it's already in a workspace and we'll build into that
486495
// workspace
487-
let pkg_src = PkgSrc::new(dest_workspace.clone(),
496+
let pkg_src = PkgSrc::new(source_workspace,
488497
dest_workspace,
489498
// Use the rust_path_hack to search for dependencies iff
490499
// we were already using it

0 commit comments

Comments
 (0)