bzr.eclass 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. # Copyright 1999-2014 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. #
  4. # @ECLASS: bzr.eclass
  5. # @MAINTAINER:
  6. # Bazaar team <bazaar@gentoo.org>
  7. # @AUTHOR:
  8. # Jorge Manuel B. S. Vicetto <jmbsvicetto@gentoo.org>
  9. # Mark Lee <bzr-gentoo-overlay@lazymalevolence.com>
  10. # Ulrich Müller <ulm@gentoo.org>
  11. # Christian Faulhammer <fauli@gentoo.org>
  12. # @BLURB: generic fetching functions for the Bazaar VCS
  13. # @DESCRIPTION:
  14. # The bzr.eclass provides functions to fetch, unpack, patch, and
  15. # bootstrap sources from repositories of the Bazaar distributed version
  16. # control system. The eclass was originally derived from git.eclass.
  17. #
  18. # Note: Just set EBZR_REPO_URI to the URI of the branch and src_unpack()
  19. # of this eclass will export the branch to ${WORKDIR}/${P}.
  20. inherit eutils
  21. EBZR="bzr.eclass"
  22. case "${EAPI:-0}" in
  23. 0|1) EXPORT_FUNCTIONS src_unpack ;;
  24. *) EXPORT_FUNCTIONS src_unpack src_prepare ;;
  25. esac
  26. DEPEND=">=dev-vcs/bzr-2.0.1"
  27. case "${EAPI:-0}" in
  28. 0|1) ;;
  29. *) [[ ${EBZR_REPO_URI%%:*} = sftp ]] \
  30. && DEPEND=">=dev-vcs/bzr-2.0.1[sftp]" ;;
  31. esac
  32. # @ECLASS-VARIABLE: EBZR_STORE_DIR
  33. # @DESCRIPTION:
  34. # The directory to store all fetched Bazaar live sources.
  35. : ${EBZR_STORE_DIR:=${PORTAGE_ACTUAL_DISTDIR:-${DISTDIR}}/bzr-src}
  36. # @ECLASS-VARIABLE: EBZR_UNPACK_DIR
  37. # @DESCRIPTION:
  38. # The working directory where the sources are copied to.
  39. : ${EBZR_UNPACK_DIR:=${WORKDIR}/${P}}
  40. # @ECLASS-VARIABLE: EBZR_INIT_REPO_CMD
  41. # @DESCRIPTION:
  42. # The Bazaar command to initialise a shared repository.
  43. : ${EBZR_INIT_REPO_CMD:="bzr init-repository --no-trees"}
  44. # @ECLASS-VARIABLE: EBZR_FETCH_CMD
  45. # @DESCRIPTION:
  46. # The Bazaar command to fetch the sources.
  47. : ${EBZR_FETCH_CMD:="bzr branch --no-tree"}
  48. # @ECLASS-VARIABLE: EBZR_UPDATE_CMD
  49. # @DESCRIPTION:
  50. # The Bazaar command to update the sources.
  51. : ${EBZR_UPDATE_CMD:="bzr pull"}
  52. # @ECLASS-VARIABLE: EBZR_EXPORT_CMD
  53. # @DESCRIPTION:
  54. # The Bazaar command to export a branch.
  55. : ${EBZR_EXPORT_CMD:="bzr export"}
  56. # @ECLASS-VARIABLE: EBZR_CHECKOUT_CMD
  57. # @DESCRIPTION:
  58. # The Bazaar command to checkout a branch.
  59. : ${EBZR_CHECKOUT_CMD:="bzr checkout --lightweight -q"}
  60. # @ECLASS-VARIABLE: EBZR_REVNO_CMD
  61. # @DESCRIPTION:
  62. # The Bazaar command to list a revision number of the branch.
  63. : ${EBZR_REVNO_CMD:="bzr revno"}
  64. # @ECLASS-VARIABLE: EBZR_OPTIONS
  65. # @DEFAULT_UNSET
  66. # @DESCRIPTION:
  67. # The options passed to the fetch and update commands.
  68. # @ECLASS-VARIABLE: EBZR_REPO_URI
  69. # @DEFAULT_UNSET
  70. # @REQUIRED
  71. # @DESCRIPTION:
  72. # The repository URI for the source package.
  73. #
  74. # Note: If the ebuild uses an sftp:// URI, then in EAPI 0 or 1 it must
  75. # make sure that dev-vcs/bzr was built with USE="sftp". In EAPI 2 or
  76. # later, the eclass will depend on dev-vcs/bzr[sftp].
  77. # @ECLASS-VARIABLE: EBZR_INITIAL_URI
  78. # @DEFAULT_UNSET
  79. # @DESCRIPTION:
  80. # The URI used for initial branching of the source repository. If this
  81. # variable is set, the initial branch will be cloned from the location
  82. # specified, followed by a pull from ${EBZR_REPO_URI}. This is intended
  83. # for special cases, e.g. when download from the original repository is
  84. # slow, but a fast mirror exists but may be out of date.
  85. #
  86. # Normally, this variable needs not be set.
  87. # @ECLASS-VARIABLE: EBZR_BOOTSTRAP
  88. # @DEFAULT_UNSET
  89. # @DESCRIPTION:
  90. # Bootstrap script or command like autogen.sh or etc.
  91. # @ECLASS-VARIABLE: EBZR_PATCHES
  92. # @DEFAULT_UNSET
  93. # @DESCRIPTION:
  94. # bzr.eclass can apply patches in bzr_bootstrap(). You can use regular
  95. # expressions in this variable like *.diff or *.patch and the like.
  96. # Note: These patches will be applied before EBZR_BOOTSTRAP is processed.
  97. #
  98. # Patches are searched both in ${PWD} and ${FILESDIR}. If not found in
  99. # either location, the installation dies.
  100. # @ECLASS-VARIABLE: EBZR_PROJECT
  101. # @DESCRIPTION:
  102. # The project name of your ebuild. Normally, the branch will be stored
  103. # in the ${EBZR_STORE_DIR}/${EBZR_PROJECT} directory.
  104. #
  105. # If EBZR_BRANCH is set (see below), then a shared repository will be
  106. # created in that directory, and the branch will be located in
  107. # ${EBZR_STORE_DIR}/${EBZR_PROJECT}/${EBZR_BRANCH}.
  108. : ${EBZR_PROJECT:=${PN}}
  109. # @ECLASS-VARIABLE: EBZR_BRANCH
  110. # @DEFAULT_UNSET
  111. # @DESCRIPTION:
  112. # The directory where to store the branch within a shared repository,
  113. # relative to ${EBZR_STORE_DIR}/${EBZR_PROJECT}.
  114. #
  115. # This variable should be set if there are several live ebuilds for
  116. # different branches of the same upstream project. The branches can
  117. # then share the same repository in EBZR_PROJECT, which will save both
  118. # data traffic volume and disk space.
  119. #
  120. # If there is only a live ebuild for one single branch, EBZR_BRANCH
  121. # needs not be set. In this case, the branch will be stored in a
  122. # stand-alone repository directly in EBZR_PROJECT.
  123. # @ECLASS-VARIABLE: EBZR_REVISION
  124. # @DEFAULT_UNSET
  125. # @DESCRIPTION:
  126. # Revision to fetch, defaults to the latest
  127. # (see http://bazaar-vcs.org/BzrRevisionSpec or bzr help revisionspec).
  128. # @ECLASS-VARIABLE: EBZR_OFFLINE
  129. # @DESCRIPTION:
  130. # Set this variable to a non-empty value to disable automatic updating
  131. # of a bzr source tree. This is intended to be set outside the ebuild
  132. # by users.
  133. : ${EBZR_OFFLINE=${EVCS_OFFLINE}}
  134. # @ECLASS-VARIABLE: EBZR_WORKDIR_CHECKOUT
  135. # @DEFAULT_UNSET
  136. # @DESCRIPTION:
  137. # If this variable is set to a non-empty value, EBZR_CHECKOUT_CMD will
  138. # be used instead of EBZR_EXPORT_CMD to copy the sources to WORKDIR.
  139. # @FUNCTION: bzr_initial_fetch
  140. # @USAGE: <repository URI> <branch directory>
  141. # @DESCRIPTION:
  142. # Internal function, retrieves the source code from a repository for the
  143. # first time, using ${EBZR_FETCH_CMD}.
  144. bzr_initial_fetch() {
  145. local repo_uri=$1 branch_dir=$2
  146. if [[ -n "${EBZR_OFFLINE}" ]]; then
  147. ewarn "EBZR_OFFLINE cannot be used when there is no local branch yet."
  148. fi
  149. # fetch branch
  150. einfo "bzr branch start -->"
  151. einfo " repository: ${repo_uri} => ${branch_dir}"
  152. ${EBZR_FETCH_CMD} ${EBZR_OPTIONS} "${repo_uri}" "${branch_dir}" \
  153. || die "${EBZR}: can't branch from ${repo_uri}"
  154. }
  155. # @FUNCTION: bzr_update
  156. # @USAGE: <repository URI> <branch directory>
  157. # @DESCRIPTION:
  158. # Internal function, updates the source code from a repository, using
  159. # ${EBZR_UPDATE_CMD}.
  160. bzr_update() {
  161. local repo_uri=$1 branch_dir=$2
  162. if [[ -n "${EBZR_OFFLINE}" ]]; then
  163. einfo "skipping bzr pull -->"
  164. einfo " repository: ${repo_uri}"
  165. else
  166. # update branch
  167. einfo "bzr pull start -->"
  168. einfo " repository: ${repo_uri}"
  169. pushd "${branch_dir}" > /dev/null \
  170. || die "${EBZR}: can't chdir to ${branch_dir}"
  171. ${EBZR_UPDATE_CMD} ${EBZR_OPTIONS} "${repo_uri}" \
  172. || die "${EBZR}: can't pull from ${repo_uri}"
  173. popd > /dev/null
  174. fi
  175. }
  176. # @FUNCTION: bzr_fetch
  177. # @DESCRIPTION:
  178. # Wrapper function to fetch sources from a Bazaar repository with
  179. # bzr branch or bzr pull, depending on whether there is an existing
  180. # working copy.
  181. bzr_fetch() {
  182. local repo_dir branch_dir
  183. local save_sandbox_write=${SANDBOX_WRITE}
  184. [[ -n ${EBZR_REPO_URI} ]] || die "${EBZR}: EBZR_REPO_URI is empty"
  185. if [[ ! -d ${EBZR_STORE_DIR} ]] ; then
  186. addwrite /
  187. mkdir -p "${EBZR_STORE_DIR}" \
  188. || die "${EBZR}: can't mkdir ${EBZR_STORE_DIR}"
  189. SANDBOX_WRITE=${save_sandbox_write}
  190. fi
  191. pushd "${EBZR_STORE_DIR}" > /dev/null \
  192. || die "${EBZR}: can't chdir to ${EBZR_STORE_DIR}"
  193. repo_dir=${EBZR_STORE_DIR}/${EBZR_PROJECT}
  194. branch_dir=${repo_dir}${EBZR_BRANCH:+/${EBZR_BRANCH}}
  195. addwrite "${EBZR_STORE_DIR}"
  196. if [[ ! -d ${branch_dir}/.bzr ]]; then
  197. if [[ ${repo_dir} != "${branch_dir}" && ! -d ${repo_dir}/.bzr ]]; then
  198. einfo "creating shared bzr repository: ${repo_dir}"
  199. ${EBZR_INIT_REPO_CMD} "${repo_dir}" \
  200. || die "${EBZR}: can't create shared repository"
  201. fi
  202. if [[ -z ${EBZR_INITIAL_URI} ]]; then
  203. bzr_initial_fetch "${EBZR_REPO_URI}" "${branch_dir}"
  204. else
  205. # Workaround for faster initial download. This clones the
  206. # branch from a fast server (which may be out of date), and
  207. # subsequently pulls from the slow original repository.
  208. bzr_initial_fetch "${EBZR_INITIAL_URI}" "${branch_dir}"
  209. if [[ ${EBZR_REPO_URI} != "${EBZR_INITIAL_URI}" ]]; then
  210. EBZR_UPDATE_CMD="${EBZR_UPDATE_CMD} --remember --overwrite" \
  211. EBZR_OFFLINE="" \
  212. bzr_update "${EBZR_REPO_URI}" "${branch_dir}"
  213. fi
  214. fi
  215. else
  216. bzr_update "${EBZR_REPO_URI}" "${branch_dir}"
  217. fi
  218. # Restore sandbox environment
  219. SANDBOX_WRITE=${save_sandbox_write}
  220. cd "${branch_dir}" || die "${EBZR}: can't chdir to ${branch_dir}"
  221. # Save revision number in environment. #311101
  222. export EBZR_REVNO=$(${EBZR_REVNO_CMD})
  223. if [[ -n ${EBZR_WORKDIR_CHECKOUT} ]]; then
  224. einfo "checking out ..."
  225. ${EBZR_CHECKOUT_CMD} ${EBZR_REVISION:+-r ${EBZR_REVISION}} \
  226. . "${EBZR_UNPACK_DIR}" || die "${EBZR}: checkout failed"
  227. else
  228. einfo "exporting ..."
  229. ${EBZR_EXPORT_CMD} ${EBZR_REVISION:+-r ${EBZR_REVISION}} \
  230. "${EBZR_UNPACK_DIR}" . || die "${EBZR}: export failed"
  231. fi
  232. einfo \
  233. "revision ${EBZR_REVISION:-${EBZR_REVNO}} is now in ${EBZR_UNPACK_DIR}"
  234. popd > /dev/null
  235. }
  236. # @FUNCTION: bzr_bootstrap
  237. # @DESCRIPTION:
  238. # Apply patches in ${EBZR_PATCHES} and run ${EBZR_BOOTSTRAP} if specified.
  239. bzr_bootstrap() {
  240. local patch lpatch
  241. pushd "${S}" > /dev/null || die "${EBZR}: can't chdir to ${S}"
  242. if [[ -n ${EBZR_PATCHES} ]] ; then
  243. einfo "apply patches -->"
  244. for patch in ${EBZR_PATCHES} ; do
  245. if [[ -f ${patch} ]] ; then
  246. epatch "${patch}"
  247. else
  248. # This loop takes care of wildcarded patches given via
  249. # EBZR_PATCHES in an ebuild
  250. for lpatch in "${FILESDIR}"/${patch} ; do
  251. if [[ -f ${lpatch} ]] ; then
  252. epatch "${lpatch}"
  253. else
  254. die "${EBZR}: ${patch} is not found"
  255. fi
  256. done
  257. fi
  258. done
  259. fi
  260. if [[ -n ${EBZR_BOOTSTRAP} ]] ; then
  261. einfo "begin bootstrap -->"
  262. if [[ -f ${EBZR_BOOTSTRAP} ]] && [[ -x ${EBZR_BOOTSTRAP} ]] ; then
  263. einfo " bootstrap with a file: ${EBZR_BOOTSTRAP}"
  264. "./${EBZR_BOOTSTRAP}" \
  265. || die "${EBZR}: can't execute EBZR_BOOTSTRAP"
  266. else
  267. einfo " bootstrap with commands: ${EBZR_BOOTSTRAP}"
  268. "${EBZR_BOOTSTRAP}" \
  269. || die "${EBZR}: can't eval EBZR_BOOTSTRAP"
  270. fi
  271. fi
  272. popd > /dev/null
  273. }
  274. # @FUNCTION: bzr_src_unpack
  275. # @DESCRIPTION:
  276. # Default src_unpack(), calls bzr_fetch. For EAPIs 0 and 1, also calls
  277. # bzr_src_prepare.
  278. bzr_src_unpack() {
  279. bzr_fetch
  280. case "${EAPI:-0}" in
  281. 0|1) bzr_src_prepare ;;
  282. esac
  283. }
  284. # @FUNCTION: bzr_src_prepare
  285. # @DESCRIPTION:
  286. # Default src_prepare(), calls bzr_bootstrap.
  287. bzr_src_prepare() {
  288. bzr_bootstrap
  289. }