@@ -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 ( root_path , & outdir , & cargo , & args) ?;
297299 }
298300
299301 if js_lint || js_typecheck {
@@ -576,34 +578,25 @@ 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- } ) ;
581+ /// Ensure that spellchecker is installed then run it at the given path
582+ fn spellcheck_runner (
583+ src_root : & Path ,
584+ outdir : & Path ,
585+ cargo : & Path ,
586+ args : & [ & str ] ,
587+ ) -> Result < ( ) , Error > {
588+ let bin_path =
589+ crate :: ensure_version_or_cargo_install ( outdir, cargo, "typos-cli" , "typos" , "1.34.0" ) ?;
590+ match Command :: new ( bin_path) . current_dir ( src_root) . args ( args) . status ( ) {
591+ Ok ( status) => {
592+ if status. success ( ) {
593+ Ok ( ( ) )
594+ } else {
595+ Err ( Error :: FailedCheck ( "typos" ) )
592596 }
593597 }
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 ( ) ) ,
598+ Err ( err) => Err ( Error :: Generic ( format ! ( "failed to run typos tool: {err:?}" ) ) ) ,
603599 }
604-
605- let status = Command :: new ( "typos" ) . args ( args) . status ( ) ?;
606- if status. success ( ) { Ok ( ( ) ) } else { Err ( Error :: FailedCheck ( "typos" ) ) }
607600}
608601
609602/// Check git for tracked files matching an extension
0 commit comments