Exemple #1
0
    def _unpackdep(self, ud, pkg, data, destdir, dldir, d):
        file = data[pkg]['tgz']
        logger.debug(2, "file to extract is %s" % file)
        if file.endswith('.tgz') or file.endswith('.tar.gz') or file.endswith(
                '.tar.Z'):
            cmd = 'tar xz --strip 1 --no-same-owner --warning=no-unknown-keyword -f %s/%s' % (
                dldir, file)
        else:
            bb.fatal("NPM package %s downloaded not a tarball!" % file)

        # Change to subdir before executing command
        if not os.path.exists(destdir):
            os.makedirs(destdir)
        path = d.getVar('PATH')
        if path:
            cmd = "PATH=\"%s\" %s" % (path, cmd)
        bb.note("Unpacking %s to %s/" % (file, destdir))
        ret = subprocess.call(cmd,
                              preexec_fn=subprocess_setup,
                              shell=True,
                              cwd=destdir)

        if ret != 0:
            raise UnpackError(
                "Unpack command %s failed with return value %s" % (cmd, ret),
                ud.url)

        if 'deps' not in data[pkg]:
            return
        for dep in data[pkg]['deps']:
            self._unpackdep(ud, dep, data[pkg]['deps'],
                            "%s/node_modules/%s" % (destdir, dep), dldir, d)
Exemple #2
0
    def _crate_unpack_old_layout(self, ud, rootdir, d):
        """
        Unpacks a crate in the old location that tried to emulate
        the Cargo registry layout.
        """
        thefile = ud.localpath

        cargo_src = self._cargo_src_path(rootdir)
        cargo_cache = self._cargo_cache_path(rootdir)

        cmd = "tar -xz --no-same-owner -f %s -C %s" % (thefile, cargo_src)

        # ensure we've got these paths made
        bb.utils.mkdirhier(cargo_cache)
        bb.utils.mkdirhier(cargo_src)

        bb.note("Copying %s to %s/" % (thefile, cargo_cache))
        shutil.copy(thefile, cargo_cache)

        # path it
        path = d.getVar('PATH', True)
        if path:
            cmd = "PATH=\"%s\" %s" % (path, cmd)
        bb.note("Unpacking %s to %s/" % (thefile, os.getcwd()))

        ret = subprocess.call(cmd, preexec_fn=subprocess_setup, shell=True)

        if ret != 0:
            raise UnpackError(
                "Unpack command %s failed with return value %s" % (cmd, ret),
                ud.url)
Exemple #3
0
    def _index_unpack(self, ud, rootdir, d):
        """
        Unpacks the index
        """
        thefile = ud.localpath

        cargo_index = self._cargo_index_path(rootdir)

        cmd = "tar -xz --no-same-owner --strip-components 1 -f %s -C %s" % (
            thefile, cargo_index)

        # change to the rootdir to unpack but save the old working dir
        save_cwd = os.getcwd()
        os.chdir(rootdir)

        # ensure we've got these paths made
        bb.utils.mkdirhier(cargo_index)

        # path it
        path = d.getVar('PATH', True)
        if path:
            cmd = "PATH=\"%s\" %s" % (path, cmd)
        bb.note("Unpacking %s to %s/" % (thefile, cargo_index))

        ret = subprocess.call(cmd, preexec_fn=subprocess_setup, shell=True)

        os.chdir(save_cwd)

        if ret != 0:
            raise UnpackError(
                "Unpack command %s failed with return value %s" % (cmd, ret),
                ud.url)
Exemple #4
0
    def _crate_unpack(self, ud, rootdir, d):
        """
        Unpacks a crate
        """
        thefile = ud.localpath

        # possible metadata we need to write out
        metadata = {}

        # change to the rootdir to unpack but save the old working dir
        save_cwd = os.getcwd()
        os.chdir(rootdir)

        pn = d.getVar('BPN', True)
        if pn == ud.parm.get('name'):
            cmd = "tar -xz --no-same-owner -f %s" % thefile
        else:
            self._crate_unpack_old_layout(ud, rootdir, d)

            cargo_bitbake = self._cargo_bitbake_path(rootdir)

            cmd = "tar -xz --no-same-owner -f %s -C %s" % (thefile,
                                                           cargo_bitbake)

            # ensure we've got these paths made
            bb.utils.mkdirhier(cargo_bitbake)

            # generate metadata necessary
            with open(thefile, 'rb') as f:
                # get the SHA256 of the original tarball
                tarhash = hashlib.sha256(f.read()).hexdigest()

            metadata['files'] = {}
            metadata['package'] = tarhash

        # path it
        path = d.getVar('PATH', True)
        if path:
            cmd = "PATH=\"%s\" %s" % (path, cmd)
        bb.note("Unpacking %s to %s/" % (thefile, os.getcwd()))

        ret = subprocess.call(cmd, preexec_fn=subprocess_setup, shell=True)

        os.chdir(save_cwd)

        if ret != 0:
            raise UnpackError(
                "Unpack command %s failed with return value %s" % (cmd, ret),
                ud.url)

        # if we have metadata to write out..
        if len(metadata) > 0:
            cratepath = os.path.splitext(os.path.basename(thefile))[0]
            bbpath = self._cargo_bitbake_path(rootdir)
            mdfile = '.cargo-checksum.json'
            mdpath = os.path.join(bbpath, cratepath, mdfile)
            with open(mdpath, "w") as f:
                json.dump(metadata, f)
Exemple #5
0
    def _crate_unpack(self, ud, rootdir, d):
        """
        Unpacks a crate
        """
        thefile = ud.localpath

        # change to the rootdir to unpack but save the old working dir
        save_cwd = os.getcwd()
        os.chdir(rootdir)

        pn = d.getVar('PN', True)
        if pn == ud.parm.get('name'):
            cmd = "tar -xz --no-same-owner -f %s" % thefile
        else:
            cargo_src = self._cargo_src_path(rootdir)
            cargo_cache = self._cargo_cache_path(rootdir)
            cargo_registry = self._cargo_registry_path(rootdir)

            cmd = "tar -xz --no-same-owner -f %s -C %s" % (thefile, cargo_src)

            # ensure we've got these paths made
            bb.utils.mkdirhier(cargo_cache)
            bb.utils.mkdirhier(cargo_registry)
            bb.utils.mkdirhier(cargo_src)

            bb.note("Copying %s to %s/" % (thefile, cargo_cache))
            shutil.copy(thefile, cargo_cache)

            bb.note("Copying %s to %s/" % (thefile, cargo_registry))
            shutil.copy(thefile, cargo_registry)

        # path it
        path = d.getVar('PATH', True)
        if path:
            cmd = "PATH=\"%s\" %s" % (path, cmd)
        bb.note("Unpacking %s to %s/" % (thefile, os.getcwd()))

        ret = subprocess.call(cmd, preexec_fn=subprocess_setup, shell=True)

        os.chdir(save_cwd)

        if ret != 0:
            raise UnpackError(
                "Unpack command %s failed with return value %s" % (cmd, ret),
                ud.url)