doebuild_environment: sanity check for bug 408817
authorZac Medico <zmedico@gentoo.org>
Mon, 19 Mar 2012 17:00:38 +0000 (10:00 -0700)
committerZac Medico <zmedico@gentoo.org>
Mon, 19 Mar 2012 17:00:38 +0000 (10:00 -0700)
Ensure that CATEGORY is determined correctly, and raise AssertionError
if it can't be determined.

pym/portage/package/ebuild/doebuild.py

index 31ecf8cdd0cf7b7af4842ba3f775a3b88e757275..56de55441f06d581686e9a503bb5be9c6d529962 100644 (file)
@@ -174,20 +174,24 @@ def doebuild_environment(myebuild, mydo, myroot=None, settings=None,
        ebuild_path = os.path.abspath(myebuild)
        pkg_dir     = os.path.dirname(ebuild_path)
        mytree = os.path.dirname(os.path.dirname(pkg_dir))
-
-       if "CATEGORY" in mysettings.configdict["pkg"]:
-               cat = mysettings.configdict["pkg"]["CATEGORY"]
-       else:
-               cat = os.path.basename(normalize_path(os.path.join(pkg_dir, "..")))
-
        mypv = os.path.basename(ebuild_path)[:-7]
-
-       mycpv = cat+"/"+mypv
        mysplit = _pkgsplit(mypv)
        if mysplit is None:
                raise IncorrectParameter(
                        _("Invalid ebuild path: '%s'") % myebuild)
 
+       if mysettings.mycpv is not None and \
+               mysettings.configdict["pkg"].get("PF") == mypv and \
+               "CATEGORY" in mysettings.configdict["pkg"]:
+               cat = mysettings.configdict["pkg"]["CATEGORY"]
+               mycpv = mysettings.mycpv
+       elif os.path.basename(pkg_dir) in (mysplit[0], mypv):
+               # portdbapi or vardbapi
+               cat = os.path.basename(os.path.dirname(pkg_dir))
+               mycpv = cat + "/" + mypv
+       else:
+               raise AssertionError("unable to determine CATEGORY")
+
        # Make a backup of PORTAGE_TMPDIR prior to calling config.reset()
        # so that the caller can override it.
        tmpdir = mysettings["PORTAGE_TMPDIR"]