diff --git a/crates/qt-build-utils/src/installation/qmake.rs b/crates/qt-build-utils/src/installation/qmake.rs index 920a48cf3..949e06ac0 100644 --- a/crates/qt-build-utils/src/installation/qmake.rs +++ b/crates/qt-build-utils/src/installation/qmake.rs @@ -102,10 +102,8 @@ impl TryFrom for QtInstallationQMake { fn try_from(qmake_path: PathBuf) -> anyhow::Result { // Attempt to read the QT_VERSION from qmake - let qmake_version = match Command::new(&qmake_path) - .args(["-query", "QT_VERSION"]) - .output() - { + let qmake_command: String = format!("{} -query QT_VERSION", qmake_path.to_string_lossy()); + let qmake_version = match utils::native_shell_command(&qmake_command).output() { Err(e) if e.kind() == ErrorKind::NotFound => Err(QtBuildError::QtMissing), Err(e) => Err(QtBuildError::QmakeFailed(e)), Ok(output) if !output.status.success() => Err(QtBuildError::QtMissing), @@ -373,9 +371,9 @@ impl QtInstallationQMake { } fn qmake_query(&self, var_name: &str) -> String { + let qmake_command = format!("{} -query {}", self.qmake_path.to_string_lossy(), var_name); String::from_utf8_lossy( - &Command::new(&self.qmake_path) - .args(["-query", var_name]) + &utils::native_shell_command(&qmake_command) .output() .unwrap() .stdout, diff --git a/crates/qt-build-utils/src/utils.rs b/crates/qt-build-utils/src/utils.rs index 347846276..a3c01afec 100644 --- a/crates/qt-build-utils/src/utils.rs +++ b/crates/qt-build-utils/src/utils.rs @@ -3,6 +3,8 @@ // // SPDX-License-Identifier: MIT OR Apache-2.0 +use std::process::Command; + /// Whether apple is the current target pub(crate) fn is_apple_target() -> bool { std::env::var("TARGET") @@ -14,3 +16,16 @@ pub(crate) fn is_apple_target() -> bool { pub(crate) fn is_emscripten_target() -> bool { std::env::var("CARGO_CFG_TARGET_OS") == Ok("emscripten".to_owned()) } + +/// Wrap a command in a native subshell +pub(crate) fn native_shell_command(command: &str) -> Command { + let mut result: Command; + if cfg!(target_os = "windows") { + result = Command::new("cmd"); + result.args(["/C", command]); + } else { + result = Command::new("sh"); + result.args(["-c", command]); + } + result +}