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

Conversation

SanderVocke
Copy link
Contributor

Ensure qmake is called either through cmd (Windows) or sh (Linux/MacOS).

The main change is this invocation. The rest of the code change is:

  • There were two places qmake were previously invoked and they didn't share code. To prevent duplicating this shell wrapper, refactored a bit to ensure they both call the same method to query qmake.
  • Due to said refactoring, also had to change the error handling a bit because the error generation moved. Added error types.

@SanderVocke
Copy link
Contributor Author

SanderVocke commented May 22, 2025

I only tested this so far on the "happy case" on Windows (that is to say: when using a qmake .bat wrapper). Will test on other platforms too.

@SanderVocke SanderVocke marked this pull request as draft May 22, 2025 18:54
@SanderVocke SanderVocke marked this pull request as ready for review May 23, 2025 09:15
@SanderVocke
Copy link
Contributor Author

SanderVocke commented May 23, 2025

I marked as ready for review.
Tested all combinations of QMAKE=qmake6 and QMAKE=(a qmake wrapper).[sh|bat] on Windows, Ubuntu and MacOS GitHub runners and cxx-qt builds fine with these combinations.

Copy link

codecov bot commented May 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (cb64b22) to head (7db4d04).

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1284   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           75        75           
  Lines        12772     12772           
=========================================
  Hits         12772     12772           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@SanderVocke SanderVocke marked this pull request as draft May 23, 2025 10:03
@SanderVocke SanderVocke force-pushed the support_qmake_scripts branch 4 times, most recently from f08b25c to e4ef4fa Compare June 11, 2025 14:18
@SanderVocke SanderVocke force-pushed the support_qmake_scripts branch from e4ef4fa to 031f080 Compare June 11, 2025 14:33
@SanderVocke SanderVocke marked this pull request as ready for review June 11, 2025 17:33
@SanderVocke
Copy link
Contributor Author

In the refactored qt-build-utils, the change was a lot more straightforward.

@SanderVocke
Copy link
Contributor Author

@ahayzen-kdab is this still on your radar?

/// 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") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we do this at build time with #[cfg(...)] rather than at runtime with cfg! ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ahayzen-kdab I actually prefer sticking with cfg! here.
AFAIK, the cfg! macro evaluates to a bool literal.
This should allow the compiler to optimize out the branches that are not used by the current cfg, but will still check that the alternative branches compile.

With #[cfg()] if you compile on Linux you will not notice if the windows part of the branch has an error that could be caught at compile-time.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess, just elsewhere where we have similar things they are at compile time and in theory CI picks up any Windows failures :-) But sure we can keep it this way for now...

Copy link
Collaborator

@LeonMatthesKDAB LeonMatthesKDAB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @SanderVocke, overall I'm in favor of adding support for this, especially for the Windows case, where you can't just make a script an executable.

I'm somewhat concerned about possible regressions to invoking plain qmake binaries (especially on Unix where it is already possible to just make any script an executable).

We definitely need to be careful around handling of spaces, as I think that is now broken.

Maybe a good way to handle this could be:
Only wrap the executable in a native shell command on Windows, and only if it matches the .bat extension.
Checking the file extension would also allow us to add support for e.g. powershell instead of cmd via checking for the .ps1 extension.

Do you think this would fit the use case on Windows? As I think on Windows we can rely on these extensions to be there, which is not necessarily the case on Linux.

@@ -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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe passing the command as a plain string here will fail if the path to qmake contains a space.

As this path is provided by the user, we must ensure this works as well.
Please make sure that we can handle paths with spaces.

I suggest adding a testcase for this by adding a test scripts/ folder that contains a qmake.sh and qmake.bat script that just echo a string or forward to qmake.

if cfg!(target_os = "windows") {
result = Command::new("cmd");
result.args(["/C", command]);
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use an else if that actively lists the operating systems that we expect to have an sh binary and fall back to a plain Command in the other cases, as otherwise this will break on any OS that does not have an sh binary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants