Skip to content

fix(build): escape regex metacharacters in unity build commands-dir match - #1281

Merged
caomengxuan666 merged 1 commit into
mainfrom
fix/cmake-regex-escape
Oct 22, 2026
Merged

caomengxuan666 merged 1 commit into
mainfrom
fix/cmake-regex-escape

Conversation

@arookieofc

Copy link
Copy Markdown
Member

Summary

With ENABLE_UNITY_BUILD=ON (default for RELEASE), the unity build selects command sources with ABS_SOURCE_FILE MATCHES "${COMMANDS_DIR}.*", building the regex from the literal source path. When the checkout path contains regex metacharacters — e.g. D:\code\C++Files\WinuxCmd — the pattern cannot compile and configure aborts at CMakeLists.txt:261:

Regular expression ... cannot compile (Nested *?+)

This PR escapes + . * ? ( ) [ ] ^ $ | and backslash in COMMANDS_DIR with string(REGEX REPLACE) before matching, so the directory matches literally (also covers paths like Program Files (x86)).

Test plan

On D:/code/C++Files/WinuxCmd (MSVC 14.44, CMake 4.3.3, Ninja):

  • before: configure fails at CMakeLists.txt:261 with unity build on
  • after: winuxcmd-commands merges 176 command files; full build succeeds; unit suite 3097 tests pass (2 chown/mktemp cases fail only when TMP is on a D: drive that rejects chown, identical on the non-unity build — environment, not this change)

…atch

The unity build picked command sources with
ABS_SOURCE_FILE MATCHES "${COMMANDS_DIR}.*", building the pattern from
the literal source path. On checkouts under paths containing regex
metacharacters (e.g. D:\code\C++Files\...), the pattern cannot compile
(Nested *?+) and configure aborts with
"Regular expression ... cannot compile" at the unity-build if().

Escape the directory with string(REGEX REPLACE) before matching, so
paths with + . * ? ( ) [ ] ^ $ | and backslash match literally.
Verified on D:/code/C++Files/WinuxCmd: configure previously failed at
CMakeLists.txt:261; now the winuxcmd-commands target merges 176 command
files, the full build and unit suite run (3095/3097, the 2 failures
reproduce identically on the existing non-unity build).
@caomengxuan666
caomengxuan666 merged commit fff03a9 into main Oct 22, 2026
5 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/cmake-regex-escape branch October 30, 2026 01:42
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.

2 participants