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.
 
 
 
 
 
 

319 lines
14 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. fi
  96. elif [ "$1" = 'post-build' ]; then
  97. if [ "$DISTRIBUTION" != "UNRELEASED" ]; then
  98. echo >&2 "REMEMBER: Tag this release with »git tag -s ${VERSION}« if you are satisfied"
  99. else
  100. echo >&2 'REMEMBER: Change to a valid distribution before release'
  101. fi
  102. dpkg-checkbuilddeps -d 'libxml2-utils'
  103. HEADERBLUEPRINT="$(mktemp)"
  104. sed -n '1,/^$/p' doc/apt.8.xml > "$HEADERBLUEPRINT"
  105. find doc -mindepth 1 -maxdepth 1 -type f -name '*.xml' | while read FILE; do
  106. if ! sed -n '1,/^$/p' "$FILE" | cmp "$HEADERBLUEPRINT" - >/dev/null 2>&1; then
  107. echo >&2 "WARNING: Manpage $FILE has not the usual header! (see diff below)"
  108. sed -n '1,/^$/p' "$FILE" | diff -u "$HEADERBLUEPRINT" - || true
  109. fi
  110. done
  111. sed -n '1,/^$/p' doc/guide.dbk > "$HEADERBLUEPRINT"
  112. find doc -mindepth 1 -maxdepth 1 -type f -name '*.dbk' | while read FILE; do
  113. if ! sed -n '1,/^$/p' "$FILE" | cmp "$HEADERBLUEPRINT" - >/dev/null 2>&1; then
  114. echo >&2 "WARNING: Documentation $FILE has not the usual header (see diff below)!"
  115. sed -n '1,/^$/p' "$FILE" | diff -u "$HEADERBLUEPRINT" - || true
  116. fi
  117. done
  118. rm "$HEADERBLUEPRINT"
  119. # check the manpages with each vendor for vendor-specific errors…
  120. find vendor -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 2 | while read DISTRO; do
  121. ln -sf ../vendor/${DISTRO}/apt-vendor.ent doc
  122. if ! xmllint --nonet --valid --noout $(find doc/ -maxdepth 1 -name '*.xml'); then
  123. echo >&2 "WARNING: original docbook manpages have errors with vendor ${DISTRO}!"
  124. fi
  125. done
  126. # lets assume we will always have a german manpage translation
  127. if [ -e */doc/de/ -o -e doc/de ]; then
  128. # … but check the translations only with one vendor for translation-specific errors
  129. if ! xmllint --path /vendor/$(./vendor/getinfo current)/ \
  130. --path doc/ \
  131. --nonet --valid --noout $(find doc/ */doc/ -mindepth 2 -maxdepth 2 -name '*.xml'); then
  132. echo >&2 "WARNING: translated docbook manpages have errors!"
  133. fi
  134. else
  135. echo >&2 "ERROR: translated manpages need to be build before they can be checked!"
  136. fi
  137. rm -f doc/apt-vendor.ent
  138. elif [ "$1" = 'library' ]; then
  139. librarysymbols() {
  140. local libname=$(echo "${1}" | cut -c 4-)
  141. local buildlib="build/bin/${1}.so.${2}"
  142. for dir in $libname */$libname; do
  143. local new_buildlib="$dir/${1}.so.${2}"
  144. if [ -r "${new_buildlib}" ] && [ ! -e "$buildlib" -o "$new_buildlib" -nt "$buildlib" ]; then
  145. local buildlib="${new_buildlib}"
  146. fi
  147. done
  148. if [ ! -r "$buildlib" ]; then
  149. echo "ERROR: The library ${1} has to be built before symbols can be checked!"
  150. return
  151. fi
  152. echo "Checking $1 in version $2 build at $(stat -L -c '%y' "$buildlib")"
  153. local tmpfile=$(mktemp)
  154. dpkg-gensymbols -p${1}${2} -e${buildlib} -Idebian/${1}${2}.symbols -O/dev/null 2> /dev/null > $tmpfile || true
  155. librarysymbolsfromfile "$tmpfile" "$(echo "${1}" | cut -c 4- | tr -d '-' | tr 'a-z' 'A-Z')_${2}"
  156. rm -f $tmpfile
  157. }
  158. librarysymbols 'libapt-pkg' "${LIBAPTPKGVERSION}"
  159. echo
  160. librarysymbols 'libapt-inst' "${LIBAPTINSTVERSION}"
  161. elif [ "$1" = 'buildlog' ]; then
  162. while [ -n "$2" ]; do
  163. librarysymbolsfromfile "$2" 'UNKNOWN'
  164. shift
  165. done
  166. elif [ "$1" = 'travis-ci' ]; then
  167. apt-get install -qy --no-install-recommends dctrl-tools equivs gdebi-core moreutils
  168. test_deb_control > test-control
  169. equivs-build test-control
  170. gdebi -n apt-test-depends_1.0_all.deb
  171. elif [ "$1" = 'coverage' ]; then
  172. DIR="${2:-./coverage}"
  173. git clean -dfX # remove ignored build artefacts for a clean start
  174. make CFLAGS+='--coverage' CXXFLAGS+='--coverage'
  175. LCOVRC='--rc geninfo_checksum=1 --rc lcov_branch_coverage=1'
  176. mkdir "$DIR"
  177. lcov --no-external --directory . --capture --initial --output-file "${DIR}/apt.coverage.init" ${LCOVRC}
  178. make test || true
  179. ./test/integration/run-tests -q || true
  180. lcov --no-external --directory . --capture --output-file "${DIR}/apt.coverage.run" ${LCOVRC}
  181. lcov -a "${DIR}/apt.coverage.init" -a "${DIR}/apt.coverage.run" -o "${DIR}/apt.coverage.total" ${LCOVRC}
  182. cp "${DIR}/apt.coverage.total" "${DIR}/apt.coverage.fixed"
  183. rewritefile() {
  184. file="$1"
  185. shift
  186. name="$(basename "$file")"
  187. while [ -n "$1" ]; do
  188. if [ -r "$1/$name" ]; then
  189. sed -i "s#$file#$1/$name#" "${DIR}/apt.coverage.fixed"
  190. break
  191. fi
  192. shift
  193. done
  194. if [ -z "$1" ]; then
  195. echo >&2 "Coverage data captured for unknown file $file"
  196. fi
  197. }
  198. grep 'build/include/' "${DIR}/apt.coverage.fixed" | sed "s#^SF:$(pwd)/##" | while read file; do
  199. rewritefile "$file" 'apt-pkg' 'apt-pkg/deb' 'apt-pkg/edsp' 'apt-pkg/contrib' \
  200. 'apt-inst' 'apt-inst/deb' 'apt-inst/contrib' 'apt-private'
  201. done
  202. genhtml --output-directory "${DIR}" "${DIR}/apt.coverage.fixed" ${LCOVRC}
  203. elif [ "$1" = 'spellcheckers' ]; then
  204. echo '### codespell in source directories:'
  205. codespell --enable-colors $(find . -mindepth 1 -maxdepth 1 -type d \! -name '.git' \! -name 'doc' \! -name 'po' \! -name 'build' \! -name 'test') | \
  206. grep -v '^.*debian/changelog.*Troup.*==>.*Troupe.*$' || true
  207. echo '### codespell in testcases:'
  208. codespell $(find test -type f \! -name 'status-*' \! -name 'Packages-*' \! -name '*.deb' \! -name '*.sec' \! -name '*.pub' \! -name '*.db')
  209. echo '### codespell in documentation:'
  210. codespell 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
  211. echo '### spellintian in source directories:'
  212. {
  213. for DIR in $(find . -mindepth 1 -maxdepth 1 -type d \! -name '.git' \! -name 'doc' \! -name 'po' \! -name 'build' \! -name 'test'); do
  214. spellintian $(find "$DIR" -type f)
  215. done
  216. } | grep -v \
  217. -e '^.*: long long (duplicate word) -> long$' \
  218. -e '^./apt-pkg/pkgcache.h: ID ID (duplicate word) -> ID$' \
  219. -e '^./apt-pkg/contrib/mmap.cc: WorkSpace WorkSpace (duplicate word) -> WorkSpace$' \
  220. -e '^./apt-pkg/contrib/md5.cc: z z (duplicate word) -> z$' \
  221. -e '^./apt-pkg/metaindex.cc: const const (duplicate word) -> const$' \
  222. -e '^./apt-pkg/acquire-method.cc: QueueBack QueueBack (duplicate word) -> QueueBack$' \
  223. -e '^./CMake/Translations.cmake: domain domain (duplicate word) -> domain$' \
  224. -e '^./CMake/apti18n.h.in: m m (duplicate word) -> m$' \
  225. -e '^./CMake/run_if_exists.sh: fi fi (duplicate word) -> fi$' \
  226. -e '^./ftparchive/byhash.cc: ByHash ByHash (duplicate word) -> ByHash$' \
  227. -e '^./ftparchive/writer.cc: this Packages -> these packages$' \
  228. -e '^./ftparchive/byhash.h: ByHash ByHash (duplicate word) -> ByHash$' \
  229. -e '^./cmdline/apt-key.in: done done (duplicate word) -> done$' \
  230. -e '^./cmdline/apt-key.in: fi fi (duplicate word) -> fi$' \
  231. -e '^./cmdline/apt-key.in: echo echo (duplicate word) -> echo$' \
  232. -e '^./triehash/.travis.yml: perl perl (duplicate word) -> perl$' \
  233. -e '^./triehash/README.md: Performance Performance (duplicate word) -> Performance$' \
  234. -e '^./debian/apt.apt-compat.cron.daily: fi fi (duplicate word) -> fi$' \
  235. -e '^./debian/apt.auto-removal.sh: done done (duplicate word) -> done$' \
  236. -e '^./debian/apt.systemd.daily: fi fi (duplicate word) -> fi$' \
  237. -e '^./debian/apt.postinst: fi fi (duplicate word) -> fi$' \
  238. -e '^./methods/http.cc: Sz Sz (duplicate word) -> Sz$' \
  239. -e '^./methods/ftp.cc: AFMap AFMap (duplicate word) -> AFMap$' \
  240. -e '^./dselect/install: fi fi (duplicate word) -> fi$' \
  241. || true
  242. echo '### spellintian in testcases:'
  243. spellintian $(find test -type f \! -name 'status-*' \! -name 'Packages-*' \! -name '*.deb' \! -name '*.sec' \! -name '*.pub' \! -name '*.db') \
  244. | grep -v \
  245. -e '^.*: long long (duplicate word) -> long$' \
  246. -e '^test/integration/.*: fi fi (duplicate word) -> fi$' \
  247. -e '^test/integration/.*: done done (duplicate word) -> done$' \
  248. -e '^test/integration/.*: echo echo (duplicate word) -> echo$' \
  249. -e '^test/integration/test-00-commands-have-help: moo moo (duplicate word) -> moo$' \
  250. -e '^test/integration/test-apt-cache: bar bar (duplicate word) -> bar$' \
  251. -e '^test/integration/test-sourceslist-trusted-options: everythingsucceeds everythingsucceeds (duplicate word) -> everythingsucceeds$' \
  252. -e '^test/integration/test-sourceslist-trusted-options: everythingfails everythingfails (duplicate word) -> everythingfails$' \
  253. -e '^test/integration/test-apt-get-changelog: foo foo (duplicate word) -> foo$' \
  254. -e '^test/integration/test-ubuntu-bug-761175-remove-purge: testround testround (duplicate word) -> testround$' \
  255. -e '^test/integration/test-apt-get-download: apt apt (duplicate word) -> apt$' \
  256. -e '^test/integration/test-apt-showlist-orgroup-in-recommends: zzz zzz (duplicate word) -> zzz$' \
  257. -e '^test/integration/test-bug-691453-apt-cache-search-multi-pattern: bar bar (duplicate word) -> bar$' \
  258. -e '^test/integration/test-allow: hold hold (duplicate word) -> hold$' \
  259. -e '^test/integration/test-apt-by-hash-update: ensureitsbroken ensureitsbroken (duplicate word) -> ensureitsbroken$' \
  260. -e '^test/integration/test-apt-source-and-build-dep: foo foo (duplicate word) -> foo$' \
  261. || true
  262. echo '### spellintian in documentation:'
  263. 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
  264. else
  265. echo >&1 "Usage:\t$0 pre-export
  266. \t$0 pre-build
  267. \t$0 post-build
  268. Updating po-files and versions as well as some basic checks are done
  269. by »pre-export« which needs to be run before package building.
  270. If you use »gbp buildpackage« you will be notified if you forget.
  271. »pre-build« and »post-build« can be used to run some more or less
  272. useful checks automatically run by »gbp« otherwise.
  273. \t$0 library
  274. \t$0 buildlog filename…
  275. »library« and »buildlog« aren't run automatically but can be useful for
  276. maintaining the (more or less experimental) symbols files we provide.
  277. »library« displays the diff between advertised symbols and the once provided
  278. by the libraries, while »buildlog« extracts this diff from the buildlogs.
  279. Both will format the diff properly.
  280. \t$0 travis-ci
  281. \t$0 coverage [output-dir]
  282. »travis-ci« is a shortcut to install all build- as well as test-dependencies
  283. used by .travis.yml.
  284. »coverage« does a clean build with the right flags for coverage reporting,
  285. runs all tests and generates a html report in the end.
  286. \t$0 spellcheckers
  287. »spellcheckers« runs »codespell« and »spellintian« on the appropiate files and
  288. filters out obvious false positives.
  289. "
  290. fi