diff options
Diffstat (limited to 'classes/base.bbclass')
-rw-r--r-- | classes/base.bbclass | 159 |
1 files changed, 55 insertions, 104 deletions
diff --git a/classes/base.bbclass b/classes/base.bbclass index 438327c95c..299e875191 100644 --- a/classes/base.bbclass +++ b/classes/base.bbclass @@ -163,117 +163,68 @@ python base_do_fetch() { raise bb.build.FuncFailed("Checksum of '%s' failed" % uri) } -def oe_unpack_file(file, data, url = None): - import subprocess - if not url: - url = "file://%s" % file - dots = file.split(".") - if dots[-1] in ['gz', 'bz2', 'Z']: - efile = os.path.join(bb.data.getVar('WORKDIR', data, 1),os.path.basename('.'.join(dots[0:-1]))) - else: - efile = file - cmd = None - (type, host, path, user, pswd, parm) = bb.decodeurl(url) - 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'): - cmd = 'tar xz --no-same-owner -f %s' % file - elif file.endswith('.tbz') or file.endswith('.tbz2') or file.endswith('.tar.bz2'): - cmd = 'bzip2 -dc %s | tar x --no-same-owner -f -' % file - elif file.endswith('.gz') or file.endswith('.Z') or file.endswith('.z'): - cmd = 'gzip -dc %s > %s' % (file, efile) - elif file.endswith('.bz2'): - cmd = 'bzip2 -dc %s > %s' % (file, efile) - elif file.endswith('.tar.xz'): - cmd = 'xz -dc %s | tar x --no-same-owner -f -' % file - elif file.endswith('.xz'): - cmd = 'xz -dc %s > %s' % (file, efile) - elif file.endswith('.zip') or file.endswith('.jar'): - cmd = 'unzip -q -o' - if 'dos' in parm: - cmd = '%s -a' % cmd - cmd = "%s '%s'" % (cmd, file) - elif (type == "file" and file.endswith('.patch') or file.endswith('.diff')) and parm.get('apply') != 'no': - # patch and diff files are special and need not be copied to workdir - cmd = "" - elif os.path.isdir(file): - destdir = "." - filespath = bb.data.getVar("FILESPATH", data, 1).split(":") - for fp in filespath: - if file[0:len(fp)] == fp: - destdir = file[len(fp):file.rfind('/')] - destdir = destdir.strip('/') - if len(destdir) < 1: - destdir = "." - elif not os.access("%s/%s" % (os.getcwd(), destdir), os.F_OK): - os.makedirs("%s/%s" % (os.getcwd(), destdir)) - break - - cmd = 'cp -pPR %s %s/%s/' % (file, os.getcwd(), destdir) - else: - if not 'patch' in parm and parm.get('apply') != 'yes': - # The "destdir" handling was specifically done for FILESPATH - # items. So, only do so for file:// entries. - if type == "file": - if not host: - dest = os.path.dirname(path) or "." - else: - # this case is for backward compatiblity with older version - # of bitbake which do not have the fix - # http://cgit.openembedded.org/cgit.cgi/bitbake/commit/?id=ca257adc587bb0937ea76d8b32b654fdbf4192b8 - # this should not be needed once all releases of bitbake has this fix - # applied/backported - dest = host + os.path.dirname(path) or "." - else: - dest = "." - bb.mkdirhier("%s" % oe.path.join(os.getcwd(),dest)) - cmd = 'cp %s %s' % (file, oe.path.join(os.getcwd(), dest)) - if not cmd: - return True - if not host: - dest = oe.path.join(os.getcwd(), path) - else: - dest = oe.path.join(os.getcwd(), oe.path.join(host, path)) - if os.path.exists(dest): - if os.path.samefile(file, dest): - return True - # Change to subdir before executing command - save_cwd = os.getcwd(); - if 'subdir' in parm: - newdir = ("%s/%s" % (os.getcwd(), parm['subdir'])) - bb.mkdirhier(newdir) - os.chdir(newdir) - - cmd = "PATH=\"%s\" %s" % (bb.data.getVar('PATH', data, 1), cmd) - bb.note("Unpacking %s to %s/" % (base_path_out(file, data), base_path_out(os.getcwd(), data))) - ret = subprocess.call(cmd, preexec_fn=subprocess_setup, shell=True) - - os.chdir(save_cwd) +def oe_unpack(d, local, urldata): + from oe.unpack import unpack_file, is_patch, UnpackError + if is_patch(local, urldata.parm): + return - return ret == 0 + subdirs = [] + if "subdir" in urldata.parm: + subdirs.append(urldata.parm["subdir"]) + + if urldata.type == "file": + if not urldata.host: + urlpath = urldata.path + else: + urlpath = oe.path.join(urldata.host, urldata.path) + + if not os.path.isabs(urlpath): + subdirs.append(os.path.dirname(urlpath)) + + workdir = d.getVar("WORKDIR", True) + if subdirs: + destdir = oe.path.join(workdir, *subdirs) + bb.mkdirhier(destdir) + else: + destdir = workdir + dos = urldata.parm.get("dos") + + bb.note("Unpacking %s to %s/" % (base_path_out(local, d), + base_path_out(destdir, d))) + try: + unpack_file(local, destdir, env={"PATH": d.getVar("PATH", True)}, dos=dos) + except UnpackError, exc: + bb.fatal(str(exc)) addtask unpack after do_fetch do_unpack[dirs] = "${WORKDIR}" python base_do_unpack() { - import re + from glob import glob + + srcurldata = bb.fetch.init(d.getVar("SRC_URI", True).split(), d, True) + filespath = d.getVar("FILESPATH", True).split(":") + + for url, urldata in srcurldata.iteritems(): + if urldata.type == "file" and "*" in urldata.path: + # The fetch code doesn't know how to handle globs, so + # we need to handle the local bits ourselves + for path in filespath: + srcdir = oe.path.join(path, urldata.host, + os.path.dirname(urldata.path)) + if os.path.exists(srcdir): + break + else: + bb.fatal("Unable to locate files for %s" % url) - localdata = bb.data.createCopy(d) - bb.data.update_data(localdata) + for filename in glob(oe.path.join(srcdir, + os.path.basename(urldata.path))): + oe_unpack(d, filename, urldata) + else: + local = urldata.localpath + if not local: + raise bb.build.FuncFailed('Unable to locate local file for %s' % url) - src_uri = bb.data.getVar('SRC_URI', localdata, True) - if not src_uri: - return - for url in src_uri.split(): - try: - local = bb.data.expand(bb.fetch.localpath(url, localdata), localdata) - except bb.MalformedUrl, e: - raise bb.build.FuncFailed('Unable to generate local path for malformed uri: %s' % e) - if not local: - raise bb.build.FuncFailed('Unable to locate local file for %s' % url) - local = os.path.realpath(local) - ret = oe_unpack_file(local, localdata, url) - if not ret: - raise bb.build.FuncFailed() + oe_unpack(d, local, urldata) } addhandler base_eventhandler |