mirror of
https://github.com/denoland/deno.git
synced 2024-11-28 16:20:57 -05:00
feat(cli): support deno bench in the config file (#16608)
This PR adds the ability to set `include/exclude` fields for `deno bench` in the configuration file.
This commit is contained in:
parent
4eb8e875fd
commit
890b065310
13 changed files with 189 additions and 11 deletions
|
@ -429,6 +429,28 @@ pub struct TestConfig {
|
||||||
pub files: FilesConfig,
|
pub files: FilesConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Default, Deserialize)]
|
||||||
|
#[serde(default, deny_unknown_fields)]
|
||||||
|
struct SerializedBenchConfig {
|
||||||
|
pub files: SerializedFilesConfig,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SerializedBenchConfig {
|
||||||
|
pub fn into_resolved(
|
||||||
|
self,
|
||||||
|
config_file_specifier: &ModuleSpecifier,
|
||||||
|
) -> Result<BenchConfig, AnyError> {
|
||||||
|
Ok(BenchConfig {
|
||||||
|
files: self.files.into_resolved(config_file_specifier)?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Default)]
|
||||||
|
pub struct BenchConfig {
|
||||||
|
pub files: FilesConfig,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize)]
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
pub enum LockConfig {
|
pub enum LockConfig {
|
||||||
|
@ -445,6 +467,7 @@ pub struct ConfigFileJson {
|
||||||
pub fmt: Option<Value>,
|
pub fmt: Option<Value>,
|
||||||
pub tasks: Option<Value>,
|
pub tasks: Option<Value>,
|
||||||
pub test: Option<Value>,
|
pub test: Option<Value>,
|
||||||
|
pub bench: Option<Value>,
|
||||||
pub lock: Option<Value>,
|
pub lock: Option<Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -653,9 +676,19 @@ impl ConfigFile {
|
||||||
|
|
||||||
pub fn to_test_config(&self) -> Result<Option<TestConfig>, AnyError> {
|
pub fn to_test_config(&self) -> Result<Option<TestConfig>, AnyError> {
|
||||||
if let Some(config) = self.json.test.clone() {
|
if let Some(config) = self.json.test.clone() {
|
||||||
let lint_config: SerializedTestConfig = serde_json::from_value(config)
|
let test_config: SerializedTestConfig = serde_json::from_value(config)
|
||||||
.context("Failed to parse \"test\" configuration")?;
|
.context("Failed to parse \"test\" configuration")?;
|
||||||
Ok(Some(lint_config.into_resolved(&self.specifier)?))
|
Ok(Some(test_config.into_resolved(&self.specifier)?))
|
||||||
|
} else {
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn to_bench_config(&self) -> Result<Option<BenchConfig>, AnyError> {
|
||||||
|
if let Some(config) = self.json.bench.clone() {
|
||||||
|
let bench_config: SerializedBenchConfig = serde_json::from_value(config)
|
||||||
|
.context("Failed to parse \"bench\" configuration")?;
|
||||||
|
Ok(Some(bench_config.into_resolved(&self.specifier)?))
|
||||||
} else {
|
} else {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ mod lockfile;
|
||||||
|
|
||||||
mod flags_allow_net;
|
mod flags_allow_net;
|
||||||
|
|
||||||
|
pub use config_file::BenchConfig;
|
||||||
pub use config_file::CompilerOptions;
|
pub use config_file::CompilerOptions;
|
||||||
pub use config_file::ConfigFile;
|
pub use config_file::ConfigFile;
|
||||||
pub use config_file::EmitConfigOptions;
|
pub use config_file::EmitConfigOptions;
|
||||||
|
@ -401,6 +402,14 @@ impl CliOptions {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn to_bench_config(&self) -> Result<Option<BenchConfig>, AnyError> {
|
||||||
|
if let Some(config_file) = &self.maybe_config_file {
|
||||||
|
config_file.to_bench_config()
|
||||||
|
} else {
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn to_fmt_config(&self) -> Result<Option<FmtConfig>, AnyError> {
|
pub fn to_fmt_config(&self) -> Result<Option<FmtConfig>, AnyError> {
|
||||||
if let Some(config) = &self.maybe_config_file {
|
if let Some(config) = &self.maybe_config_file {
|
||||||
config.to_fmt_config()
|
config.to_fmt_config()
|
||||||
|
|
|
@ -356,6 +356,31 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"bench": {
|
||||||
|
"description": "Configuration for deno bench",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"files": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"include": {
|
||||||
|
"type": "array",
|
||||||
|
"description": "List of files or directories that will be searched for benchmarks.",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"exclude": {
|
||||||
|
"type": "array",
|
||||||
|
"description": "List of files or directories that will not be searched for benchmarks.",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"lock": {
|
"lock": {
|
||||||
"description": "Whether to use a lock file or the path to use for the lock file. Can be overridden by CLI arguments.",
|
"description": "Whether to use a lock file or the path to use for the lock file. Can be overridden by CLI arguments.",
|
||||||
"type": ["string", "boolean"],
|
"type": ["string", "boolean"],
|
||||||
|
|
|
@ -165,6 +165,24 @@ mod bench {
|
||||||
exit_code: 1,
|
exit_code: 1,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
itest!(bench_with_config {
|
||||||
|
args: "bench --config bench/collect/deno.jsonc bench/collect",
|
||||||
|
exit_code: 0,
|
||||||
|
output: "bench/collect.out",
|
||||||
|
});
|
||||||
|
|
||||||
|
itest!(bench_with_config2 {
|
||||||
|
args: "bench --config bench/collect/deno2.jsonc bench/collect",
|
||||||
|
exit_code: 0,
|
||||||
|
output: "bench/collect2.out",
|
||||||
|
});
|
||||||
|
|
||||||
|
itest!(bench_with_malformed_config {
|
||||||
|
args: "bench --config bench/collect/deno.malformed.jsonc",
|
||||||
|
exit_code: 1,
|
||||||
|
output: "bench/collect_with_malformed_config.out",
|
||||||
|
});
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn recursive_permissions_pledge() {
|
fn recursive_permissions_pledge() {
|
||||||
let output = util::deno_cmd()
|
let output = util::deno_cmd()
|
||||||
|
|
10
cli/tests/testdata/bench/collect.out
vendored
10
cli/tests/testdata/bench/collect.out
vendored
|
@ -1,7 +1,17 @@
|
||||||
Check [WILDCARD]/bench/collect/bench.ts
|
Check [WILDCARD]/bench/collect/bench.ts
|
||||||
|
Check [WILDCARD]/bench/collect/include/2_bench.ts
|
||||||
|
Check [WILDCARD]/bench/collect/include/bench.ts
|
||||||
cpu: [WILDCARD]
|
cpu: [WILDCARD]
|
||||||
runtime: deno [WILDCARD] ([WILDCARD])
|
runtime: deno [WILDCARD] ([WILDCARD])
|
||||||
|
|
||||||
[WILDCARD]/bench/collect/bench.ts
|
[WILDCARD]/bench/collect/bench.ts
|
||||||
benchmark time (avg) (min … max) p75 p99 p995
|
benchmark time (avg) (min … max) p75 p99 p995
|
||||||
------------------------------------------------- -----------------------------
|
------------------------------------------------- -----------------------------
|
||||||
|
|
||||||
|
[WILDCARD]/bench/collect/include/2_bench.ts
|
||||||
|
benchmark time (avg) (min … max) p75 p99 p995
|
||||||
|
------------------------------------------------- -----------------------------
|
||||||
|
|
||||||
|
[WILDCARD]/bench/collect/include/bench.ts
|
||||||
|
benchmark time (avg) (min … max) p75 p99 p995
|
||||||
|
------------------------------------------------- -----------------------------
|
||||||
|
|
7
cli/tests/testdata/bench/collect/deno.jsonc
vendored
Normal file
7
cli/tests/testdata/bench/collect/deno.jsonc
vendored
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"bench": {
|
||||||
|
"files": {
|
||||||
|
"exclude": ["./ignore"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
5
cli/tests/testdata/bench/collect/deno.malformed.jsonc
vendored
Normal file
5
cli/tests/testdata/bench/collect/deno.malformed.jsonc
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"bench": {
|
||||||
|
"dont_know_this_field": {}
|
||||||
|
}
|
||||||
|
}
|
8
cli/tests/testdata/bench/collect/deno2.jsonc
vendored
Normal file
8
cli/tests/testdata/bench/collect/deno2.jsonc
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"bench": {
|
||||||
|
"files": {
|
||||||
|
"include": ["./include/"],
|
||||||
|
"exclude": ["./ignore", "./include/2_bench.ts"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
0
cli/tests/testdata/bench/collect/include/2_bench.ts
vendored
Normal file
0
cli/tests/testdata/bench/collect/include/2_bench.ts
vendored
Normal file
0
cli/tests/testdata/bench/collect/include/bench.ts
vendored
Normal file
0
cli/tests/testdata/bench/collect/include/bench.ts
vendored
Normal file
12
cli/tests/testdata/bench/collect2.out
vendored
Normal file
12
cli/tests/testdata/bench/collect2.out
vendored
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
Check [WILDCARD]/bench/collect/bench.ts
|
||||||
|
Check [WILDCARD]/bench/collect/include/bench.ts
|
||||||
|
cpu: [WILDCARD]
|
||||||
|
runtime: deno [WILDCARD] ([WILDCARD])
|
||||||
|
|
||||||
|
[WILDCARD]/bench/collect/bench.ts
|
||||||
|
benchmark time (avg) (min … max) p75 p99 p995
|
||||||
|
------------------------------------------------- -----------------------------
|
||||||
|
|
||||||
|
[WILDCARD]/bench/collect/include/bench.ts
|
||||||
|
benchmark time (avg) (min … max) p75 p99 p995
|
||||||
|
------------------------------------------------- -----------------------------
|
4
cli/tests/testdata/bench/collect_with_malformed_config.out
vendored
Normal file
4
cli/tests/testdata/bench/collect_with_malformed_config.out
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
error: Failed to parse "bench" configuration
|
||||||
|
|
||||||
|
Caused by:
|
||||||
|
unknown field `dont_know_this_field`, expected `files`
|
|
@ -1,5 +1,6 @@
|
||||||
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
|
use crate::args::BenchConfig;
|
||||||
use crate::args::BenchFlags;
|
use crate::args::BenchFlags;
|
||||||
use crate::args::Flags;
|
use crate::args::Flags;
|
||||||
use crate::args::TypeCheckMode;
|
use crate::args::TypeCheckMode;
|
||||||
|
@ -14,6 +15,7 @@ use crate::util::file_watcher;
|
||||||
use crate::util::file_watcher::ResolutionResult;
|
use crate::util::file_watcher::ResolutionResult;
|
||||||
use crate::util::fs::collect_specifiers;
|
use crate::util::fs::collect_specifiers;
|
||||||
use crate::util::path::is_supported_ext;
|
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 crate::worker::create_main_worker_for_test_or_bench;
|
||||||
|
|
||||||
use deno_core::error::generic_error;
|
use deno_core::error::generic_error;
|
||||||
|
@ -490,9 +492,13 @@ pub async fn run_benchmarks(
|
||||||
let ps = ProcState::build(flags).await?;
|
let ps = ProcState::build(flags).await?;
|
||||||
let permissions =
|
let permissions =
|
||||||
Permissions::from_options(&ps.options.permissions_options())?;
|
Permissions::from_options(&ps.options.permissions_options())?;
|
||||||
|
|
||||||
|
let selection =
|
||||||
|
collect_include_ignore(&bench_flags, ps.options.to_bench_config()?);
|
||||||
|
|
||||||
let specifiers = collect_specifiers(
|
let specifiers = collect_specifiers(
|
||||||
bench_flags.include.unwrap_or_else(|| vec![".".to_string()]),
|
selection.include,
|
||||||
&bench_flags.ignore.clone(),
|
&selection.ignore,
|
||||||
is_supported_bench_path,
|
is_supported_bench_path,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
@ -524,9 +530,11 @@ pub async fn run_benchmarks_with_watch(
|
||||||
let permissions =
|
let permissions =
|
||||||
Permissions::from_options(&ps.options.permissions_options())?;
|
Permissions::from_options(&ps.options.permissions_options())?;
|
||||||
|
|
||||||
let include = bench_flags.include.unwrap_or_else(|| vec![".".to_string()]);
|
let selection =
|
||||||
let ignore = bench_flags.ignore.clone();
|
collect_include_ignore(&bench_flags, ps.options.to_bench_config()?);
|
||||||
let paths_to_watch: Vec<_> = include.iter().map(PathBuf::from).collect();
|
|
||||||
|
let paths_to_watch: Vec<_> =
|
||||||
|
selection.include.iter().map(PathBuf::from).collect();
|
||||||
let no_check = ps.options.type_check_mode() == TypeCheckMode::None;
|
let no_check = ps.options.type_check_mode() == TypeCheckMode::None;
|
||||||
|
|
||||||
let resolver = |changed: Option<Vec<PathBuf>>| {
|
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 paths_to_watch_clone = paths_to_watch.clone();
|
||||||
|
|
||||||
let files_changed = changed.is_some();
|
let files_changed = changed.is_some();
|
||||||
let include = include.clone();
|
let include = selection.include.clone();
|
||||||
let ignore = ignore.clone();
|
let ignore = selection.ignore.clone();
|
||||||
let ps = ps.clone();
|
let ps = ps.clone();
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
|
@ -650,8 +658,8 @@ pub async fn run_benchmarks_with_watch(
|
||||||
|
|
||||||
let operation = |modules_to_reload: Vec<(ModuleSpecifier, ModuleKind)>| {
|
let operation = |modules_to_reload: Vec<(ModuleSpecifier, ModuleKind)>| {
|
||||||
let filter = bench_flags.filter.clone();
|
let filter = bench_flags.filter.clone();
|
||||||
let include = include.clone();
|
let include = selection.include.clone();
|
||||||
let ignore = ignore.clone();
|
let ignore = selection.ignore.clone();
|
||||||
let permissions = permissions.clone();
|
let permissions = permissions.clone();
|
||||||
let ps = ps.clone();
|
let ps = ps.clone();
|
||||||
|
|
||||||
|
@ -687,3 +695,42 @@ pub async fn run_benchmarks_with_watch(
|
||||||
|
|
||||||
Ok(())
|
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 }
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue