@@ -41,7 +41,6 @@ const RUFF_CONFIG_PATH: &[&str] = &["src", "tools", "tidy", "config", "ruff.toml
4141const RUFF_CACHE_PATH : & [ & str ] = & [ "cache" , "ruff_cache" ] ;
4242const PIP_REQ_PATH : & [ & str ] = & [ "src" , "tools" , "tidy" , "config" , "requirements.txt" ] ;
4343
44- // this must be kept in sync with with .github/workflows/spellcheck.yml
4544const SPELLCHECK_DIRS : & [ & str ] = & [ "compiler" , "library" , "src/bootstrap" , "src/librustdoc" ] ;
4645
4746pub fn check (
@@ -51,6 +50,7 @@ pub fn check(
5150 librustdoc_path : & Path ,
5251 tools_path : & Path ,
5352 npm : & Path ,
53+ cargo : & Path ,
5454 bless : bool ,
5555 extra_checks : Option < & str > ,
5656 pos_args : & [ String ] ,
@@ -63,6 +63,7 @@ pub fn check(
6363 librustdoc_path,
6464 tools_path,
6565 npm,
66+ cargo,
6667 bless,
6768 extra_checks,
6869 pos_args,
@@ -78,6 +79,7 @@ fn check_impl(
7879 librustdoc_path : & Path ,
7980 tools_path : & Path ,
8081 npm : & Path ,
82+ cargo : & Path ,
8183 bless : bool ,
8284 extra_checks : Option < & str > ,
8385 pos_args : & [ String ] ,
@@ -293,7 +295,7 @@ fn check_impl(
293295 } else {
294296 eprintln ! ( "spellcheck files" ) ;
295297 }
296- spellcheck_runner ( & args) ?;
298+ spellcheck_runner ( & outdir , & cargo , & args) ?;
297299 }
298300
299301 if js_lint || js_typecheck {
@@ -576,33 +578,12 @@ fn shellcheck_runner(args: &[&OsStr]) -> Result<(), Error> {
576578 if status. success ( ) { Ok ( ( ) ) } else { Err ( Error :: FailedCheck ( "shellcheck" ) ) }
577579}
578580
579- /// 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 typos-cli@1.34.0`" . to_owned ( ) ) ,
600- ) ) ;
601- }
602- Err ( e) => return Err ( e. into ( ) ) ,
603- }
581+ /// Ensure that spellchecker is installed then run it at the given path
582+ fn spellcheck_runner ( outdir : & Path , cargo : & Path , args : & [ & str ] ) -> Result < ( ) , Error > {
583+ let bin_path =
584+ crate :: ensure_version_or_cargo_install ( outdir, cargo, "typos-cli" , "typos" , "1.34.0" ) ?;
604585
605- let status = Command :: new ( "typos" ) . args ( args) . status ( ) ?;
586+ let status = Command :: new ( bin_path ) . args ( args) . status ( ) ?;
606587 if status. success ( ) { Ok ( ( ) ) } else { Err ( Error :: FailedCheck ( "typos" ) ) }
607588}
608589
0 commit comments