Skip to content

Commit 301170f

Browse files
authored
Uninstall old mdbook-linkcheck while installing project tools. (#2846)
Fixes #2773 .
1 parent 6d3dec9 commit 301170f

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

xtask/src/main.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use anyhow::{Ok, Result, anyhow};
2323
use clap::{Parser, Subcommand};
2424
use std::path::{Path, PathBuf};
25+
use std::process::Stdio;
2526
use std::{env, process::Command};
2627

2728
fn main() -> Result<()> {
@@ -128,9 +129,35 @@ fn install_tools() -> Result<()> {
128129
}
129130
}
130131

132+
// Uninstall original linkcheck if currently installed (see issue no 2773)
133+
uninstall_mdbook_linkcheck();
134+
131135
Ok(())
132136
}
133137

138+
fn uninstall_mdbook_linkcheck() {
139+
println!("Uninstalling old mdbook-linkcheck if installed...");
140+
let output = Command::new(env!("CARGO"))
141+
.arg("uninstall")
142+
.arg("mdbook-linkcheck")
143+
.output()
144+
.expect("Failed to execute cargo uninstall mdbook-linkcheck");
145+
146+
if !output.status.success() {
147+
if String::from_utf8_lossy(&output.stderr)
148+
.into_owned()
149+
.contains("did not match any packages")
150+
{
151+
println!("mdbook-linkcheck not installed. Continuing...");
152+
} else {
153+
eprintln!(
154+
"An error occurred during uninstallation of mdbook-linkcheck:\n{:#?}",
155+
String::from_utf8_lossy(&output.stderr)
156+
);
157+
}
158+
}
159+
}
160+
134161
fn run_web_tests(dir: Option<PathBuf>) -> Result<()> {
135162
println!("Running web tests...");
136163

0 commit comments

Comments
 (0)