Skip to content

fix(build): workaround qt_add_shaders bug with '@' in build path#864

Open
glyvut wants to merge 1 commit into
linuxdeepin:masterfrom
glyvut:cmakepath
Open

fix(build): workaround qt_add_shaders bug with '@' in build path#864
glyvut wants to merge 1 commit into
linuxdeepin:masterfrom
glyvut:cmakepath

Conversation

@glyvut
Copy link
Copy Markdown

@glyvut glyvut commented May 14, 2026

Replace qt_add_shaders with treeland_add_shaders using add_custom_command to invoke Qt6::qsb directly, avoiding the '@' splitting bug in Qt6ShaderToolsMacros.cmake.

替换 qt_add_shaders 为自定义的 treeland_add_shaders,通过 add_custom_command 直接调用 Qt6::qsb,绕过 Qt6ShaderToolsMacros.cmake 中 '@' 字符被错误拆分的 bug。

Log: 修复构建路径含 '@' 时着色器编译失败的问题
Issue: Fixes #845
Influence: 构建目录路径包含 '@' 字符(如 /tmp/u@123)时不再编译失败。

Summary by Sourcery

Work around a Qt shader compilation bug by replacing direct use of qt_add_shaders with a custom helper that invokes qsb explicitly and packages the generated shader binaries as resources.

Bug Fixes:

  • Prevent shader compilation failures when the build directory path contains the '@' character by avoiding the buggy qt_add_shaders macro.

Enhancements:

  • Introduce a treeland_add_shaders CMake helper function to generate shader binaries via Qt6::qsb and register them as resources in the build.

Replace qt_add_shaders with treeland_add_shaders using add_custom_command
to invoke Qt6::qsb directly, avoiding the '@' splitting bug in
Qt6ShaderToolsMacros.cmake.

替换 qt_add_shaders 为自定义的 treeland_add_shaders,通过 add_custom_command
直接调用 Qt6::qsb,绕过 Qt6ShaderToolsMacros.cmake 中 '@' 字符被错误拆分的 bug。

Log: 修复构建路径含 '@' 时着色器编译失败的问题
Issue: Fixes linuxdeepin#845
Influence: 构建目录路径包含 '@' 字符(如 /tmp/u@123)时不再编译失败。
@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: glyvut

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@deepin-ci-robot
Copy link
Copy Markdown

Hi @glyvut. Thanks for your PR.

I'm waiting for a linuxdeepin member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@github-actions
Copy link
Copy Markdown

CLA Assistant Lite bot:
提交邮箱中包含我们的合作伙伴,但您似乎并非合作伙伴的成员或对接人,请联系相关对接人将您添加至组织之中,或由其重新发起 Pull Request。
The commit email domain belongs to one of our partners, but it seems you are not yet a member of the current organization, please contact the contact person to add you to the organization or let them submit the Pull Request.

You can retrigger this bot by commenting recheck in this Pull Request

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 14, 2026

Reviewer's Guide

Replaces usage of qt_add_shaders with a custom treeland_add_shaders CMake helper that calls Qt6::qsb via add_custom_command to avoid a Qt shader tools bug when build paths contain '@', and wires the generated .qsb files into qt_add_resources for libtreeland.

File-Level Changes

Change Details Files
Introduce treeland_add_shaders CMake function to manually invoke Qt6::qsb and register generated shader artifacts.
  • Parse BATCHABLE, PRECOMPILE, PREFIX, BASE, and FILES arguments using cmake_parse_arguments for a new treeland_add_shaders(target, resourcename, ...) helper.
  • For each shader source file, compute an output .qsb path under CMAKE_CURRENT_BINARY_DIR/.qsb and create an add_custom_command that runs Qt6::qsb with --qt6 and an optional --batchable flag.
  • Mark generated .qsb files as GENERATED and collect them into a list of qsb_outputs.
  • Create a custom target _gen depending on all qsb_outputs and add it as a build dependency of the main target.
  • Feed the generated .qsb outputs into qt_add_resources with the provided PREFIX and BASE so they are included as resources.
cmake/DefineTarget.cmake
Switch shader build for libtreeland to use treeland_add_shaders instead of qt_add_shaders.
  • Replace the qt_add_shaders invocation for libtreeland with treeland_add_shaders while keeping the same target name and resource name.
  • Drop the PRECOMPILE option, relying on the new manual qsb invocation instead, and keep BATCHABLE, PREFIX, BASE, and FILES arguments intact.
src/CMakeLists.txt

Assessment against linked issues

