tests: cosmetic changes in t/extra-sources.sh
[platform/upstream/automake.git] / t / dist-formats.tap
1 #! /bin/sh
2 # Copyright (C) 2012-2013 Free Software Foundation, Inc.
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2, or (at your option)
7 # any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 # Check support for different compression formats used by distribution
18 # archives.
19
20 am_create_testdir=empty
21 . test-init.sh
22
23 plan_ 66
24
25 # ---------------------------------------------------- #
26 #  Common and/or auxiliary subroutines and variables.  #
27 # ---------------------------------------------------- #
28
29 ocwd=$(pwd) || fatal_ "getting current working directory"
30
31 unset TAR
32
33 # Create common aclocal.m4 file, for later tests.
34 mkdir setup \
35   && cd setup \
36   && echo 'AC_INIT([x], [0]) AM_INIT_AUTOMAKE' > configure.ac \
37   && $ACLOCAL \
38   && mv aclocal.m4 .. \
39   && cd .. \
40   && rm -rf setup \
41   || fatal_ "creating common aclocal.m4 file"
42
43 # Some make implementations (e.g., HP-UX) don't grok '-j', some require
44 # no space between '-j' and the number of jobs (e.g., older GNU make
45 # versions), and some *do* require a space between '-j' and the number
46 # of jobs (e.g., Solaris dmake).  We need a runtime test to see what
47 # works.
48 for MAKE_j4 in "$MAKE -j4" "$MAKE -j 4" false; do
49   echo all: | $MAKE_j4 -f - && break
50   : For shells with buggy 'set -e'.
51 done
52
53 # Set variables '$compressor' and '$suffix'.
54 setup_vars_for_compression_format ()
55 {
56   suffix=NONE compressor=NONE
57   case $1 in
58     gzip) suffix=tar.gz  compressor=gzip     ;;
59     lzip) suffix=tar.lz  compressor=lzip     ;;
60       xz) suffix=tar.xz  compressor=xz       ;;
61    bzip2) suffix=tar.bz2 compressor=bzip2    ;;
62      zip) suffix=zip     compressor=zip      ;;
63        *) fatal_ "invalid compression format '$1'";;
64   esac
65 }
66
67 have_compressor ()
68 {
69   test $# -eq 1 || fatal_ "have_compressor(): bad usage"
70   case $1 in
71     # Assume gzip(1) is available on every reasonable portability target.
72     gzip)
73       return 0;;
74     *)
75       case $1 in
76         # Do not use --version, or older versions bzip2 would try to
77         # compress stdin.  This would cause binary output in the test
78         # logs, with potential breakage of our testsuite harness.
79         bzip2) o=--help;;
80         # OpenSolaris zip do not support the '--version' option, but
81         # accepts the '-v' one with a similar meaning (if no further
82         # arguments are given).
83         zip) o=-v;;
84         # Assume the other compressors we care about support the
85         # '--version' option.
86         *) o=--version;;
87       esac
88       # Redirect to stderr to avoid polluting the output, in case this
89       # function is used in a command substitution (as it is, below).
90       if $1 $o </dev/null >&2; then
91         return 0
92       else
93         return 1
94       fi
95       ;;
96   esac
97   fatal_ "have_compressor(): dead code reached"
98 }
99
100 all_compression_formats='gzip lzip xz bzip2 zip'
101
102 all_compressors=$(
103   for x in $all_compression_formats; do
104     setup_vars_for_compression_format $x
105     echo $compressor
106   done | tr "$nl" ' ')
107 echo All compressors: $all_compressors
108
109 missing_compressors=$(
110   for c in $all_compressors; do
111     have_compressor $c || echo $c
112   done | tr "$nl" ' ')
113 echo Missing compressors: $missing_compressors
114
115 # Redefine to avoid re-running the already executed checks.
116 have_compressor ()
117 {
118   case " $missing_compressors " in *\ $1\ *) false;; *) : ;; esac
119 }
120
121 have_all_compressors ()
122 {
123   test -z "$missing_compressors"
124 }
125
126 start_subtest ()
127 {
128   name=$1; shift
129   test -n "$name" || fatal_ "start_subtest: no subtest name given"
130   if test $# -gt 0; then
131     eval "$@" || fatal_ "start_subtest: evaluating assignments"
132   fi
133   ac_opts=$(echo $ac_opts | tr ',' ' ')
134   am_opts=$(echo $am_opts | tr ',' ' ')
135   mkdir "$name"
136   cd "$name"
137   unindent > configure.ac <<END
138     AC_INIT([$name], [1.0])
139     AM_INIT_AUTOMAKE([$ac_opts])
140     AC_CONFIG_FILES([Makefile])
141     AC_OUTPUT
142 END
143   echo "AUTOMAKE_OPTIONS = $am_opts" > Makefile.am
144   # It is imperative that aclocal.m4 is copied after configure.ac has
145   # been created, to avoid a spurious trigger of the automatic remake
146   # rules for configure & co.
147   cp "$ocwd"/aclocal.m4 \
148      "$am_scriptdir"/missing \
149      "$am_scriptdir"/install-sh \
150      .
151 }
152
153 end_subtest ()
154 {
155   unset name; unset ac_opts; unset am_opts;
156   cd "$ocwd" || fatal_ "couldn't chdir back to '$ocwd'"
157 }
158
159 command_ok_if_have_compressor ()
160 {
161   if have_compressor "$compressor"; then
162     command_ok_ "$@"
163   else
164     skip_ -r "'$compressor' not available" "$1"
165   fi
166 }
167
168 can_compress ()
169 {
170   test $# -eq 2 || fatal_ "can_compress: bad number of arguments"
171   tarname=$1 format=$2
172   setup_vars_for_compression_format "$format"
173
174   command_ok_ "'dist-$format' target always created" $MAKE -n dist-$format
175
176   command_ok_if_have_compressor "'make dist-$format' work by default" \
177     eval '
178       rm -rf *$tarname* \
179         && $MAKE dist-$format \
180         && test -f $tarname-1.0.$suffix \
181         && ls -l *$tarname* \
182         && test "$(echo *$tarname*)" = $tarname-1.0.$suffix'
183
184   unset suffix compressor format tarname
185 }
186
187 # ---------------------------------------- #
188 #  Defaults layout of the dist-* targets.  #
189 # ---------------------------------------- #
190
191 start_subtest defaults
192
193 command_ok_ "default [automake]"        $AUTOMAKE
194 command_ok_ "default [autoconf]"        $AUTOCONF
195 command_ok_ "default [configure]"       ./configure
196 command_ok_ "default [make distcheck]"  $MAKE distcheck
197
198 command_ok_ "'make dist' only builds *.tar.gz by default" \
199             test "$(ls *defaults*)" = defaults-1.0.tar.gz
200
201 rm -rf *defaults*
202
203 for fmt in $all_compression_formats; do
204   can_compress defaults $fmt
205 done
206 unset fmt
207
208 end_subtest
209
210 # ----------------------------------------------------------- #
211 #  Check diagnostic for no-dist-gzip without another dist-*.  #
212 # ----------------------------------------------------------- #
213
214 nogzip_stderr ()
215 {
216   grep "$1:.*no-dist-gzip" stderr \
217     && grep "$1:.* at least one archive format must be enabled" stderr
218 }
219
220 nogzip_automake_failure ()
221 {
222   AUTOMAKE_fails -d "no-dist-gzip ($1) without other formats is an error"
223   command_ok_ "no-dist-gzip ($1) without other formats gives diagnostic" \
224               nogzip_stderr "$2"
225 }
226
227 start_subtest am-nogz-only am_opts=no-dist-gzip ac_opts=
228 nogzip_automake_failure 'am' 'Makefile\.am:1'
229 end_subtest
230
231 start_subtest ac-nogz-only am_opts= ac_opts=no-dist-gzip
232 nogzip_automake_failure 'ac' 'configure\.ac:2'
233 end_subtest
234
235 # ------------------------------------------------- #
236 #  Check use of no-dist-gzip with a dist-* option.  #
237 # ------------------------------------------------- #
238
239 append_to_opt ()
240 {
241   var=$1_opts val=$2
242   eval "$var=\${$var:+\"\$$var,\"}\$val" || fatal_ "evaluating \${$var}"
243   unset var val
244 }
245
246 nogzip ()
247 {
248   test $#,$1,$3,$5 = 6,in,and,in \
249     && case $2,$6 in ac,ac|ac,am|am,ac|am,am) :;; *) false;; esac \
250     || fatal_ "nogzip: invalid usage"
251   format=$4 where_dist_nogzip=$2 where_dist_format=$6
252   shift 6
253
254   am_opts= ac_opts=
255   append_to_opt $where_dist_format dist-$format
256   append_to_opt $where_dist_nogzip no-dist-gzip
257   setup_vars_for_compression_format "$format"
258   # Do these before the am_opts and ac_opts variable can be munged
259   # by 'start_subtest'.
260   desc=
261   test -n "$am_opts" && desc=${desc:+"$desc "}"am=$am_opts"
262   test -n "$ac_opts" && desc=${desc:+"$desc "}"ac=$ac_opts"
263
264   start_subtest nogzip-$format am_opts=$am_opts ac_opts=$ac_opts
265
266   unindent >> Makefile.am <<END
267     check-ark-name:
268         test \$(DIST_ARCHIVES) = \$(distdir).$suffix
269     check-ark-exists:
270         test -f \$(distdir).$suffix
271     check-no-tar-gz:
272         test ! -f \$(distdir).tar.gz
273 END
274
275   command_ok_ "$desc [automake]" $AUTOMAKE
276   command_ok_ "$desc [autoconf]" $AUTOCONF
277   command_ok_ "$desc [configure]" ./configure
278   command_ok_ "$desc [ark-name]" $MAKE check-ark-name
279   command_ok_if_have_compressor "$desc [distcheck]" $MAKE distcheck
280   command_ok_if_have_compressor "$desc [ark-exists]" $MAKE check-ark-exists
281   command_ok_ "$desc [no .tar.gz]"  $MAKE check-no-tar-gz
282
283   unset desc
284
285   end_subtest
286 }
287
288 #      $1 $2  $3   $4     $5  $6
289 nogzip in am  and  bzip2  in  am
290 nogzip in ac  and  xz     in  am
291 nogzip in am  and  lzip   in  ac
292 nogzip in ac  and  zip    in  ac
293
294
295 # ----------------------------------------------------------- #
296 #  The 'dist-gzip' target is created also with no-dist-gzip.  #
297 # ----------------------------------------------------------- #
298
299 start_subtest dist-gzip-persistence am_opts=no-dist-gzip,dist-xz
300 command_ok_ "dist-gzip persistence [automake]"  $AUTOMAKE
301 command_ok_ "dist-gzip persistence [autoconf]"  $AUTOCONF
302 command_ok_ "dist-gzip persistence [configure]" ./configure
303 can_compress dist-gzip-persistence gzip
304 end_subtest
305
306
307 # ----------------------- #
308 #  Parallel compression.  #
309 # ----------------------- #
310
311 # We only use formats requiring 'gzip', 'bzip2' and 'xz' programs,
312 # since there are the most likely to be all found on the majority
313 # of systems.
314
315 start_subtest parallel-compression ac_opts=dist-bzip2 am_opts=dist-xz
316
317 desc=gzip+bzip2+xz
318 tarname=parallel-compression-1.0
319
320 check_tarball ()
321 {
322   format=$1
323   setup_vars_for_compression_format $format
324   (
325     tarball=$tarname.$suffix \
326       && test -f $tarball \
327       && mkdir check-$format \
328       && cp $tarball check-$format \
329       && cd check-$format \
330       && $compressor -d $tarball \
331       && tar xvf $tarname.tar \
332       && diff ../Makefile.in $tarname/Makefile.in \
333       && cd .. \
334       && rm -rf check-$format
335    )
336 }
337
338 command_ok_ "$desc [automake]" $AUTOMAKE
339
340 if ! have_compressor xz && ! have_compressor bzip2; then
341   skip_reason="both 'bzip2' and 'xz' are unavailable"
342 elif ! have_compressor xz; then
343   skip_reason="'xz' not available"
344 elif ! have_compressor bzip2; then
345   skip_reason="'bzip2' not available"
346 else
347   skip_reason=
348 fi
349 if test "$MAKE_j4" = false; then
350   test -z "$skip_reason" || skip_reason="$skip_reason, and "
351   skip_reason="${skip_reason}make concurrency unavailable"
352 fi
353
354 if test -n "$skip_reason"; then
355   skip_row_ 6 -r "$skip_reason" "$desc"
356 else
357   command_ok_ "$desc [autoconf]" $AUTOCONF
358   command_ok_ "$desc [configure]" ./configure
359   command_ok_ "$desc [make -j4 dist-all]"  $MAKE_j4 dist
360   ls -l # For debugging.
361   command_ok_ "$desc [check .tar.gz tarball]"  check_tarball gzip
362   command_ok_ "$desc [check .tar.bz2 tarball]" check_tarball bzip2
363   command_ok_ "$desc [check .tar.xz tarball]"  check_tarball xz
364 fi
365
366 unset tarname desc skip_reason
367
368 end_subtest
369
370
371 # --------------------------------------------------------- #
372 #  The various 'dist-*' targets can happily work together.  #
373 # --------------------------------------------------------- #
374
375 start_subtest all-together
376
377 desc='all compressors together'
378 tarname=all-together-1.0
379
380 echo 'AM_INIT_AUTOMAKE([' > am-init.m4
381 echo 'AUTOMAKE_OPTIONS =' > Makefile.am
382
383 # Add half 'dist-*' options to AM_INIT_AUTOMAKE, half to AUTOMAKE_OPTIONS.
384 flip=:
385 for fmt in $all_compression_formats; do
386   test $fmt = gzip && continue
387   if $flip; then
388     echo "  dist-$fmt" >> am-init.m4
389     flip=false
390   else
391     echo "AUTOMAKE_OPTIONS += dist-$fmt" >> Makefile.am
392     flip=:
393   fi
394 done
395 unset flip fmt
396
397 echo '])' >> am-init.m4
398
399 sed 's/AM_INIT_AUTOMAKE.*/m4_include([am-init.m4])/' configure.ac > t
400 mv -f t configure.ac
401
402 # For debugging.
403 cat Makefile.am
404 cat configure.ac
405 cat am-init.m4
406
407 command_ok_ "$desc [aclocal]" $ACLOCAL --force
408 command_ok_ "$desc [automake]" $AUTOMAKE
409 command_ok_ "$desc [autoconf]" $AUTOCONF
410 command_ok_ "$desc [configure]" ./configure
411
412 if have_all_compressors; then
413   command_ok_ "$desc [make distcheck, real]" $MAKE distcheck
414 else
415   skip_ -r "not all compressors available" "$desc [make distcheck, real]"
416 fi
417
418 # We fake existence of all the compressors here, so that we don't have
419 # to require any of them to run the further tests.  This is especially
420 # important since it's very unlikely that a non-developer has all the
421 # compression tools installed on his machine at the same time.
422
423 mkdir bin
424 cd bin
425 cat > check-distdir <<END
426 #!/bin/sh
427 { ls -l '$tarname' && diff Makefile.am '$tarname'/Makefile.am; } >&2 \
428   || { echo "== distdir fail =="; exit 1; }
429 END
430 cat > grep-distdir-error <<'END'
431 #!/bin/sh
432 grep 'distdir fail' && exit 1
433 :
434 END
435 chmod a+x check-distdir grep-distdir-error
436 for prog in tar $all_compressors; do
437   case $prog in
438     tar|zip) cp check-distdir $prog;;
439           *) cp grep-distdir-error $prog;;
440   esac
441 done
442 unset prog
443 ls -l # For debugging.
444 cd ..
445
446 oPATH=$PATH
447 PATH=$(pwd)/bin$PATH_SEPARATOR$PATH; export PATH
448
449 command_ok_ \
450   "$desc ['make dist-all', stubbed]" \
451   $MAKE dist-all
452
453 subdesc="$desc ['make dist -j4', stubbed]"
454 if test "$MAKE_j4" = false; then
455   skip_ -r "make concurrency unavailable" "$subdesc"
456 else
457   command_ok_ "$subdesc" $MAKE_j4 dist
458 fi
459 unset subdesc
460
461 PATH=$oPATH; export PATH
462
463 end_subtest
464
465 :