Skip to content

qt-build-utils can invoke qmake when it is a script #1284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions crates/qt-build-utils/src/installation/qmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,8 @@ impl TryFrom<PathBuf> for QtInstallationQMake {

fn try_from(qmake_path: PathBuf) -> anyhow::Result<Self> {
// 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),
Expand Down Expand Up @@ -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,
Expand Down
15 changes: 15 additions & 0 deletions crates/qt-build-utils/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
}
Loading