summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/fetch2/__init__.py
diff options
context:
space:
mode:
authorMatt Madison <matt@madison.systems>2016-08-10 10:08:16 -0700
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-08-20 16:08:59 +0100
commitab09541d5517da9b1a23923ea8f5c26ddf745084 (patch)
treeb0b81a809ec783b7481c012b430b9f6618e87a73 /bitbake/lib/bb/fetch2/__init__.py
parenteefb4b66c8628fbf366ebc5c23cfe013c8fa3756 (diff)
downloadpoky-ab09541d5517da9b1a23923ea8f5c26ddf745084.tar.gz
bitbake: fetch2: preserve current working directory
Fix the methods in all fetchers so they don't change the current working directory of the calling process, which could lead to "changed cwd" warnings from bitbake. (Bitbake rev: 6aa78bf3bd1f75728209e2d01faef31cb8887333) Signed-off-by: Matt Madison <matt@madison.systems> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/fetch2/__init__.py')
-rw-r--r--bitbake/lib/bb/fetch2/__init__.py21
1 files changed, 11 insertions, 10 deletions
diff --git a/bitbake/lib/bb/fetch2/__init__.py b/bitbake/lib/bb/fetch2/__init__.py
index 9054b2ec18..7a3eb3c5ab 100644
--- a/bitbake/lib/bb/fetch2/__init__.py
+++ b/bitbake/lib/bb/fetch2/__init__.py
@@ -779,7 +779,7 @@ def localpath(url, d):
779 fetcher = bb.fetch2.Fetch([url], d) 779 fetcher = bb.fetch2.Fetch([url], d)
780 return fetcher.localpath(url) 780 return fetcher.localpath(url)
781 781
782def runfetchcmd(cmd, d, quiet=False, cleanup=None, log=None): 782def runfetchcmd(cmd, d, quiet=False, cleanup=None, log=None, workdir=None):
783 """ 783 """
784 Run cmd returning the command output 784 Run cmd returning the command output
785 Raise an error if interrupted or cmd fails 785 Raise an error if interrupted or cmd fails
@@ -821,7 +821,7 @@ def runfetchcmd(cmd, d, quiet=False, cleanup=None, log=None):
821 error_message = "" 821 error_message = ""
822 822
823 try: 823 try:
824 (output, errors) = bb.process.run(cmd, log=log, shell=True, stderr=subprocess.PIPE) 824 (output, errors) = bb.process.run(cmd, log=log, shell=True, stderr=subprocess.PIPE, cwd=workdir)
825 success = True 825 success = True
826 except bb.process.NotFoundError as e: 826 except bb.process.NotFoundError as e:
827 error_message = "Fetch command %s" % (e.command) 827 error_message = "Fetch command %s" % (e.command)
@@ -1436,17 +1436,11 @@ class FetchMethod(object):
1436 if not cmd: 1436 if not cmd:
1437 return 1437 return
1438 1438
1439 # Change to unpackdir before executing command
1440 save_cwd = os.getcwd();
1441 os.chdir(unpackdir)
1442
1443 path = data.getVar('PATH', True) 1439 path = data.getVar('PATH', True)
1444 if path: 1440 if path:
1445 cmd = "PATH=\"%s\" %s" % (path, cmd) 1441 cmd = "PATH=\"%s\" %s" % (path, cmd)
1446 bb.note("Unpacking %s to %s/" % (file, os.getcwd())) 1442 bb.note("Unpacking %s to %s/" % (file, unpackdir))
1447 ret = subprocess.call(cmd, preexec_fn=subprocess_setup, shell=True) 1443 ret = subprocess.call(cmd, preexec_fn=subprocess_setup, shell=True, cwd=unpackdir)
1448
1449 os.chdir(save_cwd)
1450 1444
1451 if ret != 0: 1445 if ret != 0:
1452 raise UnpackError("Unpack command %s failed with return value %s" % (cmd, ret), urldata.url) 1446 raise UnpackError("Unpack command %s failed with return value %s" % (cmd, ret), urldata.url)
@@ -1559,6 +1553,8 @@ class Fetch(object):
1559 network = self.d.getVar("BB_NO_NETWORK", True) 1553 network = self.d.getVar("BB_NO_NETWORK", True)
1560 premirroronly = (self.d.getVar("BB_FETCH_PREMIRRORONLY", True) == "1") 1554 premirroronly = (self.d.getVar("BB_FETCH_PREMIRRORONLY", True) == "1")
1561 1555
1556 save_cwd = os.getcwd()
1557
1562 for u in urls: 1558 for u in urls:
1563 ud = self.ud[u] 1559 ud = self.ud[u]
1564 ud.setup_localpath(self.d) 1560 ud.setup_localpath(self.d)
@@ -1633,6 +1629,7 @@ class Fetch(object):
1633 raise 1629 raise
1634 1630
1635 finally: 1631 finally:
1632 os.chdir(save_cwd)
1636 if ud.lockfile: 1633 if ud.lockfile:
1637 bb.utils.unlockfile(lf) 1634 bb.utils.unlockfile(lf)
1638 1635
@@ -1641,6 +1638,8 @@ class Fetch(object):
1641 Check all urls exist upstream 1638 Check all urls exist upstream
1642 """ 1639 """
1643 1640
1641 save_cwd = os.getcwd()
1642
1644 if not urls: 1643 if not urls:
1645 urls = self.urls 1644 urls = self.urls
1646 1645
@@ -1664,6 +1663,8 @@ class Fetch(object):
1664 if not ret: 1663 if not ret:
1665 raise FetchError("URL %s doesn't work" % u, u) 1664 raise FetchError("URL %s doesn't work" % u, u)
1666 1665
1666 os.chdir(save_cwd)
1667
1667 def unpack(self, root, urls=None): 1668 def unpack(self, root, urls=None):
1668 """ 1669 """
1669 Check all urls exist upstream 1670 Check all urls exist upstream