Skip to content

Commit 3ff8a41

Browse files
committed
add command cache in execution context
1 parent 1f5ccb8 commit 3ff8a41

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/bootstrap/src/utils/execution_context.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
//! This module provides the [`ExecutionContext`] type, which holds global configuration
44
//! relevant during the execution of commands in bootstrap. This includes dry-run
55
//! mode, verbosity level, and behavior on failure.
6+
#![allow(warnings)]
7+
use std::collections::HashMap;
68
use std::panic::Location;
79
use std::process::Child;
810
use std::sync::{Arc, Mutex};
911

1012
use crate::core::config::DryRun;
1113
#[cfg(feature = "tracing")]
1214
use crate::trace_cmd;
15+
use crate::utils::exec::CommandCacheKey;
1316
use crate::{BehaviorOnFailure, BootstrapCommand, CommandOutput, OutputMode, exit};
1417

1518
#[derive(Clone, Default)]
@@ -18,6 +21,26 @@ pub struct ExecutionContext {
1821
verbose: u8,
1922
pub fail_fast: bool,
2023
delayed_failures: Arc<Mutex<Vec<String>>>,
24+
command_cache: Arc<CommandCache>,
25+
}
26+
27+
#[derive(Default)]
28+
pub struct CommandCache {
29+
cache: Mutex<HashMap<CommandCacheKey, CommandOutput>>,
30+
}
31+
32+
impl CommandCache {
33+
pub fn new() -> Self {
34+
Self { cache: Mutex::new(HashMap::new()) }
35+
}
36+
37+
pub fn get(&self, key: &CommandCacheKey) -> Option<CommandOutput> {
38+
self.cache.lock().unwrap().get(key).cloned()
39+
}
40+
41+
pub fn insert(&self, key: CommandCacheKey, output: CommandOutput) {
42+
self.cache.lock().unwrap().insert(key, output);
43+
}
2144
}
2245

2346
impl ExecutionContext {

0 commit comments

Comments
 (0)