media-sound/snapcast: USE flag avahi > zeroconf
[gentoo.git] / eclass / darcs.eclass
1 # Copyright 1999-2018 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 DEPEND="dev-vcs/darcs
89         net-misc/rsync"
90
91 # @FUNCTION: darcs_patchcount
92 # @DESCRIPTION:
93 # Internal function to determine amount of patches in repository.
94 darcs_patchcount() {
95         set -- $(HOME="${EDARCS_TOP_DIR}" ${EDARCS_DARCS_CMD} show repo --repodir="${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}" | grep "Num Patches")
96         # handle string like: "    Num Patches: 3860"
97         echo ${3}
98 }
99
100 # @FUNCTION: darcs_fetch
101 # @DESCRIPTION:
102 # Internal function is called from darcs_src_unpack
103 darcs_fetch() {
104         # The local directory to store the repository (useful to ensure a
105         # unique local name); relative to EDARCS_TOP_DIR
106         [[ -z ${EDARCS_LOCALREPO} ]] && [[ -n ${EDARCS_REPOSITORY} ]] \
107                 && EDARCS_LOCALREPO=${EDARCS_REPOSITORY%/} \
108                 && EDARCS_LOCALREPO=${EDARCS_LOCALREPO##*/}
109
110         debug-print-function ${FUNCNAME} $*
111
112         if [[ -n ${EDARCS_CLEAN} ]]; then
113                 addwrite "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}"
114                 rm -rf "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}"
115         fi
116
117         # create the top dir if needed
118         if [[ ! -d ${EDARCS_TOP_DIR} ]]; then
119                 # note that the addwrite statements in this block are only there to allow creating EDARCS_TOP_DIR;
120                 # we've already allowed writing inside it
121                 # this is because it's simpler than trying to find out the parent path of the directory, which
122                 # would need to be the real path and not a symlink for things to work (so we can't just remove
123                 # the last path element in the string)
124                 debug-print "${FUNCNAME}: checkout mode. creating darcs directory"
125                 addwrite /foobar
126                 addwrite /
127                 mkdir -p "${EDARCS_TOP_DIR}"
128                 export SANDBOX_WRITE="${SANDBOX_WRITE//:\/foobar:\/}"
129         fi
130
131         # in case EDARCS_DARCS_DIR is a symlink to a dir, get the real
132         # dir's path, otherwise addwrite() doesn't work.
133         pushd . || die
134         cd -P "${EDARCS_TOP_DIR}" > /dev/null
135         EDARCS_TOP_DIR="`/bin/pwd`"
136
137         # disable the sandbox for this dir
138         addwrite "${EDARCS_TOP_DIR}"
139
140         # determine checkout or update mode and change to the right directory.
141         if [[ ! -d "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}/_darcs" ]]; then
142                 mode=get
143                 cd "${EDARCS_TOP_DIR}"
144         else
145                 mode=update
146                 cd "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}"
147         fi
148
149         # commands to run
150         local    cmdget="${EDARCS_DARCS_CMD} ${EDARCS_GET_CMD}          ${EDARCS_OPTIONS} --repo-name=${EDARCS_LOCALREPO} ${EDARCS_REPOSITORY}"
151         local cmdupdate="${EDARCS_DARCS_CMD} ${EDARCS_UPDATE_CMD} --all ${EDARCS_OPTIONS}                                 ${EDARCS_REPOSITORY}"
152
153         if [[ ${mode} == "get" ]]; then
154                 einfo "Running ${cmdget}"
155                 HOME="${EDARCS_TOP_DIR}" ${cmdget} || die "darcs get command failed"
156         elif [[ -n ${EDARCS_OFFLINE} ]] ; then
157                 einfo "Offline update"
158         elif [[ ${mode} == "update" ]]; then
159                 einfo "Running ${cmdupdate}"
160                 HOME="${EDARCS_TOP_DIR}" ${cmdupdate} || die "darcs update command failed"
161         fi
162
163         export EDARCS_PATCHCOUNT=$(darcs_patchcount)
164         einfo "    patches in repo: ${EDARCS_PATCHCOUNT}"
165
166         popd || die
167 }
168
169 # @FUNCTION: darcs_src_unpack
170 # @DESCRIPTION:
171 # src_upack function
172 darcs_src_unpack() {
173         # The local directory to store the repository (useful to ensure a
174         # unique local name); relative to EDARCS_TOP_DIR
175         [[ -z ${EDARCS_LOCALREPO} ]] && [[ -n ${EDARCS_REPOSITORY} ]] \
176                 && EDARCS_LOCALREPO=${EDARCS_REPOSITORY%/} \
177                 && EDARCS_LOCALREPO=${EDARCS_LOCALREPO##*/}
178
179         debug-print-function ${FUNCNAME} $*
180
181         debug-print "${FUNCNAME}: init:
182         EDARCS_DARCS_CMD=${EDARCS_DARCS_CMD}
183         EDARCS_GET_CMD=${EDARCS_GET_CMD}
184         EDARCS_UPDATE_CMD=${EDARCS_UPDATE_CMD}
185         EDARCS_OPTIONS=${EDARCS_OPTIONS}
186         EDARCS_TOP_DIR=${EDARCS_TOP_DIR}
187         EDARCS_REPOSITORY=${EDARCS_REPOSITORY}
188         EDARCS_LOCALREPO=${EDARCS_LOCALREPO}
189         EDARCS_CLEAN=${EDARCS_CLEAN}"
190
191         einfo "Fetching darcs repository ${EDARCS_REPOSITORY} into ${EDARCS_TOP_DIR}..."
192         darcs_fetch
193
194         einfo "Copying ${EDARCS_LOCALREPO} from ${EDARCS_TOP_DIR}..."
195         debug-print "Copying ${EDARCS_LOCALREPO} from ${EDARCS_TOP_DIR}..."
196
197         # probably redundant, but best to make sure
198         # Use ${WORKDIR}/${P} rather than ${S} so user can point ${S} to something inside.
199         mkdir -p "${WORKDIR}/${P}"
200
201         eshopts_push -s dotglob # get any dotfiles too.
202         rsync -rlpgo "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}"/* "${WORKDIR}/${P}"
203         eshopts_pop
204
205         einfo "Darcs repository contents are now in ${WORKDIR}/${P}"
206
207 }
208
209 EXPORT_FUNCTIONS src_unpack