You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

366 lines
16 KiB

  1. #!/bin/sh
  2. set -e
  3. cd "$(readlink -f $(dirname $0))"
  4. if [ -n "${GBP_BUILD_DIR}" ]; then
  5. cd "$GBP_BUILD_DIR"
  6. fi
  7. VERSION=$(dpkg-parsechangelog | sed -n -e '/^Version:/s/^Version: //p')
  8. DISTRIBUTION=$(dpkg-parsechangelog | sed -n -e '/^Distribution:/s/^Distribution: //p')
  9. LIBAPTPKGVERSION="$(awk -v ORS='.' '/^\#define APT_PKG_M/ {print $3}' apt-pkg/contrib/macros.h | sed 's/\.$//')"
  10. LIBAPTINSTVERSION="$(sed -nr 's/set\(MAJOR ([^)]*)\)/\1/p' apt-inst/CMakeLists.txt)"
  11. librarysymbolsfromfile() {
  12. local MISSING="$(grep '^+#MISSING' "$1")"
  13. local SYMVER="$2"
  14. echo '=== Missing optional symbols:'
  15. echo -n "$MISSING" | grep '|optional=' || true
  16. echo '=== Missing required symbols:'
  17. echo -n "$MISSING" | grep -v '|optional=' || true
  18. echo '=== New symbols:'
  19. grep '^+ ' "$1" | grep -v '^+ (c++' | cut -d' ' -f 2 | cut -d'@' -f 1 | c++filt | while read line; do
  20. echo " (c++)\"${line}@${SYMVER}\" $VERSION"
  21. done | sort -u
  22. }
  23. test_deb_control() {
  24. echo "Package: apt-test-depends"
  25. echo "Version: 1.0"
  26. echo "Architecture: all"
  27. printf "Depends:"
  28. (
  29. for i in Build-Depends Build-Depends-Indep Build-Depends-Arch; do
  30. grep-dctrl -ns $i -S apt ./debian/control && echo ,
  31. done
  32. grep-dctrl -ns Depends -F Tests run-tests ./debian/tests/control
  33. ) | tr '\n' ' '\
  34. | sed -r -e 's#<[^,<>()@]*>##g' \
  35. -e 's#@[^,<>()@]*@##g' \
  36. -e 's#\[linux-any\]*##g' \
  37. -e 's#\[[^][]*\]*##g' \
  38. -e 's#dpkg-dev \([^)]*\)#dpkg-dev#g' \
  39. -e 's#debhelper \([^)]*\)#debhelper#g' \
  40. -e 's#g\+\+ \([^)]*\)#g++#g' \
  41. -e 's#@##g' \
  42. -e 's#,(\s+,)+#, #g' \
  43. -e 's#\s+# #g'
  44. }
  45. if [ "$1" = 'pre-export' ]; then
  46. libraryversioncheck() {
  47. local LIBRARY="$1"
  48. local VERSION="$2"
  49. if [ ! -e "debian/${LIBRARY}${VERSION}.symbols" ]; then
  50. echo >&2 "Library ${LIBRARY} in version ${VERSION} has no symbols file! (maybe forgot to rename?)"
  51. exit 1
  52. fi
  53. if [ "$(head -n1 "debian/${LIBRARY}${VERSION}.symbols")" != "${LIBRARY}.so.${VERSION} ${LIBRARY}${VERSION} #MINVER#" ]; then
  54. echo >&2 "Library ${LIBRARY}${VERSION} has incorrect version in symbol header! (»$(head -n1 "debian/${LIBRARY}${VERSION}.symbols")«)"
  55. exit 2
  56. fi
  57. }
  58. libraryversioncheck 'libapt-pkg' "$LIBAPTPKGVERSION"
  59. libraryversioncheck 'libapt-inst' "$LIBAPTINSTVERSION"
  60. if [ "$DISTRIBUTION" = 'sid' ]; then
  61. echo >&2 '»sid« is not a valid distribution. Replace it with »unstable« for you'
  62. sed -i -e 's/) sid; urgency=/) unstable; urgency=/' debian/changelog
  63. DISTRIBUTION='unstable'
  64. elif [ "$DISTRIBUTION" = 'UNRELEASED' ]; then
  65. echo >&2 'WARNING: Remember to change to a valid distribution for release'
  66. VERSION="$VERSION~$(date +%Y%m%d)"
  67. fi
  68. sed -i -e "s/^set(PACKAGE_VERSION \".*\")$/set(PACKAGE_VERSION \"${VERSION}\")/" CMakeLists.txt
  69. sed -i -e "s/^<!ENTITY apt-product-version \".*\">$/<!ENTITY apt-product-version \"${VERSION}\">/" doc/apt-verbatim.ent
  70. # update the last-modification field of manpages based on git changes
  71. grep --files-with-matches '<date>' doc/*.xml | while read file; do \
  72. LASTMOD="$(date -d "@$(git log --format='%at' --max-count=1 --invert-grep --fixed-strings --grep 'review
  73. typo
  74. release
  75. Git-Dch: Ignore' "$file")" '+%Y-%m-%dT00:00:00Z')"
  76. sed -i -e "s#^\([ ]\+\)<date>.*</date>\$#\1<date>$LASTMOD</date>#" "$file"
  77. done
  78. if [ "$(date +%Y-%m-%d)" != "$(grep --max-count=1 '^"POT-Creation-Date: .*\n"$' po/apt-all.pot | cut -d' ' -f 2)" -o \
  79. "$(date +%Y-%m-%d)" != "$(grep --max-count=1 '^"POT-Creation-Date: .*\n"$' doc/po/apt-doc.pot | cut -d' ' -f 2)" ]; then
  80. echo >&2 'POT files are not up-to-date. Execute »make update-po« for you…'
  81. [ -e build ] || mkdir build
  82. ( cd build && cmake .. )
  83. cmake --build build --target update-po -- -j 4
  84. fi
  85. elif [ "$1" = 'pre-build' ]; then
  86. if [ "$DISTRIBUTION" = "UNRELEASED" ]; then
  87. echo 'BUILDING AN UNRELEASED VERSION'
  88. else
  89. CONFVERSION="$(sed -ne "s/^set(PACKAGE_VERSION \"\(.*\)\")$/\1/p" CMakeLists.txt)"
  90. if [ "$VERSION" != "$CONFVERSION" ]; then
  91. echo "changelog (${VERSION}) and CMakeLists.txt (${CONFVERSION}) talk about different versions!"
  92. echo "You probably want to run »./prepare-release pre-export« to fix this."
  93. exit 1
  94. fi
  95. NEWSDISTRIBUTION=$(dpkg-parsechangelog -l debian/NEWS | sed -n -e '/^Distribution:/s/^Distribution: //p')
  96. if [ "$NEWSDISTRIBUTION" = 'UNRELEASED' ]; then
  97. echo "changelog (${VERSION}) has a distribution (${DISTRIBUTION}) set, while the NEWS file hasn't!"
  98. echo "You probably want to edit »debian/NEWS« to fix this."
  99. exit 1
  100. fi
  101. fi
  102. elif [ "$1" = 'post-build' ]; then
  103. if [ "$DISTRIBUTION" != "UNRELEASED" ]; then
  104. echo >&2 "REMEMBER: Tag this release with »git tag -s ${VERSION}« if you are satisfied"
  105. else
  106. echo >&2 'REMEMBER: Change to a valid distribution before release'
  107. fi
  108. dpkg-checkbuilddeps -d 'libxml2-utils'
  109. HEADERBLUEPRINT="$(mktemp)"
  110. sed -n '1,/^$/p' doc/apt.8.xml > "$HEADERBLUEPRINT"
  111. find doc -mindepth 1 -maxdepth 1 -type f -name '*.xml' | while read FILE; do
  112. if ! sed -n '1,/^$/p' "$FILE" | cmp "$HEADERBLUEPRINT" - >/dev/null 2>&1; then
  113. echo >&2 "WARNING: Manpage $FILE has not the usual header! (see diff below)"
  114. sed -n '1,/^$/p' "$FILE" | diff -u "$HEADERBLUEPRINT" - || true
  115. fi
  116. done
  117. sed -n '1,/^$/p' doc/guide.dbk > "$HEADERBLUEPRINT"
  118. find doc -mindepth 1 -maxdepth 1 -type f -name '*.dbk' | while read FILE; do
  119. if ! sed -n '1,/^$/p' "$FILE" | cmp "$HEADERBLUEPRINT" - >/dev/null 2>&1; then
  120. echo >&2 "WARNING: Documentation $FILE has not the usual header (see diff below)!"
  121. sed -n '1,/^$/p' "$FILE" | diff -u "$HEADERBLUEPRINT" - || true
  122. fi
  123. done
  124. rm "$HEADERBLUEPRINT"
  125. # check the manpages with each vendor for vendor-specific errors…
  126. find vendor -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 2 | while read DISTRO; do
  127. ln -sf ../vendor/${DISTRO}/apt-vendor.ent doc
  128. if ! xmllint --nonet --valid --noout $(find doc/ -maxdepth 1 -name '*.xml'); then
  129. echo >&2 "WARNING: original docbook manpages have errors with vendor ${DISTRO}!"
  130. fi
  131. done
  132. # lets assume we will always have a german manpage translation
  133. if [ -e */doc/de/ -o -e doc/de ]; then
  134. # … but check the translations only with one vendor for translation-specific errors
  135. if ! xmllint --path /vendor/$(./vendor/getinfo current)/ \
  136. --path doc/ \
  137. --nonet --valid --noout $(find doc/ */doc/ -mindepth 2 -maxdepth 2 -name '*.xml'); then
  138. echo >&2 "WARNING: translated docbook manpages have errors!"
  139. fi
  140. else
  141. echo >&2 "ERROR: translated manpages need to be build before they can be checked!"
  142. fi
  143. rm -f doc/apt-vendor.ent
  144. elif [ "$1" = 'library' ]; then
  145. librarysymbols() {
  146. local libname=$(echo "${1}" | cut -c 4-)
  147. local buildlib="build/bin/${1}.so.${2}"
  148. for dir in $libname */$libname; do
  149. local new_buildlib="$dir/${1}.so.${2}"
  150. if [ -r "${new_buildlib}" ] && [ ! -e "$buildlib" -o "$new_buildlib" -nt "$buildlib" ]; then
  151. local buildlib="${new_buildlib}"
  152. fi
  153. done
  154. if [ ! -r "$buildlib" ]; then
  155. echo "ERROR: The library ${1} has to be built before symbols can be checked!"
  156. return
  157. fi
  158. echo "Checking $1 in version $2 build at $(stat -L -c '%y' "$buildlib")"
  159. local tmpfile=$(mktemp)
  160. dpkg-gensymbols -p${1}${2} -e${buildlib} -Idebian/${1}${2}.symbols -O/dev/null 2> /dev/null > $tmpfile || true
  161. librarysymbolsfromfile "$tmpfile" "$(echo "${1}" | cut -c 4- | tr -d '-' | tr 'a-z' 'A-Z')_${2}"
  162. rm -f $tmpfile
  163. }
  164. librarysymbols 'libapt-pkg' "${LIBAPTPKGVERSION}"
  165. echo
  166. librarysymbols 'libapt-inst' "${LIBAPTINSTVERSION}"
  167. elif [ "$1" = 'buildlog' ]; then
  168. while [ -n "$2" ]; do
  169. librarysymbolsfromfile "$2" 'UNKNOWN'
  170. shift
  171. done
  172. elif [ "$1" = 'travis-ci' ]; then
  173. apt-get install -qy --no-install-recommends dctrl-tools equivs gdebi-core moreutils
  174. test_deb_control > test-control
  175. equivs-build test-control
  176. gdebi -n apt-test-depends_1.0_all.deb
  177. elif [ "$1" = 'coverage' ]; then
  178. DIR="${2:-./coverage}"
  179. git clean -dfX # remove ignored build artifacts for a clean start
  180. make CFLAGS+='--coverage' CXXFLAGS+='--coverage'
  181. LCOVRC='--rc geninfo_checksum=1 --rc lcov_branch_coverage=1'
  182. mkdir "$DIR"
  183. lcov --no-external --directory . --capture --initial --output-file "${DIR}/apt.coverage.init" ${LCOVRC}
  184. make test || true
  185. ./test/integration/run-tests -q || true
  186. lcov --no-external --directory . --capture --output-file "${DIR}/apt.coverage.run" ${LCOVRC}
  187. lcov -a "${DIR}/apt.coverage.init" -a "${DIR}/apt.coverage.run" -o "${DIR}/apt.coverage.total" ${LCOVRC}
  188. cp "${DIR}/apt.coverage.total" "${DIR}/apt.coverage.fixed"
  189. rewritefile() {
  190. file="$1"
  191. shift
  192. name="$(basename "$file")"
  193. while [ -n "$1" ]; do
  194. if [ -r "$1/$name" ]; then
  195. sed -i "s#$file#$1/$name#" "${DIR}/apt.coverage.fixed"
  196. break
  197. fi
  198. shift
  199. done
  200. if [ -z "$1" ]; then
  201. echo >&2 "Coverage data captured for unknown file $file"
  202. fi
  203. }
  204. grep 'build/include/' "${DIR}/apt.coverage.fixed" | sed "s#^SF:$(pwd)/##" | while read file; do
  205. rewritefile "$file" 'apt-pkg' 'apt-pkg/deb' 'apt-pkg/edsp' 'apt-pkg/contrib' \
  206. 'apt-inst' 'apt-inst/deb' 'apt-inst/contrib' 'apt-private'
  207. done
  208. genhtml --output-directory "${DIR}" "${DIR}/apt.coverage.fixed" ${LCOVRC}
  209. elif [ "$1" = 'spellcheckers' -o "$1" = 'lint' ]; then
  210. is_available() {
  211. if dpkg-checkbuilddeps -d "$1" 2>/dev/null; then
  212. return 0
  213. fi
  214. echo "### SKIPPING ${2:-$1} functionality as ${1} isn't installed"
  215. }
  216. if is_available 'codespell'; then
  217. echo '### codespell in source directories:'
  218. codespell --enable-colors $(find . -mindepth 1 -maxdepth 1 -type d \! -name '.git' \! -name 'doc' \! -name 'po' \! -name 'build' \! -name 'test') \
  219. | grep -v -e '^.*debian/changelog.*Troup.*==>.*Troupe.*$' \
  220. -e '^.*apt-pkg/contrib/fileutl\.cc.*creat.*==>.*create.*$' \
  221. -e '^.*methods/aptmethod\.h.*creat.*==>.*create.*$' \
  222. -e '^.*dselect/install.*ans.*==>.*and.*$' \
  223. || true
  224. echo '### codespell in testcases:'
  225. codespell --enable-colors $(find test -type f \! -name 'status-*' \! -name 'Packages-*' \! -name '*.deb' \! -name '*.sec' \! -name '*.pub' \! -name '*.db') \
  226. | grep -v -e '^.*test/libapt/file-helpers\.cc.*creat.*==>.*create.*$' \
  227. -e '^.*test/libapt/tagfile_test\.cc.*tyes.*==>.*types.*$' \
  228. -e '^.*test/libapt/strutil_test\.cc.*Fiel.*==>.*Feel.*$' \
  229. -e '^.*test/integration/skip-bug-601016-description-translation.*Paket.*==>.*Packet.*$' \
  230. -e '^.*test/integration/skip-bug-601016-description-translation.*Wege.*==>.*Wedge.*$' \
  231. || true
  232. echo '### codespell in documentation:'
  233. codespell --enable-colors doc/*.xml doc/*.txt doc/*.dbk doc/*.ent doc/*.cmake.in doc/xml.add doc/po4a.conf doc/examples doc/po/apt-doc.pot \
  234. po/apt-all.pot README.* COPYING \
  235. || true
  236. fi
  237. if is_available 'lintian' 'spellintian'; then
  238. echo '### spellintian in source directories:'
  239. {
  240. for DIR in $(find . -mindepth 1 -maxdepth 1 -type d \! -name '.git' \! -name 'doc' \! -name 'po' \! -name 'build' \! -name 'test'); do
  241. spellintian $(find "$DIR" -type f)
  242. done
  243. } \
  244. | grep -v \
  245. -e '^.*: long long (duplicate word) -> long$' \
  246. -e '^./apt-pkg/pkgcache.h: ID ID (duplicate word) -> ID$' \
  247. -e '^./apt-pkg/contrib/mmap.cc: WorkSpace WorkSpace (duplicate word) -> WorkSpace$' \
  248. -e '^./apt-pkg/contrib/md5.cc: z z (duplicate word) -> z$' \
  249. -e '^./apt-pkg/metaindex.cc: const const (duplicate word) -> const$' \
  250. -e '^./apt-pkg/acquire-method.cc: QueueBack QueueBack (duplicate word) -> QueueBack$' \
  251. -e '^./CMake/Translations.cmake: domain domain (duplicate word) -> domain$' \
  252. -e '^./CMake/apti18n.h.in: m m (duplicate word) -> m$' \
  253. -e '^./CMake/run_if_exists.sh: fi fi (duplicate word) -> fi$' \
  254. -e '^./ftparchive/byhash.cc: ByHash ByHash (duplicate word) -> ByHash$' \
  255. -e '^./ftparchive/writer.cc: this Packages -> these packages$' \
  256. -e '^./ftparchive/byhash.h: ByHash ByHash (duplicate word) -> ByHash$' \
  257. -e '^./cmdline/apt-key.in: done done (duplicate word) -> done$' \
  258. -e '^./cmdline/apt-key.in: fi fi (duplicate word) -> fi$' \
  259. -e '^./cmdline/apt-key.in: echo echo (duplicate word) -> echo$' \
  260. -e '^./triehash/.travis.yml: perl perl (duplicate word) -> perl$' \
  261. -e '^./triehash/README.md: Performance Performance (duplicate word) -> Performance$' \
  262. -e '^./debian/apt.apt-compat.cron.daily: fi fi (duplicate word) -> fi$' \
  263. -e '^./debian/apt.auto-removal.sh: done done (duplicate word) -> done$' \
  264. -e '^./debian/apt.systemd.daily: fi fi (duplicate word) -> fi$' \
  265. -e '^./debian/apt.postinst: fi fi (duplicate word) -> fi$' \
  266. -e '^./methods/http.cc: Sz Sz (duplicate word) -> Sz$' \
  267. -e '^./methods/ftp.cc: AFMap AFMap (duplicate word) -> AFMap$' \
  268. -e '^./dselect/install: fi fi (duplicate word) -> fi$' \
  269. -e '^./CMake/Documentation.cmake: endforeach endforeach (duplicate word) -> endforeach$' \
  270. -e '^./apt-pkg/deb/deblistparser.cc: c c (duplicate word) -> c$' \
  271. -e '^./apt-private/private-install.cc: result result (duplicate word) -> result$' \
  272. -e '^./debian/changelog: the the (duplicate word) -> the$' \
  273. -e '^./debian/changelog: procceed -> proceed$' \
  274. -e '^./methods/aptmethod.h: QueueBack QueueBack (duplicate word) -> QueueBack$' \
  275. || true
  276. echo '### spellintian in testcases:'
  277. spellintian $(find test -type f \! -name 'status-*' \! -name 'Packages-*' \! -name '*.deb' \! -name '*.sec' \! -name '*.pub' \! -name '*.db') \
  278. | grep -v \
  279. -e '^.*: long long (duplicate word) -> long$' \
  280. -e '^test/integration/.*: fi fi (duplicate word) -> fi$' \
  281. -e '^test/integration/.*: done done (duplicate word) -> done$' \
  282. -e '^test/integration/.*: echo echo (duplicate word) -> echo$' \
  283. -e '^test/integration/test-00-commands-have-help: moo moo (duplicate word) -> moo$' \
  284. -e '^test/integration/test-apt-cache: bar bar (duplicate word) -> bar$' \
  285. -e '^test/integration/test-sourceslist-trusted-options: everythingsucceeds everythingsucceeds (duplicate word) -> everythingsucceeds$' \
  286. -e '^test/integration/test-sourceslist-trusted-options: everythingfails everythingfails (duplicate word) -> everythingfails$' \
  287. -e '^test/integration/test-apt-get-changelog: foo foo (duplicate word) -> foo$' \
  288. -e '^test/integration/test-ubuntu-bug-761175-remove-purge: testround testround (duplicate word) -> testround$' \
  289. -e '^test/integration/test-apt-get-download: apt apt (duplicate word) -> apt$' \
  290. -e '^test/integration/test-apt-showlist-orgroup-in-recommends: zzz zzz (duplicate word) -> zzz$' \
  291. -e '^test/integration/test-bug-691453-apt-cache-search-multi-pattern: bar bar (duplicate word) -> bar$' \
  292. -e '^test/integration/test-allow: hold hold (duplicate word) -> hold$' \
  293. -e '^test/integration/test-apt-by-hash-update: ensureitsbroken ensureitsbroken (duplicate word) -> ensureitsbroken$' \
  294. -e '^test/integration/test-apt-source-and-build-dep: foo foo (duplicate word) -> foo$' \
  295. || true
  296. echo '### spellintian in documentation:'
  297. spellintian doc/*.xml doc/*.txt doc/*.dbk doc/*.ent doc/*.cmake.in doc/xml.add doc/po4a.conf doc/examples/* doc/po/apt-doc.pot po/apt-all.pot README.* COPYING \
  298. | grep -v \
  299. -e '^doc/examples/configure-index: https https (duplicate word) -> https$' \
  300. || true
  301. fi
  302. # stay true to the old name
  303. if [ "$1" = 'spellcheckers' ]; then exit; fi
  304. if is_available 'i18nspector'; then
  305. echo '### i18nspector on translation files:'
  306. i18nspector po/*.po po/*.pot doc/po/*.pot doc/po/*.po \
  307. | grep -v \
  308. -e '^I: po/es.po: duplicate-header-field X-POFile-SpellExtra$' \
  309. || true
  310. fi
  311. else
  312. echo >&1 "Usage:\t$0 pre-export
  313. \t$0 pre-build
  314. \t$0 post-build
  315. Updating po-files and versions as well as some basic checks are done
  316. by »pre-export« which needs to be run before package building.
  317. If you use »gbp buildpackage« you will be notified if you forget.
  318. »pre-build« and »post-build« can be used to run some more or less
  319. useful checks automatically run by »gbp« otherwise.
  320. \t$0 library
  321. \t$0 buildlog filename…
  322. »library« and »buildlog« aren't run automatically but can be useful for
  323. maintaining the (more or less experimental) symbols files we provide.
  324. »library« displays the diff between advertised symbols and the once provided
  325. by the libraries, while »buildlog« extracts this diff from the buildlogs.
  326. Both will format the diff properly.
  327. \t$0 travis-ci
  328. \t$0 coverage [output-dir]
  329. »travis-ci« is a shortcut to install all build- as well as test-dependencies
  330. used by .travis.yml.
  331. »coverage« does a clean build with the right flags for coverage reporting,
  332. runs all tests and generates a html report in the end.
  333. \t$0 spellcheckers
  334. »spellcheckers« runs »codespell« and »spellintian« on the appropiate files and
  335. filters out obvious false positives.
  336. "
  337. fi