kde-plasma/breeze-gtk: x86 stable wrt bug #613144
[gentoo.git] / eclass / darcs.eclass
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: darcs.eclass
5 # @MAINTAINER:
6 # "Gentoo's Haskell Language team" <haskell@gentoo.org>
7 # Sergei Trofimovich <slyfox@gentoo.org>
8 # @AUTHOR:
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
14 # @DESCRIPTION:
15 # This eclass provides the generic darcs fetching functions.
16 #
17 # Define the EDARCS_REPOSITORY variable at least.
18 # The ${S} variable is set to ${WORKDIR}/${P}.
19
20 # TODO:
21
22 # support for tags
23
24 inherit eutils # eshopts_{push,pop}
25
26 # Don't download anything other than the darcs repository
27 SRC_URI=""
28
29 # You shouldn't change these settings yourself! The ebuild/eclass inheriting
30 # this eclass will take care of that.
31
32 # --- begin ebuild-configurable settings
33
34 # darcs command to run
35 # @ECLASS-VARIABLE: EDARCS_DARCS_CMD
36 # @DESCRIPTION:
37 # Path to darcs binary.
38 : ${EDARCS_DARCS_CMD:=darcs}
39
40 # darcs commands with command-specific options
41
42 # @ECLASS-VARIABLE: EDARCS_GET_CMD
43 # @DESCRIPTION:
44 # First fetch darcs command.
45 : ${EDARCS_GET_CMD:=get --lazy}
46
47 # @ECLASS-VARIABLE: EDARCS_UPDATE_CMD
48 # @DESCRIPTION:
49 # Repo update darcs command.
50 : ${EDARCS_UPDATE_CMD:=pull}
51
52 # @ECLASS-VARIABLE: EDARCS_OPTIONS
53 # @DESCRIPTION:
54 # Options to pass to both the "get" and "update" commands
55 : ${EDARCS_OPTIONS:=--set-scripts-executable}
56
57 # @ECLASS-VARIABLE: EDARCS_TOP_DIR
58 # @DESCRIPTION:
59 # Where the darcs repositories are stored/accessed
60 : ${EDARCS_TOP_DIR:=${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/darcs-src}
61
62 # @ECLASS-VARIABLE: EDARCS_REPOSITORY
63 # @DESCRIPTION:
64 # The URI to the repository.
65 : ${EDARCS_REPOSITORY:=}
66
67 # @ECLASS-VARIABLE: EDARCS_OFFLINE
68 # @DESCRIPTION:
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}}
73
74 # @ECLASS-VARIABLE: EDARCS_CLEAN
75 # @DESCRIPTION:
76 # Set this to something to get a clean copy when updating
77 # (removes the working directory, then uses EDARCS_GET_CMD to
78 # re-download it.)
79 : ${EDARCS_CLEAN:=}
80
81 # --- end ebuild-configurable settings ---
82
83 DEPEND="dev-vcs/darcs
84         net-misc/rsync"
85
86 # @FUNCTION: darcs_patchcount
87 # @DESCRIPTION:
88 # Internal function to determine amount of patches in repository.
89 darcs_patchcount() {
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"
92         echo ${3}
93 }
94
95 # @FUNCTION: darcs_fetch
96 # @DESCRIPTION:
97 # Internal function is called from darcs_src_unpack
98 darcs_fetch() {
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##*/}
104
105         debug-print-function ${FUNCNAME} $*
106
107         if [[ -n ${EDARCS_CLEAN} ]]; then
108                 addwrite "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}"
109                 rm -rf "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}"
110         fi
111
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"
120                 addwrite /foobar
121                 addwrite /
122                 mkdir -p "${EDARCS_TOP_DIR}"
123                 export SANDBOX_WRITE="${SANDBOX_WRITE//:\/foobar:\/}"
124         fi
125
126         # in case EDARCS_DARCS_DIR is a symlink to a dir, get the real
127         # dir's path, otherwise addwrite() doesn't work.
128         pushd . || die
129         cd -P "${EDARCS_TOP_DIR}" > /dev/null
130         EDARCS_TOP_DIR="`/bin/pwd`"
131
132         # disable the sandbox for this dir
133         addwrite "${EDARCS_TOP_DIR}"
134
135         # determine checkout or update mode and change to the right directory.
136         if [[ ! -d "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}/_darcs" ]]; then
137                 mode=get
138                 cd "${EDARCS_TOP_DIR}"
139         else
140                 mode=update
141                 cd "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}"
142         fi
143
144         # commands to run
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}"
147
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"
156         fi
157
158         export EDARCS_PATCHCOUNT=$(darcs_patchcount)
159         einfo "    patches in repo: ${EDARCS_PATCHCOUNT}"
160
161         popd || die
162 }
163
164 # @FUNCTION: darcs_src_unpack
165 # @DESCRIPTION:
166 # src_upack function
167 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##*/}
173
174         debug-print-function ${FUNCNAME} $*
175
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}"
185
186         einfo "Fetching darcs repository ${EDARCS_REPOSITORY} into ${EDARCS_TOP_DIR}..."
187         darcs_fetch
188
189         einfo "Copying ${EDARCS_LOCALREPO} from ${EDARCS_TOP_DIR}..."
190         debug-print "Copying ${EDARCS_LOCALREPO} from ${EDARCS_TOP_DIR}..."
191
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}"
195
196         eshopts_push -s dotglob # get any dotfiles too.
197         rsync -rlpgo "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}"/* "${WORKDIR}/${P}"
198         eshopts_pop
199
200         einfo "Darcs repository contents are now in ${WORKDIR}/${P}"
201
202 }
203
204 EXPORT_FUNCTIONS src_unpack