@@ -23,6 +23,8 @@ use std::process::Command;
2323use std:: str:: FromStr ;
2424use std:: { fmt, fs, io} ;
2525
26+ use build_helper:: util:: ensure_version_or_cargo_install;
27+
2628use crate :: CiInfo ;
2729
2830mod rustdoc_js;
@@ -293,7 +295,7 @@ fn check_impl(
293295 } else {
294296 eprintln ! ( "spellcheck files" ) ;
295297 }
296- spellcheck_runner ( & args) ?;
298+ spellcheck_runner ( & outdir , & args) ?;
297299 }
298300
299301 if js_lint || js_typecheck {
@@ -577,30 +579,8 @@ fn shellcheck_runner(args: &[&OsStr]) -> Result<(), Error> {
577579}
578580
579581/// Check that spellchecker is installed then run it at the given path
580- fn spellcheck_runner ( args : & [ & str ] ) -> Result < ( ) , Error > {
581- // sync version with .github/workflows/spellcheck.yml
582- let expected_version = "typos-cli 1.34.0" ;
583- match Command :: new ( "typos" ) . arg ( "--version" ) . output ( ) {
584- Ok ( o) => {
585- let stdout = String :: from_utf8_lossy ( & o. stdout ) ;
586- if stdout. trim ( ) != expected_version {
587- return Err ( Error :: Version {
588- program : "typos" ,
589- required : expected_version,
590- installed : stdout. trim ( ) . to_string ( ) ,
591- } ) ;
592- }
593- }
594- Err ( e) if e. kind ( ) == io:: ErrorKind :: NotFound => {
595- return Err ( Error :: MissingReq (
596- "typos" ,
597- "spellcheck file checks" ,
598- // sync version with .github/workflows/spellcheck.yml
599- Some ( "install tool via `cargo install [email protected] `" . to_owned ( ) ) , 600- ) ) ;
601- }
602- Err ( e) => return Err ( e. into ( ) ) ,
603- }
582+ fn spellcheck_runner ( outdir : & Path , args : & [ & str ] ) -> Result < ( ) , Error > {
583+ ensure_version_or_cargo_install ( outdir, "typos-cli" , "typos" , "1.34.0" ) ?;
604584
605585 let status = Command :: new ( "typos" ) . args ( args) . status ( ) ?;
606586 if status. success ( ) { Ok ( ( ) ) } else { Err ( Error :: FailedCheck ( "typos" ) ) }
0 commit comments