2 # Copyright 1999-2006 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4 # $Header: /var/cvsroot/gentoo-src/portage/bin/ebuild,v 1.18.2.3 2005/05/07 04:32:59 ferringb Exp $
7 # This block ensures that ^C interrupts are handled quietly.
11 def exithandler(signum,frame):
12 signal.signal(signal.SIGINT, signal.SIG_IGN)
13 signal.signal(signal.SIGTERM, signal.SIG_IGN)
16 signal.signal(signal.SIGINT, exithandler)
17 signal.signal(signal.SIGTERM, exithandler)
19 except KeyboardInterrupt:
22 def debug_signal(signum, frame):
25 signal.signal(signal.SIGUSR1, debug_signal)
30 description = "See the ebuild(1) man page for more info"
31 usage = "Usage: ebuild <ebuild file> <command> [command] ..."
32 parser = optparse.OptionParser(description=description, usage=usage)
34 force_help = "When used together with the digest or manifest " + \
35 "command, this option forces regeneration of digests for all " + \
36 "distfiles associated with the current ebuild. Any distfiles " + \
37 "that do not already exist in ${DISTDIR} will be automatically fetched."
39 parser.add_option("--force", help=force_help, action="store_true", dest="force")
40 parser.add_option("--debug", help="show debug output",
41 action="store_true", dest="debug")
42 parser.add_option("--ignore-default-opts",
44 help="do not use the EBUILD_DEFAULT_OPTS environment variable")
45 parser.add_option("--skip-manifest", help="skip all manifest checks",
46 action="store_true", dest="skip_manifest")
48 opts, pargs = parser.parse_args(args=sys.argv[1:])
51 parser.error("missing required args")
54 print "Disabling noauto in features... merge disables it. (qmerge doesn't)"
55 os.environ["FEATURES"] = os.environ.get("FEATURES", "") + " -noauto"
57 os.environ["PORTAGE_CALLER"]="ebuild"
61 from os import path as osp
62 sys.path.insert(0, osp.join(osp.dirname(osp.dirname(osp.realpath(__file__))), "pym"))
65 if not opts.ignore_default_opts:
66 default_opts = portage.settings.get("EBUILD_DEFAULT_OPTS", "").split()
67 opts, pargs = parser.parse_args(default_opts + sys.argv[1:])
72 import portage.util, portage.const
74 portage.dep._dep_check_strict = True
76 # do this _after_ 'import portage' to prevent unnecessary tracing
77 if debug and "python-trace" in portage.features:
79 portage.debug.set_trace(True)
81 if portage.settings["NOCOLOR"] in ("yes","true") or not sys.stdout.isatty():
82 portage.output.nocolor()
85 if not os.path.isabs(ebuild):
87 # Try to get the non-canonical path from the PWD evironment variable, since
88 # the canonical path returned from os.getcwd() may may be unusable in
89 # cases where the directory stucture is built from symlinks.
90 if "PWD" in os.environ and os.environ["PWD"] != mycwd and \
91 os.path.realpath(os.environ["PWD"]) == mycwd:
92 mycwd = portage.normalize_path(os.environ["PWD"])
93 ebuild = os.path.join(mycwd, ebuild)
94 ebuild = portage.normalize_path(ebuild)
95 # portdbapi uses the canonical path for the base of the portage tree, but
96 # subdirectories of the base can be built from symlinks (like crossdev does).
97 ebuild_portdir = os.path.realpath(
98 os.path.dirname(os.path.dirname(os.path.dirname(ebuild))))
99 ebuild = os.path.join(ebuild_portdir, *ebuild.split(os.path.sep)[-3:])
101 # Make sure that portdb.findname() returns the correct ebuild.
102 if ebuild_portdir not in portage.portdb.porttrees:
103 os.environ["PORTDIR_OVERLAY"] = \
104 os.environ.get("PORTDIR_OVERLAY","") + " " + ebuild_portdir
105 print "Appending %s to PORTDIR_OVERLAY..." % ebuild_portdir
106 portage.close_portdbapi_caches()
108 del portage.portdb.porttrees[1:]
109 if ebuild_portdir != portage.portdb.porttree_root:
110 portage.portdb.porttrees.append(ebuild_portdir)
112 if not os.path.exists(ebuild):
113 print "'%s' does not exist." % ebuild
116 ebuild_split = ebuild.split("/")
118 cpv = "/".join(ebuild_split[-2:])[:-7]
120 if not portage.catpkgsplit(cpv):
121 print "!!! %s does not follow correct package syntax." % (cpv)
124 if ebuild.startswith(portage.root + portage.const.VDB_PATH):
127 portage_ebuild = portage.db[portage.root][mytree].dbapi.findname(cpv)
129 if os.path.realpath(portage_ebuild) != ebuild:
130 print "!!! Portage seems to think that %s is at %s" % (cpv, portage_ebuild)
136 portage_ebuild = portage.portdb.findname(cpv)
138 if not portage_ebuild or portage_ebuild != ebuild:
139 print "!!! %s does not seem to have a valid PORTDIR structure." % ebuild
142 if len(pargs) > 1 and "config" in pargs:
143 print "config must be called on it's own, not combined with any other phase"
146 def discard_digests(myebuild, mysettings, mydbapi):
147 """Discard all distfiles digests for the given ebuild. This is useful when
148 upstream has changed the identity of the distfiles and the user would
149 otherwise have to manually remove the Manifest and files/digest-* files in
150 order to ensure correct results."""
152 portage._doebuild_manifest_exempt_depend += 1
153 pkgdir = os.path.dirname(myebuild)
154 fetchlist_dict = portage.FetchlistDict(pkgdir, mysettings, mydbapi)
155 cat, pkg = pkgdir.split(os.sep)[-2:]
156 cpv = cat + "/" + os.path.basename(myebuild)[:-7]
157 from portage.manifest import Manifest
158 mf = Manifest(pkgdir, mysettings["DISTDIR"],
159 fetchlist_dict=fetchlist_dict, manifest1_compat=False)
160 mf.create(requiredDistfiles=None,
161 assumeDistHashesSometimes=True, assumeDistHashesAlways=True)
162 distfiles = fetchlist_dict[cpv]
163 for myfile in distfiles:
165 del mf.fhashdict["DIST"][myfile]
170 portage._doebuild_manifest_exempt_depend -= 1
172 tmpsettings = portage.config(clone=portage.settings)
174 # This variable is a signal to config.regenerate() to
175 # indicate that the test phase should be enabled regardless
176 # of problems such as masked "test" USE flag.
177 tmpsettings["EBUILD_FORCE_TEST"] = "1"
178 tmpsettings.backup_changes("EBUILD_FORCE_TEST")
179 if "test" not in tmpsettings.features:
180 tmpsettings.features.append("test")
181 tmpsettings.features.sort()
182 tmpsettings["FEATURES"] = " ".join(tmpsettings.features)
183 tmpsettings.backup_changes("FEATURES")
185 if opts.skip_manifest:
186 tmpsettings["EBUILD_SKIP_MANIFEST"] = "1"
187 tmpsettings.backup_changes("EBUILD_SKIP_MANIFEST")
188 portage._doebuild_manifest_exempt_depend += 1
190 build_dir_phases = set(["setup", "unpack", "configure", "compile",
191 "test", "install", "package", "rpm"])
193 def stale_env_warning():
194 if "clean" not in pargs and \
195 "noauto" not in tmpsettings.features and \
196 tmpsettings.get("PORTAGE_QUIET") != "1" and \
197 build_dir_phases.intersection(pargs):
198 portage.doebuild_environment(ebuild, "setup", portage.root,
199 tmpsettings, debug, 1, portage.portdb)
200 env_filename = os.path.join(tmpsettings["T"], "environment")
201 if os.path.exists(env_filename):
202 msg = ("Existing ${T}/environment for '%s' will be sourced. " + \
203 "Run 'clean' to start with a fresh environment.") % \
204 (tmpsettings["PF"], )
205 from textwrap import wrap
208 portage.writemsg(">>> %s\n" % x)
210 from portage.exception import PermissionDenied, \
211 PortagePackageException, UnsupportedAPIException
212 checked_for_stale_env = False
216 if not checked_for_stale_env and arg not in ("digest","manifest"):
217 # This has to go after manifest generation since otherwise
218 # aux_get() might fail due to invalid ebuild digests.
220 checked_for_stale_env = True
222 if arg in ("digest", "manifest") and force:
223 discard_digests(ebuild, tmpsettings, portage.portdb)
224 a = portage.doebuild(ebuild, arg, portage.root, tmpsettings,
225 debug=debug, tree=mytree)
226 except KeyboardInterrupt:
232 except UnsupportedAPIException, e:
233 from textwrap import wrap
234 msg = wrap(str(e), 70)
237 portage.writemsg("!!! %s\n" % x, noiselevel=-1)
239 except PortagePackageException, e:
240 portage.writemsg("!!! %s\n" % (e,), noiselevel=-1)
242 except PermissionDenied, e:
243 portage.writemsg("!!! Permission Denied: %s\n" % (e,), noiselevel=-1)
246 print "Could not run the required binary?"