summaryrefslogtreecommitdiff
path: root/cli/tools/bench.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tools/bench.rs')
-rw-r--r--cli/tools/bench.rs116
1 files changed, 34 insertions, 82 deletions
diff --git a/cli/tools/bench.rs b/cli/tools/bench.rs
index 2d54b260d..ed788fa7f 100644
--- a/cli/tools/bench.rs
+++ b/cli/tools/bench.rs
@@ -1,8 +1,7 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
-use crate::args::BenchConfig;
-use crate::args::BenchFlags;
-use crate::args::Flags;
+use crate::args::BenchOptions;
+use crate::args::CliOptions;
use crate::args::TypeCheckMode;
use crate::colors;
use crate::graph_util::contains_specifier;
@@ -15,7 +14,6 @@ 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;
@@ -37,6 +35,7 @@ use serde::Serialize;
use std::collections::HashSet;
use std::path::Path;
use std::path::PathBuf;
+use std::sync::Arc;
use tokio::sync::mpsc::unbounded_channel;
use tokio::sync::mpsc::UnboundedSender;
@@ -487,24 +486,18 @@ fn is_supported_bench_path(path: &Path) -> bool {
}
pub async fn run_benchmarks(
- flags: Flags,
- bench_flags: BenchFlags,
+ cli_options: CliOptions,
+ bench_options: BenchOptions,
) -> Result<(), AnyError> {
- let ps = ProcState::build(flags).await?;
+ let ps = ProcState::from_options(Arc::new(cli_options)).await?;
// Various bench files should not share the same permissions in terms of
// `PermissionsContainer` - otherwise granting/revoking permissions in one
// file would have impact on other files, which is undesirable.
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(
- selection.include,
- &selection.ignore,
- is_supported_bench_path,
- )?;
+ let specifiers =
+ collect_specifiers(&bench_options.files, is_supported_bench_path)?;
if specifiers.is_empty() {
return Err(generic_error("No bench modules found"));
@@ -517,7 +510,7 @@ pub async fn run_benchmarks(
permissions,
specifiers,
BenchSpecifierOptions {
- filter: bench_flags.filter,
+ filter: bench_options.filter,
},
)
.await?;
@@ -527,21 +520,22 @@ pub async fn run_benchmarks(
// TODO(bartlomieju): heavy duplication of code with `cli/tools/test.rs`
pub async fn run_benchmarks_with_watch(
- flags: Flags,
- bench_flags: BenchFlags,
+ cli_options: CliOptions,
+ bench_options: BenchOptions,
) -> Result<(), AnyError> {
- let ps = ProcState::build(flags).await?;
+ let ps = ProcState::from_options(Arc::new(cli_options)).await?;
// Various bench files should not share the same permissions in terms of
// `PermissionsContainer` - otherwise granting/revoking permissions in one
// file would have impact on other files, which is undesirable.
let permissions =
Permissions::from_options(&ps.options.permissions_options())?;
- 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 paths_to_watch: Vec<_> = bench_options
+ .files
+ .include
+ .iter()
+ .map(PathBuf::from)
+ .collect();
let no_check = ps.options.type_check_mode() == TypeCheckMode::None;
let resolver = |changed: Option<Vec<PathBuf>>| {
@@ -549,13 +543,11 @@ pub async fn run_benchmarks_with_watch(
let paths_to_watch_clone = paths_to_watch.clone();
let files_changed = changed.is_some();
- let include = selection.include.clone();
- let ignore = selection.ignore.clone();
+ let files = bench_options.files.clone();
let ps = ps.clone();
async move {
- let bench_modules =
- collect_specifiers(include.clone(), &ignore, is_supported_bench_path)?;
+ let bench_modules = collect_specifiers(&files, is_supported_bench_path)?;
let mut paths_to_watch = paths_to_watch_clone;
let mut modules_to_reload = if files_changed {
@@ -615,7 +607,6 @@ pub async fn run_benchmarks_with_watch(
}
}
}
-
// This bench module and all it's dependencies
let mut modules = HashSet::new();
modules.insert(&specifier);
@@ -664,27 +655,27 @@ pub async fn run_benchmarks_with_watch(
};
let operation = |modules_to_reload: Vec<(ModuleSpecifier, ModuleKind)>| {
- let filter = bench_flags.filter.clone();
- let include = selection.include.clone();
- let ignore = selection.ignore.clone();
let permissions = permissions.clone();
let ps = ps.clone();
+ let filter = bench_options.filter.clone();
+ let files = bench_options.files.clone();
async move {
- let specifiers =
- collect_specifiers(include.clone(), &ignore, is_supported_bench_path)?
- .iter()
- .filter(|specifier| contains_specifier(&modules_to_reload, specifier))
- .cloned()
- .collect::<Vec<ModuleSpecifier>>();
+ let specifiers = collect_specifiers(&files, is_supported_bench_path)?
+ .iter()
+ .filter(|specifier| contains_specifier(&modules_to_reload, specifier))
+ .cloned()
+ .collect::<Vec<ModuleSpecifier>>();
check_specifiers(&ps, permissions.clone(), specifiers.clone()).await?;
- let specifier_options = BenchSpecifierOptions {
- filter: filter.clone(),
- };
- bench_specifiers(ps, permissions.clone(), specifiers, specifier_options)
- .await?;
+ bench_specifiers(
+ ps,
+ permissions.clone(),
+ specifiers,
+ BenchSpecifierOptions { filter },
+ )
+ .await?;
Ok(())
}
@@ -702,42 +693,3 @@ 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 }
-}