/[gentoo-x86]/eclass/darcs.eclass
Gentoo

Diff of /eclass/darcs.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.8 Revision 1.16
1# Copyright 2004 Gentoo Technologies, Inc. 1# Copyright 1999-2012 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/darcs.eclass,v 1.8 2010/03/14 12:31:41 kolmodin Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/darcs.eclass,v 1.16 2012/06/08 03:39:50 vapier Exp $
4
5# @ECLASS: darcs.eclass
6# @MAINTAINER:
7# "Gentoo's Haskell Language team" <haskell@gentoo.org>
8# Sergei Trofimovich <slyfox@gentoo.org>
9# @AUTHOR:
10# Original Author: Jeffrey Yasskin <jyasskin@mail.utexas.edu>
11# <rphillips@gentoo.org> (tla eclass author)
12# Andres Loeh <kosmikus@gentoo.org> (darcs.eclass author)
13# Alexander Vershilov <alexander.vershilov@gmail.com> (various contributions)
14# @BLURB: This eclass provides functions for fetch and unpack darcs repositories
15# @DESCRIPTION:
16# This eclass provides the generic darcs fetching functions.
4# 17#
5# darcs eclass author: Andres Loeh <kosmikus@gentoo.org> 18# Define the EDARCS_REPOSITORY variable at least.
6# tla eclass author: <rphillips@gentoo.org> 19# The ${S} variable is set to ${WORKDIR}/${P}.
7# Original Author: Jeffrey Yasskin <jyasskin@mail.utexas.edu>
8#
9# Originally derived from the tla eclass, which is derived from the
10# cvs eclass.
11#
12# This eclass provides the generic darcs fetching functions.
13# to use from an ebuild, set the 'ebuild-configurable settings' below in your
14# ebuild before inheriting. then either leave the default src_unpack or extend
15# over darcs_src_unpack.
16 20
17# Most of the time, you will define only $EDARCS_REPOSITORY in your 21# TODO:
18# ebuild.
19 22
20# TODO: support for tags, ... 23# support for tags
24
25inherit eutils # eshopts_{push,pop}
21 26
22# Don't download anything other than the darcs repository 27# Don't download anything other than the darcs repository
23SRC_URI="" 28SRC_URI=""
24 29
25# You shouldn't change these settings yourself! The ebuild/eclass inheriting 30# You shouldn't change these settings yourself! The ebuild/eclass inheriting
26# this eclass will take care of that. 31# this eclass will take care of that.
27 32
28# --- begin ebuild-configurable settings 33# --- begin ebuild-configurable settings
29 34
30# darcs command to run 35# darcs command to run
31[ -z "$EDARCS_DARCS_CMD" ] && EDARCS_DARCS_CMD="darcs" 36# @ECLASS-VARIABLE: EDARCS_DARCS_CMD
37# @DESCRIPTION:
38# Path to darcs binary.
39: ${EDARCS_DARCS_CMD:=darcs}
32 40
33# darcs commands with command-specific options 41# darcs commands with command-specific options
34[ -z "$EDARCS_GET_CMD" ] && EDARCS_GET_CMD="get --partial"
35[ -z "$EDARCS_UPDATE_CMD" ] && EDARCS_UPDATE_CMD="pull"
36 42
43# @ECLASS-VARIABLE: EDARCS_GET_CMD
44# @DESCRIPTION:
45# First fetch darcs command.
46: ${EDARCS_GET_CMD:=get --lazy}
47
48# @ECLASS-VARIABLE: EDARCS_UPDATE_CMD
49# @DESCRIPTION:
50# Repo update darcs command.
51: ${EDARCS_UPDATE_CMD:=pull}
52
53# @ECLASS-VARIABLE: EDARCS_OPTIONS
54# @DESCRIPTION:
37# options to pass to both the "get" and "update" commands 55# Options to pass to both the "get" and "update" commands
38[ -z "$EDARCS_OPTIONS" ] && EDARCS_OPTIONS="--set-scripts-executable" 56: ${EDARCS_OPTIONS:=--set-scripts-executable}
39 57
58# @ECLASS-VARIABLE: EDARCS_TOP_DIR
59# @DESCRIPTION:
40# Where the darcs repositories are stored/accessed 60# Where the darcs repositories are stored/accessed
41[ -z "$EDARCS_TOP_DIR" ] && EDARCS_TOP_DIR="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/darcs-src" 61: ${EDARCS_TOP_DIR:=${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/darcs-src}
42 62
63# @ECLASS-VARIABLE: EDARCS_REPOSITORY
64# @DESCRIPTION:
43# The URI to the repository. 65# The URI to the repository.
44[ -z "$EDARCS_REPOSITORY" ] && EDARCS_REPOSITORY="" 66: ${EDARCS_REPOSITORY:=}
45 67
68# @ECLASS-VARIABLE: EDARCS_OFFLINE
69# @DESCRIPTION:
70# Set this variable to a non-empty value to disable the automatic updating of
71# a darcs repository. This is intended to be set outside the darcs source
72# tree by users. Defaults to EVCS_OFFLINE value.
73: ${EDARCS_OFFLINE:=${EVCS_OFFLINE}}
46 74
75# @ECLASS-VARIABLE: EDARCS_CLEAN
76# @DESCRIPTION:
47# EDARCS_CLEAN: set this to something to get a clean copy when updating 77# Set this to something to get a clean copy when updating
48# (removes the working directory, then uses $EDARCS_GET_CMD to 78# (removes the working directory, then uses EDARCS_GET_CMD to
49# re-download it.) 79# re-download it.)
80: ${EDARCS_CLEAN:=}
50 81
51# --- end ebuild-configurable settings --- 82# --- end ebuild-configurable settings ---
52 83
53# add darcs to deps
54DEPEND="dev-vcs/darcs" 84DEPEND="dev-vcs/darcs
85 net-misc/rsync"
55 86
87# @FUNCTION: darcs_patchcount
88# @DESCRIPTION:
89# Internal function to determine amount of patches in repository.
90darcs_patchcount() {
91 set -- $(${EDARCS_DARCS_CMD} show repo | grep "Num Patches")
92 # handle string like: " Num Patches: 3860"
93 echo ${3}
94}
95
96# @FUNCTION: darcs_fetch
97# @DESCRIPTION:
56# is called from darcs_src_unpack 98# Internal function is called from darcs_src_unpack
57darcs_fetch() { 99darcs_fetch() {
58
59 # The local directory to store the repository (useful to ensure a 100 # The local directory to store the repository (useful to ensure a
60 # unique local name); relative to EDARCS_TOP_DIR 101 # unique local name); relative to EDARCS_TOP_DIR
61 [ -z "$EDARCS_LOCALREPO" ] && [ -n "$EDARCS_REPOSITORY" ] \ 102 [[ -z ${EDARCS_LOCALREPO} ]] && [[ -n ${EDARCS_REPOSITORY} ]] \
62 && EDARCS_LOCALREPO=${EDARCS_REPOSITORY%/} \ 103 && EDARCS_LOCALREPO=${EDARCS_REPOSITORY%/} \
63 && EDARCS_LOCALREPO=${EDARCS_LOCALREPO##*/} 104 && EDARCS_LOCALREPO=${EDARCS_LOCALREPO##*/}
64 105
65 debug-print-function $FUNCNAME $* 106 debug-print-function ${FUNCNAME} $*
66 107
67 if [ -n "$EDARCS_CLEAN" ]; then 108 if [[ -n ${EDARCS_CLEAN} ]]; then
109 addwrite "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}"
68 rm -rf $EDARCS_TOP_DIR/$EDARCS_LOCALREPO 110 rm -rf "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}"
69 fi 111 fi
70 112
71 # create the top dir if needed 113 # create the top dir if needed
72 if [ ! -d "$EDARCS_TOP_DIR" ]; then 114 if [[ ! -d ${EDARCS_TOP_DIR} ]]; then
73 # note that the addwrite statements in this block are only there to allow creating EDARCS_TOP_DIR; 115 # note that the addwrite statements in this block are only there to allow creating EDARCS_TOP_DIR;
74 # we've already allowed writing inside it 116 # we've already allowed writing inside it
75 # this is because it's simpler than trying to find out the parent path of the directory, which 117 # this is because it's simpler than trying to find out the parent path of the directory, which
76 # would need to be the real path and not a symlink for things to work (so we can't just remove 118 # would need to be the real path and not a symlink for things to work (so we can't just remove
77 # the last path element in the string) 119 # the last path element in the string)
78 debug-print "$FUNCNAME: checkout mode. creating darcs directory" 120 debug-print "${FUNCNAME}: checkout mode. creating darcs directory"
79 addwrite /foobar 121 addwrite /foobar
80 addwrite / 122 addwrite /
81 mkdir -p "$EDARCS_TOP_DIR" 123 mkdir -p "${EDARCS_TOP_DIR}"
82 export SANDBOX_WRITE="${SANDBOX_WRITE//:\/foobar:\/}" 124 export SANDBOX_WRITE="${SANDBOX_WRITE//:\/foobar:\/}"
83 fi 125 fi
84 126
85 # in case EDARCS_DARCS_DIR is a symlink to a dir, get the real 127 # in case EDARCS_DARCS_DIR is a symlink to a dir, get the real
86 # dir's path, otherwise addwrite() doesn't work. 128 # dir's path, otherwise addwrite() doesn't work.
87 pushd . 129 pushd .
88 cd -P "$EDARCS_TOP_DIR" > /dev/null 130 cd -P "${EDARCS_TOP_DIR}" > /dev/null
89 EDARCS_TOP_DIR="`/bin/pwd`" 131 EDARCS_TOP_DIR="`/bin/pwd`"
90 132
91 # disable the sandbox for this dir 133 # disable the sandbox for this dir
92 addwrite "$EDARCS_TOP_DIR" 134 addwrite "${EDARCS_TOP_DIR}"
93 135
94 # determine checkout or update mode and change to the right directory. 136 # determine checkout or update mode and change to the right directory.
95 if [ ! -d "$EDARCS_TOP_DIR/$EDARCS_LOCALREPO/_darcs" ]; then 137 if [[ ! -d "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}/_darcs" ]]; then
96 mode=get 138 mode=get
97 cd "$EDARCS_TOP_DIR" 139 cd "${EDARCS_TOP_DIR}"
98 else 140 else
99 mode=update 141 mode=update
100 cd "$EDARCS_TOP_DIR/$EDARCS_LOCALREPO" 142 cd "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}"
101 fi 143 fi
102 144
103 # commands to run 145 # commands to run
104 local cmdget="${EDARCS_DARCS_CMD} ${EDARCS_GET_CMD} ${EDARCS_OPTIONS} --repo-name=${EDARCS_LOCALREPO} ${EDARCS_REPOSITORY}" 146 local cmdget="${EDARCS_DARCS_CMD} ${EDARCS_GET_CMD} ${EDARCS_OPTIONS} --repo-name=${EDARCS_LOCALREPO} ${EDARCS_REPOSITORY}"
105 local cmdupdate="${EDARCS_DARCS_CMD} ${EDARCS_UPDATE_CMD} --all ${EDARCS_OPTIONS} ${EDARCS_REPOSITORY}" 147 local cmdupdate="${EDARCS_DARCS_CMD} ${EDARCS_UPDATE_CMD} --all ${EDARCS_OPTIONS} ${EDARCS_REPOSITORY}"
106 148
107 if [ "${mode}" == "get" ]; then 149 if [[ ${mode} == "get" ]]; then
108 einfo "Running $cmdget" 150 einfo "Running ${cmdget}"
109 eval $cmdget || die "darcs get command failed" 151 eval ${cmdget} || die "darcs get command failed"
152 elif [[ -n ${EDARCS_OFFLINE} ]] ; then
153 einfo "Offline update"
110 elif [ "${mode}" == "update" ]; then 154 elif [[ ${mode} == "update" ]]; then
111 einfo "Running $cmdupdate" 155 einfo "Running ${cmdupdate}"
112 eval $cmdupdate || die "darcs update command failed" 156 eval ${cmdupdate} || die "darcs update command failed"
113 fi 157 fi
158
159 export EDARCS_PATCHCOUNT=$(darcs_patchcount)
160 einfo " patches in repo: ${EDARCS_PATCHCOUNT}"
114 161
115 popd 162 popd
116} 163}
117 164
118 165# @FUNCTION: darcs_src_unpack
166# @DESCRIPTION:
167# src_upack function
119darcs_src_unpack() { 168darcs_src_unpack() {
120 # The local directory to store the repository (useful to ensure a 169 # The local directory to store the repository (useful to ensure a
121 # unique local name); relative to EDARCS_TOP_DIR 170 # unique local name); relative to EDARCS_TOP_DIR
122 [ -z "$EDARCS_LOCALREPO" ] && [ -n "$EDARCS_REPOSITORY" ] \ 171 [[ -z ${EDARCS_LOCALREPO} ]] && [[ -n ${EDARCS_REPOSITORY} ]] \
123 && EDARCS_LOCALREPO=${EDARCS_REPOSITORY%/} \ 172 && EDARCS_LOCALREPO=${EDARCS_REPOSITORY%/} \
124 && EDARCS_LOCALREPO=${EDARCS_LOCALREPO##*/} 173 && EDARCS_LOCALREPO=${EDARCS_LOCALREPO##*/}
125 local EDARCS_SHOPT
126 174
127 debug-print-function $FUNCNAME $* 175 debug-print-function ${FUNCNAME} $*
128 176
129 debug-print "$FUNCNAME: init: 177 debug-print "${FUNCNAME}: init:
130 EDARCS_DARCS_CMD=$EDARCS_DARCS_CMD 178 EDARCS_DARCS_CMD=${EDARCS_DARCS_CMD}
131 EDARCS_GET_CMD=$EDARCS_GET_CMD 179 EDARCS_GET_CMD=${EDARCS_GET_CMD}
132 EDARCS_UPDATE_CMD=$EDARCS_UPDATE_CMD 180 EDARCS_UPDATE_CMD=${EDARCS_UPDATE_CMD}
133 EDARCS_OPTIONS=$EDARCS_OPTIONS 181 EDARCS_OPTIONS=${EDARCS_OPTIONS}
134 EDARCS_TOP_DIR=$EDARCS_TOP_DIR 182 EDARCS_TOP_DIR=${EDARCS_TOP_DIR}
135 EDARCS_REPOSITORY=$EDARCS_REPOSITORY 183 EDARCS_REPOSITORY=${EDARCS_REPOSITORY}
136 EDARCS_LOCALREPO=$EDARCS_LOCALREPO 184 EDARCS_LOCALREPO=${EDARCS_LOCALREPO}
137 EDARCS_CLEAN=$EDARCS_CLEAN" 185 EDARCS_CLEAN=${EDARCS_CLEAN}"
138 186
139 einfo "Fetching darcs repository $EDARCS_REPOSITORY into $EDARCS_TOP_DIR..." 187 einfo "Fetching darcs repository ${EDARCS_REPOSITORY} into ${EDARCS_TOP_DIR}..."
140 darcs_fetch 188 darcs_fetch
141 189
142 einfo "Copying $EDARCS_LOCALREPO from $EDARCS_TOP_DIR..." 190 einfo "Copying ${EDARCS_LOCALREPO} from ${EDARCS_TOP_DIR}..."
143 debug-print "Copying $EDARCS_LOCALREPO from $EDARCS_TOP_DIR..." 191 debug-print "Copying ${EDARCS_LOCALREPO} from ${EDARCS_TOP_DIR}..."
144 192
145 # probably redundant, but best to make sure 193 # probably redundant, but best to make sure
146 # Use ${WORKDIR}/${P} rather than ${S} so user can point ${S} to something inside. 194 # Use ${WORKDIR}/${P} rather than ${S} so user can point ${S} to something inside.
147 mkdir -p "${WORKDIR}/${P}" 195 mkdir -p "${WORKDIR}/${P}"
148 196
149 EDARCS_SHOPT=$(shopt -p dotglob)
150 shopt -s dotglob # get any dotfiles too. 197 eshopts_push -s dotglob # get any dotfiles too.
151 rsync -rlpgo --exclude="_darcs/" "$EDARCS_TOP_DIR/$EDARCS_LOCALREPO"/* "${WORKDIR}/${P}" 198 rsync -rlpgo "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}"/* "${WORKDIR}/${P}"
152 eval ${EDARCS_SHOPT} # reset shopt 199 eshopts_pop
153 200
154 einfo "Darcs repository contents are now in ${WORKDIR}/${P}" 201 einfo "Darcs repository contents are now in ${WORKDIR}/${P}"
155 202
156} 203}
157 204

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.16

  ViewVC Help
Powered by ViewVC 1.1.20