Open
Description
Problem
When using a build script (to cause cargo to enumerate crate files) and when the crate is within a git repo that has a valid head (so it is considered a valid git repo initially) but lacks some objects and the Cargo.toml
doesn't have an include
key (so we use the git repo), cargo check
(and likely other operations that need to run build scripts) fail to build with:
Caused by:
failed to determine the most recently modified file in /Users/cody/p/cargo-alternate-git-bug/b
Caused by:
failed to determine list of files in /Users/cody/p/cargo-alternate-git-bug/b
Caused by:
object not found - no match for id (305157a396c6858705a9cb625bab219053264ee4); class=Odb (9); code=NotFound (-3)
(hashes/paths will not be the same, but the remainder of the error should be consistent).
Steps
- run this reproduction script:
#! /usr/bin/env bash
set -euf -o pipefail
cargo new a
git -C a add .
git -C a commit -am 'init'
git clone --no-local --reference a a b
sed -i.bak -e "3ibuild = \"build.rs\"" b/Cargo.toml
echo "fn main() {}" >b/build.rs
git -C b add .
git -C b commit -am 'need a valid head & a build script'
mv a a.broken
cd b
cargo check
- note this output (or similar, you will not have the same hashes):
[nix-shell:~/p/cargo-alternate-git-bug]$ ./reproduce.sh
Created binary (application) `a` package
[master (root-commit) 28ca98b] init
3 files changed, 12 insertions(+)
create mode 100644 .gitignore
create mode 100644 Cargo.toml
create mode 100644 src/main.rs
Cloning into 'b'...
[master f2c7667] need a valid head & a build script
3 files changed, 10 insertions(+)
create mode 100644 Cargo.toml.bak
create mode 100644 build.rs
error: failed to determine package fingerprint for build script for a v0.1.0 (/Users/cody/p/cargo-alternate-git-bug/b)
Caused by:
failed to determine the most recently modified file in /Users/cody/p/cargo-alternate-git-bug/b
Caused by:
failed to determine list of files in /Users/cody/p/cargo-alternate-git-bug/b
Caused by:
object not found - no match for id (305157a396c6858705a9cb625bab219053264ee4); class=Odb (9); code=NotFound (-3)
Possible Solution(s)
- Cargo could fall back to the non-git-repo file enumeration if any error occurs when trying to use the git file enumeration.
- Alternately, we could make discover_git_repo more robust (though I wonder how reasonable it is to increase it's robustness).
- Or we could modify
list_files_git
to avoid triggering this object lookup, or make the object lookup failure non-fatal inlist_files_git
Notes
This was observed when trying to build a repo that was bind mounted into a docker container, and as a result did not have access to the path in b/.git/objects/info/alternates
, resulting in this failure.
Version
cargo 1.56.0 (4ed5d137b 2021-10-04)
release: 1.56.0
commit-hash: 4ed5d137baff5eccf1bae5a7b2ae4b57efad4a7d
commit-date: 2021-10-04