Skip to content

Commit 1574e51

Browse files
committed
[WIP] option for store dir relative to the target dir
Still to figure out: - [ ] Write tests for parsing configuration. - [ ] Write tests which set configuration and ensure that output gets written to the right spot. - [ ] How should remapped archive directories be handled? Archive target directories are typically temporary directories which will be deleted at the end of the run. Using that as the store directory seems wrong. In that case, we may wish to use another location instead.
1 parent ccffb23 commit 1574e51

25 files changed

+306
-137
lines changed

cargo-nextest/src/dispatch.rs

Lines changed: 77 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ use nextest_runner::{
2424
errors::{TargetTripleError, WriteTestListError},
2525
input::InputHandlerKind,
2626
list::{
27-
BinaryList, OutputFormat, RustTestArtifact, SerializableFormat, TestExecuteContext,
28-
TestList,
27+
BinaryList, OutputFormat, RustBuildMeta, RustTestArtifact, SerializableFormat,
28+
TestExecuteContext, TestList, TestListState,
2929
},
3030
partition::PartitionerBuilder,
3131
platform::{BuildPlatforms, HostPlatform, PlatformLibdir, TargetPlatform},
3232
redact::Redactor,
3333
reporter::{
3434
events::{FinalRunStats, RunStatsFailureKind},
35-
highlight_end, structured, FinalStatusLevel, ReporterBuilder, StatusLevel,
35+
highlight_end, structured, EventAggregator, FinalStatusLevel, ReporterBuilder, StatusLevel,
3636
TestOutputDisplay, TestOutputErrorSlice,
3737
},
3838
reuse_build::{archive_to_file, ArchiveReporter, PathMapper, ReuseBuildInfo},
@@ -611,20 +611,14 @@ impl TestBuildFilter {
611611
test_filter_builder: TestFilterBuilder,
612612
env: EnvironmentMap,
613613
ecx: &EvalContext<'_>,
614-
reuse_build: &ReuseBuildInfo,
614+
rust_build_meta: RustBuildMeta<TestListState>,
615+
path_mapper: &PathMapper,
615616
) -> Result<TestList<'g>> {
616-
let path_mapper = make_path_mapper(
617-
reuse_build,
618-
graph,
619-
&binary_list.rust_build_meta.target_directory,
620-
)?;
621-
622-
let rust_build_meta = binary_list.rust_build_meta.map_paths(&path_mapper);
623617
let test_artifacts = RustTestArtifact::from_binary_list(
624618
graph,
625619
binary_list,
626620
&rust_build_meta,
627-
&path_mapper,
621+
path_mapper,
628622
self.platform_filter.into(),
629623
)?;
630624
TestList::new(
@@ -1420,12 +1414,11 @@ impl BaseApp {
14201414
let binary_list = self.build_binary_list()?;
14211415
let path_mapper = PathMapper::noop();
14221416

1423-
let build_platforms = binary_list.rust_build_meta.build_platforms.clone();
14241417
let pcx = ParseContext::new(self.graph());
14251418
let (_, config) = self.load_config(&pcx)?;
14261419
let profile = self
14271420
.load_profile(&config)?
1428-
.apply_build_platforms(&build_platforms);
1421+
.into_evaluatable(&binary_list.rust_build_meta.build_platforms);
14291422

14301423
let redactor = if should_redact() {
14311424
Redactor::build_active(&binary_list.rust_build_meta)
@@ -1502,11 +1495,6 @@ impl BaseApp {
15021495
let profile = config
15031496
.profile(profile_name)
15041497
.map_err(ExpectedError::profile_not_found)?;
1505-
let store_dir = profile.store_dir();
1506-
std::fs::create_dir_all(store_dir).map_err(|err| ExpectedError::StoreDirCreateError {
1507-
store_dir: store_dir.to_owned(),
1508-
err,
1509-
})?;
15101498
Ok(profile)
15111499
}
15121500
}
@@ -1569,6 +1557,8 @@ impl App {
15691557
binary_list: Arc<BinaryList>,
15701558
test_filter_builder: TestFilterBuilder,
15711559
ecx: &EvalContext<'_>,
1560+
rust_build_meta: RustBuildMeta<TestListState>,
1561+
path_mapper: &PathMapper,
15721562
) -> Result<TestList> {
15731563
let env = EnvironmentMap::new(&self.base.cargo_configs);
15741564
self.build_filter.compute_test_list(
@@ -1579,7 +1569,8 @@ impl App {
15791569
test_filter_builder,
15801570
env,
15811571
ecx,
1582-
&self.base.reuse_build,
1572+
rust_build_meta,
1573+
path_mapper,
15831574
)
15841575
}
15851576

@@ -1617,16 +1608,29 @@ impl App {
16171608
.base
16181609
.load_runner(&binary_list.rust_build_meta.build_platforms);
16191610
let profile =
1620-
profile.apply_build_platforms(&binary_list.rust_build_meta.build_platforms);
1611+
profile.into_evaluatable(&binary_list.rust_build_meta.build_platforms);
16211612
let ctx = TestExecuteContext {
16221613
profile_name: profile.name(),
16231614
double_spawn,
16241615
target_runner,
16251616
};
16261617
let ecx = profile.filterset_ecx();
16271618

1628-
let test_list =
1629-
self.build_test_list(&ctx, binary_list, test_filter_builder, &ecx)?;
1619+
let path_mapper = make_path_mapper(
1620+
&self.base.reuse_build,
1621+
self.base.graph(),
1622+
&binary_list.rust_build_meta.target_directory,
1623+
)?;
1624+
let rust_build_meta = binary_list.rust_build_meta.map_paths(&path_mapper);
1625+
1626+
let test_list = self.build_test_list(
1627+
&ctx,
1628+
binary_list,
1629+
test_filter_builder,
1630+
&ecx,
1631+
rust_build_meta,
1632+
&path_mapper,
1633+
)?;
16301634

16311635
let mut writer = output_writer.stdout_writer();
16321636
test_list.write(
@@ -1673,15 +1677,29 @@ impl App {
16731677

16741678
let double_spawn = self.base.load_double_spawn();
16751679
let target_runner = self.base.load_runner(&build_platforms);
1676-
let profile = profile.apply_build_platforms(&build_platforms);
1680+
let profile = profile.into_evaluatable(&build_platforms);
16771681
let ctx = TestExecuteContext {
16781682
profile_name: profile.name(),
16791683
double_spawn,
16801684
target_runner,
16811685
};
16821686
let ecx = profile.filterset_ecx();
16831687

1684-
let test_list = self.build_test_list(&ctx, binary_list, test_filter_builder, &ecx)?;
1688+
let path_mapper = make_path_mapper(
1689+
&self.base.reuse_build,
1690+
self.base.graph(),
1691+
&binary_list.rust_build_meta.target_directory,
1692+
)?;
1693+
let rust_build_meta = binary_list.rust_build_meta.map_paths(&path_mapper);
1694+
1695+
let test_list = self.build_test_list(
1696+
&ctx,
1697+
binary_list,
1698+
test_filter_builder,
1699+
&ecx,
1700+
rust_build_meta,
1701+
&path_mapper,
1702+
)?;
16851703

16861704
let mut writer = output_writer.stdout_writer();
16871705

@@ -1712,7 +1730,8 @@ impl App {
17121730
let (version_only_config, config) = self.base.load_config(&pcx)?;
17131731
let profile = self.base.load_profile(&config)?;
17141732

1715-
// Construct this here so that errors are reported before the build step.
1733+
// Construct this here so that errors are reported before the build
1734+
// step.
17161735
let mut structured_reporter = structured::StructuredReporter::new();
17171736
match reporter_opts.message_format {
17181737
MessageFormat::Human => {}
@@ -1752,19 +1771,40 @@ impl App {
17521771
let test_filter_builder = self.build_filter.make_test_filter_builder(filter_exprs)?;
17531772

17541773
let binary_list = self.base.build_binary_list()?;
1755-
let build_platforms = &binary_list.rust_build_meta.build_platforms.clone();
1774+
let path_mapper = make_path_mapper(
1775+
&self.base.reuse_build,
1776+
self.base.graph(),
1777+
&binary_list.rust_build_meta.target_directory,
1778+
)?;
1779+
let rust_build_meta = binary_list.rust_build_meta.map_paths(&path_mapper);
1780+
1781+
let profile = profile.into_evaluatable(&binary_list.rust_build_meta.build_platforms);
1782+
1783+
// This is the earliest point where we can create the aggregator, since
1784+
// we need the remapped target directory which is only available after
1785+
// the test list is built.
1786+
let aggregator = EventAggregator::new(&profile, &rust_build_meta.target_directory)?;
1787+
17561788
let double_spawn = self.base.load_double_spawn();
1757-
let target_runner = self.base.load_runner(build_platforms);
1789+
let target_runner = self
1790+
.base
1791+
.load_runner(&binary_list.rust_build_meta.build_platforms);
17581792

1759-
let profile = profile.apply_build_platforms(build_platforms);
17601793
let ctx = TestExecuteContext {
17611794
profile_name: profile.name(),
17621795
double_spawn,
17631796
target_runner,
17641797
};
17651798
let ecx = profile.filterset_ecx();
17661799

1767-
let test_list = self.build_test_list(&ctx, binary_list, test_filter_builder, &ecx)?;
1800+
let test_list = self.build_test_list(
1801+
&ctx,
1802+
binary_list,
1803+
test_filter_builder,
1804+
&ecx,
1805+
rust_build_meta,
1806+
&path_mapper,
1807+
)?;
17681808

17691809
let output = output_writer.reporter_output();
17701810
let should_colorize = self
@@ -1805,7 +1845,13 @@ impl App {
18051845
let mut reporter = reporter_opts
18061846
.to_builder(no_capture, should_colorize)
18071847
.set_verbose(self.base.output.verbose)
1808-
.build(&test_list, &profile, output, structured_reporter);
1848+
.build(
1849+
&test_list,
1850+
&profile,
1851+
output,
1852+
aggregator,
1853+
structured_reporter,
1854+
);
18091855

18101856
configure_handle_inheritance(no_capture)?;
18111857
let run_stats = runner.try_execute(|event| {

cargo-nextest/src/errors.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,10 @@ pub enum ExpectedError {
6969
#[from]
7070
err: ProfileNotFound,
7171
},
72-
#[error("failed to create store directory")]
73-
StoreDirCreateError {
74-
store_dir: Utf8PathBuf,
75-
#[source]
76-
err: std::io::Error,
72+
#[error("junit setup error")]
73+
JunitSetupError {
74+
#[from]
75+
err: JunitSetupError,
7776
},
7877
#[error("cargo config error")]
7978
CargoConfigError {
@@ -395,7 +394,7 @@ impl ExpectedError {
395394
| Self::SetCurrentDirFailed { .. }
396395
| Self::GetCurrentExeFailed { .. }
397396
| Self::ProfileNotFound { .. }
398-
| Self::StoreDirCreateError { .. }
397+
| Self::JunitSetupError { .. }
399398
| Self::RootManifestNotFound { .. }
400399
| Self::CargoConfigError { .. }
401400
| Self::TestFilterBuilderError { .. }
@@ -521,12 +520,9 @@ impl ExpectedError {
521520
);
522521
None
523522
}
524-
Self::StoreDirCreateError { store_dir, err } => {
525-
error!(
526-
"failed to create store dir at `{}`",
527-
store_dir.style(styles.bold)
528-
);
529-
Some(err as &dyn Error)
523+
Self::JunitSetupError { err } => {
524+
error!("{}", err);
525+
err.source()
530526
}
531527
Self::CargoConfigError { err } => {
532528
error!("{}", err);

nextest-runner/src/config/archive.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ mod tests {
307307
config
308308
.profile("default")
309309
.expect("default profile exists")
310-
.apply_build_platforms(&build_platforms())
310+
.into_evaluatable(&build_platforms())
311311
.archive_config(),
312312
&default_config,
313313
"default matches"
@@ -317,7 +317,7 @@ mod tests {
317317
config
318318
.profile("profile1")
319319
.expect("profile exists")
320-
.apply_build_platforms(&build_platforms())
320+
.into_evaluatable(&build_platforms())
321321
.archive_config(),
322322
&ArchiveConfig {
323323
include: vec![ArchiveInclude {
@@ -334,7 +334,7 @@ mod tests {
334334
config
335335
.profile("profile2")
336336
.expect("default profile exists")
337-
.apply_build_platforms(&build_platforms())
337+
.into_evaluatable(&build_platforms())
338338
.archive_config(),
339339
&ArchiveConfig { include: vec![] },
340340
"profile2 matches"
@@ -344,7 +344,7 @@ mod tests {
344344
config
345345
.profile("profile3")
346346
.expect("default profile exists")
347-
.apply_build_platforms(&build_platforms())
347+
.into_evaluatable(&build_platforms())
348348
.archive_config(),
349349
&default_config,
350350
"profile3 matches"

0 commit comments

Comments
 (0)