dist-formats.tap 13 KB

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