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.
 
 
 
 
 
 

378 lines
17 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 '^.*debian/changelog.*readd.*==>.*readd.*$' \
  221. -e '^.*debian/changelog.*Tim.*==>.*Time.*$' \
  222. -e '^.*apt-pkg/contrib/fileutl\.cc.*creat.*==>.*create.*$' \
  223. -e '^.*apt-pkg/pkgcache\.h.*mmaped.*==>.*mapped.*$' \
  224. -e '^.*apt-pkg/pkgcachegen\.cc.*mmaped.*==>.*mapped.*$' \
  225. -e '^.*apt-pkg/contrib/mmap\.h.*mmaped.*==>.*mapped.*$' \
  226. -e '^.*cmdline/apt-key\.in.*dashs.*==>.*dashes.*$' \
  227. -e '^.*methods/aptmethod\.h.*creat.*==>.*create.*$' \
  228. -e '^.*dselect/install.*ans.*==>.*and.*$' \
  229. -e '^.*ftparchive/writer\.h.*Delink.*==>.*Unlink.*$' \
  230. -e '^.*ftparchive/writer\.cc.*De[Ll]ink.*==>.*[Uu]nlink.*$' \
  231. || true
  232. echo '### codespell in testcases:'
  233. codespell --enable-colors $(find test -type f \! -name 'status-*' \! -name 'Packages-*' \! -name '*.deb' \! -name '*.sec' \! -name '*.pub' \! -name '*.db') \
  234. | grep -v -e '^.*test/libapt/file-helpers\.cc.*creat.*==>.*create.*$' \
  235. -e '^.*test/libapt/tagfile_test\.cc.*tyes.*==>.*types.*$' \
  236. -e '^.*test/libapt/strutil_test\.cc.*Fiel.*==>.*Feel.*$' \
  237. -e '^.*test/libapt/cdromfindpackages_test\.cc.*Signatur.*==>.*Signature.*$' \
  238. -e '^.*test/integration/skip-bug-601016-description-translation.*Paket.*==>.*Packet.*$' \
  239. -e '^.*test/integration/skip-bug-601016-description-translation.*Wege.*==>.*Wedge.*$' \
  240. -e '^.*test/integration/skip-bug-601016-description-translation.*Methoden.*==>.*Methods.*$' \
  241. -e '^.*test/integration/test-apt-update-not-modified.*readd.*==>.*readd.*$' \
  242. || true
  243. echo '### codespell in documentation:'
  244. 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 \
  245. po/apt-all.pot README.* COPYING \
  246. | grep -v -e '^.*po/apt-all\.pot.*DeLink.*==>.*unlink.*$' \
  247. || true
  248. fi
  249. if is_available 'lintian' 'spellintian'; then
  250. echo '### spellintian in source directories:'
  251. {
  252. for DIR in $(find . -mindepth 1 -maxdepth 1 -type d \! -name '.git' \! -name 'doc' \! -name 'po' \! -name 'build' \! -name 'test'); do
  253. spellintian $(find "$DIR" -type f)
  254. done
  255. } \
  256. | grep -v \
  257. -e '^.*: long long (duplicate word) -> long$' \
  258. -e '^./apt-pkg/pkgcache.h: ID ID (duplicate word) -> ID$' \
  259. -e '^./apt-pkg/contrib/mmap.cc: WorkSpace WorkSpace (duplicate word) -> WorkSpace$' \
  260. -e '^./apt-pkg/contrib/md5.cc: z z (duplicate word) -> z$' \
  261. -e '^./apt-pkg/metaindex.cc: const const (duplicate word) -> const$' \
  262. -e '^./apt-pkg/acquire-method.cc: QueueBack QueueBack (duplicate word) -> QueueBack$' \
  263. -e '^./CMake/Translations.cmake: domain domain (duplicate word) -> domain$' \
  264. -e '^./CMake/apti18n.h.in: m m (duplicate word) -> m$' \
  265. -e '^./CMake/run_if_exists.sh: fi fi (duplicate word) -> fi$' \
  266. -e '^./ftparchive/byhash.cc: ByHash ByHash (duplicate word) -> ByHash$' \
  267. -e '^./ftparchive/writer.cc: this Packages -> these packages$' \
  268. -e '^./ftparchive/byhash.h: ByHash ByHash (duplicate word) -> ByHash$' \
  269. -e '^./cmdline/apt-key.in: done done (duplicate word) -> done$' \
  270. -e '^./cmdline/apt-key.in: fi fi (duplicate word) -> fi$' \
  271. -e '^./cmdline/apt-key.in: echo echo (duplicate word) -> echo$' \
  272. -e '^./triehash/.travis.yml: perl perl (duplicate word) -> perl$' \
  273. -e '^./triehash/README.md: Performance Performance (duplicate word) -> Performance$' \
  274. -e '^./debian/apt.apt-compat.cron.daily: fi fi (duplicate word) -> fi$' \
  275. -e '^./debian/apt.auto-removal.sh: done done (duplicate word) -> done$' \
  276. -e '^./debian/apt.systemd.daily: fi fi (duplicate word) -> fi$' \
  277. -e '^./debian/apt.postinst: fi fi (duplicate word) -> fi$' \
  278. -e '^./methods/http.cc: Sz Sz (duplicate word) -> Sz$' \
  279. -e '^./methods/ftp.cc: AFMap AFMap (duplicate word) -> AFMap$' \
  280. -e '^./dselect/install: fi fi (duplicate word) -> fi$' \
  281. -e '^./CMake/Documentation.cmake: endforeach endforeach (duplicate word) -> endforeach$' \
  282. -e '^./apt-pkg/deb/deblistparser.cc: c c (duplicate word) -> c$' \
  283. -e '^./apt-private/private-install.cc: result result (duplicate word) -> result$' \
  284. -e '^./debian/changelog: the the (duplicate word) -> the$' \
  285. -e '^./debian/changelog: procceed -> proceed$' \
  286. -e '^./methods/aptmethod.h: QueueBack QueueBack (duplicate word) -> QueueBack$' \
  287. || true
  288. echo '### spellintian in testcases:'
  289. spellintian $(find test -type f \! -name 'status-*' \! -name 'Packages-*' \! -name '*.deb' \! -name '*.sec' \! -name '*.pub' \! -name '*.db') \
  290. | grep -v \
  291. -e '^.*: long long (duplicate word) -> long$' \
  292. -e '^test/integration/.*: fi fi (duplicate word) -> fi$' \
  293. -e '^test/integration/.*: done done (duplicate word) -> done$' \
  294. -e '^test/integration/.*: echo echo (duplicate word) -> echo$' \
  295. -e '^test/integration/test-00-commands-have-help: moo moo (duplicate word) -> moo$' \
  296. -e '^test/integration/test-apt-cache: bar bar (duplicate word) -> bar$' \
  297. -e '^test/integration/test-sourceslist-trusted-options: everythingsucceeds everythingsucceeds (duplicate word) -> everythingsucceeds$' \
  298. -e '^test/integration/test-sourceslist-trusted-options: everythingfails everythingfails (duplicate word) -> everythingfails$' \
  299. -e '^test/integration/test-apt-get-changelog: foo foo (duplicate word) -> foo$' \
  300. -e '^test/integration/test-ubuntu-bug-761175-remove-purge: testround testround (duplicate word) -> testround$' \
  301. -e '^test/integration/test-apt-get-download: apt apt (duplicate word) -> apt$' \
  302. -e '^test/integration/test-apt-showlist-orgroup-in-recommends: zzz zzz (duplicate word) -> zzz$' \
  303. -e '^test/integration/test-bug-691453-apt-cache-search-multi-pattern: bar bar (duplicate word) -> bar$' \
  304. -e '^test/integration/test-allow: hold hold (duplicate word) -> hold$' \
  305. -e '^test/integration/test-apt-by-hash-update: ensureitsbroken ensureitsbroken (duplicate word) -> ensureitsbroken$' \
  306. -e '^test/integration/test-apt-source-and-build-dep: foo foo (duplicate word) -> foo$' \
  307. || true
  308. echo '### spellintian in documentation:'
  309. 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 \
  310. | grep -v \
  311. -e '^doc/examples/configure-index: https https (duplicate word) -> https$' \
  312. || true
  313. fi
  314. # stay true to the old name
  315. if [ "$1" = 'spellcheckers' ]; then exit; fi
  316. if is_available 'i18nspector'; then
  317. echo '### i18nspector on translation files:'
  318. i18nspector po/*.po po/*.pot doc/po/*.pot doc/po/*.po \
  319. | grep -v \
  320. -e '^I: po/es.po: duplicate-header-field X-POFile-SpellExtra$' \
  321. || true
  322. fi
  323. else
  324. echo >&1 "Usage:\t$0 pre-export
  325. \t$0 pre-build
  326. \t$0 post-build
  327. Updating po-files and versions as well as some basic checks are done
  328. by »pre-export« which needs to be run before package building.
  329. If you use »gbp buildpackage« you will be notified if you forget.
  330. »pre-build« and »post-build« can be used to run some more or less
  331. useful checks automatically run by »gbp« otherwise.
  332. \t$0 library
  333. \t$0 buildlog filename…
  334. »library« and »buildlog« aren't run automatically but can be useful for
  335. maintaining the (more or less experimental) symbols files we provide.
  336. »library« displays the diff between advertised symbols and the once provided
  337. by the libraries, while »buildlog« extracts this diff from the buildlogs.
  338. Both will format the diff properly.
  339. \t$0 travis-ci
  340. \t$0 coverage [output-dir]
  341. »travis-ci« is a shortcut to install all build- as well as test-dependencies
  342. used by .travis.yml.
  343. »coverage« does a clean build with the right flags for coverage reporting,
  344. runs all tests and generates a html report in the end.
  345. \t$0 spellcheckers
  346. »spellcheckers« runs »codespell« and »spellintian« on the appropiate files and
  347. filters out obvious false positives.
  348. "
  349. fi