summaryrefslogtreecommitdiff
path: root/py
diff options
context:
space:
mode:
authorAngus Gratton <angus@redyak.com.au>2025-03-11 17:17:39 +1100
committerDamien George <damien@micropython.org>2025-03-27 17:51:12 +1100
commitcccac2cc0127eb43de4524c74424ecaaa594c80e (patch)
treea3f6e8a83f44759bc1719cae16b02ef66b9ee29e /py
parent2db0c0225f41292f85b2cf49257d663856d5c8db (diff)
rp2,esp32,extmod: Implement UPDATE_SUBMODULES in CMake.
Rather than having Make calling CMake to generate a list of submodules and then run a Make target (which is complex and prone to masking other errors), implement the submodule update logic in CMake itself. Internal CMake-side changes are that GIT_SUBMODULES is now a CMake list, and the trigger variable name is changed from ECHO_SUBMODULES to UPDATE_SUBMODULES. The run is otherwise 100% a normal CMake run now, so most of the other special casing can be removed. Signed-off-by: Angus Gratton <angus@redyak.com.au>
Diffstat (limited to 'py')
-rw-r--r--py/mkrules.cmake42
-rw-r--r--py/mkrules.mk9
2 files changed, 29 insertions, 22 deletions
diff --git a/py/mkrules.cmake b/py/mkrules.cmake
index cafcbce56..4374b8b4d 100644
--- a/py/mkrules.cmake
+++ b/py/mkrules.cmake
@@ -209,16 +209,11 @@ if(MICROPY_FROZEN_MANIFEST)
# Note: target_compile_definitions already added earlier.
if(NOT MICROPY_LIB_DIR)
- string(CONCAT GIT_SUBMODULES "${GIT_SUBMODULES} " lib/micropython-lib)
+ list(APPEND GIT_SUBMODULES lib/micropython-lib)
set(MICROPY_LIB_DIR ${MICROPY_DIR}/lib/micropython-lib)
endif()
- if(ECHO_SUBMODULES)
- # No-op, we're just doing submodule/variant discovery.
- # Note: All the following rules are safe to run in discovery mode even
- # though the submodule might not be available as they do not directly depend
- # on anything from the submodule.
- elseif(NOT EXISTS ${MICROPY_LIB_DIR}/README.md)
+ if(NOT UPDATE_SUBMODULES AND NOT EXISTS ${MICROPY_LIB_DIR}/README.md)
message(FATAL_ERROR " micropython-lib not initialized.\n Run 'make BOARD=${MICROPY_BOARD} submodules'")
endif()
@@ -272,12 +267,29 @@ if(MICROPY_FROZEN_MANIFEST)
)
endif()
-# Update submodules
-if(ECHO_SUBMODULES)
- # If cmake is run with GIT_SUBMODULES defined on command line, process the port / board
- # settings then print the final GIT_SUBMODULES variable and exit.
- # Note: the GIT_SUBMODULES is done via echo rather than message, as message splits
- # the output onto multiple lines
- execute_process(COMMAND ${CMAKE_COMMAND} -E echo "GIT_SUBMODULES=${GIT_SUBMODULES}")
- message(FATAL_ERROR "Done")
+# Update submodules, this is invoked on some ports via 'make submodules'.
+#
+# Note: This logic has a Makefile equivalent in py/mkrules.mk
+if(UPDATE_SUBMODULES AND GIT_SUBMODULES)
+ macro(run_git)
+ execute_process(COMMAND git ${ARGV} WORKING_DIRECTORY ${MICROPY_DIR}
+ RESULT_VARIABLE RES)
+ endmacro()
+
+ list(JOIN GIT_SUBMODULES " " GIT_SUBMODULES_MSG)
+ message("Updating submodules: ${GIT_SUBMODULES_MSG}")
+ run_git(submodule sync ${GIT_SUBMODULES})
+ if(RES EQUAL 0)
+ # If available, do blobless partial clones of submodules to save time and space.
+ # A blobless partial clone lazily fetches data as needed, but has all the metadata available (tags, etc.).
+ run_git(submodule update --init --filter=blob:none ${GIT_SUBMODULES})
+ # Fallback to standard submodule update if blobless isn't available (earlier than git 2.36.0)
+ if (NOT RES EQUAL 0)
+ run_git(submodule update --init ${GIT_SUBMODULES})
+ endif()
+ endif()
+
+ if (NOT RES EQUAL 0)
+ message(FATAL_ERROR "Submodule update failed")
+ endif()
endif()
diff --git a/py/mkrules.mk b/py/mkrules.mk
index ad855c0d7..495d8d48b 100644
--- a/py/mkrules.mk
+++ b/py/mkrules.mk
@@ -262,19 +262,14 @@ endif
# If available, do blobless partial clones of submodules to save time and space.
# A blobless partial clone lazily fetches data as needed, but has all the metadata available (tags, etc.).
# Fallback to standard submodule update if blobless isn't available (earlier than 2.36.0)
+#
+# Note: This target has a CMake equivalent in py/mkrules.cmake
submodules:
$(ECHO) "Updating submodules: $(GIT_SUBMODULES)"
ifneq ($(GIT_SUBMODULES),)
$(Q)cd $(TOP) && git submodule sync $(GIT_SUBMODULES)
$(Q)cd $(TOP) && git submodule update --init --filter=blob:none $(GIT_SUBMODULES) || \
git submodule update --init $(GIT_SUBMODULES)
-else
-ifeq ($(GIT_SUBMODULES_FAIL_IF_EMPTY),1)
- # If you see this error, it may mean the internal step run by the port's build
- # system to find git submodules has failed. Double-check dependencies are set correctly.
- $(ECHO) "Internal build error: The submodule list should not be empty."
- exit 1
-endif
endif
.PHONY: submodules