Skip to content

Commit

Permalink
windows
Browse files Browse the repository at this point in the history
  • Loading branch information
weihanglo committed Jun 20, 2024
1 parent 67de46e commit 3c7d764
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/cargo/core/source_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -787,15 +787,23 @@ mod tests {
// changing and why the old value can't be easily preserved.
//
// The hash value should be stable across platforms, and doesn't depend on
// endianness and bit-width.
// endianness and bit-width. One caveat is that absolute paths is inherently
// different on Windows than on Unix-like platforms. Unless we omit or strip
// the prefix components (e.g. `C:`), there is not way to have a
// cross-platform stable hash for absolute paths.
#[test]
fn test_stable_hash() {
use crate::util::StableHasher;
use std::path::Path;

#[cfg(not(windows))]
let ws_root = Path::new("/tmp/ws");
#[cfg(windows)]
let ws_root = Path::new(r"C:\tmp\ws");

let gen_hash = |source_id: SourceId| {
let mut hasher = StableHasher::new();
source_id.stable_hash(Path::new("/tmp/ws"), &mut hasher);
source_id.stable_hash(ws_root, &mut hasher);
hasher.finish()
};

Expand Down Expand Up @@ -828,8 +836,7 @@ mod tests {
assert_eq!(gen_hash(source_id), 3109465066469481245);
assert_eq!(crate::util::hex::short_hash(&source_id), "1d5b66d8000a272b");

let path = Path::new("/tmp/ws/crate");

let path = &ws_root.join("crate");
let source_id = SourceId::for_local_registry(path).unwrap();
assert_eq!(gen_hash(source_id), 17171351456028149232);
assert_eq!(crate::util::hex::short_hash(&source_id), "f0c5f1e92be54cee");
Expand Down

0 comments on commit 3c7d764

Please sign in to comment.