Skip to content

Commit 4eb6b8f

Browse files
authored
Rollup merge of #147120 - Shunpoco:issue-147105, r=Kobzol
Fix --extra-checks=spellcheck to prevent cargo install every time Fixes #147105 ## Background Current implementation of `ensure_version_of_cargo_install` uses `bin_name` to check if it exists, but it should use `<tool_root_dir>/<tool_bin_dir>/<bin_name>` instead. Otherwise the check fails every time, hence the function falls back to install the binary. ## Change Move lines which define bin_path at the top of the function, and use bin_path for the check
2 parents aa6bd55 + 5e9cab3 commit 4eb6b8f

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/tools/tidy/src/lib.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,16 @@ pub fn ensure_version_or_cargo_install(
167167
bin_name: &str,
168168
version: &str,
169169
) -> io::Result<PathBuf> {
170+
let tool_root_dir = build_dir.join("misc-tools");
171+
let tool_bin_dir = tool_root_dir.join("bin");
172+
let bin_path = tool_bin_dir.join(bin_name).with_extension(env::consts::EXE_EXTENSION);
173+
170174
// ignore the process exit code here and instead just let the version number check fail.
171175
// we also importantly don't return if the program wasn't installed,
172176
// instead we want to continue to the fallback.
173177
'ck: {
174178
// FIXME: rewrite as if-let chain once this crate is 2024 edition.
175-
let Ok(output) = Command::new(bin_name).arg("--version").output() else {
179+
let Ok(output) = Command::new(&bin_path).arg("--version").output() else {
176180
break 'ck;
177181
};
178182
let Ok(s) = str::from_utf8(&output.stdout) else {
@@ -182,12 +186,10 @@ pub fn ensure_version_or_cargo_install(
182186
break 'ck;
183187
};
184188
if v == version {
185-
return Ok(PathBuf::from(bin_name));
189+
return Ok(bin_path);
186190
}
187191
}
188192

189-
let tool_root_dir = build_dir.join("misc-tools");
190-
let tool_bin_dir = tool_root_dir.join("bin");
191193
eprintln!("building external tool {bin_name} from package {pkg_name}@{version}");
192194
// use --force to ensure that if the required version is bumped, we update it.
193195
// use --target-dir to ensure we have a build cache so repeated invocations aren't slow.
@@ -213,7 +215,6 @@ pub fn ensure_version_or_cargo_install(
213215
if !cargo_exit_code.success() {
214216
return Err(io::Error::other("cargo install failed"));
215217
}
216-
let bin_path = tool_bin_dir.join(bin_name).with_extension(env::consts::EXE_EXTENSION);
217218
assert!(
218219
matches!(bin_path.try_exists(), Ok(true)),
219220
"cargo install did not produce the expected binary"

0 commit comments

Comments
 (0)