summaryrefslogtreecommitdiff
blob: 606897a85dd460672a0634eff9426a737ba8fdbc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# Copyright 2003 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/eclass/tla.eclass,v 1.1 2003/11/21 17:39:58 rphillips Exp $
#
# Original Author:    Jeffrey Yasskin <jyasskin@mail.utexas.edu>
#
# Originally derived from the cvs eclass.
#
# This eclass provides the generic tla fetching functions.
# to use from an ebuild, set the 'ebuild-configurable settings' below in your
# ebuild before inheriting.  then either leave the default src_unpack or extend
# over tla_src_unpack.

# Most of the time, you will define only $ETLA_VERSION and $ETLA_ARCHIVES in
# your ebuild.

# TODO:
# Make it support particular revisions.

ECLASS=tla
INHERITED="$INHERITED $ECLASS"

# Don't download anything other than the tla archive
SRC_URI=""

# You shouldn't change these settings yourself! The ebuild/eclass inheriting
# this eclass will take care of that. 

# --- begin ebuild-configurable settings

# tla command to run. Theoretically, substituting any arch derivative should be
# relatively easy.
[ -z "$ETLA_TLA_CMD" ] && ETLA_TLA_CMD="tla"

# tla commands with options
[ -z "$ETLA_GET_CMD" ] && ETLA_GET_CMD="get"
[ -z "$ETLA_UPDATE_CMD" ] && ETLA_UPDATE_CMD="replay"

# Where the tla modules are stored/accessed
[ -z "$ETLA_TOP_DIR" ] && ETLA_TOP_DIR="${DISTDIR}/tla-src"

# Name of tla version in the format
#  user@example.com--archive-name/category--branch--version
# (in other words, an argument to tla get, update, or replay)
[ -z "$ETLA_VERSION" ] && ETLA_VERSION=""

# A space-separated list of significant archive URLs. You should definitely
# include the URL for the archive your version is stored in, and if it refers
# to any other archives, also list them.
[ -z "$ETLA_ARCHIVES" ] && ETLA_ARCHIVES=""

# The location in which to cache the version, relative to $ETLA_TOP_DIR.
[ -z "$ETLA_CACHE_DIR" ] && ETLA_CACHE_DIR="${ETLA_VERSION}"

# ETLA_CLEAN: set this to something to get a clean copy when updating (removes
# the working directory, then uses $ETLA_GET_CMD to re-download it.)

# --- end ebuild-configurable settings ---

# add tla to deps
newdepend "dev-util/tla"

# registers archives mentioned in $ETLA_ARCHIVES
tla_register_archives() {
	debug-print-function $FUNCNAME $* $ETLA_ARCHIVES

	for archive in $ETLA_ARCHIVES; do
		$ETLA_TLA_CMD register-archive $archive || die "Could not register archive $archive"
	done
}

# checks that configuration variables have rational values.
tla_check_vars() {
	[ -z "$ETLA_VERSION" ] && die "ETLA_VERSION must be set by the ebuild. Please fix this ebuild."
	$ETLA_TLA_CMD valid-package-name --archive --vsn $ETLA_VERSION || \
		die "ETLA_VERSION has an invalid format. Please fix this ebuild."
}

