gnulib-tool.py: Make --megatest behaviour more similar to shell impl.
[gnulib.git] / all-modules
blob997b51584ea097d797efcff368e4c9f6dab1ca2c
1 #!/bin/sh
3 # Copyright (C) 2022-2024 Free Software Foundation, Inc.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 progname=$0
20 package=gnulib
22 # func_exit STATUS
23 # exits with a given status.
24 # This function needs to be used, rather than 'exit', when a 'trap' handler is
25 # in effect that refers to $?.
26 func_exit ()
28 (exit $1); exit $1
31 # func_fatal_error message
32 # outputs to stderr a fatal error message, and terminates the program.
33 # Input:
34 # - progname name of this program
35 func_fatal_error ()
37 echo "$progname: *** $1" 1>&2
38 echo "$progname: *** Stop." 1>&2
39 func_exit 1
42 # func_readlink SYMLINK
43 # outputs the target of the given symlink.
44 if (type readlink) > /dev/null 2>&1; then
45 func_readlink ()
47 # Use the readlink program from GNU coreutils.
48 readlink "$1"
50 else
51 func_readlink ()
53 # Use two sed invocations. A single sed -n -e 's,^.* -> \(.*\)$,\1,p'
54 # would do the wrong thing if the link target contains " -> ".
55 LC_ALL=C ls -l "$1" | sed -e 's, -> ,#%%#,' | sed -n -e 's,^.*#%%#\(.*\)$,\1,p'
59 # func_gnulib_dir
60 # locates the directory where the gnulib repository lives
61 # Input:
62 # - progname name of this program
63 # Sets variables
64 # - self_abspathname absolute pathname of this program
65 # - gnulib_dir absolute pathname of gnulib repository
66 func_gnulib_dir ()
68 case "$progname" in
69 /* | ?:*) self_abspathname="$progname" ;;
70 */*) self_abspathname=`pwd`/"$progname" ;;
72 # Look in $PATH.
73 # Iterate through the elements of $PATH.
74 # We use IFS=: instead of
75 # for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`
76 # because the latter does not work when some PATH element contains spaces.
77 # We use a canonicalized $pathx instead of $PATH, because empty PATH
78 # elements are by definition equivalent to '.', however field splitting
79 # according to IFS=: loses empty fields in many shells:
80 # - /bin/sh on OSF/1 and Solaris loses all empty fields (at the
81 # beginning, at the end, and in the middle),
82 # - /bin/sh on IRIX and /bin/ksh on IRIX and OSF/1 lose empty fields
83 # at the beginning and at the end,
84 # - GNU bash, /bin/sh on AIX and HP-UX, and /bin/ksh on AIX, HP-UX,
85 # Solaris lose empty fields at the end.
86 # The 'case' statement is an optimization, to avoid evaluating the
87 # explicit canonicalization command when $PATH contains no empty fields.
88 self_abspathname=
89 if test "${PATH_SEPARATOR+set}" != set; then
90 # Determine PATH_SEPARATOR by trying to find /bin/sh in a PATH which
91 # contains only /bin. Note that ksh looks also at the FPATH variable,
92 # so we have to set that as well for the test.
93 PATH_SEPARATOR=:
94 (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \
95 && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \
96 || PATH_SEPARATOR=';'
99 if test "${PATH_SEPARATOR+set}" != set; then
100 # Determine PATH_SEPARATOR by trying to find /bin/sh in a PATH which
101 # contains only /bin. Note that ksh looks also at the FPATH variable,
102 # so we have to set that as well for the test.
103 PATH_SEPARATOR=:
104 (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \
105 && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \
106 || PATH_SEPARATOR=';'
109 if test "$PATH_SEPARATOR" = ";"; then
110 # On Windows, programs are searched in "." before $PATH.
111 pathx=".;$PATH"
112 else
113 # On Unix, we have to convert empty PATH elements to ".".
114 pathx="$PATH"
115 case :$PATH: in
116 *::*)
117 pathx=`echo ":$PATH:" | sed -e 's/:::*/:.:/g' -e 's/^://' -e 's/:\$//'`
119 esac
121 saved_IFS="$IFS"
122 IFS="$PATH_SEPARATOR"
123 for d in $pathx; do
124 IFS="$saved_IFS"
125 test -z "$d" && d=.
126 if test -x "$d/$progname" && test ! -d "$d/$progname"; then
127 self_abspathname="$d/$progname"
128 break
130 done
131 IFS="$saved_IFS"
132 if test -z "$self_abspathname"; then
133 func_fatal_error "could not locate the all-modules program - how did you invoke it?"
136 esac
137 while test -h "$self_abspathname"; do
138 # Resolve symbolic link.
139 linkval=`func_readlink "$self_abspathname"`
140 test -n "$linkval" || break
141 case "$linkval" in
142 /* | ?:* ) self_abspathname="$linkval" ;;
143 * ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
144 esac
145 done
146 gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
149 # func_usage
150 # outputs to stdout the --help usage message.
151 func_usage ()
153 echo "\
154 Usage: all-modules [option]
156 Lists the gnulib-tool command line options that can be used when creating
157 a testdir of nearly all of gnulib.
159 Options:
161 --for-mingw list only modules that work on mingw
162 --for-msvc list only modules that work on MSVC
164 Report bugs to <bug-gnulib@gnu.org>."
167 # func_version
168 # outputs to stdout the --version message.
169 func_version ()
171 func_gnulib_dir
172 if test -d "$gnulib_dir"/.git \
173 && (git --version) >/dev/null 2>/dev/null \
174 && (date --version) >/dev/null 2>/dev/null; then
175 # gnulib checked out from git.
176 sed_extract_first_date='/^Date/{
177 s/^Date:[ ]*//p
180 date=`cd "$gnulib_dir" && git log -n 1 --format=medium --date=iso ChangeLog | sed -n -e "$sed_extract_first_date"`
181 # Turn "Fri Mar 21 07:16:51 2008 -0600" into "Mar 21 2008 07:16:51 -0600".
182 sed_year_before_time='s/^[^ ]* \([^ ]*\) \([0-9]*\) \([0-9:]*\) \([0-9]*\) /\1 \2 \4 \3 /'
183 date=`echo "$date" | sed -e "$sed_year_before_time"`
184 # Use GNU date to compute the time in GMT.
185 date=`date -d "$date" -u +"%Y-%m-%d %H:%M:%S"`
186 version=' '`cd "$gnulib_dir" && ./build-aux/git-version-gen /dev/null | sed -e 's/-dirty/-modified/'`
187 else
188 # gnulib copy without versioning information.
189 date=`sed -e 's/ .*//;q' "$gnulib_dir"/ChangeLog`
190 version=
192 year=`"$gnulib_dir"/build-aux/mdate-sh "$self_abspathname" | sed 's,^.* ,,'`
193 echo "\
194 all-modules (GNU $package $date)$version
195 Copyright (C) $year Free Software Foundation, Inc.
196 License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
197 This is free software: you are free to change and redistribute it.
198 There is NO WARRANTY, to the extent permitted by law.
200 Written by" "Bruno Haible"
203 # Excludes for mingw and MSVC.
204 exclude_for_mingw=
205 # <pwd.h> and <grp.h> do not exist.
206 exclude_for_mingw="$exclude_for_mingw idcache"
207 exclude_for_mingw="$exclude_for_mingw pt_chown grantpt posix_openpt-tests posix_openpt"
208 exclude_for_mingw="$exclude_for_mingw userspec-tests userspec"
209 # The functions getuid, getgid, geteuid, getegid don't exist.
210 exclude_for_mingw="$exclude_for_mingw faccessat"
211 exclude_for_mingw="$exclude_for_mingw fchownat-tests fchownat chownat"
212 # The functions fork, setsid, ttyname don't exist.
213 exclude_for_mingw="$exclude_for_mingw forkpty-tests forkpty login_tty-tests login_tty"
215 # Excludes for MSVC.
216 exclude_for_msvc="$exclude_for_mingw"
218 # Command-line option processing.
219 exclude="year2038-recommended"
220 while test $# -gt 0; do
221 case "$1" in
222 --for-mingw | --for-ming | --for-min | --for-mi )
223 exclude="$exclude $exclude_for_mingw"
224 shift ;;
225 --for-msvc | --for-msv | --for-ms )
226 exclude="$exclude $exclude_for_msvc"
227 shift ;;
228 --help | --hel | --he | --h )
229 func_usage
230 exit $? ;;
231 --version | --versio | --versi | --vers | --ver | --ve | --v )
232 func_version
233 exit $? ;;
234 -* )
235 echo "all-modules: unknown option $1" 1>&2
236 echo "Try 'all-modules --help' for more information." 1>&2
237 exit 1 ;;
239 echo "all-modules: too many arguments" 1>&2
240 echo "Try 'all-modules --help' for more information." 1>&2
241 exit 1 ;;
242 esac
243 done
245 # gnulib-tool --create-testdir collects all modules by default.
246 # We only need to filter out the excludes.
247 for m in $exclude; do
248 printf '%s\n' "--avoid=$m"
249 done
251 # Local Variables:
252 # indent-tabs-mode: nil
253 # whitespace-check-buffer-indent: nil
254 # End: