mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-11-22 22:50:49 +08:00
* build(git): check only the submodules a build needs Tools/check_submodules.sh fetches every missing submodule, so a build that uses a handful of PX4 libraries still clones NuttX, the simulators and the middleware. Paths given as arguments now limit the check, and the configure step passes PX4_GIT_SUBMODULES when it is set. Builds that do not set it check all submodules as before. A path that is not a submodule, or a submodule the build uses but that is not checked out, stops the configure instead of failing later in the build. Assisted-by: Claude:opus-5.5 Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org> * docs(dev_setup): document PX4_GIT_SUBMODULES The submodule check can be limited to the submodules a build needs. List the variable next to GIT_SUBMODULES_ARE_EVIL, the other way to control the check. Assisted-by: Claude:opus-5.5 Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org> * test(git): cover the submodule check limited to given paths A second top-level submodule gives the tests one to leave out, so they check that paths given to check_submodules.sh limit both the fetch of missing submodules and the report of changed ones, and that a path that is not a submodule fails the check. Assisted-by: Claude:opus-5.5 Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org> --------- Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org> Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
62 lines
2.4 KiB
Bash
Executable File
62 lines
2.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# Make sure the git submodules are ready to build, before any build starts:
|
|
#
|
|
# at the commit PX4 records nothing to do
|
|
# missing fetch it
|
|
# at another commit warn and build it as it is (an error in CI)
|
|
#
|
|
# A submodule at another commit is never reset: that is how changes to a
|
|
# submodule are developed and tested. Set GIT_SUBMODULES_ARE_EVIL to skip
|
|
# the check entirely. Paths given as arguments limit the check to those
|
|
# submodules.
|
|
|
|
[ -n "$GIT_SUBMODULES_ARE_EVIL" ] && exit 0
|
|
|
|
cd "$(dirname "$0")/.." || exit 1
|
|
|
|
# nothing to check outside a git checkout, e.g. a source archive
|
|
git rev-parse --is-inside-work-tree > /dev/null 2>&1 || exit 0
|
|
|
|
# Fetch the missing submodules of one repository ('-' in git submodule status),
|
|
# naming only those so submodules at another commit are left alone. Run in
|
|
# PX4 and then, through foreach, in every submodule, which reaches nested
|
|
# submodules missing inside a submodule someone changed.
|
|
submodule_paths="-- $*"
|
|
|
|
# a path that is not a submodule makes git submodule status list nothing, so
|
|
# the checks below would pass without looking at any submodule
|
|
[ $# -eq 0 ] || git submodule status -- "$@" > /dev/null || {
|
|
echo -e "\033[31mError: not a submodule in: $*\033[0m"
|
|
exit 1
|
|
}
|
|
|
|
fetch_missing='
|
|
missing=$(git submodule status $submodule_paths | sed -n "s/^-[0-9a-f]* \([^ ]*\).*/\1/p")
|
|
[ -z "$missing" ] || {
|
|
echo "Fetching submodules in ${displaypath:-.}:" $missing
|
|
git submodule --quiet sync --recursive -- $missing &&
|
|
git submodule --quiet update --init --recursive --jobs 8 -- $missing
|
|
}'
|
|
eval "$fetch_missing" && git submodule --quiet foreach --recursive "$fetch_missing" || {
|
|
echo -e "\033[31mError: could not fetch submodules\033[0m"
|
|
exit 1
|
|
}
|
|
|
|
# '+' at another commit, 'U' merge conflict
|
|
changed=$(git submodule status --recursive $submodule_paths | sed -n "s/^[+U][0-9a-f]* \([^ ]*\).*/ \1/p")
|
|
if [ -n "$changed" ]; then
|
|
if [ "$CI" = "true" ]; then
|
|
echo -e "\033[31mError: submodules not at the commit PX4 records:\033[0m"
|
|
else
|
|
echo -e "\033[33mWarning: building submodules not at the commit PX4 records:\033[0m"
|
|
fi
|
|
echo "$changed"
|
|
echo "To check out the recorded commits, run:"
|
|
echo -e " \033[94mgit submodule sync --recursive && git submodule update --init --recursive\033[0m"
|
|
# CI must build exactly what the commit under test records
|
|
[ "$CI" = "true" ] && exit 1
|
|
fi
|
|
|
|
exit 0
|