示例#1
0
文件: repo.py 项目: 3v1n0/snapcraft
def _skip_link(target):
    global _skip_list
    if not _skip_list:
        output = common.run_output(['dpkg', '-L', 'libc6']).split()
        _skip_list = [i for i in output if 'lib' in i]

    return target in _skip_list
示例#2
0
def run_script(script, **kwargs):
    """Run the script and return the output."""
    with tempfile.NamedTemporaryFile("w+") as tempf:
        print("#!/bin/sh", file=tempf)
        print(script, file=tempf)
        tempf.flush()
        return common.run_output(["/bin/sh", tempf.name], **kwargs)
示例#3
0
def which(command, **kwargs):
    """Returns the result of `which` run with the correct environment."""
    with tempfile.NamedTemporaryFile('w+') as tempf:
        tempf.write('#!/bin/sh\n')
        tempf.write('which {}'.format(command))
        tempf.flush()
        return common.run_output(['/bin/sh', tempf.name], **kwargs)
示例#4
0
 def run_output(self, cmd, cwd=None, **kwargs):
     if cwd is None:
         cwd = self.builddir
     if True:
         print(" ".join(cmd))
     os.makedirs(cwd, exist_ok=True)
     return common.run_output(cmd, cwd=cwd, **kwargs)
示例#5
0
def _get_jhbuild_user():
    """Discover the User ID of the jhbuild user"""
    uid = os.getuid()
    if uid != 0:
        return uid

    try:
        uid = common.run_output(['id', '-u', 'jhbuild'])
    except subprocess.CalledProcessError:
        uid = 0
    return uid
示例#6
0
文件: elf.py 项目: mvo5/snapcraft
    def load_dependencies(
        self, root_path: str, core_base_path: str, soname_cache: SonameCache = None
    ) -> Set[str]:
        """Load the set of libraries that are needed to satisfy elf's runtime.

        This may include libraries contained within the project.
        The object's .dependencies attribute is set after loading.

        :param str root_path: the root path to search for missing dependencies.
        :param str core_base_path: the core base path to search for missing
                                   dependencies.
        :param SonameCache soname_cache: a cache of previously search
                                         dependencies.
        :returns: a set of string with paths to the library dependencies of
                  elf.
        """
        if soname_cache is None:
            soname_cache = SonameCache()

        logger.debug("Getting dependencies for {!r}".format(self.path))
        ldd_out = []  # type: List[str]
        try:
            # ldd output sample:
            # /lib64/ld-linux-x86-64.so.2 (0x00007fb3c5298000)
            # libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fb3bef03000)
            ldd_out = common.run_output(["ldd", self.path]).split("\n")
        except subprocess.CalledProcessError:
            logger.warning(
                "Unable to determine library dependencies for {!r}".format(self.path)
            )
            return set()
        ldd_out_split = [l.split() for l in ldd_out]
        libs = set()
        for ldd_line in ldd_out_split:
            if len(ldd_line) > 2:
                libs.add(
                    Library(
                        soname=ldd_line[0],
                        path=ldd_line[2],
                        root_path=root_path,
                        core_base_path=core_base_path,
                        arch=self.arch,
                        soname_cache=soname_cache,
                    )
                )

        self.dependencies = libs

        # Return a set useful only for fetching libraries from the host
        library_paths = set()  # type: Set[str]
        for l in libs:
            if os.path.exists(l.path) and not l.in_base_snap and not l.system_lib:
                library_paths.add(l.path)
        return library_paths
示例#7
0
def _get_jhbuild_group():
    """Discover the Group ID of the jhbuild user
    This is required because we add the user ourselves with a
    non-deterministic ID
    :return: The group ID
    :rtype: int"""
    uid = os.getuid()
    gid = os.getgid()
    if uid != 0:
        return gid or 65534

    try:
        gid = common.run_output(['id', '-g', 'jhbuild'])
    except subprocess.CalledProcessError:
        gid = os.getgid()

    return gid or 65534
示例#8
0
    def load_dependencies(self, root_path: str,
                          core_base_path: str) -> Set[str]:
        """Load the set of libraries that are needed to satisfy elf's runtime.

        This may include libraries contained within the project.
        The object's .dependencies attribute is set after loading.

        :param str root_path: the base path to search for missing dependencies.
        :returns: a set of string with paths to the library dependencies of
                  elf.
        """
        logger.debug('Getting dependencies for {!r}'.format(self.path))
        ldd_out = []  # type: List[str]
        try:
            # ldd output sample:
            # /lib64/ld-linux-x86-64.so.2 (0x00007fb3c5298000)
            # libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fb3bef03000)
            ldd_out = common.run_output(['ldd', self.path]).split('\n')
        except subprocess.CalledProcessError:
            logger.warning('Unable to determine library dependencies for '
                           '{!r}'.format(self.path))
            return set()
        ldd_out_split = [l.split() for l in ldd_out]
        libs = set()
        for ldd_line in ldd_out_split:
            if len(ldd_line) > 2:
                libs.add(
                    Library(soname=ldd_line[0],
                            path=ldd_line[2],
                            root_path=root_path,
                            core_base_path=core_base_path))

        self.dependencies = libs

        # Return a set useful only for fetching libraries from the host
        library_paths = set()  # type: Set[str]
        for l in libs:
            if (os.path.exists(l.path) and not l.in_base_snap
                    and not l.system_lib):
                library_paths.add(l.path)
        return library_paths
