dev-qt/qtpositioning: stable 5.14.2 for ppc, bug #719732
[gentoo.git] / eclass / darcs.eclass
1 # Copyright 1999-2019 Gentoo Authors
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 # eshopts_{push,pop}
25 case "${EAPI:-0}" in
26         4|5|6) inherit eutils ;;
27         7)     inherit estack ;;
28         *) ;;
29 esac
30
31 # Don't download anything other than the darcs repository
32 SRC_URI=""
33
34 # You shouldn't change these settings yourself! The ebuild/eclass inheriting
35 # this eclass will take care of that.
36
37 # --- begin ebuild-configurable settings
38
39 # darcs command to run
40 # @ECLASS-VARIABLE: EDARCS_DARCS_CMD
41 # @DESCRIPTION:
42 # Path to darcs binary.
43 : ${EDARCS_DARCS_CMD:=darcs}
44
45 # darcs commands with command-specific options
46
47 # @ECLASS-VARIABLE: EDARCS_GET_CMD
48 # @DESCRIPTION:
49 # First fetch darcs command.
50 : ${EDARCS_GET_CMD:=get --lazy}
51
52 # @ECLASS-VARIABLE: EDARCS_UPDATE_CMD
53 # @DESCRIPTION:
54 # Repo update darcs command.
55 : ${EDARCS_UPDATE_CMD:=pull}
56
57 # @ECLASS-VARIABLE: EDARCS_OPTIONS
58 # @DESCRIPTION:
59 # Options to pass to both the "get" and "update" commands
60 : ${EDARCS_OPTIONS:=--set-scripts-executable}
61
62 # @ECLASS-VARIABLE: EDARCS_TOP_DIR
63 # @DESCRIPTION:
64 # Where the darcs repositories are stored/accessed
65 : ${EDARCS_TOP_DIR:=${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/darcs-src}
66
67 # @ECLASS-VARIABLE: EDARCS_REPOSITORY
68 # @DESCRIPTION:
69 # The URI to the repository.
70 : ${EDARCS_REPOSITORY:=}
71
72 # @ECLASS-VARIABLE: EDARCS_OFFLINE
73 # @DESCRIPTION:
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}}
78
79 # @ECLASS-VARIABLE: EDARCS_CLEAN
80 # @DESCRIPTION:
81 # Set this to something to get a clean copy when updating
82 # (removes the working directory, then uses EDARCS_GET_CMD to
83 # re-download it.)
84 : ${EDARCS_CLEAN:=}
85
86 # --- end ebuild-configurable settings ---
87
88 PROPERTIES+=" live"
89
90 case ${EAPI:-0} in
91         [0-6]) # no need to care about 5-HDEPEND and similar
92                 DEPEND="dev-vcs/darcs
93                         net-misc/rsync"
94                 ;;
95         *)
96                 BDEPEND="dev-vcs/darcs
97                         net-misc/rsync"
98                 ;;
99 esac
100
101 # @FUNCTION: darcs_patchcount
102 # @DESCRIPTION:
103 # Internal function to determine amount of patches in repository.
104 darcs_patchcount() {
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"
107         echo ${3}
108 }
109
110 # @FUNCTION: darcs_fetch
111 # @DESCRIPTION:
112 # Internal function is called from darcs_src_unpack
113 darcs_fetch() {
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##*/}
119
120         debug-print-function ${FUNCNAME} $*
121
122         if [[ -n ${EDARCS_CLEAN} ]]; then
123                 addwrite "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}"
124                 rm -rf "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}"
125         fi
126
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"
135                 addwrite /foobar
136                 addwrite /
137                 mkdir -p "${EDARCS_TOP_DIR}"
138                 export SANDBOX_WRITE="${SANDBOX_WRITE//:\/foobar:\/}"
139         fi
140
141         # in case EDARCS_DARCS_DIR is a symlink to a dir, get the real
142         # dir's path, otherwise addwrite() doesn't work.
143         pushd . || die
144         cd -P "${EDARCS_TOP_DIR}" > /dev/null
145         EDARCS_TOP_DIR="`/bin/pwd`"
146
147         # disable the sandbox for this dir
148         addwrite "${EDARCS_TOP_DIR}"
149
150         # determine checkout or update mode and change to the right directory.
151         if [[ ! -d "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}/_darcs" ]]; then
152                 mode=get
153                 cd "${EDARCS_TOP_DIR}"
154         else
155                 mode=update
156                 cd "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}"
157         fi
158
159         # commands to run
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}"
162
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"
171         fi
172
173         export EDARCS_PATCHCOUNT=$(darcs_patchcount)
174         einfo "    patches in repo: ${EDARCS_PATCHCOUNT}"
175
176         popd || die
177 }
178
179 # @FUNCTION: darcs_src_unpack
180 # @DESCRIPTION:
181 # src_upack function
182 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##*/}
188
189         debug-print-function ${FUNCNAME} $*
190
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}"
200
201         einfo "Fetching darcs repository ${EDARCS_REPOSITORY} into ${EDARCS_TOP_DIR}..."
202         darcs_fetch
203
204         einfo "Copying ${EDARCS_LOCALREPO} from ${EDARCS_TOP_DIR}..."
205         debug-print "Copying ${EDARCS_LOCALREPO} from ${EDARCS_TOP_DIR}..."
206
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}"
210
211         eshopts_push -s dotglob # get any dotfiles too.
212         rsync -rlpgo "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}"/* "${WORKDIR}/${P}"
213         eshopts_pop
214
215         einfo "Darcs repository contents are now in ${WORKDIR}/${P}"
216
217 }
218
219 EXPORT_FUNCTIONS src_unpack