Issue Objective Addressed Explanation
#845 Make the project build succeed when the project/build path contains an '@' character by working around the qt_add_shaders / Qt6ShaderToolsMacros.cmake bug.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 2 issues, and left some high level feedback:

  • The custom qsb output directory ${CMAKE_CURRENT_BINARY_DIR}/.qsb is assumed to exist but never created; consider adding a file(MAKE_DIRECTORY ...) or a small add_custom_command with cmake -E make_directory to avoid build failures on a clean tree.
  • The PRECOMPILE argument is parsed but not used in treeland_add_shaders; either implement equivalent behavior to the original qt_add_shaders flag or drop the argument to avoid confusion.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The custom qsb output directory `${CMAKE_CURRENT_BINARY_DIR}/.qsb` is assumed to exist but never created; consider adding a `file(MAKE_DIRECTORY ...)` or a small `add_custom_command` with `cmake -E make_directory` to avoid build failures on a clean tree.
- The `PRECOMPILE` argument is parsed but not used in `treeland_add_shaders`; either implement equivalent behavior to the original `qt_add_shaders` flag or drop the argument to avoid confusion.

## Individual Comments

### Comment 1
<location path="cmake/DefineTarget.cmake" line_range="68-69" />
<code_context>
+
+    set(qsb_outputs "")
+    foreach(shader_file IN LISTS arg_FILES)
+        get_filename_component(shader_name "${shader_file}" NAME)
+        set(qsb_file "${CMAKE_CURRENT_BINARY_DIR}/.qsb/${shader_name}.qsb")
+        list(APPEND qsb_outputs "${qsb_file}")
+
</code_context>
<issue_to_address>
**issue (bug_risk):** Using only the file name for qsb output paths can cause collisions for shaders with the same basename in different directories.

Since `shader_name` uses `NAME`, inputs like `foo/lighting.glsl` and `bar/lighting.glsl` both produce `.qsb/lighting.glsl.qsb`, causing overwrites and incorrect dependencies. Use a scheme that guarantees uniqueness, e.g. include part of the directory in the name or hash the full input path when generating the output filename.
</issue_to_address>

### Comment 2
<location path="cmake/DefineTarget.cmake" line_range="69-72" />
<code_context>
+    set(qsb_outputs "")
+    foreach(shader_file IN LISTS arg_FILES)
+        get_filename_component(shader_name "${shader_file}" NAME)
+        set(qsb_file "${CMAKE_CURRENT_BINARY_DIR}/.qsb/${shader_name}.qsb")
+        list(APPEND qsb_outputs "${qsb_file}")
+
+        add_custom_command(
+            OUTPUT "${qsb_file}"
+            COMMAND Qt6::qsb --qt6 $<$<BOOL:${arg_BATCHABLE}>:--batchable> "${shader_file}" -o "${qsb_file}"
</code_context>
<issue_to_address>
**issue (bug_risk):** The `.qsb` output directory may not exist when the custom command runs, causing qsb to fail.

CMake does not create `${CMAKE_CURRENT_BINARY_DIR}/.qsb` automatically, so the first `Qt6::qsb` invocation can fail with "No such file or directory". Add a `${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/.qsb"` command before calling qsb, or create the directory once outside the loop with `file(MAKE_DIRECTORY ...)`.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread cmake/DefineTarget.cmake
Comment on lines +68 to +69
get_filename_component(shader_name "${shader_file}" NAME)
set(qsb_file "${CMAKE_CURRENT_BINARY_DIR}/.qsb/${shader_name}.qsb")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): Using only the file name for qsb output paths can cause collisions for shaders with the same basename in different directories.

Since shader_name uses NAME, inputs like foo/lighting.glsl and bar/lighting.glsl both produce .qsb/lighting.glsl.qsb, causing overwrites and incorrect dependencies. Use a scheme that guarantees uniqueness, e.g. include part of the directory in the name or hash the full input path when generating the output filename.

Comment thread cmake/DefineTarget.cmake
Comment on lines +69 to +72
set(qsb_file "${CMAKE_CURRENT_BINARY_DIR}/.qsb/${shader_name}.qsb")
list(APPEND qsb_outputs "${qsb_file}")

add_custom_command(
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): The .qsb output directory may not exist when the custom command runs, causing qsb to fail.

CMake does not create ${CMAKE_CURRENT_BINARY_DIR}/.qsb automatically, so the first Qt6::qsb invocation can fail with "No such file or directory". Add a ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/.qsb" command before calling qsb, or create the directory once outside the loop with file(MAKE_DIRECTORY ...).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: 项目路径中存在 @ 字符会导致构建失败

2 participants