1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # @ECLASS: darcs.eclass
7 # "Gentoo's Haskell Language team" <haskell@gentoo.org>
8 # Sergei Trofimovich <slyfox@gentoo.org>
10 # Original Author: Jeffrey Yasskin <jyasskin@mail.utexas.edu>
11 # <rphillips@gentoo.org> (tla eclass author)
12 # Andres Loeh <kosmikus@gentoo.org> (darcs.eclass author)
13 # Alexander Vershilov <alexander.vershilov@gmail.com> (various contributions)
14 # @BLURB: This eclass provides functions for fetch and unpack darcs repositories
16 # This eclass provides the generic darcs fetching functions.
18 # Define the EDARCS_REPOSITORY variable at least.
19 # The ${S} variable is set to ${WORKDIR}/${P}.
25 inherit eutils # eshopts_{push,pop}
27 # Don't download anything other than the darcs repository
30 # You shouldn't change these settings yourself! The ebuild/eclass inheriting
31 # this eclass will take care of that.
33 # --- begin ebuild-configurable settings
35 # darcs command to run
36 # @ECLASS-VARIABLE: EDARCS_DARCS_CMD
38 # Path to darcs binary.
39 : ${EDARCS_DARCS_CMD:=darcs}
41 # darcs commands with command-specific options
43 # @ECLASS-VARIABLE: EDARCS_GET_CMD
45 # First fetch darcs command.
46 : ${EDARCS_GET_CMD:=get --lazy}
48 # @ECLASS-VARIABLE: EDARCS_UPDATE_CMD
50 # Repo update darcs command.
51 : ${EDARCS_UPDATE_CMD:=pull}
53 # @ECLASS-VARIABLE: EDARCS_OPTIONS
55 # Options to pass to both the "get" and "update" commands
56 : ${EDARCS_OPTIONS:=--set-scripts-executable}
58 # @ECLASS-VARIABLE: EDARCS_TOP_DIR
60 # Where the darcs repositories are stored/accessed
61 : ${EDARCS_TOP_DIR:=${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/darcs-src}
63 # @ECLASS-VARIABLE: EDARCS_REPOSITORY
65 # The URI to the repository.
66 : ${EDARCS_REPOSITORY:=}
68 # @ECLASS-VARIABLE: EDARCS_OFFLINE
70 # Set this variable to a non-empty value to disable the automatic updating of
71 # a darcs repository. This is intended to be set outside the darcs source
72 # tree by users. Defaults to EVCS_OFFLINE value.
73 : ${EDARCS_OFFLINE:=${EVCS_OFFLINE}}
75 # @ECLASS-VARIABLE: EDARCS_CLEAN
77 # Set this to something to get a clean copy when updating
78 # (removes the working directory, then uses EDARCS_GET_CMD to
82 # --- end ebuild-configurable settings ---
87 # @FUNCTION: darcs_patchcount
89 # Internal function to determine amount of patches in repository.
91 set -- $(HOME="${EDARCS_TOP_DIR}" ${EDARCS_DARCS_CMD} show repo --repodir="${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}" | grep "Num Patches")
92 # handle string like: " Num Patches: 3860"
96 # @FUNCTION: darcs_fetch
98 # Internal function is called from darcs_src_unpack
100 # The local directory to store the repository (useful to ensure a
101 # unique local name); relative to EDARCS_TOP_DIR
102 [[ -z ${EDARCS_LOCALREPO} ]] && [[ -n ${EDARCS_REPOSITORY} ]] \
103 && EDARCS_LOCALREPO=${EDARCS_REPOSITORY%/} \
104 && EDARCS_LOCALREPO=${EDARCS_LOCALREPO##*/}
106 debug-print-function ${FUNCNAME} $*
108 if [[ -n ${EDARCS_CLEAN} ]]; then
109 addwrite "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}"
110 rm -rf "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}"
113 # create the top dir if needed
114 if [[ ! -d ${EDARCS_TOP_DIR} ]]; then
115 # note that the addwrite statements in this block are only there to allow creating EDARCS_TOP_DIR;
116 # we've already allowed writing inside it
117 # this is because it's simpler than trying to find out the parent path of the directory, which
118 # would need to be the real path and not a symlink for things to work (so we can't just remove
119 # the last path element in the string)
120 debug-print "${FUNCNAME}: checkout mode. creating darcs directory"
123 mkdir -p "${EDARCS_TOP_DIR}"
124 export SANDBOX_WRITE="${SANDBOX_WRITE//:\/foobar:\/}"
127 # in case EDARCS_DARCS_DIR is a symlink to a dir, get the real
128 # dir's path, otherwise addwrite() doesn't work.
130 cd -P "${EDARCS_TOP_DIR}" > /dev/null
131 EDARCS_TOP_DIR="`/bin/pwd`"
133 # disable the sandbox for this dir
134 addwrite "${EDARCS_TOP_DIR}"
136 # determine checkout or update mode and change to the right directory.
137 if [[ ! -d "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}/_darcs" ]]; then
139 cd "${EDARCS_TOP_DIR}"
142 cd "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}"
146 local cmdget="${EDARCS_DARCS_CMD} ${EDARCS_GET_CMD} ${EDARCS_OPTIONS} --repo-name=${EDARCS_LOCALREPO} ${EDARCS_REPOSITORY}"
147 local cmdupdate="${EDARCS_DARCS_CMD} ${EDARCS_UPDATE_CMD} --all ${EDARCS_OPTIONS} ${EDARCS_REPOSITORY}"
149 if [[ ${mode} == "get" ]]; then
150 einfo "Running ${cmdget}"
151 HOME="${EDARCS_TOP_DIR}" ${cmdget} || die "darcs get command failed"
152 elif [[ -n ${EDARCS_OFFLINE} ]] ; then
153 einfo "Offline update"
154 elif [[ ${mode} == "update" ]]; then
155 einfo "Running ${cmdupdate}"
156 HOME="${EDARCS_TOP_DIR}" ${cmdupdate} || die "darcs update command failed"
159 export EDARCS_PATCHCOUNT=$(darcs_patchcount)
160 einfo " patches in repo: ${EDARCS_PATCHCOUNT}"
165 # @FUNCTION: darcs_src_unpack
169 # The local directory to store the repository (useful to ensure a
170 # unique local name); relative to EDARCS_TOP_DIR
171 [[ -z ${EDARCS_LOCALREPO} ]] && [[ -n ${EDARCS_REPOSITORY} ]] \
172 && EDARCS_LOCALREPO=${EDARCS_REPOSITORY%/} \
173 && EDARCS_LOCALREPO=${EDARCS_LOCALREPO##*/}
175 debug-print-function ${FUNCNAME} $*
177 debug-print "${FUNCNAME}: init:
178 EDARCS_DARCS_CMD=${EDARCS_DARCS_CMD}
179 EDARCS_GET_CMD=${EDARCS_GET_CMD}
180 EDARCS_UPDATE_CMD=${EDARCS_UPDATE_CMD}
181 EDARCS_OPTIONS=${EDARCS_OPTIONS}
182 EDARCS_TOP_DIR=${EDARCS_TOP_DIR}
183 EDARCS_REPOSITORY=${EDARCS_REPOSITORY}
184 EDARCS_LOCALREPO=${EDARCS_LOCALREPO}
185 EDARCS_CLEAN=${EDARCS_CLEAN}"
187 einfo "Fetching darcs repository ${EDARCS_REPOSITORY} into ${EDARCS_TOP_DIR}..."
190 einfo "Copying ${EDARCS_LOCALREPO} from ${EDARCS_TOP_DIR}..."
191 debug-print "Copying ${EDARCS_LOCALREPO} from ${EDARCS_TOP_DIR}..."
193 # probably redundant, but best to make sure
194 # Use ${WORKDIR}/${P} rather than ${S} so user can point ${S} to something inside.
195 mkdir -p "${WORKDIR}/${P}"
197 eshopts_push -s dotglob # get any dotfiles too.
198 rsync -rlpgo "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}"/* "${WORKDIR}/${P}"
201 einfo "Darcs repository contents are now in ${WORKDIR}/${P}"
205 EXPORT_FUNCTIONS src_unpack