Skip to content

Commit

Permalink
Fix depending on git repos with workspaces
Browse files Browse the repository at this point in the history
When we're recursively walking over a git repository we can safely ignore any
workspace Cargo.toml files we find instead of generating an error.
  • Loading branch information
alexcrichton committed Aug 1, 2016
1 parent 4fe39fd commit 9243f06
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/cargo/ops/cargo_read_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,15 @@ fn read_nested_packages(path: &Path,
visited: &mut HashSet<PathBuf>) -> CargoResult<()> {
if !visited.insert(path.to_path_buf()) { return Ok(()) }

let manifest = try!(find_project_manifest_exact(path, "Cargo.toml"));
let manifest_path = try!(find_project_manifest_exact(path, "Cargo.toml"));

let (manifest, nested) = try!(read_manifest(&manifest_path, source_id, config));
let manifest = match manifest {
EitherManifest::Real(manifest) => manifest,
EitherManifest::Virtual(..) => return Ok(()),
};
let pkg = Package::new(manifest, &manifest_path);

let (pkg, nested) = try!(read_package(&manifest, source_id, config));
let pkg_id = pkg.package_id().clone();
if !all_packages.contains_key(&pkg_id) {
all_packages.insert(pkg_id, pkg);
Expand Down
35 changes: 34 additions & 1 deletion tests/workspaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::io::{Read, Write};
use std::fs::File;

use cargotest::sleep_ms;
use cargotest::support::{project, execs};
use cargotest::support::{project, execs, git};
use cargotest::support::registry::Package;
use hamcrest::{assert_that, existing_file, existing_dir, is_not};

Expand Down Expand Up @@ -877,3 +877,36 @@ fn rebuild_please() {
assert_that(p.cargo("run").cwd(p.root().join("bin")),
execs().with_status(101));
}

#[test]
fn workspace_in_git() {
let git_project = git::new("dep1", |project| {
project
.file("Cargo.toml", r#"
[workspace]
members = ["foo"]
"#)
.file("foo/Cargo.toml", r#"
[package]
name = "foo"
version = "0.1.0"
"#)
.file("foo/src/lib.rs", "")
}).unwrap();
let p = project("foo")
.file("Cargo.toml", &format!(r#"
[package]
name = "lib"
version = "0.1.0"
[dependencies.foo]
git = '{}'
"#, git_project.url()))
.file("src/lib.rs", r#"
pub fn foo() -> u32 { 0 }
"#);
p.build();

assert_that(p.cargo("build"),
execs().with_status(0));
}

0 comments on commit 9243f06

Please sign in to comment.