]> git.proxmox.com Git - mirror_qemu.git/blame - scripts/git-submodule.sh
iotests: add filter_qmp_generated_node_ids()
[mirror_qemu.git] / scripts / git-submodule.sh
CommitLineData
aef45d51
DB
1#!/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
aef45d51
DB
6substat=".git-submodule-status"
7
8command=$1
9shift
37b5e74e 10maybe_modules="$@"
aef45d51 11
8edddaa2 12test -z "$maybe_modules" && exit 0
50cfed80 13test -z "$GIT" && GIT=$(command -v git)
cc84d63a 14
7d7dbf9d
DS
15cd "$(dirname "$0")/.."
16
8edddaa2
PB
17no_git_error=
18if ! test -e ".git"; then
19 no_git_error='no git checkout exists'
20elif test -z "$GIT"; then
21 no_git_error='git binary not found'
22fi
23
24is_git() {
25 test -z "$no_git_error"
26}
27
7d7dbf9d 28update_error() {
cc84d63a
DB
29 echo "$0: $*"
30 echo
31 echo "Unable to automatically checkout GIT submodules '$modules'."
32 echo "If you require use of an alternative GIT binary (for example to"
50cfed80
PB
33 echo "enable use of a transparent proxy), please disable automatic"
34 echo "GIT submodule checkout with:"
f62bbee5 35 echo
6f3ae23b 36 echo " $ ./configure --disable-download"
f62bbee5
DB
37 echo
38 echo "and then manually update submodules prior to running make, with:"
39 echo
50cfed80 40 echo " $ GIT='tsocks git' scripts/git-submodule.sh update $modules"
f62bbee5 41 echo
cc84d63a
DB
42 exit 1
43}
44
7d7dbf9d 45validate_error() {
8edddaa2 46 if is_git && test "$1" = "validate"; then
7d7dbf9d
DS
47 echo "GIT submodules checkout is out of date, and submodules"
48 echo "configured for validate only. Please run"
49 echo " scripts/git-submodule.sh update $maybe_modules"
50 echo "from the source directory or call configure with"
6f3ae23b 51 echo " --enable-download"
7d7dbf9d
DS
52 fi
53 exit 1
54}
55
d120116b
PB
56check_updated() {
57 local CURSTATUS OLDSTATUS
58 CURSTATUS=$($GIT submodule status $module)
59 OLDSTATUS=$(grep $module $substat)
60 test "$CURSTATUS" = "$OLDSTATUS"
61}
62
8edddaa2
PB
63if is_git; then
64 test -e $substat || touch $substat
65 modules=""
66 for m in $maybe_modules
67 do
68 $GIT submodule status $m 1> /dev/null 2>&1
69 if test $? = 0
70 then
71 modules="$modules $m"
72 grep $m $substat > /dev/null 2>&1 || $GIT submodule status $module >> $substat
73 else
74 echo "warn: ignoring non-existent submodule $m"
75 fi
76 done
77else
78 modules=$maybe_modules
50cfed80
PB
79fi
80
aef45d51 81case "$command" in
7d7dbf9d 82status|validate)
1a920d2b 83 for module in $modules; do
8edddaa2
PB
84 if is_git; then
85 check_updated $module || validate_error "$command"
86 elif ! (set xyz "$module"/* && test -e "$2"); then
87 # The directory does not exist or it contains no files
88 echo "$0: sources not available for $module and $no_git_error"
89 validate_error "$command"
90 fi
1a920d2b 91 done
aef45d51 92 ;;
8edddaa2 93
aef45d51 94update)
8edddaa2
PB
95 is_git || {
96 echo "$0: unexpectedly called with submodules but $no_git_error"
97 exit 1
98 }
49ad3cfa 99
cc84d63a 100 $GIT submodule update --init $modules 1>/dev/null
7d7dbf9d 101 test $? -ne 0 && update_error "failed to update modules"
d120116b
PB
102 for module in $modules; do
103 check_updated $module || echo Updated "$module"
104 done
cc84d63a 105
f9540bb1 106 (while read -r REPLY; do
fdb8fd8c
PB
107 for module in $modules; do
108 case $REPLY in
109 *" $module "*) continue 2 ;;
110 esac
111 done
112 printf '%s\n' "$REPLY"
113 done
114 $GIT submodule status $modules
115 test $? -ne 0 && update_error "failed to save git submodule status" >&2) < $substat > $substat.new
116 mv -f $substat.new $substat
aef45d51
DB
117 ;;
118esac
cc84d63a
DB
119
120exit 0