diff options
Diffstat (limited to 'dom/webgpu/tests/cts/vendor/src')
-rw-r--r-- | dom/webgpu/tests/cts/vendor/src/fs.rs | 33 | ||||
-rw-r--r-- | dom/webgpu/tests/cts/vendor/src/main.rs | 49 |
2 files changed, 65 insertions, 17 deletions
diff --git a/dom/webgpu/tests/cts/vendor/src/fs.rs b/dom/webgpu/tests/cts/vendor/src/fs.rs index 31697f9758..3062f27cdb 100644 --- a/dom/webgpu/tests/cts/vendor/src/fs.rs +++ b/dom/webgpu/tests/cts/vendor/src/fs.rs @@ -245,15 +245,6 @@ impl Display for Child<'_> { } } -pub(crate) fn existing_file<P>(path: P) -> P -where - P: AsRef<Path>, -{ - let p = path.as_ref(); - assert!(p.is_file(), "{p:?} does not exist as a file"); - path -} - pub(crate) fn copy_dir<P, Q>(source: P, dest: Q) -> miette::Result<()> where P: Display + AsRef<Path>, @@ -297,6 +288,30 @@ where }) } +pub(crate) fn rename<P1, P2>(from: P1, to: P2) -> miette::Result<()> +where + P1: AsRef<Path>, + P2: AsRef<Path>, +{ + fs::rename(&from, &to).into_diagnostic().wrap_err_with(|| { + format!( + "failed to rename {} to {}", + from.as_ref().display(), + to.as_ref().display() + ) + }) +} + +pub(crate) fn try_exists<P>(path: P) -> miette::Result<bool> +where + P: AsRef<Path>, +{ + let path = path.as_ref(); + path.try_exists() + .into_diagnostic() + .wrap_err_with(|| format!("failed to check if path exists: {}", path.display())) +} + pub(crate) fn create_dir_all<P>(path: P) -> miette::Result<()> where P: AsRef<Path>, diff --git a/dom/webgpu/tests/cts/vendor/src/main.rs b/dom/webgpu/tests/cts/vendor/src/main.rs index 750b65c62e..1171c90b3a 100644 --- a/dom/webgpu/tests/cts/vendor/src/main.rs +++ b/dom/webgpu/tests/cts/vendor/src/main.rs @@ -6,12 +6,13 @@ use std::{ }; use clap::Parser; +use itertools::Itertools; use lets_find_up::{find_up_with, FindUpKind, FindUpOptions}; use miette::{bail, ensure, miette, Context, Diagnostic, IntoDiagnostic, Report, SourceSpan}; use regex::Regex; use crate::{ - fs::{copy_dir, create_dir_all, existing_file, remove_file, FileRoot}, + fs::{copy_dir, create_dir_all, remove_file, FileRoot}, path::join_path, process::{which, EasyCommand}, }; @@ -277,13 +278,6 @@ fn run(args: CliArgs) -> miette::Result<()> { })?; let cts_https_html_path = out_wpt_dir.child("cts.https.html"); - log::info!("refining the output of {cts_https_html_path} with `npm run gen_wpt_cts_html …`…"); - EasyCommand::new(&npm_bin, |cmd| { - cmd.args(["run", "gen_wpt_cts_html"]).arg(existing_file( - &cts_ckt.child("tools/gen_wpt_cfg_unchunked.json"), - )) - }) - .spawn()?; { let extra_cts_https_html_path = out_wpt_dir.child("cts-chunked2sec.https.html"); @@ -551,6 +545,45 @@ fn run(args: CliArgs) -> miette::Result<()> { log::info!(" …removing {cts_https_html_path}, now that it's been divided up…"); remove_file(&cts_https_html_path)?; + log::info!("moving ready-to-go WPT test files into `cts`…"); + + let webgpu_dir = out_wpt_dir.child("webgpu"); + let ready_to_go_tests = wax::Glob::new("**/*.{html,{any,sub,worker}.js}") + .unwrap() + .walk(&webgpu_dir) + .map_ok(|entry| webgpu_dir.child(entry.into_path())) + .collect::<Result<Vec<_>, _>>() + .map_err(Report::msg) + .wrap_err_with(|| { + format!("failed to walk {webgpu_dir} for ready-to-go WPT test files") + })?; + + log::trace!(" …will move the following: {ready_to_go_tests:#?}"); + + for file in ready_to_go_tests { + let path_relative_to_webgpu_dir = file.strip_prefix(&webgpu_dir).unwrap(); + let dst_path = cts_tests_dir.child(path_relative_to_webgpu_dir); + log::trace!("…moving {file} to {dst_path}…"); + ensure!( + !fs::try_exists(&dst_path)?, + "internal error: duplicate path found while moving ready-to-go test {} to {}", + file, + dst_path, + ); + fs::create_dir_all(dst_path.parent().unwrap()).wrap_err_with(|| { + format!( + concat!( + "failed to create destination parent dirs. ", + "while recursively moving from {} to {}", + ), + file, dst_path, + ) + })?; + fs::rename(&file, &dst_path) + .wrap_err_with(|| format!("failed to move {file} to {dst_path}"))?; + } + log::debug!(" …finished moving ready-to-go WPT test files"); + Ok(()) })?; |