# is called from tla_src_unpack
tla_fetch() {

	debug-print-function $FUNCNAME $*

	if [ -n "$ETLA_CLEAN" ]; then
		rm -rf $ETLA_TOP_DIR/$ETLA_CACHE_DIR
	fi

	# create the top dir if needed
	if [ ! -d "$ETLA_TOP_DIR" ]; then
		# note that the addwrite statements in this block are only there to allow creating ETLA_TOP_DIR;
		# we've already allowed writing inside it
		# this is because it's simpler than trying to find out the parent path of the directory, which
		# would need to be the real path and not a symlink for things to work (so we can't just remove
		# the last path element in the string)
		debug-print "$FUNCNAME: checkout mode. creating tla directory"
		addwrite /foobar
		addwrite /
		mkdir -p "$ETLA_TOP_DIR"
		export SANDBOX_WRITE="${SANDBOX_WRITE//:\/foobar:\/}"
	fi

	# in case ETLA_TOP_DIR is a symlink to a dir, get the real dir's path,
	# otherwise addwrite() doesn't work.
	cd -P "$ETLA_TOP_DIR" > /dev/null
	ETLA_TOP_DIR="`/bin/pwd`"

	# disable the sandbox for this dir
	addwrite "$ETLA_TOP_DIR"

	# break $ETLA_VERSION into pieces
	local tla_archive=`$ETLA_TLA_CMD parse-package-name --arch $ETLA_VERSION`
	local tla_version=`$ETLA_TLA_CMD parse-package-name --package-version $ETLA_VERSION`
	#local tla_revision=`$ETLA_TLA_CMD parse-package-name --lvl $ETLA_VERSION`
	
	# determine checkout or update mode and change to the right directory.
	if [ ! -d "$ETLA_TOP_DIR/$ETLA_CACHE_DIR/{arch}" ]; then
		mode=get
		mkdir -p "$ETLA_TOP_DIR/$ETLA_CACHE_DIR"
		cd "$ETLA_TOP_DIR/$ETLA_CACHE_DIR/.."
		rmdir "`basename "$ETLA_CACHE_DIR"`"
	else
		mode=update
		cd "$ETLA_TOP_DIR/$ETLA_CACHE_DIR"
	fi

	# switch versions automagically if needed
	if [ "$mode" == "update" ]; then
		local oldversion="`$ETLA_TLA_CMD tree-version`"
		if [ "$tla_archive/$tla_version" != "$oldversion" ]; then

			einfo "Changing TLA version from $oldversion to $tla_archive/$tla_version:"
			debug-print "$FUNCNAME: Changing TLA version from $oldversion to $tla_archive/$tla_version:"

			$ETLA_TLA_CMD set-tree-version $tla_archive/$tla_version

		fi
	fi

	# commands to run
	local cmdget="${ETLA_TLA_CMD} ${ETLA_GET_CMD} ${ETLA_VERSION} `basename $ETLA_CACHE_DIR`"
	local cmdupdate="${ETLA_TLA_CMD} ${ETLA_UPDATE_CMD} ${ETLA_VERSION}"

	if [ "${mode}" == "get" ]; then
		einfo "Running $cmdget" 
		eval $cmdget || die "tla get command failed"
	elif [ "${mode}" == "update" ]; then
		einfo "Running $cmdupdate"
		eval $cmdupdate || die "tla update command failed"
	fi

}


tla_src_unpack() {

	debug-print-function $FUNCNAME $*

	debug-print "$FUNCNAME: init:
	ETLA_TLA_CMD=$ETLA_TLA_CMD
	ETLA_GET_CMD=$ETLA_GET_CMD
	ETLA_UPDATE_CMD=$ETLA_UPDATE_CMD
	ETLA_TOP_DIR=$ETLA_TOP_DIR
	ETLA_VERSION=$ETLA_VERSION
	ETLA_ARCHIVES=$ETLA_ARCHIVES
	ETLA_CACHE_DIR=$ETLA_CACHE_DIR
	ETLA_CLEAN=$ETLA_CLEAN"

	einfo "Registering Archives..."
	tla_register_archives

	einfo "Checking that passed-in variables are rational..."
	tla_check_vars

	einfo "Fetching tla version $ETLA_VERSION into $ETLA_TOP_DIR..."
	tla_fetch
	
	einfo "Copying $ETLA_CACHE_DIR from $ETLA_TOP_DIR..."
	debug-print "Copying $ETLA_CACHE_DIR from $ETLA_TOP_DIR..."

	# probably redundant, but best to make sure
	# Use ${WORKDIR}/${P} rather than ${S} so user can point ${S} to something inside.
	mkdir -p "${WORKDIR}/${P}"

	shopt -s dotglob	# get any dotfiles too.
	cp -Rf "$ETLA_TOP_DIR/$ETLA_CACHE_DIR"/* "${WORKDIR}/${P}"

	# implement some of base_src_unpack's functionality;
	# note however that base.eclass may not have been inherited!
	#if [ -n "$PATCHES" ]; then
	#	debug-print "$FUNCNAME: PATCHES=$PATCHES, S=$S, autopatching"
	#	cd "$S"
	#	for x in $PATCHES; do
	#		debug-print "patching from $x"
	#		patch -p0 < "$x"
	#	done
	#	# make sure we don't try to apply patches more than once, since
	#	# tla_src_unpack may be called several times
	#	export PATCHES=""
	#fi
	
	einfo "Version ${ETLA_VERSION} is now in ${WORKDIR}/${P}"

}

EXPORT_FUNCTIONS src_unpack