Skip to content

Commit a2cddee

Browse files
committed
Ignore broken Cargo.toml in git sources
Commit 3d6de41 (#3998) made cargo ignore Cargo.toml files that are invalid TOML in a git source. This change further ignores Cargo.toml files that are valid TOML but cannot really be loaded. This is potentially an alternative fix for #6822.
1 parent 62180bf commit a2cddee

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/cargo/ops/cargo_read_manifest.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,26 @@ fn read_nested_packages(
193193
if !source_id.is_registry() {
194194
for p in nested.iter() {
195195
let path = util::normalize_path(&path.join(p));
196-
read_nested_packages(&path, all_packages, source_id, config, visited, errors)?;
196+
let result =
197+
read_nested_packages(&path, all_packages, source_id, config, visited, errors);
198+
// Ignore broken manifests found on git repositories.
199+
//
200+
// A well formed manifest might still fail to load due to reasons
201+
// like referring to a "path" that requires an extra build step.
202+
//
203+
// See https://github.com/rust-lang/cargo/issues/6822.
204+
if let Err(err) = result {
205+
if source_id.is_git() {
206+
info!(
207+
"skipping nested package found at `{}`: {:?}",
208+
path.display(),
209+
&err,
210+
);
211+
errors.push(err);
212+
} else {
213+
return Err(err);
214+
}
215+
}
197216
}
198217
}
199218

tests/testsuite/git.rs

+10
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,16 @@ fn cargo_compile_with_malformed_nested_paths() {
323323
"#,
324324
)
325325
.file("vendor/dep2/Cargo.toml", "!INVALID!")
326+
.file(
327+
"vendor/dep3/Cargo.toml",
328+
r#"
329+
[project]
330+
name = "dep3"
331+
version = "0.5.0"
332+
[dependencies]
333+
subdep1 = { path = "../require-extra-build-step" }"#,
334+
)
335+
.file("vendor/dep3/src/lib.rs", "")
326336
});
327337

328338
let p = project()

0 commit comments

Comments
 (0)