Skip to content

Commit c32589e

Browse files
committed
[meta] share a single ParseContext everywhere
This allows caches to be reused across all filterset evaluations.
1 parent 605fdaf commit c32589e

File tree

13 files changed

+133
-90
lines changed

13 files changed

+133
-90
lines changed

cargo-nextest/src/dispatch.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,12 @@ impl ConfigOpts {
286286
pub fn make_config(
287287
&self,
288288
workspace_root: &Utf8Path,
289-
graph: &PackageGraph,
289+
pcx: &ParseContext<'_>,
290290
experimental: &BTreeSet<ConfigExperimental>,
291291
) -> Result<NextestConfig> {
292292
NextestConfig::from_sources(
293293
workspace_root,
294-
graph,
294+
pcx,
295295
self.config_file.as_deref(),
296296
&self.tool_config_files,
297297
experimental,
@@ -1222,7 +1222,7 @@ impl BaseApp {
12221222
})
12231223
}
12241224

1225-
fn load_config(&self) -> Result<(VersionOnlyConfig, NextestConfig)> {
1225+
fn load_config(&self, pcx: &ParseContext<'_>) -> Result<(VersionOnlyConfig, NextestConfig)> {
12261226
// Load the version-only config first to avoid incompatibilities with parsing the rest of
12271227
// the config.
12281228
let version_only_config = self
@@ -1244,7 +1244,7 @@ impl BaseApp {
12441244

12451245
let config = self.config_opts.make_config(
12461246
&self.workspace_root,
1247-
self.graph(),
1247+
pcx,
12481248
version_only_config.experimental(),
12491249
)?;
12501250

@@ -1421,7 +1421,8 @@ impl BaseApp {
14211421
let path_mapper = PathMapper::noop();
14221422

14231423
let build_platforms = binary_list.rust_build_meta.build_platforms.clone();
1424-
let (_, config) = self.load_config()?;
1424+
let pcx = ParseContext::new(self.graph());
1425+
let (_, config) = self.load_config(&pcx)?;
14251426
let profile = self
14261427
.load_profile(&config)?
14271428
.apply_build_platforms(&build_platforms);
@@ -1547,13 +1548,12 @@ impl App {
15471548
Ok(Self { base, build_filter })
15481549
}
15491550

1550-
fn build_filtering_expressions(&self) -> Result<Vec<Filterset>> {
1551-
let pcx = ParseContext::new(self.base.graph());
1551+
fn build_filtering_expressions(&self, pcx: &ParseContext<'_>) -> Result<Vec<Filterset>> {
15521552
let (exprs, all_errors): (Vec<_>, Vec<_>) = self
15531553
.build_filter
15541554
.filterset
15551555
.iter()
1556-
.map(|input| Filterset::parse(input.clone(), &pcx, FiltersetKind::Test))
1556+
.map(|input| Filterset::parse(input.clone(), pcx, FiltersetKind::Test))
15571557
.partition_result();
15581558

15591559
if !all_errors.is_empty() {
@@ -1589,9 +1589,11 @@ impl App {
15891589
list_type: ListType,
15901590
output_writer: &mut OutputWriter,
15911591
) -> Result<()> {
1592-
let (version_only_config, config) = self.base.load_config()?;
1592+
let pcx = ParseContext::new(self.base.graph());
1593+
1594+
let (version_only_config, config) = self.base.load_config(&pcx)?;
15931595
let profile = self.base.load_profile(&config)?;
1594-
let filter_exprs = self.build_filtering_expressions()?;
1596+
let filter_exprs = self.build_filtering_expressions(&pcx)?;
15951597
let test_filter_builder = self.build_filter.make_test_filter_builder(filter_exprs)?;
15961598

15971599
let binary_list = self.base.build_binary_list()?;
@@ -1650,7 +1652,8 @@ impl App {
16501652
groups: Vec<TestGroup>,
16511653
output_writer: &mut OutputWriter,
16521654
) -> Result<()> {
1653-
let (_, config) = self.base.load_config()?;
1655+
let pcx = ParseContext::new(self.base.graph());
1656+
let (_, config) = self.base.load_config(&pcx)?;
16541657
let profile = self.base.load_profile(&config)?;
16551658

16561659
// Validate test groups before doing any other work.
@@ -1662,7 +1665,7 @@ impl App {
16621665
};
16631666
let settings = ShowTestGroupSettings { mode, show_default };
16641667

1665-
let filter_exprs = self.build_filtering_expressions()?;
1668+
let filter_exprs = self.build_filtering_expressions(&pcx)?;
16661669
let test_filter_builder = self.build_filter.make_test_filter_builder(filter_exprs)?;
16671670

16681671
let binary_list = self.base.build_binary_list()?;
@@ -1705,7 +1708,8 @@ impl App {
17051708
cli_args: Vec<String>,
17061709
output_writer: &mut OutputWriter,
17071710
) -> Result<i32> {
1708-
let (version_only_config, config) = self.base.load_config()?;
1711+
let pcx = ParseContext::new(self.base.graph());
1712+
let (version_only_config, config) = self.base.load_config(&pcx)?;
17091713
let profile = self.base.load_profile(&config)?;
17101714

17111715
// Construct this here so that errors are reported before the build step.
@@ -1744,7 +1748,7 @@ impl App {
17441748
CaptureStrategy::Combined
17451749
};
17461750

1747-
let filter_exprs = self.build_filtering_expressions()?;
1751+
let filter_exprs = self.build_filtering_expressions(&pcx)?;
17481752
let test_filter_builder = self.build_filter.make_test_filter_builder(filter_exprs)?;
17491753

17501754
let binary_list = self.base.build_binary_list()?;

nextest-runner/src/config/archive.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ mod tests {
248248
use camino_tempfile::tempdir;
249249
use config::ConfigError;
250250
use indoc::indoc;
251+
use nextest_filtering::ParseContext;
251252
use test_case::test_case;
252253

253254
#[test]
@@ -274,9 +275,11 @@ mod tests {
274275

275276
let graph = temp_workspace(workspace_dir.path(), config_contents);
276277

278+
let pcx = ParseContext::new(&graph);
279+
277280
let config = NextestConfig::from_sources(
278281
graph.workspace().root(),
279-
&graph,
282+
&pcx,
280283
None,
281284
[],
282285
&Default::default(),
@@ -424,9 +427,11 @@ mod tests {
424427

425428
let graph = temp_workspace(workspace_path, config_contents);
426429

430+
let pcx = ParseContext::new(&graph);
431+
427432
let config_err = NextestConfig::from_sources(
428433
graph.workspace().root(),
429-
&graph,
434+
&pcx,
430435
None,
431436
[],
432437
&Default::default(),

nextest-runner/src/config/config_impl.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ use camino::{Utf8Path, Utf8PathBuf};
2121
use config::{
2222
builder::DefaultState, Config, ConfigBuilder, ConfigError, File, FileFormat, FileSourceFile,
2323
};
24-
use guppy::graph::PackageGraph;
2524
use indexmap::IndexMap;
26-
use nextest_filtering::{EvalContext, TestQuery};
25+
use nextest_filtering::{EvalContext, ParseContext, TestQuery};
2726
use serde::Deserialize;
2827
use std::{
2928
collections::{hash_map, BTreeMap, BTreeSet, HashMap},
@@ -96,7 +95,7 @@ impl NextestConfig {
9695
/// default config options.
9796
pub fn from_sources<'a, I>(
9897
workspace_root: impl Into<Utf8PathBuf>,
99-
graph: &PackageGraph,
98+
pcx: &ParseContext<'_>,
10099
config_file: Option<&Utf8Path>,
101100
tool_config_files: impl IntoIterator<IntoIter = I>,
102101
experimental: &BTreeSet<ConfigExperimental>,
@@ -106,7 +105,7 @@ impl NextestConfig {
106105
{
107106
Self::from_sources_impl(
108107
workspace_root,
109-
graph,
108+
pcx,
110109
config_file,
111110
tool_config_files,
112111
experimental,
@@ -135,7 +134,7 @@ impl NextestConfig {
135134
// A custom unknown_callback can be passed in while testing.
136135
fn from_sources_impl<'a, I>(
137136
workspace_root: impl Into<Utf8PathBuf>,
138-
graph: &PackageGraph,
137+
pcx: &ParseContext<'_>,
139138
config_file: Option<&Utf8Path>,
140139
tool_config_files: impl IntoIterator<IntoIter = I>,
141140
experimental: &BTreeSet<ConfigExperimental>,
@@ -147,7 +146,7 @@ impl NextestConfig {
147146
let workspace_root = workspace_root.into();
148147
let tool_config_files_rev = tool_config_files.into_iter().rev();
149148
let (inner, compiled) = Self::read_from_sources(
150-
graph,
149+
pcx,
151150
&workspace_root,
152151
config_file,
153152
tool_config_files_rev,
@@ -205,7 +204,7 @@ impl NextestConfig {
205204
// ---
206205

207206
fn read_from_sources<'a>(
208-
graph: &PackageGraph,
207+
pcx: &ParseContext<'_>,
209208
workspace_root: &Utf8Path,
210209
file: Option<&Utf8Path>,
211210
tool_config_files_rev: impl Iterator<Item = &'a ToolConfigFile>,
@@ -226,7 +225,7 @@ impl NextestConfig {
226225
for ToolConfigFile { config_file, tool } in tool_config_files_rev {
227226
let source = File::new(config_file.as_str(), FileFormat::Toml);
228227
Self::deserialize_individual_config(
229-
graph,
228+
pcx,
230229
workspace_root,
231230
config_file,
232231
Some(tool),
@@ -253,7 +252,7 @@ impl NextestConfig {
253252
};
254253

255254
Self::deserialize_individual_config(
256-
graph,
255+
pcx,
257256
workspace_root,
258257
&config_file,
259258
None,
@@ -283,7 +282,7 @@ impl NextestConfig {
283282

284283
#[expect(clippy::too_many_arguments)]
285284
fn deserialize_individual_config(
286-
graph: &PackageGraph,
285+
pcx: &ParseContext<'_>,
287286
workspace_root: &Utf8Path,
288287
config_file: &Utf8Path,
289288
tool: Option<&str>,
@@ -391,7 +390,7 @@ impl NextestConfig {
391390
}
392391

393392
// Compile the overrides for this file.
394-
let this_compiled = CompiledByProfile::new(graph, &this_config)
393+
let this_compiled = CompiledByProfile::new(pcx, &this_config)
395394
.map_err(|kind| ConfigParseError::new(config_file, tool, kind))?;
396395

397396
// Check that all overrides specify known test groups.
@@ -1097,11 +1096,13 @@ mod tests {
10971096
let tool_path = workspace_root.join(".config/tool.toml");
10981097
std::fs::write(&tool_path, tool_config_contents).unwrap();
10991098

1099+
let pcx = ParseContext::new(&graph);
1100+
11001101
let mut unknown_keys = HashMap::new();
11011102

11021103
let _ = NextestConfig::from_sources_impl(
11031104
workspace_root,
1104-
&graph,
1105+
&pcx,
11051106
None,
11061107
&[ToolConfigFile {
11071108
tool: "my-tool".to_owned(),

nextest-runner/src/config/max_fail.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ mod tests {
172172
};
173173
use camino_tempfile::tempdir;
174174
use indoc::indoc;
175+
use nextest_filtering::ParseContext;
175176
use test_case::test_case;
176177

177178
#[test]
@@ -243,9 +244,11 @@ mod tests {
243244
let workspace_dir = tempdir().unwrap();
244245
let graph = temp_workspace(workspace_dir.path(), config_contents);
245246

247+
let pcx = ParseContext::new(&graph);
248+
246249
let config = NextestConfig::from_sources(
247250
graph.workspace().root(),
248-
&graph,
251+
&pcx,
249252
None,
250253
[],
251254
&Default::default(),
@@ -335,10 +338,11 @@ mod tests {
335338
fn invalid_fail_fast(config_contents: &str, error_str: &str) {
336339
let workspace_dir = tempdir().unwrap();
337340
let graph = temp_workspace(workspace_dir.path(), config_contents);
341+
let pcx = ParseContext::new(&graph);
338342

339343
let error = NextestConfig::from_sources(
340344
graph.workspace().root(),
341-
&graph,
345+
&pcx,
342346
None,
343347
[],
344348
&Default::default(),

0 commit comments

Comments
 (0)