@@ -23,6 +23,8 @@ use std::process::Command;
23
23
use std:: str:: FromStr ;
24
24
use std:: { fmt, fs, io} ;
25
25
26
+ use build_helper:: util:: ensure_version_or_cargo_install;
27
+
26
28
use crate :: CiInfo ;
27
29
28
30
mod rustdoc_js;
@@ -293,7 +295,7 @@ fn check_impl(
293
295
} else {
294
296
eprintln ! ( "spellcheck files" ) ;
295
297
}
296
- spellcheck_runner ( & args) ?;
298
+ spellcheck_runner ( & outdir , & args) ?;
297
299
}
298
300
299
301
if js_lint || js_typecheck {
@@ -577,32 +579,10 @@ fn shellcheck_runner(args: &[&OsStr]) -> Result<(), Error> {
577
579
}
578
580
579
581
/// 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
+ let bin_path = ensure_version_or_cargo_install ( outdir, "typos-cli" , "typos" , "1.34.0" ) ?;
604
584
605
- let status = Command :: new ( "typos" ) . args ( args) . status ( ) ?;
585
+ let status = Command :: new ( bin_path ) . args ( args) . status ( ) ?;
606
586
if status. success ( ) { Ok ( ( ) ) } else { Err ( Error :: FailedCheck ( "typos" ) ) }
607
587
}
608
588
0 commit comments