building.sgml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <chapter id="gbp.building">
  2. <title>Building packages from the &git; repository</title>
  3. <para>
  4. In order to build a &debian; package from the &git; repository, you use:
  5. &gbp-buildpackage;. This builds the upstream tarball (as will be described below) and
  6. invokes &debuild; to build the package. To use another build command, you
  7. can use the <option>--git-builder</option> option as described later in the manual,
  8. but &debuild; is nice since it can invoke <productname>lintian</productname>.
  9. During the development phase (when you're either not on the
  10. <emphasis>debian-branch</emphasis> or when you have uncommitted changes in
  11. your repository), you'll usually use:
  12. </para>
  13. <programlisting>
  14. &gbp-buildpackage; <option>--git-ignore-new</option>
  15. </programlisting>
  16. <para>If &gbp-buildpackage; doesn't find a valid upstream tarball, it will
  17. create one by looking at the tag matching the upstream version. To change
  18. this behaviour, see the <option>--git-upstream-tree</option> option.
  19. </para><para>
  20. If you want to recreate the original tarball using the additional
  21. information from the <option>pristine-tar branch</option>, you have to
  22. specify the <option>--git-pristine-tar</option> option. This will make sure
  23. the upstream tarball matches exactly the one imported. Using this option is
  24. the recommended way of recreating the upstream tarball.
  25. </para>
  26. <para>Once you're satisfied with the build and want to do a release, you commit all
  27. your changes and issue:</para>
  28. <programlisting>
  29. &gbp-buildpackage; <option>--git-tag</option>
  30. </programlisting>
  31. <para>This will again build the &debian; package and tag the final result after
  32. extracting the current version from the changelog. If you want &gpg;-signed
  33. tags, you can use the <option>--git-sign</option> and
  34. <option>--git-keyid</option> options. To save typing, these option can be
  35. specified via the configuration files. You can furthermore change the tag
  36. format used when creating tags with the <option>debian-tag</option>
  37. option; the default is <replaceable>debian/&lt;version&gt;</replaceable>.</para>
  38. <sect1 id="gbp.building.export">
  39. <title>Using a separate build dir</title>
  40. <para>Tools like &svn-buildpackage; use a separate build-area. To achieve a similar behaviour
  41. with &gbp-buildpackage;, use the <option>--git-export-dir</option> option:</para>
  42. <programlisting>
  43. &gbp-buildpackage; <option>--git-export-dir</option>=<replaceable>../build-area/</replaceable>
  44. </programlisting>
  45. <para>This will export the head of the current branch to
  46. <replaceable>../build-area/package-version</replaceable> and build the
  47. package. If you don't want to export the current branch head, you can use
  48. <option>--git-export</option> to export any treeish object. Here are some
  49. examples:</para>
  50. <programlisting>
  51. &gbp-buildpackage; <option>--git-export-dir</option>=<replaceable>../build-area</replaceable> <option>--git-export</option>=<replaceable>debian/0.4.3</replaceable>
  52. &gbp-buildpackage; <option>--git-export-dir</option>=<replaceable>../build-area</replaceable> <option>--git-export</option>=<replaceable>etch</replaceable>
  53. &gbp-buildpackage; <option>--git-export-dir</option>=<replaceable>../build-area</replaceable> <option>--git-export</option>=<replaceable>8caed309653d69b7ab440e3d35abc090eb4c6697</replaceable>
  54. &gbp-buildpackage; <option>--git-export-dir</option>=<replaceable>../build-area</replaceable> <option>--git-export</option>=<replaceable>INDEX</replaceable>
  55. &gbp-buildpackage; <option>--git-export-dir</option>=<replaceable>../build-area</replaceable> <option>--git-export</option>=<replaceable>WC</replaceable>
  56. </programlisting>
  57. <para>The special argument <replaceable>INDEX</replaceable> exports the
  58. state of the current index, which can be used to include staged but uncommitted
  59. changes in the build. Whereas the special argument
  60. <replaceable>WC</replaceable> exports the current working copy as is.</para>
  61. <para>If you want to default to build in a separate build area, you can
  62. specify the directory to use in the <filename>gbp.conf</filename> file.
  63. <programlisting>
  64. [git-buildpackage]
  65. # use a build area relative to the git repository
  66. export-dir=../build-area
  67. # to use the same build area for all packages use an absolute path:
  68. #export-dir=/home/debian-packages/build-area
  69. </programlisting>
  70. &gbp-buildpackage; will cleanup the build-area after a successful build. If
  71. you want to keep the build tree, use <replaceable>--git-no-purge</replaceable>.
  72. </para>
  73. </sect1>
  74. <sect1 id="gbp.building.hooks">
  75. <title>Invoking external programs</title>
  76. <para>
  77. Besides the commands for cleaning the package build dir
  78. (<option>cleaner</option>) and building the package
  79. (<option>builder</option>), you can also invoke hooks during the package
  80. build: immediately before a build (<option>prebuild</option>),
  81. after a successful build (<option>postbuild</option>), and after
  82. creating a tag (<option>posttag</option>). Typical applications are running
  83. <productname>lintian</productname> or pushing changes into a remote
  84. repository.
  85. </para>
  86. <sect2 id="gbp.building.lintian">
  87. <title>Running lintian</title>
  88. <para>&gbp-buildpackage; exports several variables into the
  89. <option>posttag</option>'s environment (for details see the <xref
  90. linkend="man.gbp.buildpackage"/>).
  91. To invoke &lintian;, we need to tell it where to find the changes file:
  92. <programlisting>
  93. &gbp-buildpackage; <option>--git-postbuild</option>=<replaceable>'lintian $GBP_CHANGES_FILE'</replaceable>
  94. </programlisting>
  95. To call &lintian; automatically after each successful build, add:
  96. <programlisting>
  97. <option>postbuild</option>=<replaceable>lintian $GBP_CHANGES_FILE</replaceable>
  98. </programlisting>
  99. to your <filename>.gbp.conf</filename>.
  100. </para>
  101. </sect2>
  102. <sect2 id="gbp.building.push">
  103. <title>Pushing into a remote repository</title>
  104. <para>If you want to push your changes automatically after a successful build and tag,
  105. you can use &gbp-buildpackage;'s posttag hook. A very simple invocation would look like this:
  106. <programlisting>
  107. &gbp-buildpackage; <option>--git-tag</option> <option>--git-posttag</option>=<replaceable>"git push &amp;&amp; git push --tags"</replaceable>
  108. </programlisting>
  109. This assumes you have set up a remote repository to push to in
  110. <filename>.git/config</filename>.</para>
  111. <para>Usually, you want to make sure you don't push out any
  112. unrelated changes into the remote repository. This is handled by the
  113. following hook which only pushes out the created tag to where you pulled
  114. from and also forwards the corresponding remote branch to that position:
  115. <programlisting>
  116. #!/bin/sh -e
  117. #
  118. # gbp-posttag-push: post tag hook to push out the newly created tag and to
  119. # forward the remote branch to that position
  120. if ! REMOTE=$(git config --get branch."${GBP_BRANCH}".remote); then
  121. REMOTE=origin
  122. fi
  123. if [ "$GBP_TAG" ]; then
  124. echo "Pushing $GBP_TAG to $REMOTE"
  125. git push "$REMOTE" "$GBP_TAG"
  126. else
  127. echo "GBP_TAG not set."
  128. exit 1
  129. fi
  130. if [ "$GBP_SHA1" ] &amp;&amp; [ "$GBP_BRANCH" ]; then
  131. git push "$REMOTE" "$GBP_SHA1":"$GBP_BRANCH"
  132. else
  133. echo "GBP_SHA1 or GBP_BRANCH not set."
  134. exit 1
  135. fi
  136. echo "done."
  137. </programlisting>
  138. <envar>GBP_TAG</envar>, <envar>GBP_SHA1</envar>
  139. and <envar>GBP_BRANCH</envar> are passed to the hook via the
  140. environment. To call this hook automatically upon tag creation, add:
  141. <programlisting>
  142. <option>posttag</option>=<replaceable>"gbp-posttag-push"</replaceable>
  143. </programlisting>
  144. to your <filename>.gbp.conf</filename> and make sure <filename>gbp-push</filename>
  145. is somewhere in your <envar>$PATH</envar>. On &debian;
  146. systems, a more complete example can be found in
  147. <filename>/usr/share/doc/examples/git-buildpackage/examples/gbp-posttag-push</filename>.
  148. </para>
  149. </sect2>
  150. <sect2 id="gbp.building.postexport">
  151. <title>Running postexport hook</title>
  152. <para>&gbp-buildpackage; exports several variables into the
  153. <option>postexport</option>'s environment (for details see
  154. the <xref linkend="man.gbp.buildpackage"/>). The motivation
  155. for the postexport action is to allow further adjustment of
  156. the sources prior to building the package. A typical use case
  157. scenario is to allow creating multiple source and binary
  158. packages from one &debian; branch, e.g. the bootstrap gcc and
  159. in the next stage the full gcc.
  160. </para>
  161. <para>The postexport action postpones the creation of the
  162. upstream tarball, so that the metadata for creating it is
  163. already present in the exported source tree. The example
  164. postexport script below (<filename>crosstoolchain-expand.sh</filename>)
  165. expands changelog, lintian override files, rules and control files
  166. according to an environment variable <envar>PKG_FLAVOR</envar>.
  167. </para>
  168. <para>Sample <filename>gbp.conf</filename> - enables source tree export
  169. by specifying the export directory:
  170. </para>
  171. <programlisting>
  172. [git-buildpackage]
  173. # use a build area relative to the git repository
  174. export-dir = ../build-area
  175. # disable the since the sources are being exported first
  176. cleaner =
  177. # post export script that handles expansion of &debian; specific files
  178. postexport = crosstoolchain-expand.sh
  179. </programlisting>
  180. <para>Sample postexport script: <filename>crosstoolchain-expand.sh</filename></para>
  181. <programlisting>
  182. #!/bin/sh
  183. #
  184. # Purpose: this script is intended for creating multiple source and
  185. # binary Debian packages from one source tree. It can be used in
  186. # conjunction with git-buildpackage that support a postexport hook
  187. #
  188. # A typical use is preparing a bootstrap gcc package that is needed
  189. # for building newlib and then preparing a full gcc package from the
  190. # same source tree. The user may specify the package flavor via
  191. # PKG_FLAVOR environmental variable.
  192. #
  193. #
  194. # The script expands/processes the following files:
  195. #
  196. # - changelog.tmpl is converted to standard Debian changelog
  197. #
  198. #
  199. # - all binary package lintian override template files are expanded
  200. # and renamed to the requested package flavor
  201. #
  202. # - source package lintian override template file is expanded and
  203. # renamed
  204. #
  205. # - rules.$PKG_FLAVOR and control.$PKG_FLAVOR are renamed to rules and
  206. # control resp.
  207. # the template string has been carefully chosen, so that
  208. # e.g. changelogs that refer to the source package can still be
  209. # processed by dch/git-dch resp.
  210. TMPL_STR=-XXXXXX
  211. # by default replace string for the template is empty
  212. REPLACE_STR=
  213. if [ -n "$PKG_FLAVOR" ]; then
  214. REPLACE_STR=-$PKG_FLAVOR
  215. fi
  216. REPLACE_EXPR="s/$TMPL_STR/$REPLACE_STR/g"
  217. # actual processing of relevant files
  218. cd debian
  219. # expand the template changelog
  220. # remove the symlinked version
  221. rm changelog
  222. chglog_tmpl=changelog.tmpl
  223. [ -f "$chglog_tmpl" ] || {
  224. echo "Missing changelog template (debian/$chglog_tmpl)"
  225. exit 1
  226. }
  227. cat changelog.tmpl | sed -e "$REPLACE_EXPR" > changelog
  228. rm changelog.tmpl
  229. # process binary package lintian overrides - each override must match
  230. # its package name
  231. for f in *.lintian-overrides.tmpl; do
  232. outfile=${f%.tmpl}
  233. [ -f "$f" ] || {
  234. echo "Missing lintian override files for binary packages"
  235. exit 1
  236. }
  237. cat $f | sed -e "$REPLACE_EXPR" > ${outfile/$TMPL_STR/$REPLACE_STR}
  238. rm $f
  239. done
  240. # process the only source package lintian override
  241. source_lintian=source/lintian-overrides.tmpl
  242. cat $source_lintian | sed -e "$REPLACE_EXPR" > ${source_lintian%.tmpl}
  243. rm $source_lintian
  244. # rules and control file are package flavor specific
  245. [ -f rules.$PKG_FLAVOR ] &amp;&amp; mv rules.$PKG_FLAVOR rules
  246. [ -f control.$PKG_FLAVOR ] &amp;&amp; mv control.$PKG_FLAVOR control
  247. rm -f rules.* control.*
  248. exit 0
  249. </programlisting>
  250. </sect2>
  251. </sect1>
  252. </chapter>