示例#9
0
def get_dependencies(elf):
    """Return a list of libraries that are needed to satisfy elf's runtime.

    This may include libraries contained within the project.
    """
    logger.debug('Getting dependencies for {!r}'.format(elf))
    ldd_out = ''
    try:
        ldd_out = common.run_output(['ldd', elf]).split('\n')
    except subprocess.CalledProcessError:
        logger.warning(
            'Unable to determine library dependencies for {!r}'.format(elf))
        return []
    ldd_out = [l.split() for l in ldd_out]
    ldd_out = [l[2] for l in ldd_out if len(l) > 2 and os.path.exists(l[2])]

    # Now lets filter out what would be on the system
    system_libs = _get_system_libs()
    libs = [l for l in ldd_out if not os.path.basename(l) in system_libs]

    return libs
示例#10
0
def get_dependencies(elf):
    """Return a list of libraries that are needed to satisfy elf's runtime.

    This may include libraries contained within the project.
    """
    logger.debug('Getting dependencies for {!r}'.format(elf))
    ldd_out = ''
    try:
        ldd_out = common.run_output(['ldd', elf]).split('\n')
    except subprocess.CalledProcessError:
        logger.warning(
            'Unable to determine library dependencies for {!r}'.format(elf))
        return []
    ldd_out = [l.split() for l in ldd_out]
    ldd_out = [l[2] for l in ldd_out if len(l) > 2 and os.path.exists(l[2])]

    # Now lets filter out what would be on the system
    system_libs = _get_system_libs()
    libs = [l for l in ldd_out if not os.path.basename(l) in system_libs]

    return libs
示例#11
0
def get_dependencies(elf):
    """Return a list of libraries that are needed to satisfy elf's runtime.

    This may include libraries contained within the project.
    """
    logger.debug('Getting dependencies for {!r}'.format(str(elf)))
    ldd_out = ''
    try:
        ldd_out = common.run_output(['ldd', elf]).split('\n')
    except subprocess.CalledProcessError:
        logger.warning(
            'Unable to determine library dependencies for {!r}'.format(elf))
        return []
    ldd_out = [l.split() for l in ldd_out]
    ldd_out = [l[2] for l in ldd_out if len(l) > 2 and os.path.exists(l[2])]

    # Now lets filter out what would be on the system
    system_libs = _get_system_libs()
    libs = [l for l in ldd_out if not os.path.basename(l) in system_libs]
    # Classic confinement won't do what you want with library crawling
    # and has a nasty side effect described in LP: #1670100
    libs = [l for l in libs if not l.startswith('/snap/')]

    return libs
示例#12
0
def get_dependencies(elf):
    """Return a list of libraries that are needed to satisfy elf's runtime.

    This may include libraries contained within the project.
    """
    logger.debug('Getting dependencies for {!r}'.format(str(elf)))
    ldd_out = ''
    try:
        ldd_out = common.run_output(['ldd', elf]).split('\n')
    except subprocess.CalledProcessError:
        logger.warning(
            'Unable to determine library dependencies for {!r}'.format(elf))
        return []
    ldd_out = [l.split() for l in ldd_out]
    ldd_out = [l[2] for l in ldd_out if len(l) > 2 and os.path.exists(l[2])]

    # Now lets filter out what would be on the system
    system_libs = _get_system_libs()
    libs = [l for l in ldd_out if not os.path.basename(l) in system_libs]
    # Classic confinement won't do what you want with library crawling
    # and has a nasty side effect described in LP: #1670100
    libs = [l for l in libs if not l.startswith('/snap/')]

    return libs
示例#13
0
 def _get_machine_manifest(self):
     return {
         'uname': common.run_output(['uname', '-srvmpio']),
         'installed-packages': repo.Repo.get_installed_packages(),
         'installed-snaps': repo.snaps.get_installed_snaps()
     }
示例#14
0
 def run_output(self, cmd, cwd=None, **kwargs):
     if not cwd:
         cwd = self.builddir
     os.makedirs(cwd, exist_ok=True)
     return common.run_output(cmd, cwd=cwd, **kwargs)
示例#15
0
 def run_output(self, cmd, cwd=None, **kwargs):
     if not cwd:
         cwd = self.builddir
     os.makedirs(cwd, exist_ok=True)
     return common.run_output(cmd, cwd=cwd, **kwargs)
示例#16
0
 def _get_machine_manifest(self):
     return {
         'uname': common.run_output(['uname', '-srvmpio']),
         'installed-packages': repo.Repo.get_installed_packages(),
         'installed-snaps': repo.snaps.get_installed_snaps()
     }