-
Notifications
You must be signed in to change notification settings - Fork 333
Automatically initialize submodule if missing #1052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,6 +10,30 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.gitmodules" AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| find_package(Git QUIET) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if(Git_FOUND) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
LeiWang1999 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| execute_process( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| RESULT_VARIABLE TILELANG_GIT_SUBMODULE_RESULT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if(NOT TILELANG_GIT_SUBMODULE_RESULT EQUAL 0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| message( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FATAL_ERROR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Failed to initialize git submodules. Please run " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "`git submodule update --init --recursive` and re-run CMake." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| endif() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+16
to
+27
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prevent hangs and improve diagnostics for submodule update Add non-interactive env, timeouts, and capture stderr/stdout. Otherwise CMake can hang (e.g., auth prompts, offline CI) and failures lack context. - execute_process(
- COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
- RESULT_VARIABLE TILELANG_GIT_SUBMODULE_RESULT
- )
+ # Sync URLs and update submodules non-interactively with timeouts
+ execute_process(
+ COMMAND ${CMAKE_COMMAND} -E env "GIT_TERMINAL_PROMPT=0"
+ ${GIT_EXECUTABLE} submodule sync --recursive
+ WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
+ RESULT_VARIABLE TILELANG_GIT_SUBMODULE_SYNC_RESULT
+ OUTPUT_VARIABLE TILELANG_GIT_SUBMODULE_SYNC_OUT
+ ERROR_VARIABLE TILELANG_GIT_SUBMODULE_SYNC_ERR
+ TIMEOUT 120
+ )
+ execute_process(
+ COMMAND ${CMAKE_COMMAND} -E env "GIT_TERMINAL_PROMPT=0"
+ ${GIT_EXECUTABLE} submodule update --init --recursive
+ WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
+ RESULT_VARIABLE TILELANG_GIT_SUBMODULE_RESULT
+ OUTPUT_VARIABLE TILELANG_GIT_SUBMODULE_OUT
+ ERROR_VARIABLE TILELANG_GIT_SUBMODULE_ERR
+ TIMEOUT 600
+ )
if(NOT TILELANG_GIT_SUBMODULE_RESULT EQUAL 0)
message(
FATAL_ERROR
- "Failed to initialize git submodules. Please run "
- "`git submodule update --init --recursive` and re-run CMake."
+ "Failed to initialize git submodules. Please run "
+ "`git submodule update --init --recursive` and re-run CMake.\n"
+ "Git stderr:\n${TILELANG_GIT_SUBMODULE_ERR}"
)
endif()📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| message( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FATAL_ERROR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Git is required to initialize TileLang submodules. " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Please install git or fetch the submodules manually." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| endif() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| endif() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| find_program(CCACHE_PROGRAM ccache) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if(CCACHE_PROGRAM) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}" CACHE STRING "C compiler launcher") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, you could use
FetchContentto enable building without the.gitdirectory. This will allow us to completely remove.gitmodulesand the3rdpartydirectory.An example: https://github.com/metaopt/optree/blob/4b2aad3276ec391cc68b9445cf18d163dea8aa9c/CMakeLists.txt#L258-L283
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I'll take alook
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think at least the
3rdparty/tvmdirectory isn’t very stable — we occasionally need to update it. Managing it with Git would make things much more convenient. Once it becomes more stable, we can consider switching to that approach.