From 906285ff00d6ffd3fd7713af52250e7c6503edb7 Mon Sep 17 00:00:00 2001 From: Mark Hatle Date: Mon, 7 Feb 2011 18:18:18 -0600 Subject: fetch2: Add SRPM knowledge Enable the fetcher to be able to unpack and SRPM. By default the system will unpack the contents of the SRPM into the WORKDIR. A new syntax "unpack=file" was developed for the SRC_URI, to allow for a recipe to extract a specific file within an SRPM. An unpack operation will then be executed on the extracted file. In order to apply extracted patches (or unpack files not specified with unpack), you must specify the path using WORKDIR, i.e.: file://${WORKDIR}/mypatch.patch Signed-off-by: Mark Hatle --- bitbake/lib/bb/fetch2/__init__.py | 62 ++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 24 deletions(-) (limited to 'bitbake/lib') diff --git a/bitbake/lib/bb/fetch2/__init__.py b/bitbake/lib/bb/fetch2/__init__.py index ee3476bcc8..9a4acc2ede 100644 --- a/bitbake/lib/bb/fetch2/__init__.py +++ b/bitbake/lib/bb/fetch2/__init__.py @@ -628,6 +628,7 @@ class FetchMethod(object): def unpack(self, urldata, rootdir, data): import subprocess + iterate = False file = urldata.localpath dots = file.split(".") if dots[-1] in ['gz', 'bz2', 'Z']: @@ -635,6 +636,7 @@ class FetchMethod(object): else: efile = file cmd = None + if file.endswith('.tar'): cmd = 'tar x --no-same-owner -f %s' % file elif file.endswith('.tgz') or file.endswith('.tar.gz') or file.endswith('.tar.Z'): @@ -654,36 +656,43 @@ class FetchMethod(object): if 'dos' in urldata.parm: cmd = '%s -a' % cmd cmd = "%s '%s'" % (cmd, file) - elif os.path.isdir(file): - filesdir = os.path.realpath(bb.data.getVar("FILESDIR", data, True)) - destdir = "." - if file[0:len(filesdir)] == filesdir: - destdir = file[len(filesdir):file.rfind('/')] - destdir = destdir.strip('/') - if len(destdir) < 1: - destdir = "." - elif not os.access("%s/%s" % (rootdir, destdir), os.F_OK): - os.makedirs("%s/%s" % (rootdir, destdir)) - cmd = 'cp -pPR %s %s/%s/' % (file, rootdir, destdir) + elif file.endswith('.src.rpm') or file.endswith('.srpm'): + if 'unpack' in urldata.parm: + unpack_file = ("%s" % urldata.parm['unpack']) + cmd = 'rpm2cpio.sh %s | cpio -i %s' % (file, unpack_file) + iterate = True + iterate_file = unpack_file + else: + cmd = 'rpm2cpio.sh %s | cpio -i' % (file) else: - if not 'patch' in urldata.parm: - # The "destdir" handling was specifically done for FILESPATH - # items. So, only do so for file:// entries. - if urldata.type == "file" and urldata.path.find("/") != -1: - destdir = urldata.path.rsplit("/", 1)[0] - else: + # If file == dest, then avoid any copies, as we already put the file into dest! + dest = os.path.join(rootdir, os.path.basename(file)) + if (file != dest) and not (os.path.exists(dest) and os.path.samefile(file, dest)): + if os.path.isdir(file): + filesdir = os.path.realpath(bb.data.getVar("FILESDIR", data, True)) destdir = "." - bb.mkdirhier("%s/%s" % (rootdir, destdir)) - cmd = 'cp %s %s/%s/' % (file, rootdir, destdir) + if file[0:len(filesdir)] == filesdir: + destdir = file[len(filesdir):file.rfind('/')] + destdir = destdir.strip('/') + if len(destdir) < 1: + destdir = "." + elif not os.access("%s/%s" % (rootdir, destdir), os.F_OK): + os.makedirs("%s/%s" % (rootdir, destdir)) + cmd = 'cp -pPR %s %s/%s/' % (file, rootdir, destdir) + else: + if not 'patch' in urldata.parm: + # The "destdir" handling was specifically done for FILESPATH + # items. So, only do so for file:// entries. + if urldata.type == "file" and urldata.path.find("/") != -1: + destdir = urldata.path.rsplit("/", 1)[0] + else: + destdir = "." + bb.mkdirhier("%s/%s" % (rootdir, destdir)) + cmd = 'cp %s %s/%s/' % (file, rootdir, destdir) if not cmd: return - dest = os.path.join(rootdir, os.path.basename(file)) - if os.path.exists(dest): - if os.path.samefile(file, dest): - return - # Change to subdir before executing command save_cwd = os.getcwd(); os.chdir(rootdir) @@ -701,6 +710,11 @@ class FetchMethod(object): if ret != 0: raise UnpackError("Unpack command %s failed with return value %s" % (cmd, ret), urldata.url) + if iterate is True: + iterate_urldata = urldata + iterate_urldata.localpath = "%s/%s" % (rootdir, iterate_file) + self.unpack(urldata, rootdir, data) + return def try_premirror(self, url, urldata, d): -- cgit v1.2.3