Skip to content

Commit 9243f06

Browse files
committed
Fix depending on git repos with workspaces
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.
1 parent 4fe39fd commit 9243f06

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

src/cargo/ops/cargo_read_manifest.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,15 @@ fn read_nested_packages(path: &Path,
119119
visited: &mut HashSet<PathBuf>) -> CargoResult<()> {
120120
if !visited.insert(path.to_path_buf()) { return Ok(()) }
121121

122-
let manifest = try!(find_project_manifest_exact(path, "Cargo.toml"));
122+
let manifest_path = try!(find_project_manifest_exact(path, "Cargo.toml"));
123+
124+
let (manifest, nested) = try!(read_manifest(&manifest_path, source_id, config));
125+
let manifest = match manifest {
126+
EitherManifest::Real(manifest) => manifest,
127+
EitherManifest::Virtual(..) => return Ok(()),
128+
};
129+
let pkg = Package::new(manifest, &manifest_path);
123130

124-
let (pkg, nested) = try!(read_package(&manifest, source_id, config));
125131
let pkg_id = pkg.package_id().clone();
126132
if !all_packages.contains_key(&pkg_id) {
127133
all_packages.insert(pkg_id, pkg);

tests/workspaces.rs

+34-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::io::{Read, Write};
66
use std::fs::File;
77

88
use cargotest::sleep_ms;
9-
use cargotest::support::{project, execs};
9+
use cargotest::support::{project, execs, git};
1010
use cargotest::support::registry::Package;
1111
use hamcrest::{assert_that, existing_file, existing_dir, is_not};
1212

@@ -877,3 +877,36 @@ fn rebuild_please() {
877877
assert_that(p.cargo("run").cwd(p.root().join("bin")),
878878
execs().with_status(101));
879879
}
880+
881+
#[test]
882+
fn workspace_in_git() {
883+
let git_project = git::new("dep1", |project| {
884+
project
885+
.file("Cargo.toml", r#"
886+
[workspace]
887+
members = ["foo"]
888+
"#)
889+
.file("foo/Cargo.toml", r#"
890+
[package]
891+
name = "foo"
892+
version = "0.1.0"
893+
"#)
894+
.file("foo/src/lib.rs", "")
895+
}).unwrap();
896+
let p = project("foo")
897+
.file("Cargo.toml", &format!(r#"
898+
[package]
899+
name = "lib"
900+
version = "0.1.0"
901+
902+
[dependencies.foo]
903+
git = '{}'
904+
"#, git_project.url()))
905+
.file("src/lib.rs", r#"
906+
pub fn foo() -> u32 { 0 }
907+
"#);
908+
p.build();
909+
910+
assert_that(p.cargo("build"),
911+
execs().with_status(0));
912+
}

0 commit comments

Comments
 (0)