Skip to content

Commit 0f8a06b

Browse files
committed
use a shared headers cache
1 parent 0f364ac commit 0f8a06b

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

src/tools/compiletest/src/header.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,24 @@ use tracing::*;
1111
use crate::common::{Config, Debugger, FailMode, Mode, PassMode};
1212
use crate::header::cfg::parse_cfg_name_directive;
1313
use crate::header::cfg::MatchOutcome;
14+
use crate::header::needs::CachedNeedsConditions;
1415
use crate::{extract_cdb_version, extract_gdb_version};
1516

1617
mod cfg;
1718
mod needs;
1819
#[cfg(test)]
1920
mod tests;
2021

22+
pub struct HeadersCache {
23+
needs: CachedNeedsConditions,
24+
}
25+
26+
impl HeadersCache {
27+
pub fn load(config: &Config) -> Self {
28+
Self { needs: CachedNeedsConditions::load(config) }
29+
}
30+
}
31+
2132
/// Properties which must be known very early, before actually running
2233
/// the test.
2334
#[derive(Default)]
@@ -849,6 +860,7 @@ where
849860

850861
pub fn make_test_description<R: Read>(
851862
config: &Config,
863+
cache: &HeadersCache,
852864
name: test::TestName,
853865
path: &Path,
854866
src: R,
@@ -859,8 +871,6 @@ pub fn make_test_description<R: Read>(
859871
let mut ignore_message = None;
860872
let mut should_fail = false;
861873

862-
let needs_cache = needs::CachedNeedsConditions::load(config);
863-
864874
iter_header(path, src, &mut |revision, ln, line_number| {
865875
if revision.is_some() && revision != cfg {
866876
return;
@@ -888,7 +898,7 @@ pub fn make_test_description<R: Read>(
888898

889899
decision!(cfg::handle_ignore(config, ln));
890900
decision!(cfg::handle_only(config, ln));
891-
decision!(needs::handle_needs(&needs_cache, config, ln));
901+
decision!(needs::handle_needs(&cache.needs, config, ln));
892902
decision!(ignore_llvm(config, ln));
893903
decision!(ignore_cdb(config, ln));
894904
decision!(ignore_gdb(config, ln));

src/tools/compiletest/src/header/tests.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::io::Read;
22
use std::path::Path;
33

44
use crate::common::{Config, Debugger};
5-
use crate::header::{parse_normalization_string, EarlyProps};
5+
use crate::header::{parse_normalization_string, EarlyProps, HeadersCache};
66

77
fn make_test_description<R: Read>(
88
config: &Config,
@@ -11,8 +11,10 @@ fn make_test_description<R: Read>(
1111
src: R,
1212
cfg: Option<&str>,
1313
) -> test::TestDesc {
14+
let cache = HeadersCache::load(config);
1415
let mut poisoned = false;
15-
let test = crate::header::make_test_description(config, name, path, src, cfg, &mut poisoned);
16+
let test =
17+
crate::header::make_test_description(config, &cache, name, path, src, cfg, &mut poisoned);
1618
if poisoned {
1719
panic!("poisoned!");
1820
}

src/tools/compiletest/src/main.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use tracing::*;
2525
use walkdir::WalkDir;
2626

2727
use self::header::{make_test_description, EarlyProps};
28+
use crate::header::HeadersCache;
2829
use std::sync::Arc;
2930

3031
#[cfg(test)]
@@ -556,9 +557,11 @@ pub fn make_tests(
556557
panic!("modified_tests got error from dir: {}, error: {}", config.src_base.display(), err)
557558
});
558559

560+
let cache = HeadersCache::load(&config);
559561
let mut poisoned = false;
560562
collect_tests_from_dir(
561563
config.clone(),
564+
&cache,
562565
&config.src_base,
563566
&PathBuf::new(),
564567
&inputs,
@@ -636,6 +639,7 @@ fn modified_tests(config: &Config, dir: &Path) -> Result<Vec<PathBuf>, String> {
636639

637640
fn collect_tests_from_dir(
638641
config: Arc<Config>,
642+
cache: &HeadersCache,
639643
dir: &Path,
640644
relative_dir_path: &Path,
641645
inputs: &Stamp,
@@ -654,7 +658,7 @@ fn collect_tests_from_dir(
654658
file: dir.to_path_buf(),
655659
relative_dir: relative_dir_path.parent().unwrap().to_path_buf(),
656660
};
657-
tests.extend(make_test(config, &paths, inputs, poisoned));
661+
tests.extend(make_test(config, cache, &paths, inputs, poisoned));
658662
return Ok(());
659663
}
660664

@@ -680,13 +684,14 @@ fn collect_tests_from_dir(
680684
let paths =
681685
TestPaths { file: file_path, relative_dir: relative_dir_path.to_path_buf() };
682686

683-
tests.extend(make_test(config.clone(), &paths, inputs, poisoned))
687+
tests.extend(make_test(config.clone(), cache, &paths, inputs, poisoned))
684688
} else if file_path.is_dir() {
685689
let relative_file_path = relative_dir_path.join(file.file_name());
686690
if &file_name != "auxiliary" {
687691
debug!("found directory: {:?}", file_path.display());
688692
collect_tests_from_dir(
689693
config.clone(),
694+
cache,
690695
&file_path,
691696
&relative_file_path,
692697
inputs,
@@ -718,6 +723,7 @@ pub fn is_test(file_name: &OsString) -> bool {
718723

719724
fn make_test(
720725
config: Arc<Config>,
726+
cache: &HeadersCache,
721727
testpaths: &TestPaths,
722728
inputs: &Stamp,
723729
poisoned: &mut bool,
@@ -745,8 +751,9 @@ fn make_test(
745751
std::fs::File::open(&test_path).expect("open test file to parse ignores");
746752
let cfg = revision.map(|v| &**v);
747753
let test_name = crate::make_test_name(&config, testpaths, revision);
748-
let mut desc =
749-
make_test_description(&config, test_name, &test_path, src_file, cfg, poisoned);
754+
let mut desc = make_test_description(
755+
&config, cache, test_name, &test_path, src_file, cfg, poisoned,
756+
);
750757
// Ignore tests that already run and are up to date with respect to inputs.
751758
if !config.force_rerun {
752759
desc.ignore |= is_up_to_date(

0 commit comments

Comments
 (0)