Fix cross-prefix bugs, and test.
authorZac Medico <zmedico@gentoo.org>
Wed, 19 Jun 2013 23:41:12 +0000 (16:41 -0700)
committerZac Medico <zmedico@gentoo.org>
Wed, 19 Jun 2013 23:41:12 +0000 (16:41 -0700)
* Fix create_trees to correctly handle the case where ROOT=/ for two
  different EPREFIX offsets.
* For best/has_version, handle the case where ROOT=/ for bug prefixes,
  though each has a different EPREFIX offset.
* Use portage.const.EPREFIX for default EMERGE_LOG_DIR offset, which
  is analogous to existing un-prefixed behavior.
* Use portage.const.EPREFIX for default PORTAGE_CONFIGROOT, which is
  analogous to existing un-prefixed behavior.
* Add cross-prefix cases to emerge tests, including chpathtool for
  binpkgs.

bin/phase-helpers.sh
pym/_emerge/actions.py
pym/portage/__init__.py
pym/portage/package/ebuild/_config/LocationsManager.py
pym/portage/tests/emerge/test_simple.py

index 3d51eb0029d5e478fea0b60648870f6b1a8a7187..ba12f1fbd8da039ff25224fabc52add240fb9400 100644 (file)
@@ -676,7 +676,10 @@ has_version() {
        fi
 
        if ___eapi_has_prefix_variables; then
-               if [[ ${root} == / ]] ; then
+               # [[ ${root} == / ]] would be ambiguous here,
+               # since both prefixes can share root=/ while
+               # having different EPREFIX offsets.
+               if ${host_root} ; then
                        eroot=${root%/}${PORTAGE_OVERRIDE_EPREFIX}/
                else
                        eroot=${root%/}${EPREFIX}/
@@ -732,7 +735,10 @@ best_version() {
        fi
 
        if ___eapi_has_prefix_variables; then
-               if [[ ${root} == / ]] ; then
+               # [[ ${root} == / ]] would be ambiguous here,
+               # since both prefixes can share root=/ while
+               # having different EPREFIX offsets.
+               if ${host_root} ; then
                        eroot=${root%/}${PORTAGE_OVERRIDE_EPREFIX}/
                else
                        eroot=${root%/}${EPREFIX}/
index b331b10c1b9f845b67b9b8aec399ecc95b17589b..c31ad1d86d35021db48473fdfaf5fabb3cec30a1 100644 (file)
@@ -3800,8 +3800,7 @@ def run_action(emerge_config):
                                _emerge.emergelog._emerge_log_dir = emerge_log_dir
                else:
                        _emerge.emergelog._emerge_log_dir = os.path.join(os.sep,
-                               emerge_config.target_config.settings["EPREFIX"].lstrip(os.sep),
-                               "var", "log")
+                               portage.const.EPREFIX.lstrip(os.sep), "var", "log")
                        portage.util.ensure_dirs(_emerge.emergelog._emerge_log_dir)
 
        if not "--pretend" in emerge_config.opts:
index 2510f86b5ce207a62b23ab09c589f4442869a87f..7656c6ebefa4523bd4d3251db388c56690b278d4 100644 (file)
@@ -577,7 +577,7 @@ def create_trees(config_root=None, target_root=None, trees=None, env=None,
 
        trees._target_eroot = settings['EROOT']
        myroots = [(settings['EROOT'], settings)]
-       if settings["ROOT"] == "/":
+       if settings["ROOT"] == "/" and settings["EPREFIX"] == const.EPREFIX:
                trees._running_eroot = trees._target_eroot
        else:
 
@@ -593,7 +593,7 @@ def create_trees(config_root=None, target_root=None, trees=None, env=None,
                        if v is not None:
                                clean_env[k] = v
                settings = config(config_root=None, target_root="/",
-                       env=clean_env, eprefix=eprefix)
+                       env=clean_env, eprefix=None)
                settings.lock()
                trees._running_eroot = settings['EROOT']
                myroots.append((settings['EROOT'], settings))
index 7e799b8407518008a22b52d5dd1d898f63a78f5e..e328441a7fce0b4d8ab1eefdfc310d2757a75d14 100644 (file)
@@ -49,7 +49,7 @@ class LocationsManager(object):
                        self.eprefix = portage.const.EPREFIX
 
                if self.config_root is None:
-                       self.config_root = self.eprefix + os.sep
+                       self.config_root = portage.const.EPREFIX + os.sep
 
                self.config_root = normalize_path(os.path.abspath(
                        self.config_root)).rstrip(os.path.sep) + os.path.sep
index c1abd52bd79f86476fc6fcba5934d6e5aabfa611..dc7ddb75a22be1f504d9e3b04b239398b9552854 100644 (file)
@@ -201,6 +201,8 @@ pkg_preinst() {
                test_ebuild = portdb.findname("dev-libs/A-1")
                self.assertFalse(test_ebuild is None)
 
+               cross_prefix = os.path.join(eprefix, "cross_prefix")
+
                test_commands = (
                        env_update_cmd,
                        portageq_cmd + ("envvar", "-v", "CONFIG_PROTECT", "EROOT",
@@ -266,6 +268,24 @@ pkg_preinst() {
                        emerge_cmd + ("-p", "--unmerge", "-q", eroot + "usr"),
                        emerge_cmd + ("--unmerge", "--quiet", "dev-libs/A"),
                        emerge_cmd + ("-C", "--quiet", "dev-libs/B"),
+
+                       # Test cross-prefix usage, including chpathtool for binpkgs.
+                       ({"EPREFIX" : cross_prefix},) + \
+                               emerge_cmd + ("--usepkgonly", "dev-libs/A"),
+                       ({"EPREFIX" : cross_prefix},) + \
+                               portageq_cmd + ("has_version", cross_prefix, "dev-libs/A"),
+                       ({"EPREFIX" : cross_prefix},) + \
+                               portageq_cmd + ("has_version", cross_prefix, "dev-libs/B"),
+                       ({"EPREFIX" : cross_prefix},) + \
+                               emerge_cmd + ("-C", "--quiet", "dev-libs/B"),
+                       ({"EPREFIX" : cross_prefix},) + \
+                               emerge_cmd + ("-C", "--quiet", "dev-libs/A"),
+                       ({"EPREFIX" : cross_prefix},) + \
+                               emerge_cmd + ("dev-libs/A",),
+                       ({"EPREFIX" : cross_prefix},) + \
+                               portageq_cmd + ("has_version", cross_prefix, "dev-libs/A"),
+                       ({"EPREFIX" : cross_prefix},) + \
+                               portageq_cmd + ("has_version", cross_prefix, "dev-libs/B"),
                )
 
                distdir = playground.distdir