1 # Copyright 1999-2015 Gentoo Foundation
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}.
24 inherit eutils # eshopts_{push,pop}
26 # Don't download anything other than the darcs repository
29 # You shouldn't change these settings yourself! The ebuild/eclass inheriting
30 # this eclass will take care of that.
32 # --- begin ebuild-configurable settings
34 # darcs command to run
35 # @ECLASS-VARIABLE: EDARCS_DARCS_CMD
37 # Path to darcs binary.
38 : ${EDARCS_DARCS_CMD:=darcs}
40 # darcs commands with command-specific options
42 # @ECLASS-VARIABLE: EDARCS_GET_CMD
44 # First fetch darcs command.
45 : ${EDARCS_GET_CMD:=get --lazy}
47 # @ECLASS-VARIABLE: EDARCS_UPDATE_CMD
49 # Repo update darcs command.
50 : ${EDARCS_UPDATE_CMD:=pull}
52 # @ECLASS-VARIABLE: EDARCS_OPTIONS
54 # Options to pass to both the "get" and "update" commands
55 : ${EDARCS_OPTIONS:=--set-scripts-executable}
57 # @ECLASS-VARIABLE: EDARCS_TOP_DIR
59 # Where the darcs repositories are stored/accessed
60 : ${EDARCS_TOP_DIR:=${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/darcs-src}
62 # @ECLASS-VARIABLE: EDARCS_REPOSITORY
64 # The URI to the repository.
65 : ${EDARCS_REPOSITORY:=}
67 # @ECLASS-VARIABLE: EDARCS_OFFLINE
69 # Set this variable to a non-empty value to disable the automatic updating of
70 # a darcs repository. This is intended to be set outside the darcs source
71 # tree by users. Defaults to EVCS_OFFLINE value.
72 : ${EDARCS_OFFLINE:=${EVCS_OFFLINE}}
74 # @ECLASS-VARIABLE: EDARCS_CLEAN
76 # Set this to something to get a clean copy when updating
77 # (removes the working directory, then uses EDARCS_GET_CMD to
81 # --- end ebuild-configurable settings ---
86 # @FUNCTION: darcs_patchcount
88 # Internal function to determine amount of patches in repository.
90 set -- $(HOME="${EDARCS_TOP_DIR}" ${EDARCS_DARCS_CMD} show repo --repodir="${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}" | grep "Num Patches")
91 # handle string like: " Num Patches: 3860"
95 # @FUNCTION: darcs_fetch
97 # Internal function is called from darcs_src_unpack
99 # The local directory to store the repository (useful to ensure a
100 # unique local name); relative to EDARCS_TOP_DIR
101 [[ -z ${EDARCS_LOCALREPO} ]] && [[ -n ${EDARCS_REPOSITORY} ]] \
102 && EDARCS_LOCALREPO=${EDARCS_REPOSITORY%/} \
103 && EDARCS_LOCALREPO=${EDARCS_LOCALREPO##*/}
105 debug-print-function ${FUNCNAME} $*
107 if [[ -n ${EDARCS_CLEAN} ]]; then
108 addwrite "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}"
109 rm -rf "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}"
112 # create the top dir if needed
113 if [[ ! -d ${EDARCS_TOP_DIR} ]]; then
114 # note that the addwrite statements in this block are only there to allow creating EDARCS_TOP_DIR;
115 # we've already allowed writing inside it
116 # this is because it's simpler than trying to find out the parent path of the directory, which
117 # would need to be the real path and not a symlink for things to work (so we can't just remove
118 # the last path element in the string)
119 debug-print "${FUNCNAME}: checkout mode. creating darcs directory"
122 mkdir -p "${EDARCS_TOP_DIR}"
123 export SANDBOX_WRITE="${SANDBOX_WRITE//:\/foobar:\/}"
126 # in case EDARCS_DARCS_DIR is a symlink to a dir, get the real
127 # dir's path, otherwise addwrite() doesn't work.
129 cd -P "${EDARCS_TOP_DIR}" > /dev/null
130 EDARCS_TOP_DIR="`/bin/pwd`"
132 # disable the sandbox for this dir
133 addwrite "${EDARCS_TOP_DIR}"
135 # determine checkout or update mode and change to the right directory.
136 if [[ ! -d "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}/_darcs" ]]; then
138 cd "${EDARCS_TOP_DIR}"
141 cd "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}"
145 local cmdget="${EDARCS_DARCS_CMD} ${EDARCS_GET_CMD} ${EDARCS_OPTIONS} --repo-name=${EDARCS_LOCALREPO} ${EDARCS_REPOSITORY}"
146 local cmdupdate="${EDARCS_DARCS_CMD} ${EDARCS_UPDATE_CMD} --all ${EDARCS_OPTIONS} ${EDARCS_REPOSITORY}"
148 if [[ ${mode} == "get" ]]; then
149 einfo "Running ${cmdget}"
150 HOME="${EDARCS_TOP_DIR}" ${cmdget} || die "darcs get command failed"
151 elif [[ -n ${EDARCS_OFFLINE} ]] ; then
152 einfo "Offline update"
153 elif [[ ${mode} == "update" ]]; then
154 einfo "Running ${cmdupdate}"
155 HOME="${EDARCS_TOP_DIR}" ${cmdupdate} || die "darcs update command failed"
158 export EDARCS_PATCHCOUNT=$(darcs_patchcount)
159 einfo " patches in repo: ${EDARCS_PATCHCOUNT}"
164 # @FUNCTION: darcs_src_unpack
168 # The local directory to store the repository (useful to ensure a
169 # unique local name); relative to EDARCS_TOP_DIR
170 [[ -z ${EDARCS_LOCALREPO} ]] && [[ -n ${EDARCS_REPOSITORY} ]] \
171 && EDARCS_LOCALREPO=${EDARCS_REPOSITORY%/} \
172 && EDARCS_LOCALREPO=${EDARCS_LOCALREPO##*/}
174 debug-print-function ${FUNCNAME} $*
176 debug-print "${FUNCNAME}: init:
177 EDARCS_DARCS_CMD=${EDARCS_DARCS_CMD}
178 EDARCS_GET_CMD=${EDARCS_GET_CMD}
179 EDARCS_UPDATE_CMD=${EDARCS_UPDATE_CMD}
180 EDARCS_OPTIONS=${EDARCS_OPTIONS}
181 EDARCS_TOP_DIR=${EDARCS_TOP_DIR}
182 EDARCS_REPOSITORY=${EDARCS_REPOSITORY}
183 EDARCS_LOCALREPO=${EDARCS_LOCALREPO}
184 EDARCS_CLEAN=${EDARCS_CLEAN}"
186 einfo "Fetching darcs repository ${EDARCS_REPOSITORY} into ${EDARCS_TOP_DIR}..."
189 einfo "Copying ${EDARCS_LOCALREPO} from ${EDARCS_TOP_DIR}..."
190 debug-print "Copying ${EDARCS_LOCALREPO} from ${EDARCS_TOP_DIR}..."
192 # probably redundant, but best to make sure
193 # Use ${WORKDIR}/${P} rather than ${S} so user can point ${S} to something inside.
194 mkdir -p "${WORKDIR}/${P}"
196 eshopts_push -s dotglob # get any dotfiles too.
197 rsync -rlpgo "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}"/* "${WORKDIR}/${P}"
200 einfo "Darcs repository contents are now in ${WORKDIR}/${P}"
204 EXPORT_FUNCTIONS src_unpack