|
7 | 7 | use std::collections::HashMap;
|
8 | 8 | use std::ffi::OsStr;
|
9 | 9 | use std::fmt::{Debug, Formatter};
|
10 |
| -use std::hash::{Hash, Hasher}; |
| 10 | +use std::hash::{DefaultHasher, Hash, Hasher}; |
11 | 11 | use std::path::Path;
|
12 | 12 | use std::process::{Command, CommandArgs, CommandEnvs, ExitStatus, Output, Stdio};
|
13 | 13 | use std::sync::Mutex;
|
@@ -55,14 +55,6 @@ impl OutputMode {
|
55 | 55 | }
|
56 | 56 | }
|
57 | 57 |
|
58 |
| -#[derive(Clone, Debug, PartialEq, Eq, Hash, Default)] |
59 |
| -pub struct CommandCacheKey { |
60 |
| - program: String, |
61 |
| - args: Vec<String>, |
62 |
| - envs: Vec<(String, String)>, |
63 |
| - cwd: Option<PathBuf>, |
64 |
| -} |
65 |
| - |
66 | 58 | /// Wrapper around `std::process::Command`.
|
67 | 59 | ///
|
68 | 60 | /// By default, the command will exit bootstrap if it fails.
|
@@ -234,13 +226,13 @@ impl<'a> BootstrapCommand {
|
234 | 226 | }
|
235 | 227 | }
|
236 | 228 |
|
237 |
| - pub fn cache_key(&self) -> CommandCacheKey { |
238 |
| - CommandCacheKey { |
239 |
| - program: self.program.clone(), |
240 |
| - args: self.args.clone(), |
241 |
| - envs: self.envs.clone(), |
242 |
| - cwd: self.cwd.clone(), |
243 |
| - } |
| 229 | + pub fn compute_cache_hash(&self) -> u64 { |
| 230 | + let mut hasher = DefaultHasher::new(); |
| 231 | + self.program.hash(&mut hasher); |
| 232 | + self.args.hash(&mut hasher); |
| 233 | + self.envs.hash(&mut hasher); |
| 234 | + self.cwd.hash(&mut hasher); |
| 235 | + hasher.finish() |
244 | 236 | }
|
245 | 237 | }
|
246 | 238 |
|
@@ -387,6 +379,26 @@ impl Default for CommandOutput {
|
387 | 379 | }
|
388 | 380 | }
|
389 | 381 |
|
| 382 | +impl Hash for BootstrapCommand { |
| 383 | + fn hash<H: Hasher>(&self, state: &mut H) { |
| 384 | + self.program.hash(state); |
| 385 | + self.args.hash(state); |
| 386 | + self.envs.hash(state); |
| 387 | + self.cwd.hash(state); |
| 388 | + } |
| 389 | +} |
| 390 | + |
| 391 | +impl PartialEq for BootstrapCommand { |
| 392 | + fn eq(&self, other: &Self) -> bool { |
| 393 | + self.program == other.program |
| 394 | + && self.args == other.args |
| 395 | + && self.envs == other.envs |
| 396 | + && self.cwd == other.cwd |
| 397 | + } |
| 398 | +} |
| 399 | + |
| 400 | +impl Eq for BootstrapCommand {} |
| 401 | + |
390 | 402 | /// Helper trait to format both Command and BootstrapCommand as a short execution line,
|
391 | 403 | /// without all the other details (e.g. environment variables).
|
392 | 404 | #[cfg(feature = "tracing")]
|
|
0 commit comments