Skip to content

Commit efa4628

Browse files
authored
Assert that the repo directory is named executorch (#6480)
Our C++ include path assumes that the repo lives in a directory named exactly `executorch`. Users who name it something else run into hard-to-debug issues (see #6475). Since we require it, add an explicit check and point users to the issue that tracks the fix. ## Test Plan Tried generating cmake files under a directory named `executorch` and named `not-executorch`: ``` (rm -rf cmake-out \ && mkdir cmake-out \ && cd cmake-out \ && cmake ../) ``` Note that I added a trailing slash just in case CMAKE_CURRENT_SOURCE_DIR included that slash and might confuse `cmake_path()`. (note that CMAKE_CURRENT_SOURCE_DIR does not include the trailing slash in this case) This command succeeded when the directory is named `executorch`. Under `not-executorch` it failed with the error: ``` CMake Error at CMakeLists.txt:332 (message): The ExecuTorch repo must be cloned into a directory named exactly `executorch`; found `not-executorch`. See #6475 for progress on a fix for this restriction. ``` Also tested with the instructions at [pytorch.org/executorch/main/llm/getting-started.html](https://pytorch.org/executorch/main/llm/getting-started.html), where executorch is a sub-repo of the top project. It builds when following the directions, but if I rename the repo to third-party/not-executorch then I see the expected error.
1 parent 7b03a8b commit efa4628

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,19 @@ message(STATUS "Using python executable '${PYTHON_EXECUTABLE}'")
324324
set(_common_compile_options -Wno-deprecated-declarations -fPIC)
325325

326326
# Let files say "include <executorch/path/to/header.h>".
327+
# TODO(#6475): This requires/assumes that the repo lives in a directory named
328+
# exactly `executorch`. Check the assumption first. Remove this check once we
329+
# stop relying on the assumption.
330+
cmake_path(GET CMAKE_CURRENT_SOURCE_DIR FILENAME _repo_dir_name)
331+
if(NOT "${_repo_dir_name}" STREQUAL "executorch")
332+
message(
333+
FATAL_ERROR
334+
"The ExecuTorch repo must be cloned into a directory named exactly "
335+
"`executorch`; found `${_repo_dir_name}`. See "
336+
"https://github.com/pytorch/executorch/issues/6475 for progress on a "
337+
"fix for this restriction."
338+
)
339+
endif()
327340
set(_common_include_directories ${CMAKE_CURRENT_SOURCE_DIR}/..)
328341

329342
#

0 commit comments

Comments
 (0)