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

Diff of /eclass/darcs.eclass

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

Revision 1.5 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.5 2007/06/17 21:33:57 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
46# The local directory to store the repository (useful to ensure a 68# @ECLASS-VARIABLE: EDARCS_OFFLINE
47# unique local name); relative to EDARCS_TOP_DIR 69# @DESCRIPTION:
48[ -z "$EDARCS_LOCALREPO" ] && [ -n "$EDARCS_REPOSITORY" ] \ 70# Set this variable to a non-empty value to disable the automatic updating of
49 && EDARCS_LOCALREPO=${EDARCS_REPOSITORY%/} \ 71# a darcs repository. This is intended to be set outside the darcs source
50 && EDARCS_LOCALREPO=${EDARCS_LOCALREPO##*/} 72# tree by users. Defaults to EVCS_OFFLINE value.
73: ${EDARCS_OFFLINE:=${EVCS_OFFLINE}}
51 74
75# @ECLASS-VARIABLE: EDARCS_CLEAN
76# @DESCRIPTION:
52# 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
53# (removes the working directory, then uses $EDARCS_GET_CMD to 78# (removes the working directory, then uses EDARCS_GET_CMD to
54# re-download it.) 79# re-download it.)
80: ${EDARCS_CLEAN:=}
55 81
56# --- end ebuild-configurable settings --- 82# --- end ebuild-configurable settings ---
57 83
58# add darcs to deps
59DEPEND="dev-util/darcs" 84DEPEND="dev-vcs/darcs
85 net-misc/rsync"
60 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:
61# is called from darcs_src_unpack 98# Internal function is called from darcs_src_unpack
62darcs_fetch() { 99darcs_fetch() {
100 # The local directory to store the repository (useful to ensure a
101 # unique local name); relative to EDARCS_TOP_DIR
102 [[ -z ${EDARCS_LOCALREPO} ]] && [[ -n ${EDARCS_REPOSITORY} ]] \
103 && EDARCS_LOCALREPO=${EDARCS_REPOSITORY%/} \
104 && EDARCS_LOCALREPO=${EDARCS_LOCALREPO##*/}
63 105
64 debug-print-function $FUNCNAME $* 106 debug-print-function ${FUNCNAME} $*
65 107
66 if [ -n "$EDARCS_CLEAN" ]; then 108 if [[ -n ${EDARCS_CLEAN} ]]; then
109 addwrite "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}"
67 rm -rf $EDARCS_TOP_DIR/$EDARCS_LOCALREPO 110 rm -rf "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}"
68 fi 111 fi
69 112
70 # create the top dir if needed 113 # create the top dir if needed
71 if [ ! -d "$EDARCS_TOP_DIR" ]; then 114 if [[ ! -d ${EDARCS_TOP_DIR} ]]; then
72 # 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;
73 # we've already allowed writing inside it 116 # we've already allowed writing inside it
74 # 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
75 # 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
76 # the last path element in the string) 119 # the last path element in the string)
77 debug-print "$FUNCNAME: checkout mode. creating darcs directory" 120 debug-print "${FUNCNAME}: checkout mode. creating darcs directory"
78 addwrite /foobar 121 addwrite /foobar
79 addwrite / 122 addwrite /
80 mkdir -p "$EDARCS_TOP_DIR" 123 mkdir -p "${EDARCS_TOP_DIR}"
81 export SANDBOX_WRITE="${SANDBOX_WRITE//:\/foobar:\/}" 124 export SANDBOX_WRITE="${SANDBOX_WRITE//:\/foobar:\/}"
82 fi 125 fi
83 126
84 # 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
85 # dir's path, otherwise addwrite() doesn't work. 128 # dir's path, otherwise addwrite() doesn't work.
86 pushd . 129 pushd .
87 cd -P "$EDARCS_TOP_DIR" > /dev/null 130 cd -P "${EDARCS_TOP_DIR}" > /dev/null
88 EDARCS_TOP_DIR="`/bin/pwd`" 131 EDARCS_TOP_DIR="`/bin/pwd`"
89 132
90 # disable the sandbox for this dir 133 # disable the sandbox for this dir
91 addwrite "$EDARCS_TOP_DIR" 134 addwrite "${EDARCS_TOP_DIR}"
92 135
93 # determine checkout or update mode and change to the right directory. 136 # determine checkout or update mode and change to the right directory.
94 if [ ! -d "$EDARCS_TOP_DIR/$EDARCS_LOCALREPO/_darcs" ]; then 137 if [[ ! -d "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}/_darcs" ]]; then
95 mode=get 138 mode=get
96 cd "$EDARCS_TOP_DIR" 139 cd "${EDARCS_TOP_DIR}"
97 else 140 else
98 mode=update 141 mode=update
99 cd "$EDARCS_TOP_DIR/$EDARCS_LOCALREPO" 142 cd "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}"
100 fi 143 fi
101 144
102 # commands to run 145 # commands to run
103 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}"
104 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}"
105 148
106 if [ "${mode}" == "get" ]; then 149 if [[ ${mode} == "get" ]]; then
107 einfo "Running $cmdget" 150 einfo "Running ${cmdget}"
108 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"
109 elif [ "${mode}" == "update" ]; then 154 elif [[ ${mode} == "update" ]]; then
110 einfo "Running $cmdupdate" 155 einfo "Running ${cmdupdate}"
111 eval $cmdupdate || die "darcs update command failed" 156 eval ${cmdupdate} || die "darcs update command failed"
112 fi 157 fi
158
159 export EDARCS_PATCHCOUNT=$(darcs_patchcount)
160 einfo " patches in repo: ${EDARCS_PATCHCOUNT}"
113 161
114 popd 162 popd
115} 163}
116 164
117 165# @FUNCTION: darcs_src_unpack
166# @DESCRIPTION:
167# src_upack function
118darcs_src_unpack() { 168darcs_src_unpack() {
119 local EDARCS_SHOPT 169 # The local directory to store the repository (useful to ensure a
170 # unique local name); relative to EDARCS_TOP_DIR
171 [[ -z ${EDARCS_LOCALREPO} ]] && [[ -n ${EDARCS_REPOSITORY} ]] \
172 && EDARCS_LOCALREPO=${EDARCS_REPOSITORY%/} \
173 && EDARCS_LOCALREPO=${EDARCS_LOCALREPO##*/}
120 174
121 debug-print-function $FUNCNAME $* 175 debug-print-function ${FUNCNAME} $*
122 176
123 debug-print "$FUNCNAME: init: 177 debug-print "${FUNCNAME}: init:
124 EDARCS_DARCS_CMD=$EDARCS_DARCS_CMD 178 EDARCS_DARCS_CMD=${EDARCS_DARCS_CMD}
125 EDARCS_GET_CMD=$EDARCS_GET_CMD 179 EDARCS_GET_CMD=${EDARCS_GET_CMD}
126 EDARCS_UPDATE_CMD=$EDARCS_UPDATE_CMD 180 EDARCS_UPDATE_CMD=${EDARCS_UPDATE_CMD}
127 EDARCS_OPTIONS=$EDARCS_OPTIONS 181 EDARCS_OPTIONS=${EDARCS_OPTIONS}
128 EDARCS_TOP_DIR=$EDARCS_TOP_DIR 182 EDARCS_TOP_DIR=${EDARCS_TOP_DIR}
129 EDARCS_REPOSITORY=$EDARCS_REPOSITORY 183 EDARCS_REPOSITORY=${EDARCS_REPOSITORY}
130 EDARCS_LOCALREPO=$EDARCS_LOCALREPO 184 EDARCS_LOCALREPO=${EDARCS_LOCALREPO}
131 EDARCS_CLEAN=$EDARCS_CLEAN" 185 EDARCS_CLEAN=${EDARCS_CLEAN}"
132 186
133 einfo "Fetching darcs repository $EDARCS_REPOSITORY into $EDARCS_TOP_DIR..." 187 einfo "Fetching darcs repository ${EDARCS_REPOSITORY} into ${EDARCS_TOP_DIR}..."
134 darcs_fetch 188 darcs_fetch
135 189
136 einfo "Copying $EDARCS_LOCALREPO from $EDARCS_TOP_DIR..." 190 einfo "Copying ${EDARCS_LOCALREPO} from ${EDARCS_TOP_DIR}..."
137 debug-print "Copying $EDARCS_LOCALREPO from $EDARCS_TOP_DIR..." 191 debug-print "Copying ${EDARCS_LOCALREPO} from ${EDARCS_TOP_DIR}..."
138 192
139 # probably redundant, but best to make sure 193 # probably redundant, but best to make sure
140 # 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.
141 mkdir -p "${WORKDIR}/${P}" 195 mkdir -p "${WORKDIR}/${P}"
142 196
143 EDARCS_SHOPT=$(shopt -p dotglob)
144 shopt -s dotglob # get any dotfiles too. 197 eshopts_push -s dotglob # get any dotfiles too.
145 cp -Rf "$EDARCS_TOP_DIR/$EDARCS_LOCALREPO"/* "${WORKDIR}/${P}" 198 rsync -rlpgo "${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}"/* "${WORKDIR}/${P}"
146 eval ${EDARCS_SHOPT} # reset shopt 199 eshopts_pop
147 200
148 einfo "Darcs repository contents are now in ${WORKDIR}/${P}" 201 einfo "Darcs repository contents are now in ${WORKDIR}/${P}"
149 202
150} 203}
151 204

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

  ViewVC Help
Powered by ViewVC 1.1.20