Skip to content

Commit

Permalink
regex-escape filenames that are string-interpolated into regex patterns
Browse files Browse the repository at this point in the history
Summary:
Fixes: #1696.

When the `folly` project is checked out into a directory where the path contains any of the special characters that are meaningful in regex evaluation, the cmake build would fail. The example given is a directory like `C:/code/c++/folly`.

Reviewed By: Gownta

Differential Revision: D62077198

fbshipit-source-id: 5d53ddf4e54adef73f4942f0dde64e8bb68fcbb1
  • Loading branch information
yfeldblum authored and facebook-github-bot committed Sep 3, 2024
1 parent f13c956 commit 0f698c3
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ set(
FOLLY_DIR_PREFIXES
"${CMAKE_CURRENT_SOURCE_DIR}:${CMAKE_CURRENT_BINARY_DIR}"
)
# https://gitlab.kitware.com/cmake/cmake/-/issues/18580#note_1405108
string(REGEX REPLACE "(.)" "\\\\\\1" FOLLY_DIR_REGEX_ESCAPED "${FOLLY_DIR}")

include(GNUInstallDirs)

Expand Down Expand Up @@ -163,12 +165,12 @@ auto_sources(hfiles "*.h" "RECURSE" "${FOLLY_DIR}")
# library sources. Test sources are listed separately below.
REMOVE_MATCHES_FROM_LISTS(files hfiles
MATCHES
"^${FOLLY_DIR}/build/"
"^${FOLLY_DIR}/docs/examples/"
"^${FOLLY_DIR}/logging/example/"
"^${FOLLY_DIR}/(.*/)?test/"
"^${FOLLY_DIR}/(.*/)?tool/"
"^${FOLLY_DIR}/facebook/"
"^${FOLLY_DIR_REGEX_ESCAPED}/build/"
"^${FOLLY_DIR_REGEX_ESCAPED}/docs/examples/"
"^${FOLLY_DIR_REGEX_ESCAPED}/logging/example/"
"^${FOLLY_DIR_REGEX_ESCAPED}/(.*/)?test/"
"^${FOLLY_DIR_REGEX_ESCAPED}/(.*/)?tool/"
"^${FOLLY_DIR_REGEX_ESCAPED}/facebook/"
"Benchmark.cpp$"
"Test.cpp$"
)
Expand All @@ -177,7 +179,7 @@ REMOVE_MATCHES_FROM_LISTS(files hfiles
if (${FOLLY_NO_EXCEPTION_TRACER})
REMOVE_MATCHES_FROM_LISTS(files hfiles
MATCHES
"^${FOLLY_DIR}/debugging/exception_tracer/"
"^${FOLLY_DIR_REGEX_ESCAPED}/debugging/exception_tracer/"
)
endif()

Expand Down

0 comments on commit 0f698c3

Please sign in to comment.