[pacman-dev] [PATCH] pmtest: resolve path to scriptlet shell

Dave Reisner dreisner at archlinux.org
Sun Nov 25 17:12:13 EST 2012

In order to support a variety of values for the --with-scriptlet-shell
configure flag, pmtest has to be aware of what kind of path was passed,
be it an absolute path or a fragment for a path lookup. For absolute
paths, leave the path alone. For fragments, search the PATH environment
var for the resolved path to the binary. In both cases, join the
resultant path to the root directory defined for the test, not a
pre-determined bin directory.

Signed-off-by: Dave Reisner <dreisner at archlinux.org>
This applies to allan's working branch.

 test/pacman/pmtest.py | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/test/pacman/pmtest.py b/test/pacman/pmtest.py
index b69275b..a644860 100644
--- a/test/pacman/pmtest.py
+++ b/test/pacman/pmtest.py
@@ -103,6 +103,17 @@ def load(self):
             raise IOError("file %s does not exist!" % self.name)
+    def resolve_binary(self, binary):
+        if binary[0] == '/':
+            return binary
+        for path in os.environ["PATH"].split(':'):
+            resolved = os.path.join(path, binary)
+            if os.path.exists(resolved):
+                return resolved
+        return binary
     def generate(self, pacman):
         print "==> Generating test environment"
@@ -121,13 +132,16 @@ def generate(self, pacman):
         etcdir = os.path.join(self.root, os.path.dirname(util.PACCONF))
         bindir = os.path.join(self.root, "bin")
         sbindir = os.path.join(self.root, "sbin")
-        sys_dirs = [dbdir, cachedir, syncdir, tmpdir, logdir, etcdir, bindir, sbindir]
+        scriptlet_shell = self.resolve_binary(pacman["scriptlet-shell"])
+        sys_dirs = [dbdir, cachedir, syncdir, tmpdir, logdir, etcdir, bindir,
+                    sbindir, os.path.dirname(scriptlet_shell)]
         for sys_dir in sys_dirs:
             if not os.path.isdir(sys_dir):
                 vprint("\t%s" % sys_dir[len(self.root)+1:])
                 os.makedirs(sys_dir, 0755)
         # Only the dynamically linked binary is needed for fakechroot
-        shutil.copy("/bin/sh", os.path.join(sbindir, pacman["scriptlet-shell"]))
+        if not os.path.samefile("/bin/sh", os.path.join(self.root, scriptlet_shell)):
+            shutil.copy("/bin/sh", os.path.join(self.root, scriptlet_shell))
         shutil.copy(os.path.join(util.SELFPATH, "ldconfig.stub"),
             os.path.join(sbindir, "ldconfig"))
         ld_so_conf = open(os.path.join(etcdir, "ld.so.conf"), "w")

More information about the pacman-dev mailing list