Skip to content

Commit cd6e9f4

Browse files
committed
auto merge of #10110 : catamorphism/rust/rustpkg-dependency-build-dir, r=metajack
r? @metajack 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.
2 parents 2ab4a6f + 0e6a575 commit cd6e9f4

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
@@ -587,8 +587,6 @@ impl CtxMethods for BuildContext {
587587
build_inputs,
588588
&pkg_src.destination_workspace,
589589
&id).map(|s| Path::new(s.as_slice()));
590-
debug!("install: id = {}, about to call discover_outputs, {:?}",
591-
id.to_str(), result.map(|p| p.display().to_str()));
592590
installed_files = installed_files + result;
593591
note(format!("Installed package {} to {}",
594592
id.to_str(),

src/librustpkg/tests.rs

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

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

src/librustpkg/util.rs

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

0 commit comments

Comments
 (0)