Skip to content

Commit

Permalink
Retry on ExecutableFileBusy (#403)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmichi authored Jan 20, 2022
1 parent 813fd22 commit 3495c43
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions src/cmd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,18 +515,27 @@ fn do_optimization(
///
/// Currently this must be a version >= 99.
fn check_wasm_opt_version_compatibility(wasm_opt_path: &Path) -> Result<()> {
let cmd = Command::new(wasm_opt_path)
.arg("--version")
.output()
.map_err(|err| {
anyhow::anyhow!(
"Executing `{:?} --version` failed with {:?}",
wasm_opt_path.display(),
err
)
})?;
if !cmd.status.success() {
let err = str::from_utf8(&cmd.stderr)
let mut cmd_res = Command::new(wasm_opt_path).arg("--version").output();

// The following condition is a workaround for a spurious CI failure:
// ```
// Executing `"/tmp/cargo-contract.test.GGnC0p/wasm-opt-mocked" --version` failed with
// Os { code: 26, kind: ExecutableFileBusy, message: "Text file busy" }
// ```
if cmd_res.is_err() && format!("{:?}", cmd_res).contains("ExecutableFileBusy") {
std::thread::sleep(std::time::Duration::from_secs(1));
cmd_res = Command::new(wasm_opt_path).arg("--version").output();
}

let res = cmd_res.map_err(|err| {
anyhow::anyhow!(
"Executing `{:?} --version` failed with {:?}",
wasm_opt_path.display(),
err
)
})?;
if !res.status.success() {
let err = str::from_utf8(&res.stderr)
.expect("Cannot convert stderr output of wasm-opt to string")
.trim();
anyhow::bail!(
Expand All @@ -545,7 +554,7 @@ fn check_wasm_opt_version_compatibility(wasm_opt_path: &Path) -> Result<()> {
way forward is to download a recent binary release directly:\n\n\
https://github.com/WebAssembly/binaryen/releases\n\n\
Make sure that the `wasm-opt` file from that release is in your `PATH`.";
let version_stdout = str::from_utf8(&cmd.stdout)
let version_stdout = str::from_utf8(&res.stdout)
.expect("Cannot convert stdout output of wasm-opt to string")
.trim();
let re = Regex::new(r"wasm-opt version (\d+)").expect("invalid regex");
Expand Down

0 comments on commit 3495c43

Please sign in to comment.