| 1 |
# Copyright 2004 Gentoo Technologies, Inc.
|
| 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 $
|
| 4 |
#
|
| 5 |
# darcs eclass author: Andres Loeh <kosmikus@gentoo.org>
|
| 6 |
# tla eclass author: <rphillips@gentoo.org>
|
| 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 |
|
| 17 |
# Most of the time, you will define only $EDARCS_REPOSITORY in your
|
| 18 |
# ebuild.
|
| 19 |
|
| 20 |
# TODO: support for tags, ...
|
| 21 |
|
| 22 |
# Don't download anything other than the darcs repository
|
| 23 |
SRC_URI=""
|
| 24 |
|
| 25 |
# You shouldn't change these settings yourself! The ebuild/eclass inheriting
|
| 26 |
# this eclass will take care of that.
|
| 27 |
|
| 28 |
# --- begin ebuild-configurable settings
|
| 29 |
|
| 30 |
# darcs command to run
|
| 31 |
[ -z "$EDARCS_DARCS_CMD" ] && EDARCS_DARCS_CMD="darcs"
|
| 32 |
|
| 33 |
# 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 |
|
| 37 |
# options to pass to both the "get" and "update" commands
|
| 38 |
[ -z "$EDARCS_OPTIONS" ] && EDARCS_OPTIONS="--set-scripts-executable"
|
| 39 |
|
| 40 |
# Where the darcs repositories are stored/accessed
|
| 41 |
[ -z "$EDARCS_TOP_DIR" ] && EDARCS_TOP_DIR="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/darcs-src"
|
| 42 |
|
| 43 |
# The URI to the repository.
|
| 44 |
[ -z "$EDARCS_REPOSITORY" ] && EDARCS_REPOSITORY=""
|
| 45 |
|
| 46 |
# The local directory to store the repository (useful to ensure a
|
| 47 |
# unique local name); relative to EDARCS_TOP_DIR
|
| 48 |
[ -z "$EDARCS_LOCALREPO" ] && [ -n "$EDARCS_REPOSITORY" ] \
|
| 49 |
&& EDARCS_LOCALREPO=${EDARCS_REPOSITORY%/} \
|
| 50 |
&& EDARCS_LOCALREPO=${EDARCS_LOCALREPO##*/}
|
| 51 |
|
| 52 |
# EDARCS_CLEAN: set this to something to get a clean copy when updating
|
| 53 |
# (removes the working directory, then uses $EDARCS_GET_CMD to
|
| 54 |
# re-download it.)
|
| 55 |
|
| 56 |
# --- end ebuild-configurable settings ---
|
| 57 |
|
| 58 |
# add darcs to deps
|
| 59 |
DEPEND="dev-util/darcs"
|
| 60 |
|
| 61 |
# is called from darcs_src_unpack
|
| 62 |
darcs_fetch() {
|
| 63 |
|
| 64 |
debug-print-function $FUNCNAME $*
|
| 65 |
|
| 66 |
if [ -n "$EDARCS_CLEAN" ]; then
|
| 67 |
rm -rf $EDARCS_TOP_DIR/$EDARCS_LOCALREPO
|
| 68 |
fi
|
| 69 |
|
| 70 |
# create the top dir if needed
|
| 71 |
if [ ! -d "$EDARCS_TOP_DIR" ]; then
|
| 72 |
# 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
|
| 74 |
# 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
|
| 76 |
# the last path element in the string)
|
| 77 |
debug-print "$FUNCNAME: checkout mode. creating darcs directory"
|
| 78 |
addwrite /foobar
|
| 79 |
addwrite /
|
| 80 |
mkdir -p "$EDARCS_TOP_DIR"
|
| 81 |
export SANDBOX_WRITE="${SANDBOX_WRITE//:\/foobar:\/}"
|
| 82 |
fi
|
| 83 |
|
| 84 |
# in case EDARCS_DARCS_DIR is a symlink to a dir, get the real
|
| 85 |
# dir's path, otherwise addwrite() doesn't work.
|
| 86 |
pushd .
|
| 87 |
cd -P "$EDARCS_TOP_DIR" > /dev/null
|
| 88 |
EDARCS_TOP_DIR="`/bin/pwd`"
|
| 89 |
|
| 90 |
# disable the sandbox for this dir
|
| 91 |
addwrite "$EDARCS_TOP_DIR"
|
| 92 |
|
| 93 |
# determine checkout or update mode and change to the right directory.
|
| 94 |
if [ ! -d "$EDARCS_TOP_DIR/$EDARCS_LOCALREPO/_darcs" ]; then
|
| 95 |
mode=get
|
| 96 |
cd "$EDARCS_TOP_DIR"
|
| 97 |
else
|
| 98 |
mode=update
|
| 99 |
cd "$EDARCS_TOP_DIR/$EDARCS_LOCALREPO"
|
| 100 |
fi
|
| 101 |
|
| 102 |
# commands to run
|
| 103 |
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}"
|
| 105 |
|
| 106 |
if [ "${mode}" == "get" ]; then
|
| 107 |
einfo "Running $cmdget"
|
| 108 |
eval $cmdget || die "darcs get command failed"
|
| 109 |
elif [ "${mode}" == "update" ]; then
|
| 110 |
einfo "Running $cmdupdate"
|
| 111 |
eval $cmdupdate || die "darcs update command failed"
|
| 112 |
fi
|
| 113 |
|
| 114 |
popd
|
| 115 |
}
|
| 116 |
|
| 117 |
|
| 118 |
darcs_src_unpack() {
|
| 119 |
local EDARCS_SHOPT
|
| 120 |
|
| 121 |
debug-print-function $FUNCNAME $*
|
| 122 |
|
| 123 |
debug-print "$FUNCNAME: init:
|
| 124 |
EDARCS_DARCS_CMD=$EDARCS_DARCS_CMD
|
| 125 |
EDARCS_GET_CMD=$EDARCS_GET_CMD
|
| 126 |
EDARCS_UPDATE_CMD=$EDARCS_UPDATE_CMD
|
| 127 |
EDARCS_OPTIONS=$EDARCS_OPTIONS
|
| 128 |
EDARCS_TOP_DIR=$EDARCS_TOP_DIR
|
| 129 |
EDARCS_REPOSITORY=$EDARCS_REPOSITORY
|
| 130 |
EDARCS_LOCALREPO=$EDARCS_LOCALREPO
|
| 131 |
EDARCS_CLEAN=$EDARCS_CLEAN"
|
| 132 |
|
| 133 |
einfo "Fetching darcs repository $EDARCS_REPOSITORY into $EDARCS_TOP_DIR..."
|
| 134 |
darcs_fetch
|
| 135 |
|
| 136 |
einfo "Copying $EDARCS_LOCALREPO from $EDARCS_TOP_DIR..."
|
| 137 |
debug-print "Copying $EDARCS_LOCALREPO from $EDARCS_TOP_DIR..."
|
| 138 |
|
| 139 |
# probably redundant, but best to make sure
|
| 140 |
# Use ${WORKDIR}/${P} rather than ${S} so user can point ${S} to something inside.
|
| 141 |
mkdir -p "${WORKDIR}/${P}"
|
| 142 |
|
| 143 |
EDARCS_SHOPT=$(shopt -p dotglob)
|
| 144 |
shopt -s dotglob # get any dotfiles too.
|
| 145 |
rsync -rlpgo --exclude="_darcs/" "$EDARCS_TOP_DIR/$EDARCS_LOCALREPO"/* "${WORKDIR}/${P}"
|
| 146 |
eval ${EDARCS_SHOPT} # reset shopt
|
| 147 |
|
| 148 |
einfo "Darcs repository contents are now in ${WORKDIR}/${P}"
|
| 149 |
|
| 150 |
}
|
| 151 |
|
| 152 |
EXPORT_FUNCTIONS src_unpack
|