blob: e6819b9dabd6d088d2056b129c1694a479290d9a [file] [log] [blame]
#!/usr/bin/python -O
# Copyright 1999-2006 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 "Usage: ebuild <ebuild file> <command> [command] ..."
print ""
print "See the ebuild(1) man page for more info"
sys.exit(1)
opts, pargs = getopt.getopt(sys.argv[1:], '', ['debug', 'force'])
debug = ("--debug",'') in opts
force = ("--force",'') 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, portage_const
# do this _after_ 'import portage' to prevent unnecessary tracing
if debug and "python-trace" in portage.features:
import portage_debug
portage_debug.set_trace(True)
if portage.settings["NOCOLOR"] in ("yes","true") or not sys.stdout.isatty():
import output
output.nocolor()
ebuild = os.path.realpath(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]
if not portage.catpkgsplit(cpv):
print "!!! %s does not follow correct package syntax." % (cpv)
sys.exit(1)
if ebuild.startswith(portage.root + portage_const.VDB_PATH):
mytree = "vartree"
portage_ebuild = portage.db[portage.root][mytree].dbapi.findname(cpv)
if os.path.realpath(portage_ebuild) != ebuild:
print "!!! Portage seems to think that %s is at %s" % (cpv, portage_ebuild)
sys.exit(1)
else:
mytree = "porttree"
portage_ebuild = portage.portdb.findname(cpv)
if not portage_ebuild or os.path.realpath(portage_ebuild) != ebuild:
overlay = "/".join(ebuild_split[:-2])
os.environ["PORTDIR_OVERLAY"] = os.environ.get("PORTDIR_OVERLAY","") + " " + overlay
print "Appending %s to PORTDIR_OVERLAY..." % overlay
reload(portage)
portage_ebuild = portage.portdb.findname(cpv)
if not portage_ebuild or os.path.realpath(portage_ebuild) != ebuild:
print "!!! %s does not seem to have a valid PORTDIR structure." % overlay
sys.exit(1)
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)
def discard_digests(myebuild, mysettings, mydbapi):
"""Discard all distfiles digests for the given ebuild. This is useful when
upstream has changed the identity of the distfiles and the user would
otherwise have to manually remove the Manifest and files/digest-* files in
order to ensure correct results."""
pkgdir = os.path.dirname(myebuild)
fetchlist_dict = portage.FetchlistDict(pkgdir, mysettings, mydbapi)
cat, pkg = pkgdir.split(os.sep)[-2:]
cpv = cat + "/" + os.path.basename(myebuild)[:-7]
from portage_manifest import Manifest
mf = Manifest(pkgdir, mysettings["DISTDIR"],
fetchlist_dict=fetchlist_dict)
mf.create(requiredDistfiles=None,
assumeDistHashesSometimes=True, assumeDistHashesAlways=True)
distfiles = fetchlist_dict[cpv]
for myfile in distfiles:
try:
del mf.fhashdict["DIST"][myfile]
except KeyError:
pass
mf.write()
for arg in pargs:
try:
tmpsettings = portage.config(clone=portage.settings)
if arg == "digest" and force:
discard_digests(ebuild, tmpsettings, portage.portdb)
a = portage.doebuild(ebuild, arg, portage.root, tmpsettings, debug=debug, cleanup=("noauto" not in portage.features), tree=mytree)
except KeyboardInterrupt:
print "Interrupted."
a = 1
except KeyError:
# aux_get error
a = 1
if a == None:
print "Could not run the required binary?"
a = 127
if a:
sys.exit(a)