@@ -41,7 +41,6 @@ const RUFF_CONFIG_PATH: &[&str] = &["src", "tools", "tidy", "config", "ruff.toml
41
41
const RUFF_CACHE_PATH : & [ & str ] = & [ "cache" , "ruff_cache" ] ;
42
42
const PIP_REQ_PATH : & [ & str ] = & [ "src" , "tools" , "tidy" , "config" , "requirements.txt" ] ;
43
43
44
- // this must be kept in sync with with .github/workflows/spellcheck.yml
45
44
const SPELLCHECK_DIRS : & [ & str ] = & [ "compiler" , "library" , "src/bootstrap" , "src/librustdoc" ] ;
46
45
47
46
pub fn check (
@@ -51,6 +50,7 @@ pub fn check(
51
50
librustdoc_path : & Path ,
52
51
tools_path : & Path ,
53
52
npm : & Path ,
53
+ cargo : & Path ,
54
54
bless : bool ,
55
55
extra_checks : Option < & str > ,
56
56
pos_args : & [ String ] ,
@@ -63,6 +63,7 @@ pub fn check(
63
63
librustdoc_path,
64
64
tools_path,
65
65
npm,
66
+ cargo,
66
67
bless,
67
68
extra_checks,
68
69
pos_args,
@@ -78,6 +79,7 @@ fn check_impl(
78
79
librustdoc_path : & Path ,
79
80
tools_path : & Path ,
80
81
npm : & Path ,
82
+ cargo : & Path ,
81
83
bless : bool ,
82
84
extra_checks : Option < & str > ,
83
85
pos_args : & [ String ] ,
@@ -293,7 +295,7 @@ fn check_impl(
293
295
} else {
294
296
eprintln ! ( "spellcheck files" ) ;
295
297
}
296
- spellcheck_runner ( & args) ?;
298
+ spellcheck_runner ( root_path , & outdir , & cargo , & args) ?;
297
299
}
298
300
299
301
if js_lint || js_typecheck {
@@ -576,34 +578,25 @@ fn shellcheck_runner(args: &[&OsStr]) -> Result<(), Error> {
576
578
if status. success ( ) { Ok ( ( ) ) } else { Err ( Error :: FailedCheck ( "shellcheck" ) ) }
577
579
}
578
580
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" ) )
592
596
}
593
597
}
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:?}" ) ) ) ,
603
599
}
604
-
605
- let status = Command :: new ( "typos" ) . args ( args) . status ( ) ?;
606
- if status. success ( ) { Ok ( ( ) ) } else { Err ( Error :: FailedCheck ( "typos" ) ) }
607
600
}
608
601
609
602
/// Check git for tracked files matching an extension
0 commit comments