Skip to content

Commit

Permalink
pw_build/cmake: Enforce full path in CMake library names
Browse files Browse the repository at this point in the history
Instead of only enforcing the parent directory to be in the CMake
library name, pw_add_module_library is updated to enforce that
the entire relative to PW root directory path is in the library
name in a dot separated format.

Change-Id: I29f3fa499474a53ff29a04ed2f353d560edd1451
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/94540
Pigweed-Auto-Submit: Ewout van Bekkum <[email protected]>
Reviewed-by: Keir Mierle <[email protected]>
Commit-Queue: Auto-Submit <[email protected]>
  • Loading branch information
Ewout van Bekkum authored and CQ Bot Account committed May 13, 2022
1 parent f3ba3aa commit fa8e4c3
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pw_build/pigweed.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,15 @@ function(pw_add_module_library NAME)
_pw_add_library_multi_value_args(multi_value_args IMPLEMENTS_FACADES)
pw_parse_arguments_strict(pw_add_module_library 1 "" "" "${multi_value_args}")

# Check that the library's name is prefixed by the module name.
get_filename_component(module "${CMAKE_CURRENT_SOURCE_DIR}" NAME)

if(NOT "${NAME}" MATCHES "${module}(\\.[^\\.]+)?(\\.facade)?$")
# Check that the library's name is prefixed by the relative PW path with dot
# separators instead of forward slashes.
file(RELATIVE_PATH rel_path $ENV{PW_ROOT} ${CMAKE_CURRENT_SOURCE_DIR})
string(REPLACE "/" "." dot_rel_path ${rel_path})
if(NOT "${NAME}" MATCHES "${dot_rel_path}(\\.[^\\.]+)?(\\.facade)?$")
message(FATAL_ERROR
"Module libraries must match the module name or be in the form "
"'MODULE_NAME.LIBRARY_NAME'. The library '${NAME}' does not match."
"'PATH_TO.THE_TARGET.NAME'. The library '${NAME}' does not match. "
"Expected ${dot_rel_path}.LIBRARY_NAME"
)
endif()

Expand Down

0 comments on commit fa8e4c3

Please sign in to comment.