Skip to content

Commit 5d04264

Browse files
committed
prepare: detect missing git deps even when a lockfile is present
1 parent e87c50e commit 5d04264

File tree

5 files changed

+33
-4
lines changed

5 files changed

+33
-4
lines changed

src/prepare.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ impl<'a> Prepare<'a> {
134134

135135
fn fetch_deps(&mut self) -> Result<(), Error> {
136136
let mut outdated_lockfile = false;
137+
let mut missing_deps = false;
137138
let res = Command::new(self.workspace, self.toolchain.cargo())
138139
.args(&["fetch", "--locked", "--manifest-path", "Cargo.toml"])
139140
.cd(&self.source_dir)
@@ -142,21 +143,23 @@ impl<'a> Prepare<'a> {
142143
"Cargo.lock needs to be updated but --locked was passed to prevent this",
143144
) {
144145
outdated_lockfile = true;
146+
} else if line.contains("failed to load source for dependency") {
147+
missing_deps = true;
145148
}
146149
})
147150
.run();
148151
match res {
149-
Ok(_) => {}
152+
Ok(_) => Ok(()),
150153
Err(_) if outdated_lockfile && !self.lockfile_captured => {
151154
info!("the lockfile is outdated, regenerating it");
152155
// Force-update the lockfile and recursively call this function to fetch
153156
// dependencies again.
154157
self.capture_lockfile(true)?;
155-
return self.fetch_deps();
158+
self.fetch_deps()
156159
}
157-
err => return err.map_err(|e| e.into()),
160+
Err(_) if missing_deps => Err(PrepareError::MissingDependencies.into()),
161+
err => err.map_err(|e| e.into()),
158162
}
159-
Ok(())
160163
}
161164
}
162165

tests/buildtest/crates/missing-deps-git-locked/Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "missing-deps-git-locked"
3+
version = "0.1.0"
4+
authors = ["Pietro Albini <pietro@pietroalbini.org>"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]
10+
not-a-git-repo = { git = "https://www.example.com/definitely-not-a-git-repo.git" }
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("Hello, world!");
3+
}

tests/buildtest/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ test_prepare_error!(
138138
MissingDependencies
139139
);
140140

141+
test_prepare_error!(
142+
test_missing_deps_git_locked,
143+
"missing-deps-git-locked",
144+
MissingDependencies
145+
);
146+
141147
test_prepare_error!(
142148
test_missing_deps_registry,
143149
"missing-deps-registry",

0 commit comments

Comments
 (0)