prepare-release 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. if [ "$1" = 'pre-export' ]; then
  24. libraryversioncheck() {
  25. local LIBRARY="$1"
  26. local VERSION="$2"
  27. if [ ! -e "debian/${LIBRARY}${VERSION}.symbols" ]; then
  28. echo >&2 "Library ${LIBRARY} in version ${VERSION} has no symbols file! (maybe forgot to rename?)"
  29. exit 1
  30. fi
  31. if [ "$(head -n1 "debian/${LIBRARY}${VERSION}.symbols")" != "${LIBRARY}.so.${VERSION} ${LIBRARY}${VERSION} #MINVER#" ]; then
  32. echo >&2 "Library ${LIBRARY}${VERSION} has incorrect version in symbol header! (»$(head -n1 "debian/${LIBRARY}${VERSION}.symbols")«)"
  33. exit 2
  34. fi
  35. }
  36. libraryversioncheck 'libapt-pkg' "$LIBAPTPKGVERSION"
  37. libraryversioncheck 'libapt-inst' "$LIBAPTINSTVERSION"
  38. if [ "$DISTRIBUTION" = 'sid' ]; then
  39. echo >&2 '»sid« is not a valid distribution. Replace it with »unstable« for you'
  40. sed -i -e 's/) sid; urgency=/) unstable; urgency=/' debian/changelog
  41. DISTRIBUTION='unstable'
  42. elif [ "$DISTRIBUTION" = 'UNRELEASED' ]; then
  43. echo >&2 'WARNING: Remember to change to a valid distribution for release'
  44. VERSION="$VERSION~$(date +%Y%m%d)"
  45. fi
  46. sed -i -e "s/^set(PACKAGE_VERSION \".*\")$/set(PACKAGE_VERSION \"${VERSION}\")/" CMakeLists.txt
  47. sed -i -e "s/^<!ENTITY apt-product-version \".*\">$/<!ENTITY apt-product-version \"${VERSION}\">/" doc/apt-verbatim.ent
  48. # update the last-modification field of manpages based on git changes
  49. grep --files-with-matches '<date>' doc/*.xml | while read file; do \
  50. LASTMOD="$(date -d "@$(git log --format='%at' --max-count=1 --invert-grep --fixed-strings --grep 'review
  51. typo
  52. release
  53. Git-Dch: Ignore' "$file")" '+%Y-%m-%dT00:00:00Z')"
  54. sed -i -e "s#^\([ ]\+\)<date>.*</date>\$#\1<date>$LASTMOD</date>#" "$file"
  55. done
  56. if [ "$(date +%Y-%m-%d)" != "$(grep --max-count=1 '^"POT-Creation-Date: .*\n"$' po/apt-all.pot | cut -d' ' -f 2)" -o \
  57. "$(date +%Y-%m-%d)" != "$(grep --max-count=1 '^"POT-Creation-Date: .*\n"$' doc/po/apt-doc.pot | cut -d' ' -f 2)" ]; then
  58. echo >&2 'POT files are not up-to-date. Execute »make update-po« for you…'
  59. [ -e build ] || mkdir build
  60. ( cd build && cmake .. )
  61. cmake --build build --target update-po -- -j 4
  62. fi
  63. elif [ "$1" = 'pre-build' ]; then
  64. if [ "$DISTRIBUTION" = "UNRELEASED" ]; then
  65. echo 'BUILDING AN UNRELEASED VERSION'
  66. else
  67. CONFVERSION="$(sed -ne "s/^set(PACKAGE_VERSION \"\(.*\)\")$/\1/p" CMakeLists.txt)"
  68. if [ "$VERSION" != "$CONFVERSION" ]; then
  69. echo "changelog (${VERSION}) and CMakeLists.txt (${CONFVERSION}) talk about different versions!"
  70. echo "You probably want to run »./prepare-release pre-export« to fix this."
  71. exit 1
  72. fi
  73. fi
  74. elif [ "$1" = 'post-build' ]; then
  75. if [ "$DISTRIBUTION" != "UNRELEASED" ]; then
  76. echo >&2 "REMEMBER: Tag this release with »git tag -s ${VERSION}« if you are satisfied"
  77. else
  78. echo >&2 'REMEMBER: Change to a valid distribution before release'
  79. fi
  80. dpkg-checkbuilddeps -d 'libxml2-utils'
  81. HEADERBLUEPRINT="$(mktemp)"
  82. sed -n '1,/^$/p' doc/apt.8.xml > "$HEADERBLUEPRINT"
  83. find doc -mindepth 1 -maxdepth 1 -type f -name '*.xml' | while read FILE; do
  84. if ! sed -n '1,/^$/p' "$FILE" | cmp "$HEADERBLUEPRINT" - >/dev/null 2>&1; then
  85. echo >&2 "WARNING: Manpage $FILE has not the usual header! (see diff below)"
  86. sed -n '1,/^$/p' "$FILE" | diff -u "$HEADERBLUEPRINT" - || true
  87. fi
  88. done
  89. sed -n '1,/^$/p' doc/guide.dbk > "$HEADERBLUEPRINT"
  90. find doc -mindepth 1 -maxdepth 1 -type f -name '*.dbk' | while read FILE; do
  91. if ! sed -n '1,/^$/p' "$FILE" | cmp "$HEADERBLUEPRINT" - >/dev/null 2>&1; then
  92. echo >&2 "WARNING: Documentation $FILE has not the usual header (see diff below)!"
  93. sed -n '1,/^$/p' "$FILE" | diff -u "$HEADERBLUEPRINT" - || true
  94. fi
  95. done
  96. rm "$HEADERBLUEPRINT"
  97. # check the manpages with each vendor for vendor-specific errors…
  98. find vendor -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 2 | while read DISTRO; do
  99. ln -sf ../vendor/${DISTRO}/apt-vendor.ent doc
  100. if ! xmllint --nonet --valid --noout $(find doc/ -maxdepth 1 -name '*.xml'); then
  101. echo >&2 "WARNING: original docbook manpages have errors with vendor ${DISTRO}!"
  102. fi
  103. done
  104. # lets assume we will always have a german manpage translation
  105. if [ -e */doc/de/ -o -e doc/de ]; then
  106. # … but check the translations only with one vendor for translation-specific errors
  107. if ! xmllint --path /vendor/$(./vendor/getinfo current)/ \
  108. --path doc/ \
  109. --nonet --valid --noout $(find doc/ */doc/ -mindepth 2 -maxdepth 2 -name '*.xml'); then
  110. echo >&2 "WARNING: translated docbook manpages have errors!"
  111. fi
  112. else
  113. echo >&2 "ERROR: translated manpages need to be build before they can be checked!"
  114. fi
  115. rm -f doc/apt-vendor.ent
  116. elif [ "$1" = 'library' ]; then
  117. librarysymbols() {
  118. local libname=$(echo "${1}" | cut -c 4-)
  119. local buildlib="build/bin/${1}.so.${2}"
  120. for dir in $libname */$libname; do
  121. local new_buildlib="$dir/${1}.so.${2}"
  122. if [ -r "${new_buildlib}" ] && [ ! -e "$buildlib" -o "$new_buildlib" -nt "$buildlib" ]; then
  123. local buildlib="${new_buildlib}"
  124. fi
  125. done
  126. if [ ! -r "$buildlib" ]; then
  127. echo "ERROR: The library ${1} has to be built before symbols can be checked!"
  128. return
  129. fi
  130. echo "Checking $1 in version $2 build at $(stat -L -c '%y' "$buildlib")"
  131. local tmpfile=$(mktemp)
  132. dpkg-gensymbols -p${1}${2} -e${buildlib} -Idebian/${1}${2}.symbols -O/dev/null 2> /dev/null > $tmpfile || true
  133. librarysymbolsfromfile "$tmpfile" "$(echo "${1}" | cut -c 4- | tr -d '-' | tr 'a-z' 'A-Z')_${2}"
  134. rm -f $tmpfile
  135. }
  136. librarysymbols 'libapt-pkg' "${LIBAPTPKGVERSION}"
  137. echo
  138. librarysymbols 'libapt-inst' "${LIBAPTINSTVERSION}"
  139. elif [ "$1" = 'buildlog' ]; then
  140. while [ -n "$2" ]; do
  141. librarysymbolsfromfile "$2" 'UNKNOWN'
  142. shift
  143. done
  144. elif [ "$1" = 'travis-ci' ]; then
  145. apt-get install -qy --no-install-recommends dctrl-tools
  146. apt-get install -qy --no-install-recommends $(grep-dctrl -S -s Build-Depends,Build-Depends-Indep,Build-Depends-Arch apt ./debian/control | sed -e 's#([^)]*)##g' -e 's#^Build-Depends\(-Indep\|-Arch\)\?: ##' -e 's#<.*>##g' | tr -s '\n,' ' ')
  147. apt-get install -qy --no-install-recommends $(grep-dctrl -F Tests -s Depends run-tests ./debian/tests/control | tr -s '\n,' ' ' | cut -d'@' -f 4- | sed -e 's#gnupg1#gnupg2#' -e 's#gpgv1#gpgv2#')
  148. elif [ "$1" = 'coverage' ]; then
  149. DIR="${2:-./coverage}"
  150. git clean -dfX # remove ignored build artefacts for a clean start
  151. make CFLAGS+='--coverage' CXXFLAGS+='--coverage'
  152. LCOVRC='--rc geninfo_checksum=1 --rc lcov_branch_coverage=1'
  153. mkdir "$DIR"
  154. lcov --no-external --directory . --capture --initial --output-file "${DIR}/apt.coverage.init" ${LCOVRC}
  155. make test || true
  156. ./test/integration/run-tests -q || true
  157. lcov --no-external --directory . --capture --output-file "${DIR}/apt.coverage.run" ${LCOVRC}
  158. lcov -a "${DIR}/apt.coverage.init" -a "${DIR}/apt.coverage.run" -o "${DIR}/apt.coverage.total" ${LCOVRC}
  159. cp "${DIR}/apt.coverage.total" "${DIR}/apt.coverage.fixed"
  160. rewritefile() {
  161. file="$1"
  162. shift
  163. name="$(basename "$file")"
  164. while [ -n "$1" ]; do
  165. if [ -r "$1/$name" ]; then
  166. sed -i "s#$file#$1/$name#" "${DIR}/apt.coverage.fixed"
  167. break
  168. fi
  169. shift
  170. done
  171. if [ -z "$1" ]; then
  172. echo >&2 "Coverage data captured for unknown file $file"
  173. fi
  174. }
  175. grep 'build/include/' "${DIR}/apt.coverage.fixed" | sed "s#^SF:$(pwd)/##" | while read file; do
  176. rewritefile "$file" 'apt-pkg' 'apt-pkg/deb' 'apt-pkg/edsp' 'apt-pkg/contrib' \
  177. 'apt-inst' 'apt-inst/deb' 'apt-inst/contrib' 'apt-private'
  178. done
  179. genhtml --output-directory "${DIR}" "${DIR}/apt.coverage.fixed" ${LCOVRC}
  180. else
  181. echo >&1 "Usage:\t$0 pre-export
  182. \t$0 pre-build
  183. \t$0 post-build
  184. Updating po-files and versions as well as some basic checks are done
  185. by »pre-export« which needs to be run before package building.
  186. If you use »gbp buildpackage« you will be notified if you forget.
  187. »pre-build« and »post-build« can be used to run some more or less
  188. useful checks automatically run by »gbp« otherwise.
  189. \t$0 library
  190. \t$0 buildlog filename…
  191. »library« and »buildlog« aren't run automatically but can be useful for
  192. maintaining the (more or less experimental) symbols files we provide.
  193. »library« displays the diff between advertised symbols and the once provided
  194. by the libraries, while »buildlog« extracts this diff from the buildlogs.
  195. Both will format the diff properly.
  196. \t$0 travis-ci
  197. \t$0 coverage [output-dir]
  198. »travis-ci« is a shortcut to install all build- as well as test-dependencies
  199. used by .travis.yml.
  200. »coverage« does a clean build with the right flags for coverage reporting,
  201. runs all tests and generates a html report in the end.
  202. "
  203. fi