summaryrefslogtreecommitdiffstats
path: root/bin/ebuild
blob: 45f2442e6d1892f05377f11ad536718c370f06c2 (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
#!/usr/bin/python -O
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-src/portage/bin/ebuild,v 1.18.2.3 2005/05/07 04:32:59 ferringb Exp $

import getopt, os, sys

if len(sys.argv)<=2:
	print "expecting two arguments."
	sys.exit(1)


(opts, pargs) = getopt.getopt(sys.argv[1:], '', ['debug'])
debug = ("--debug",'') in opts


if "merge" in pargs:
	print "Disabling noauto in features... merge disables it. (qmerge doesn't)"
	os.environ["FEATURES"] = os.environ.get("FEATURES", "") + " -noauto"

os.environ["PORTAGE_CALLER"]="ebuild"
sys.path = ["/usr/lib/portage/pym"]+sys.path

import portage, portage_util


root = os.path.normpath(os.environ.get("ROOT", "") + "/")
ebuild = os.path.abspath(pargs.pop(0))

if not os.path.exists(ebuild):
	print "'%s' does not exist." % ebuild
	sys.exit(1)

ebuild_split = ebuild.split("/")
del ebuild_split[-2]
cpv = "/".join(ebuild_split[-2:])[:-7]

portage_ebuild = portage.portdb.findname(cpv)

if not portage_ebuild or os.path.abspath(portage_ebuild) != ebuild:
	os.environ["PORTDIR_OVERLAY"] = "/".join(ebuild_split[:-2])
	print "Adjusting PORTDIR_OVERLAY to '%s'..." % os.environ["PORTDIR_OVERLAY"]
	reload(portage)


if len(pargs) > 1 and "config" in pargs:
	print "config must be called on it's own, not combined with any other phase"
	sys.exit(1)


for arg in pargs:
	try:
		tmpsettings = portage.config(clone=portage.settings)
		a = portage.doebuild(ebuild, arg, root, tmpsettings, debug=debug, cleanup=("noauto" not in portage.features))
	except KeyboardInterrupt:
		print "Interrupted."
		a = 1
	if a == None:
		print "Could not run the required binary?"
		a = 127
	if a:
		sys.exit(a)