Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2 | # Copyright (c) 2013-2014 Intel Corporation |
| 3 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6 | |
| 7 | # DESCRIPTION |
| 8 | # This module is mainly used by scripts/oe-selftest and modules under meta/oeqa/selftest |
| 9 | # It provides a class and methods for running commands on the host in a convienent way for tests. |
| 10 | |
| 11 | |
| 12 | |
| 13 | import os |
| 14 | import sys |
| 15 | import signal |
| 16 | import subprocess |
| 17 | import threading |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 18 | import time |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 19 | import logging |
| 20 | from oeqa.utils import CommandError |
| 21 | from oeqa.utils import ftools |
| 22 | import re |
| 23 | import contextlib |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 24 | # Export test doesn't require bb |
| 25 | try: |
| 26 | import bb |
| 27 | except ImportError: |
| 28 | pass |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 29 | |
| 30 | class Command(object): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 31 | def __init__(self, command, bg=False, timeout=None, data=None, output_log=None, **options): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 32 | |
| 33 | self.defaultopts = { |
| 34 | "stdout": subprocess.PIPE, |
| 35 | "stderr": subprocess.STDOUT, |
| 36 | "stdin": None, |
| 37 | "shell": False, |
| 38 | "bufsize": -1, |
| 39 | } |
| 40 | |
| 41 | self.cmd = command |
| 42 | self.bg = bg |
| 43 | self.timeout = timeout |
| 44 | self.data = data |
| 45 | |
| 46 | self.options = dict(self.defaultopts) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 47 | if isinstance(self.cmd, str): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 48 | self.options["shell"] = True |
| 49 | if self.data: |
| 50 | self.options['stdin'] = subprocess.PIPE |
| 51 | self.options.update(options) |
| 52 | |
| 53 | self.status = None |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 54 | # We collect chunks of output before joining them at the end. |
| 55 | self._output_chunks = [] |
| 56 | self._error_chunks = [] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 57 | self.output = None |
| 58 | self.error = None |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 59 | self.threads = [] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 60 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 61 | self.output_log = output_log |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 62 | self.log = logging.getLogger("utils.commands") |
| 63 | |
| 64 | def run(self): |
| 65 | self.process = subprocess.Popen(self.cmd, **self.options) |
| 66 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 67 | def readThread(output, stream, logfunc): |
| 68 | if logfunc: |
| 69 | for line in stream: |
| 70 | output.append(line) |
| 71 | logfunc(line.decode("utf-8", errors='replace').rstrip()) |
| 72 | else: |
| 73 | output.append(stream.read()) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 74 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 75 | def readStderrThread(): |
| 76 | readThread(self._error_chunks, self.process.stderr, self.output_log.error if self.output_log else None) |
| 77 | |
| 78 | def readStdoutThread(): |
| 79 | readThread(self._output_chunks, self.process.stdout, self.output_log.info if self.output_log else None) |
| 80 | |
| 81 | def writeThread(): |
| 82 | try: |
| 83 | self.process.stdin.write(self.data) |
| 84 | self.process.stdin.close() |
| 85 | except OSError as ex: |
| 86 | # It's not an error when the command does not consume all |
| 87 | # of our data. subprocess.communicate() also ignores that. |
| 88 | if ex.errno != EPIPE: |
| 89 | raise |
| 90 | |
| 91 | # We write in a separate thread because then we can read |
| 92 | # without worrying about deadlocks. The additional thread is |
| 93 | # expected to terminate by itself and we mark it as a daemon, |
| 94 | # so even it should happen to not terminate for whatever |
| 95 | # reason, the main process will still exit, which will then |
| 96 | # kill the write thread. |
| 97 | if self.data: |
| 98 | threading.Thread(target=writeThread, daemon=True).start() |
| 99 | if self.process.stderr: |
| 100 | thread = threading.Thread(target=readStderrThread) |
| 101 | thread.start() |
| 102 | self.threads.append(thread) |
| 103 | if self.output_log: |
| 104 | self.output_log.info('Running: %s' % self.cmd) |
| 105 | thread = threading.Thread(target=readStdoutThread) |
| 106 | thread.start() |
| 107 | self.threads.append(thread) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 108 | |
| 109 | self.log.debug("Running command '%s'" % self.cmd) |
| 110 | |
| 111 | if not self.bg: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 112 | if self.timeout is None: |
| 113 | for thread in self.threads: |
| 114 | thread.join() |
| 115 | else: |
| 116 | deadline = time.time() + self.timeout |
| 117 | for thread in self.threads: |
| 118 | timeout = deadline - time.time() |
| 119 | if timeout < 0: |
| 120 | timeout = 0 |
| 121 | thread.join(timeout) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 122 | self.stop() |
| 123 | |
| 124 | def stop(self): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 125 | for thread in self.threads: |
| 126 | if thread.isAlive(): |
| 127 | self.process.terminate() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 128 | # let's give it more time to terminate gracefully before killing it |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 129 | thread.join(5) |
| 130 | if thread.isAlive(): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 131 | self.process.kill() |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 132 | thread.join() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 133 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 134 | def finalize_output(data): |
| 135 | if not data: |
| 136 | data = "" |
| 137 | else: |
| 138 | data = b"".join(data) |
| 139 | data = data.decode("utf-8", errors='replace').rstrip() |
| 140 | return data |
| 141 | |
| 142 | self.output = finalize_output(self._output_chunks) |
| 143 | self._output_chunks = None |
| 144 | # self.error used to be a byte string earlier, probably unintentionally. |
| 145 | # Now it is a normal string, just like self.output. |
| 146 | self.error = finalize_output(self._error_chunks) |
| 147 | self._error_chunks = None |
| 148 | # At this point we know that the process has closed stdout/stderr, so |
| 149 | # it is safe and necessary to wait for the actual process completion. |
| 150 | self.status = self.process.wait() |
Brad Bishop | f86d055 | 2018-12-04 14:18:15 -0800 | [diff] [blame] | 151 | self.process.stdout.close() |
| 152 | if self.process.stderr: |
| 153 | self.process.stderr.close() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 154 | |
| 155 | self.log.debug("Command '%s' returned %d as exit code." % (self.cmd, self.status)) |
| 156 | # logging the complete output is insane |
| 157 | # bitbake -e output is really big |
| 158 | # and makes the log file useless |
| 159 | if self.status: |
| 160 | lout = "\n".join(self.output.splitlines()[-20:]) |
| 161 | self.log.debug("Last 20 lines:\n%s" % lout) |
| 162 | |
| 163 | |
| 164 | class Result(object): |
| 165 | pass |
| 166 | |
| 167 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 168 | def runCmd(command, ignore_status=False, timeout=None, assert_error=True, |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 169 | native_sysroot=None, limit_exc_output=0, output_log=None, **options): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 170 | result = Result() |
| 171 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 172 | if native_sysroot: |
| 173 | extra_paths = "%s/sbin:%s/usr/sbin:%s/usr/bin" % \ |
| 174 | (native_sysroot, native_sysroot, native_sysroot) |
| 175 | nenv = dict(options.get('env', os.environ)) |
| 176 | nenv['PATH'] = extra_paths + ':' + nenv.get('PATH', '') |
| 177 | options['env'] = nenv |
| 178 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 179 | cmd = Command(command, timeout=timeout, output_log=output_log, **options) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 180 | cmd.run() |
| 181 | |
| 182 | result.command = command |
| 183 | result.status = cmd.status |
| 184 | result.output = cmd.output |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 185 | result.error = cmd.error |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 186 | result.pid = cmd.process.pid |
| 187 | |
| 188 | if result.status and not ignore_status: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 189 | exc_output = result.output |
| 190 | if limit_exc_output > 0: |
| 191 | split = result.output.splitlines() |
| 192 | if len(split) > limit_exc_output: |
| 193 | exc_output = "\n... (last %d lines of output)\n" % limit_exc_output + \ |
| 194 | '\n'.join(split[-limit_exc_output:]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 195 | if assert_error: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 196 | raise AssertionError("Command '%s' returned non-zero exit status %d:\n%s" % (command, result.status, exc_output)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 197 | else: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 198 | raise CommandError(result.status, command, exc_output) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 199 | |
| 200 | return result |
| 201 | |
| 202 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 203 | def bitbake(command, ignore_status=False, timeout=None, postconfig=None, output_log=None, **options): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 204 | |
| 205 | if postconfig: |
| 206 | postconfig_file = os.path.join(os.environ.get('BUILDDIR'), 'oeqa-post.conf') |
| 207 | ftools.write_file(postconfig_file, postconfig) |
| 208 | extra_args = "-R %s" % postconfig_file |
| 209 | else: |
| 210 | extra_args = "" |
| 211 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 212 | if isinstance(command, str): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 213 | cmd = "bitbake " + extra_args + " " + command |
| 214 | else: |
| 215 | cmd = [ "bitbake" ] + [a for a in (command + extra_args.split(" ")) if a not in [""]] |
| 216 | |
| 217 | try: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 218 | return runCmd(cmd, ignore_status, timeout, output_log=output_log, **options) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 219 | finally: |
| 220 | if postconfig: |
| 221 | os.remove(postconfig_file) |
| 222 | |
| 223 | |
| 224 | def get_bb_env(target=None, postconfig=None): |
| 225 | if target: |
| 226 | return bitbake("-e %s" % target, postconfig=postconfig).output |
| 227 | else: |
| 228 | return bitbake("-e", postconfig=postconfig).output |
| 229 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 230 | def get_bb_vars(variables=None, target=None, postconfig=None): |
| 231 | """Get values of multiple bitbake variables""" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 232 | bbenv = get_bb_env(target, postconfig=postconfig) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 233 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 234 | if variables is not None: |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 235 | variables = list(variables) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 236 | var_re = re.compile(r'^(export )?(?P<var>\w+(_.*)?)="(?P<value>.*)"$') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 237 | unset_re = re.compile(r'^unset (?P<var>\w+)$') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 238 | lastline = None |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 239 | values = {} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 240 | for line in bbenv.splitlines(): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 241 | match = var_re.match(line) |
| 242 | val = None |
| 243 | if match: |
| 244 | val = match.group('value') |
| 245 | else: |
| 246 | match = unset_re.match(line) |
| 247 | if match: |
| 248 | # Handle [unexport] variables |
| 249 | if lastline.startswith('# "'): |
| 250 | val = lastline.split('"')[1] |
| 251 | if val: |
| 252 | var = match.group('var') |
| 253 | if variables is None: |
| 254 | values[var] = val |
| 255 | else: |
| 256 | if var in variables: |
| 257 | values[var] = val |
| 258 | variables.remove(var) |
| 259 | # Stop after all required variables have been found |
| 260 | if not variables: |
| 261 | break |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 262 | lastline = line |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 263 | if variables: |
| 264 | # Fill in missing values |
| 265 | for var in variables: |
| 266 | values[var] = None |
| 267 | return values |
| 268 | |
| 269 | def get_bb_var(var, target=None, postconfig=None): |
| 270 | return get_bb_vars([var], target, postconfig)[var] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 271 | |
| 272 | def get_test_layer(): |
| 273 | layers = get_bb_var("BBLAYERS").split() |
| 274 | testlayer = None |
| 275 | for l in layers: |
| 276 | if '~' in l: |
| 277 | l = os.path.expanduser(l) |
| 278 | if "/meta-selftest" in l and os.path.isdir(l): |
| 279 | testlayer = l |
| 280 | break |
| 281 | return testlayer |
| 282 | |
| 283 | def create_temp_layer(templayerdir, templayername, priority=999, recipepathspec='recipes-*/*'): |
| 284 | os.makedirs(os.path.join(templayerdir, 'conf')) |
| 285 | with open(os.path.join(templayerdir, 'conf', 'layer.conf'), 'w') as f: |
| 286 | f.write('BBPATH .= ":${LAYERDIR}"\n') |
| 287 | f.write('BBFILES += "${LAYERDIR}/%s/*.bb \\' % recipepathspec) |
| 288 | f.write(' ${LAYERDIR}/%s/*.bbappend"\n' % recipepathspec) |
| 289 | f.write('BBFILE_COLLECTIONS += "%s"\n' % templayername) |
| 290 | f.write('BBFILE_PATTERN_%s = "^${LAYERDIR}/"\n' % templayername) |
| 291 | f.write('BBFILE_PRIORITY_%s = "%d"\n' % (templayername, priority)) |
| 292 | f.write('BBFILE_PATTERN_IGNORE_EMPTY_%s = "1"\n' % templayername) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 293 | f.write('LAYERSERIES_COMPAT_%s = "${LAYERSERIES_COMPAT_core}"\n' % templayername) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 294 | |
| 295 | @contextlib.contextmanager |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 296 | def runqemu(pn, ssh=True, runqemuparams='', image_fstype=None, launch_cmd=None, qemuparams=None, overrides={}, discard_writes=True): |
| 297 | """ |
| 298 | launch_cmd means directly run the command, don't need set rootfs or env vars. |
| 299 | """ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 300 | |
| 301 | import bb.tinfoil |
| 302 | import bb.build |
| 303 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 304 | # Need a non-'BitBake' logger to capture the runner output |
| 305 | targetlogger = logging.getLogger('TargetRunner') |
| 306 | targetlogger.setLevel(logging.DEBUG) |
| 307 | handler = logging.StreamHandler(sys.stdout) |
| 308 | targetlogger.addHandler(handler) |
| 309 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 310 | tinfoil = bb.tinfoil.Tinfoil() |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 311 | tinfoil.prepare(config_only=False, quiet=True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 312 | try: |
| 313 | tinfoil.logger.setLevel(logging.WARNING) |
| 314 | import oeqa.targetcontrol |
| 315 | tinfoil.config_data.setVar("TEST_LOG_DIR", "${WORKDIR}/testimage") |
| 316 | tinfoil.config_data.setVar("TEST_QEMUBOOT_TIMEOUT", "1000") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 317 | # Tell QemuTarget() whether need find rootfs/kernel or not |
| 318 | if launch_cmd: |
| 319 | tinfoil.config_data.setVar("FIND_ROOTFS", '0') |
| 320 | else: |
| 321 | tinfoil.config_data.setVar("FIND_ROOTFS", '1') |
| 322 | |
| 323 | recipedata = tinfoil.parse_recipe(pn) |
| 324 | for key, value in overrides.items(): |
| 325 | recipedata.setVar(key, value) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 326 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 327 | logdir = recipedata.getVar("TEST_LOG_DIR") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 328 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 329 | qemu = oeqa.targetcontrol.QemuTarget(recipedata, targetlogger, image_fstype) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 330 | finally: |
| 331 | # We need to shut down tinfoil early here in case we actually want |
| 332 | # to run tinfoil-using utilities with the running QEMU instance. |
| 333 | # Luckily QemuTarget doesn't need it after the constructor. |
| 334 | tinfoil.shutdown() |
| 335 | |
| 336 | try: |
| 337 | qemu.deploy() |
| 338 | try: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 339 | qemu.start(params=qemuparams, ssh=ssh, runqemuparams=runqemuparams, launch_cmd=launch_cmd, discard_writes=discard_writes) |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 340 | except EXception as e: |
| 341 | msg = str(e) + '\nFailed to start QEMU - see the logs in %s' % logdir |
Brad Bishop | f86d055 | 2018-12-04 14:18:15 -0800 | [diff] [blame] | 342 | if os.path.exists(qemu.qemurunnerlog): |
| 343 | with open(qemu.qemurunnerlog, 'r') as f: |
| 344 | msg = msg + "Qemurunner log output from %s:\n%s" % (qemu.qemurunnerlog, f.read()) |
| 345 | raise Exception(msg) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 346 | |
| 347 | yield qemu |
| 348 | |
| 349 | finally: |
Brad Bishop | f86d055 | 2018-12-04 14:18:15 -0800 | [diff] [blame] | 350 | targetlogger.removeHandler(handler) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 351 | try: |
| 352 | qemu.stop() |
| 353 | except: |
| 354 | pass |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 355 | |
| 356 | def updateEnv(env_file): |
| 357 | """ |
| 358 | Source a file and update environment. |
| 359 | """ |
| 360 | |
| 361 | cmd = ". %s; env -0" % env_file |
| 362 | result = runCmd(cmd) |
| 363 | |
| 364 | for line in result.output.split("\0"): |
| 365 | (key, _, value) = line.partition("=") |
| 366 | os.environ[key] = value |