diff options
Diffstat (limited to 'cli/tools')
-rw-r--r-- | cli/tools/bench.rs | 65 |
1 files changed, 56 insertions, 9 deletions
diff --git a/cli/tools/bench.rs b/cli/tools/bench.rs index eeda3ea1a..2bebe124b 100644 --- a/cli/tools/bench.rs +++ b/cli/tools/bench.rs @@ -1,5 +1,6 @@ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. +use crate::args::BenchConfig; use crate::args::BenchFlags; use crate::args::Flags; use crate::args::TypeCheckMode; @@ -14,6 +15,7 @@ use crate::util::file_watcher; use crate::util::file_watcher::ResolutionResult; use crate::util::fs::collect_specifiers; use crate::util::path::is_supported_ext; +use crate::util::path::specifier_to_file_path; use crate::worker::create_main_worker_for_test_or_bench; use deno_core::error::generic_error; @@ -490,9 +492,13 @@ pub async fn run_benchmarks( let ps = ProcState::build(flags).await?; let permissions = Permissions::from_options(&ps.options.permissions_options())?; + + let selection = + collect_include_ignore(&bench_flags, ps.options.to_bench_config()?); + let specifiers = collect_specifiers( - bench_flags.include.unwrap_or_else(|| vec![".".to_string()]), - &bench_flags.ignore.clone(), + selection.include, + &selection.ignore, is_supported_bench_path, )?; @@ -524,9 +530,11 @@ pub async fn run_benchmarks_with_watch( let permissions = Permissions::from_options(&ps.options.permissions_options())?; - let include = bench_flags.include.unwrap_or_else(|| vec![".".to_string()]); - let ignore = bench_flags.ignore.clone(); - let paths_to_watch: Vec<_> = include.iter().map(PathBuf::from).collect(); + let selection = + collect_include_ignore(&bench_flags, ps.options.to_bench_config()?); + + let paths_to_watch: Vec<_> = + selection.include.iter().map(PathBuf::from).collect(); let no_check = ps.options.type_check_mode() == TypeCheckMode::None; let resolver = |changed: Option<Vec<PathBuf>>| { @@ -534,8 +542,8 @@ pub async fn run_benchmarks_with_watch( let paths_to_watch_clone = paths_to_watch.clone(); let files_changed = changed.is_some(); - let include = include.clone(); - let ignore = ignore.clone(); + let include = selection.include.clone(); + let ignore = selection.ignore.clone(); let ps = ps.clone(); async move { @@ -650,8 +658,8 @@ pub async fn run_benchmarks_with_watch( let operation = |modules_to_reload: Vec<(ModuleSpecifier, ModuleKind)>| { let filter = bench_flags.filter.clone(); - let include = include.clone(); - let ignore = ignore.clone(); + let include = selection.include.clone(); + let ignore = selection.ignore.clone(); let permissions = permissions.clone(); let ps = ps.clone(); @@ -687,3 +695,42 @@ pub async fn run_benchmarks_with_watch( Ok(()) } + +struct IncludeIgnoreCollection { + include: Vec<String>, + ignore: Vec<PathBuf>, +} + +fn collect_include_ignore( + bench_flags: &BenchFlags, + maybe_bench_config: Option<BenchConfig>, +) -> IncludeIgnoreCollection { + let mut include = bench_flags.include.clone().unwrap_or_default(); + let mut ignore = bench_flags.ignore.clone(); + + if let Some(bench_config) = maybe_bench_config { + if include.is_empty() { + include = bench_config + .files + .include + .iter() + .map(|s| s.to_string()) + .collect::<Vec<_>>(); + } + + if ignore.is_empty() { + ignore = bench_config + .files + .exclude + .iter() + .filter_map(|s| specifier_to_file_path(s).ok()) + .collect::<Vec<_>>(); + } + } + + if include.is_empty() { + include.push(".".to_string()); + } + + IncludeIgnoreCollection { include, ignore } +} |