-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathplan_request.rs
More file actions
80 lines (69 loc) · 2.86 KB
/
plan_request.rs
File metadata and controls
80 lines (69 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use std::{ffi::OsStr, sync::Arc};
use rustc_hash::FxHashMap;
use vite_path::AbsolutePath;
use vite_str::Str;
use vite_task_graph::{config::UserCacheConfig, query::TaskQuery};
/// A parsed command from a task script, passed to [`super::PlanRequestParser::get_plan_request`].
///
/// All fields use `Arc` for cheap reassignment. The implementation can mutate
/// these fields to modify how the command is executed when it falls through as a
/// normal process (i.e., when `get_plan_request` returns `None`).
#[derive(Debug)]
pub struct ScriptCommand {
pub program: Str,
pub args: Arc<[Str]>,
pub envs: Arc<FxHashMap<Arc<OsStr>, Arc<OsStr>>>,
pub cwd: Arc<AbsolutePath>,
}
impl ScriptCommand {
/// Convert this `ScriptCommand` to a `SyntheticPlanRequest` with the given `cache_config`.
#[must_use]
pub fn to_synthetic_plan_request(&self, cache_config: UserCacheConfig) -> SyntheticPlanRequest {
SyntheticPlanRequest {
program: Arc::from(OsStr::new(&self.program)),
args: self.args.clone(),
cache_config,
envs: self.envs.clone(),
}
}
}
#[derive(Debug)]
pub struct PlanOptions {
pub extra_args: Arc<[Str]>,
}
#[derive(Debug)]
pub struct QueryPlanRequest {
/// The query to run against the task graph. For example: `-r build`
pub query: TaskQuery,
/// Other options affecting the planning process, not the task graph querying itself.
///
/// For example: `-- arg1 arg2`
pub plan_options: PlanOptions,
}
/// The request to run a synthetic task (e.g., one generated by `TaskSynthesizer` from `vp lint` in a script).
/// Synthetic tasks are not defined in the task graph, but are generated on-the-fly.
#[derive(Debug)]
pub struct SyntheticPlanRequest {
/// The program to execute
pub program: Arc<OsStr>,
/// The arguments to pass to the program
pub args: Arc<[Str]>,
/// The cache config as if it's defined in `vite.config.*`
pub cache_config: UserCacheConfig,
/// All environment variables to set for the synthetic task.
///
/// This is set in the plan stage before resolving envs for caching.
/// Therefore, these envs are subject to env configurations in `UserTaskOptions`.
///
/// - To set envs that are not subject to caching but still passed to the spawned child, use `task_options` to configure `pass_through_envs`.
/// - To set envs that should be fingerprinted, use `task_options` to configure `envs`.
/// - If neither is set, and caching is enabled, these envs will have not effect.
pub envs: Arc<FxHashMap<Arc<OsStr>, Arc<OsStr>>>,
}
#[derive(Debug)]
pub enum PlanRequest {
/// The request to run tasks queried from the task graph, like `vp run ...`.
Query(QueryPlanRequest),
/// The request to run a synthetic task (not defined in the task graph), e.g., from `TaskSynthesizer`.
Synthetic(SyntheticPlanRequest),
}