1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: darcs.eclass
6 # "Gentoo's Haskell Language team" <haskell@gentoo.org>
7 # Sergei Trofimovich <slyfox@gentoo.org>
9 # Original Author: Jeffrey Yasskin <jyasskin@mail.utexas.edu>
10 # <rphillips@gentoo.org> (tla eclass author)
11 # Andres Loeh <kosmikus@gentoo.org> (darcs.eclass author)
12 # Alexander Vershilov <alexander.vershilov@gmail.com> (various contributions)
13 # @BLURB: This eclass provides functions for fetch and unpack darcs repositories
15 # This eclass provides the generic darcs fetching functions.
17 # Define the EDARCS_REPOSITORY variable at least.
18 # The ${S} variable is set to ${WORKDIR}/${P}.
26 4|5|6) inherit eutils ;;
31 # Don't download anything other than the darcs repository
34 # You shouldn't change these settings yourself! The ebuild/eclass inheriting
35 # this eclass will take care of that.
37 # --- begin ebuild-configurable settings
39 # darcs command to run
40 # @ECLASS-VARIABLE: EDARCS_DARCS_CMD
42 # Path to darcs binary.
43 : ${EDARCS_DARCS_CMD:=darcs}
45 # darcs commands with command-specific options
47 # @ECLASS-VARIABLE: EDARCS_GET_CMD
49 # First fetch darcs command.
50 : ${EDARCS_GET_CMD:=get --lazy}
52 # @ECLASS-VARIABLE: EDARCS_UPDATE_CMD
54 # Repo update darcs command.
55 : ${EDARCS_UPDATE_CMD:=pull}
57 # @ECLASS-VARIABLE: EDARCS_OPTIONS
59 # Options to pass to both the "get" and "update" commands
60 : ${EDARCS_OPTIONS:=--set-scripts-executable}
62 # @ECLASS-VARIABLE: EDARCS_TOP_DIR
64 # Where the darcs repositories are stored/accessed
65 : ${EDARCS_TOP_DIR:=${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/darcs-src}
67 # @ECLASS-VARIABLE: EDARCS_REPOSITORY
69 # The URI to the repository.
70 : ${EDARCS_REPOSITORY:=}
72 # @ECLASS-VARIABLE: EDARCS_OFFLINE
74 # Set this variable to a non-empty value to disable the automatic updating of
75 # a darcs repository. This is intended to be set outside the darcs source
76 # tree by users. Defaults to EVCS_OFFLINE value.
77 : ${EDARCS_OFFLINE:=${EVCS_OFFLINE}}
79 # @ECLASS-VARIABLE: EDARCS_CLEAN
81 # Set this to something to get a clean copy when updating
82 # (removes the working directory, then uses EDARCS_GET_CMD to
86 # --- end ebuild-configurable settings ---
91 [0-6]) # no need to care about 5-HDEPEND and similar
96 BDEPEND="dev-vcs/darcs
101 # @FUNCTION: darcs_patchcount
103 # Internal function to determine amount of patches in repository.
105 set -- $(HOME="${EDARCS_TOP_DIR}" ${EDARCS_DARCS_CMD} show repo --repodir="${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}" | grep "Num Patches")
106 # handle string like: " Num Patches: 3860"
110 # @FUNCTION: darcs_fetch
112 # Internal function is called from darcs_src_unpack
114 # The local directory to store the repository (useful to ensure a
115 # unique local name); relative to EDARCS_TOP_DIR
116 [[ -z ${EDARCS_LOCALREPO} ]] && [[ -n ${EDARCS_REPOSITORY} ]] \
117 && EDARCS_LOCALREPO=${EDARCS_REPOSITORY%/} \
118 && EDARCS_LOCALREPO=${EDARCS_LOCALREPO##*/}
120 debug-print-function ${FUNCNAME} $*
122 if [[ -n ${EDARCS_CLEAN} ]]; then
123 addwrite "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}"
124 rm -rf "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}"
127 # create the top dir if needed
128 if [[ ! -d ${EDARCS_TOP_DIR} ]]; then
129 # note that the addwrite statements in this block are only there to allow creating EDARCS_TOP_DIR;
130 # we've already allowed writing inside it
131 # this is because it's simpler than trying to find out the parent path of the directory, which
132 # would need to be the real path and not a symlink for things to work (so we can't just remove
133 # the last path element in the string)
134 debug-print "${FUNCNAME}: checkout mode. creating darcs directory"
137 mkdir -p "${EDARCS_TOP_DIR}"
138 export SANDBOX_WRITE="${SANDBOX_WRITE//:\/foobar:\/}"
141 # in case EDARCS_DARCS_DIR is a symlink to a dir, get the real
142 # dir's path, otherwise addwrite() doesn't work.
144 cd -P "${EDARCS_TOP_DIR}" > /dev/null
145 EDARCS_TOP_DIR="`/bin/pwd`"
147 # disable the sandbox for this dir
148 addwrite "${EDARCS_TOP_DIR}"
150 # determine checkout or update mode and change to the right directory.
151 if [[ ! -d "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}/_darcs" ]]; then
153 cd "${EDARCS_TOP_DIR}"
156 cd "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}"
160 local cmdget="${EDARCS_DARCS_CMD} ${EDARCS_GET_CMD} ${EDARCS_OPTIONS} --repo-name=${EDARCS_LOCALREPO} ${EDARCS_REPOSITORY}"
161 local cmdupdate="${EDARCS_DARCS_CMD} ${EDARCS_UPDATE_CMD} --all ${EDARCS_OPTIONS} ${EDARCS_REPOSITORY}"
163 if [[ ${mode} == "get" ]]; then
164 einfo "Running ${cmdget}"
165 HOME="${EDARCS_TOP_DIR}" ${cmdget} || die "darcs get command failed"
166 elif [[ -n ${EDARCS_OFFLINE} ]] ; then
167 einfo "Offline update"
168 elif [[ ${mode} == "update" ]]; then
169 einfo "Running ${cmdupdate}"
170 HOME="${EDARCS_TOP_DIR}" ${cmdupdate} || die "darcs update command failed"
173 export EDARCS_PATCHCOUNT=$(darcs_patchcount)
174 einfo " patches in repo: ${EDARCS_PATCHCOUNT}"
179 # @FUNCTION: darcs_src_unpack
183 # The local directory to store the repository (useful to ensure a
184 # unique local name); relative to EDARCS_TOP_DIR
185 [[ -z ${EDARCS_LOCALREPO} ]] && [[ -n ${EDARCS_REPOSITORY} ]] \
186 && EDARCS_LOCALREPO=${EDARCS_REPOSITORY%/} \
187 && EDARCS_LOCALREPO=${EDARCS_LOCALREPO##*/}
189 debug-print-function ${FUNCNAME} $*
191 debug-print "${FUNCNAME}: init:
192 EDARCS_DARCS_CMD=${EDARCS_DARCS_CMD}
193 EDARCS_GET_CMD=${EDARCS_GET_CMD}
194 EDARCS_UPDATE_CMD=${EDARCS_UPDATE_CMD}
195 EDARCS_OPTIONS=${EDARCS_OPTIONS}
196 EDARCS_TOP_DIR=${EDARCS_TOP_DIR}
197 EDARCS_REPOSITORY=${EDARCS_REPOSITORY}
198 EDARCS_LOCALREPO=${EDARCS_LOCALREPO}
199 EDARCS_CLEAN=${EDARCS_CLEAN}"
201 einfo "Fetching darcs repository ${EDARCS_REPOSITORY} into ${EDARCS_TOP_DIR}..."
204 einfo "Copying ${EDARCS_LOCALREPO} from ${EDARCS_TOP_DIR}..."
205 debug-print "Copying ${EDARCS_LOCALREPO} from ${EDARCS_TOP_DIR}..."
207 # probably redundant, but best to make sure
208 # Use ${WORKDIR}/${P} rather than ${S} so user can point ${S} to something inside.
209 mkdir -p "${WORKDIR}/${P}"
211 eshopts_push -s dotglob # get any dotfiles too.
212 rsync -rlpgo "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}"/* "${WORKDIR}/${P}"
215 einfo "Darcs repository contents are now in ${WORKDIR}/${P}"
219 EXPORT_FUNCTIONS src_unpack