aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Larson <clarson@mvista.com>2010-01-19 19:00:41 +0000
committerHolger Hans Peter Freyther <zecke@selfish.org>2010-01-28 14:21:30 +0100
commita4238313d07c1e756e22975f9559077dfd9c491d (patch)
treeff68d65e9a9eb07614c8cff548081cf38ff7e9ba
parentdbdc8df2841f66796e4882407b0d4b8e1e346518 (diff)
downloadopenembedded-a4238313d07c1e756e22975f9559077dfd9c491d.tar.gz
base.bbclass: add popen/system convenience functions
Provides oe_popen, which is a subprocess.Popen wrapper that automatically provides our exported variables in the environment, including the PATH, and oe_system, which is just a wrapper that acts like system. Signed-off-by: Chris Larson <clarson@mvista.com>
-rw-r--r--classes/base.bbclass37
1 files changed, 31 insertions, 6 deletions
diff --git a/classes/base.bbclass b/classes/base.bbclass
index d26ef47600..4cf983dc4e 100644
--- a/classes/base.bbclass
+++ b/classes/base.bbclass
@@ -1,5 +1,36 @@
BB_DEFAULT_TASK ?= "build"
+python () {
+ env = {}
+ for v in d.keys():
+ if d.getVarFlag(v, "export"):
+ env[v] = d.getVar(v, True) or ""
+ d.setVar("__oe_popen_env", env)
+}
+
+def subprocess_setup():
+ import signal
+ # Python installs a SIGPIPE handler by default. This is usually not what
+ # non-Python subprocesses expect.
+ signal.signal(signal.SIGPIPE, signal.SIG_DFL)
+
+def oe_popen(d, cmd, **kwargs):
+ """ Convenience function to call out processes with our exported
+ variables in the environment.
+ """
+ from subprocess import Popen
+
+ if kwargs.get("env") is None:
+ kwargs["env"] = d.getVar("__oe_popen_env", 0)
+
+ kwargs["preexec_fn"] = subprocess_setup
+
+ return Popen(cmd, **kwargs)
+
+def oe_system(d, cmd):
+ """ Popen based version of os.system. """
+ return oe_popen(d, cmd, shell=True).wait()
+
# like os.path.join but doesn't treat absolute RHS specially
def base_path_join(a, *p):
path = a
@@ -771,12 +802,6 @@ base_do_buildall() {
:
}
-def subprocess_setup():
- import signal
- # Python installs a SIGPIPE handler by default. This is usually not what
- # non-Python subprocesses expect.
- signal.signal(signal.SIGPIPE, signal.SIG_DFL)
-
def oe_unpack_file(file, data, url = None):
import subprocess
if not url: