From 3495c43b79df5fbbed71afa265a5a78e89e9de4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20M=C3=BCller?= Date: Thu, 20 Jan 2022 08:47:56 +0100 Subject: [PATCH] Retry on `ExecutableFileBusy` (#403) --- src/cmd/build.rs | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 02f3ae066..808822659 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -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!( @@ -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");