Beispiel #1
0
    def __init__(self, install_dir, *args, **kwargs):
        """Produce a module finder that ignores PYTHONPATH and only
                reports the direct imports of a module.

                run_paths as a keyword argument specifies a list of additional
                paths to use when searching for modules."""

        # ModuleFinder.__init__ doesn't expect run_paths
        run_paths = kwargs.pop("run_paths", [])

        # Check to see whether a python path has been set.
        if python_path in os.environ:
            py_path = [os.path.normpath(fp) for fp in os.environ[python_path].split(os.pathsep)]
        else:
            py_path = []

        # Remove any paths that start with the defined python paths.
        new_path = [fp for fp in sys.path[1:] if not self.startswith_path(fp, py_path)]
        new_path.append(install_dir)

        if run_paths:
            # add our detected runpath into the user-supplied one
            # (if any)
            new_path = base.insert_default_runpath(new_path, run_paths)

        modulefinder.ModuleFinder.__init__(self, path=new_path, *args, **kwargs)
Beispiel #2
0
        def __init__(self, install_dir, *args, **kwargs):
                """Produce a module finder that ignores PYTHONPATH and only
                reports the direct imports of a module.

                run_paths as a keyword argument specifies a list of additional
                paths to use when searching for modules."""

                # ModuleFinder.__init__ doesn't expect run_paths
                run_paths = kwargs.pop("run_paths", [])

                # Check to see whether a python path has been set.
                if python_path in os.environ:
                        py_path = [
                            os.path.normpath(fp)
                            for fp in os.environ[python_path].split(os.pathsep)
                        ]
                else:
                        py_path = []

                # Remove any paths that start with the defined python paths.
                new_path = [
                    fp
                    for fp in sys.path[1:]
                    if not self.startswith_path(fp, py_path)
                ]
                new_path.append(install_dir)

                if run_paths:
                        if __name__ != "__main__":
                                # add our detected runpath into the
                                # user-supplied one (if any)
                                new_path = base.insert_default_runpath(new_path,
                                    run_paths)
                        else:
                                # This is a copy of the above function call.
                                # insert our default search path where the
                                # PD_DEFAULT_RUNPATH token was found
                                try:
                                        index = run_paths.index(
                                            PD_DEFAULT_RUNPATH)
                                        run_paths = run_paths[:index] + \
                                            new_path + run_paths[index + 1:]
                                        if PD_DEFAULT_RUNPATH in run_paths:
                                                raise MultipleDefaultRunPaths()
                                except ValueError:
                                        # no PD_DEFAULT_PATH token, so we
                                        # override the whole default search path
                                        pass
                                new_path = run_paths

                modulefinder.ModuleFinder.__init__(self, path=new_path,
                    *args, **kwargs)
Beispiel #3
0
def process_elf_dependencies(action, pkg_vars, dyn_tok_conv, run_paths,
    **kwargs):
        """Produce the elf dependencies for the file delivered in the action
        provided.

        'action' is the file action to analyze.

        'pkg_vars' is the list of variants against which the package delivering
        the action was published.

        'dyn_tok_conv' is the dictionary which maps the dynamic tokens, like
        $PLATFORM, to the values they should be expanded to.

        'run_paths' contains the run paths which elf binaries should use.
        """

        if not action.name == "file":
                return [], [], {}

        installed_path = action.attrs[action.key_attr]

        proto_file = action.attrs[PD_LOCAL_PATH]

        if not os.path.exists(proto_file):
                raise base.MissingFile(proto_file)

        if not elf.is_elf_object(proto_file):
                return [], [], {}

        try:
                ei = elf.get_info(proto_file)
                ed = elf.get_dynamic(proto_file)
        except elf.ElfError as e:
                raise BadElfFile(proto_file, e)
        deps = [
            d[0]
            for d in ed.get("deps", [])
        ]
        rp = ed.get("runpath", "").split(":")
        if len(rp) == 1 and rp[0] == "":
                rp = []

        dyn_tok_conv["$ORIGIN"] = [os.path.join("/",
            os.path.dirname(installed_path))]

        kernel64 = None

        # For kernel modules, default path resolution is /platform/<platform>,
        # /kernel, /usr/kernel.  But how do we know what <platform> would be for
        # a given module?  Does it do fallbacks to, say, sun4u?
        if installed_path.startswith("kernel") or \
            installed_path.startswith("usr/kernel") or \
            (installed_path.startswith("platform") and \
            installed_path.split("/")[2] == "kernel"):
                if rp and (len(rp) > 1 or
                    not re.match(r'^/usr/gcc/\d/lib$', rp[0])):
                        raise RuntimeError("RUNPATH set for kernel module "
                            "({0}): {1}".format(installed_path, rp))
                # Add this platform to the search path.
                if installed_path.startswith("platform"):
                        rp.append("/platform/{0}/kernel".format(
                            installed_path.split("/")[1]))
                else:
                        for p in dyn_tok_conv.get("$PLATFORM", []):
                                rp.append("/platform/{0}/kernel".format(p))
                # Default kernel search path
                rp.extend(["/kernel", "/usr/kernel"])
                # What subdirectory should we look in for 64-bit kernel modules?
                if ei["bits"] == 64:
                        if ei["arch"] == "i386":
                                kernel64 = "amd64"
                        elif ei["arch"] == "sparc":
                                kernel64 = "sparcv9"
                        else:
                                raise RuntimeError("Unknown arch:{0}".format(
                                    ei["arch"]))
        else:
                for p in default_run_paths:
                        if ei["bits"] == 64:
                                p += "/64"
                        if p not in rp:
                                rp.append(p)

        elist = []
        if run_paths:
                # add our detected runpaths into the user-supplied one (if any)
                rp = base.insert_default_runpath(rp, run_paths)

        rp, errs = expand_variables(rp, dyn_tok_conv)

        elist.extend([
            UnsupportedDynamicToken(proto_file, installed_path, p, tok)
            for p, tok in errs
        ])

        res = []

        for d in deps:
                pn, fn = os.path.split(d)
                pathlist = []
                for p in rp:
                        if kernel64:
                                # Find 64-bit modules the way krtld does.
                                # XXX We don't resolve dependencies found in
                                # /platform, since we don't know where under
                                # /platform to look.
                                deppath = \
                                    os.path.join(p, pn, kernel64, fn).lstrip(
                                    os.path.sep)
                        else:
                                deppath = os.path.join(p, d).lstrip(os.path.sep)
                        # deppath includes filename; remove that.
                        head, tail = os.path.split(deppath)
                        if head:
                                pathlist.append(head)
                res.append(ElfDependency(action, fn, pathlist, pkg_vars,
                    action.attrs[PD_PROTO_DIR]))
        del dyn_tok_conv["$ORIGIN"]
        return res, elist, {}
Beispiel #4
0
                        elif ei["arch"] == "sparc":
                                kernel64 = "sparcv9"
                        else:
                                raise RuntimeError("Unknown arch:%s" %
                                    ei["arch"])
        else:
                for p in default_run_paths:
                        if ei["bits"] == 64:
                                p += "/64"
                        if p not in rp:
                                rp.append(p)

        elist = []
        if run_paths:
                # add our detected runpaths into the user-supplied one (if any)
                rp = base.insert_default_runpath(rp, run_paths)

        rp, errs = expand_variables(rp, dyn_tok_conv)

        elist.extend([
            UnsupportedDynamicToken(proto_file, installed_path, p, tok)
            for p, tok in errs
        ])

        res = []

        for d in deps:
                pn, fn = os.path.split(d)
                pathlist = []
                for p in rp:
                        if kernel64: