diff options
author | Chris Larson <chris_larson@mentor.com> | 2010-03-17 08:05:40 -0700 |
---|---|---|
committer | Chris Larson <chris_larson@mentor.com> | 2010-04-23 14:20:41 -0700 |
commit | 5c8bfd6873939024d57278343035cfab0257bdb3 (patch) | |
tree | 6c4fcea025d8f27da70cf0e06513384e4705a09c /classes/base.bbclass | |
parent | 241a98e1771cdf4037b4534be67dcdba01e066d5 (diff) |
do_unpack: shift some responsibility around, clean things up
- Move the unpacking message printing into do_unpack
- Move the destination directory determination into do_unpack
- Use subprocess's ability to pass in PATH and cwd rather than mangling the cmd
- Use shutil.copy2/copytree for ordinary file "unpack"
- Use the existing urldata from bb.fetch.init rather than re-decodeurl'ing the urls
- Only display the unpack destdir to the user when debugging is enabled, as we
all know they unpack into WORKDIR
Signed-off-by: Chris Larson <chris_larson@mentor.com>
Diffstat (limited to 'classes/base.bbclass')
-rw-r--r-- | classes/base.bbclass | 104 |
1 files changed, 42 insertions, 62 deletions
diff --git a/classes/base.bbclass b/classes/base.bbclass index b8499b9db8..c43f2b2b35 100644 --- a/classes/base.bbclass +++ b/classes/base.bbclass @@ -152,92 +152,72 @@ def oe_unpack_file(file, data, url = None): 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) + base, ext = os.path.splitext(file) + cmd = 'gzip -dc %s > %s' % (file, base) elif file.endswith('.bz2'): - cmd = 'bzip2 -dc %s > %s' % (file, efile) + base, ext = os.path.splitext(file) + cmd = 'bzip2 -dc %s > %s' % (file, base) 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) + base, ext = os.path.splitext(file) + cmd = 'xz -dc %s > %s' % (file, base) elif file.endswith('.zip') or file.endswith('.jar'): cmd = 'unzip -q -o' - (type, host, path, user, pswd, parm) = bb.decodeurl(url) - if 'dos' in parm: + if 'dos' in options: cmd = '%s -a' % cmd cmd = "%s '%s'" % (cmd, file) 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) + shutil.rmtree(dest, True) + shutil.copytree(file, dest, True) else: - (type, host, path, user, pswd, parm) = bb.decodeurl(url) - if not 'patch' in parm: - # The "destdir" handling was specifically done for FILESPATH - # items. So, only do so for file:// entries. - if type == "file": - destdir = bb.decodeurl(url)[1] or "." - else: - destdir = "." - bb.mkdirhier("%s/%s" % (os.getcwd(), destdir)) - cmd = 'cp %s %s/%s/' % (file, os.getcwd(), destdir) + if not "patch" in options: + shutil.copy2(file, dest) if not cmd: return True - dest = os.path.join(os.getcwd(), os.path.basename(file)) - if os.path.exists(dest): - if os.path.samefile(file, dest): - return True - - # Change to subdir before executing command - save_cwd = os.getcwd(); - parm = bb.decodeurl(url)[5] - 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) + ret = subprocess.call(cmd, preexec_fn=subprocess_setup, shell=True, + cwd=destdir, env=options.get("env")) return ret == 0 addtask unpack after do_fetch do_unpack[dirs] = "${WORKDIR}" python base_do_unpack() { - import re + workdir = d.getVar("WORKDIR", True) + urldatadict = bb.fetch.init(d.getVar("SRC_URI", True).split(), d, True) - localdata = bb.data.createCopy(d) - bb.data.update_data(localdata) + env = { + "PATH": d.getVar("PATH", True), + } + for url, urldata in urldatadict.iteritems(): + if not urldata.setup: + urldata.setup_localpath(d) - src_uri = bb.data.getVar('SRC_URI', localdata) - if not src_uri: - return - src_uri = bb.data.expand(src_uri, localdata) - 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) + local = urldata.localpath 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() + + if bb.msg.debug_level['default']: + bb.note("Unpacking %s to %s/" % (base_path_out(local, d), + base_path_out(destdir))) + else: + bb.note("Unpacking %s" % base_path_out(local, d)) + + subdirs = [] + if "subdir" in urldata.parm: + subdirs.append(urldata.parm["subdir"]) + if urldata.type == "file": + if urldata.host: + subdirs.append(urldata.host) + + if subdirs: + destdir = os.path.join(workdir, *subdirs) + bb.mkdirhier(destdir) + else: + destdir = workdir + oe_unpack_file(local, destdir, env=env, **urldata.parm) } addhandler base_eventhandler |