blob: e225d3a9634447ea2b2915ec3cb19376101d8a56 [file] [log] [blame]
Daniel P. Berrangeaef45d52017-09-29 11:11:56 +01001#!/bin/sh
2#
3# This code is licensed under the GPL version 2 or later. See
4# the COPYING file in the top-level directory.
5
Daniel P. Berrangeaef45d52017-09-29 11:11:56 +01006substat=".git-submodule-status"
7
8command=$1
9shift
Daniel P. Berrange37b5e742017-10-27 10:49:58 +010010maybe_modules="$@"
Daniel P. Berrangeaef45d52017-09-29 11:11:56 +010011
Dan Streetman7d7dbf92021-01-19 12:20:46 -050012# if --with-git-submodules=ignore, do nothing
13test "$command" = "ignore" && exit 0
14
Daniel P. Berrangecc84d632017-10-20 15:02:43 +010015test -z "$GIT" && GIT=git
16
Dan Streetman7d7dbf92021-01-19 12:20:46 -050017cd "$(dirname "$0")/.."
18
19update_error() {
Daniel P. Berrangecc84d632017-10-20 15:02:43 +010020 echo "$0: $*"
21 echo
22 echo "Unable to automatically checkout GIT submodules '$modules'."
23 echo "If you require use of an alternative GIT binary (for example to"
24 echo "enable use of a transparent proxy), then please specify it by"
25 echo "running configure by with the '--with-git' argument. e.g."
26 echo
27 echo " $ ./configure --with-git='tsocks git'"
28 echo
Daniel P. Berrangef62bbee2017-10-26 13:52:26 +010029 echo "Alternatively you may disable automatic GIT submodule checkout"
30 echo "with:"
31 echo
Dan Streetman7d7dbf92021-01-19 12:20:46 -050032 echo " $ ./configure --with-git-submodules=validate"
Daniel P. Berrangef62bbee2017-10-26 13:52:26 +010033 echo
34 echo "and then manually update submodules prior to running make, with:"
35 echo
Laurent Vivierbff8a0b2018-01-19 11:32:33 +010036 echo " $ scripts/git-submodule.sh update $modules"
Daniel P. Berrangef62bbee2017-10-26 13:52:26 +010037 echo
Daniel P. Berrangecc84d632017-10-20 15:02:43 +010038 exit 1
39}
40
Dan Streetman7d7dbf92021-01-19 12:20:46 -050041validate_error() {
42 if test "$1" = "validate"; then
43 echo "GIT submodules checkout is out of date, and submodules"
44 echo "configured for validate only. Please run"
45 echo " scripts/git-submodule.sh update $maybe_modules"
46 echo "from the source directory or call configure with"
47 echo " --with-git-submodules=update"
48 echo "To disable GIT submodules validation, use"
49 echo " --with-git-submodules=ignore"
50 fi
51 exit 1
52}
53
Daniel P. Berrange37b5e742017-10-27 10:49:58 +010054modules=""
55for m in $maybe_modules
56do
57 $GIT submodule status $m 1> /dev/null 2>&1
58 if test $? = 0
59 then
60 modules="$modules $m"
61 else
62 echo "warn: ignoring non-existent submodule $m"
63 fi
64done
65
Daniel P. Berrange49ad3cf2017-10-30 09:29:29 +010066if test -n "$maybe_modules" && ! test -e ".git"
Daniel P. Berrangeaef45d52017-09-29 11:11:56 +010067then
68 echo "$0: unexpectedly called with submodules but no git checkout exists"
69 exit 1
70fi
71
72case "$command" in
Dan Streetman7d7dbf92021-01-19 12:20:46 -050073status|validate)
Daniel P. Berrange49ad3cf2017-10-30 09:29:29 +010074 if test -z "$maybe_modules"
75 then
Dan Streetman7d7dbf92021-01-19 12:20:46 -050076 test -s ${substat} && validate_error "$command" || exit 0
Daniel P. Berrange49ad3cf2017-10-30 09:29:29 +010077 fi
78
Dan Streetman7d7dbf92021-01-19 12:20:46 -050079 test -f "$substat" || validate_error "$command"
Juan Quintela1a920d22020-01-29 11:21:13 +010080 for module in $modules; do
81 CURSTATUS=$($GIT submodule status $module)
82 OLDSTATUS=$(cat $substat | grep $module)
83 if test "$CURSTATUS" != "$OLDSTATUS"; then
Dan Streetman7d7dbf92021-01-19 12:20:46 -050084 validate_error "$command"
Juan Quintela1a920d22020-01-29 11:21:13 +010085 fi
86 done
87 exit 0
Daniel P. Berrangeaef45d52017-09-29 11:11:56 +010088 ;;
89update)
Daniel P. Berrange49ad3cf2017-10-30 09:29:29 +010090 if test -z "$maybe_modules"
91 then
92 test -e $substat || touch $substat
93 exit 0
94 fi
95
Daniel P. Berrangecc84d632017-10-20 15:02:43 +010096 $GIT submodule update --init $modules 1>/dev/null
Dan Streetman7d7dbf92021-01-19 12:20:46 -050097 test $? -ne 0 && update_error "failed to update modules"
Daniel P. Berrangecc84d632017-10-20 15:02:43 +010098
99 $GIT submodule status $modules > "${substat}"
Dan Streetman7d7dbf92021-01-19 12:20:46 -0500100 test $? -ne 0 && update_error "failed to save git submodule status" >&2
Daniel P. Berrangeaef45d52017-09-29 11:11:56 +0100101 ;;
102esac
Daniel P. Berrangecc84d632017-10-20 15:02:43 +0100103
104exit 0