diff options
author | William Deegan <bill@baddogconsulting.com> | 2022-06-14 22:24:45 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-14 22:24:45 (GMT) |
commit | 49e50671de9309fd38e5006071332a802161e7c1 (patch) | |
tree | 6d1ebe1856d2ce4b7e216c5ba5fa289d7c6904ec /testing/framework | |
parent | a52667a5919079f9b8da7a51115fd9ca43502d32 (diff) | |
parent | 9f7213c53bd53d5554423fa91c23e8c55334b5bd (diff) | |
download | SCons-49e50671de9309fd38e5006071332a802161e7c1.zip SCons-49e50671de9309fd38e5006071332a802161e7c1.tar.gz SCons-49e50671de9309fd38e5006071332a802161e7c1.tar.bz2 |
Merge pull request #4170 from dmoody256/ninja_exit_daemon
[NINJA] Added new alias 'shutdown-ninja-scons-daemon' to allow ninja to shutdown the daemon
Diffstat (limited to 'testing/framework')
-rw-r--r-- | testing/framework/TestCmd.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/testing/framework/TestCmd.py b/testing/framework/TestCmd.py index a70df0f..fc5e328 100644 --- a/testing/framework/TestCmd.py +++ b/testing/framework/TestCmd.py @@ -299,9 +299,12 @@ __version__ = "1.3" import atexit import difflib import errno +import hashlib import os import re +import psutil import shutil +import signal import stat import subprocess import sys @@ -310,6 +313,7 @@ import threading import time import traceback from collections import UserList, UserString +from pathlib import Path from subprocess import PIPE, STDOUT from typing import Optional @@ -383,6 +387,37 @@ def _caller(tblist, skip): return string +def clean_up_ninja_daemon(self, result_type): + """ + Kill any running scons daemon started by ninja and clean up it's working dir and + temp files. + """ + if self: + for path in Path(self.workdir).rglob('.ninja'): + daemon_dir = Path(tempfile.gettempdir()) / ( + "scons_daemon_" + str(hashlib.md5(str(path.resolve()).encode()).hexdigest()) + ) + pidfiles = [daemon_dir / 'pidfile', path / 'scons_daemon_dirty'] + for pidfile in pidfiles: + if pidfile.exists(): + with open(pidfile) as f: + try: + pid = int(f.read()) + os.kill(pid, signal.SIGINT) + except OSError: + pass + + while True: + if pid not in [proc.pid for proc in psutil.process_iter()]: + break + else: + time.sleep(0.1) + + if not self._preserve[result_type]: + if daemon_dir.exists(): + shutil.rmtree(daemon_dir) + + def fail_test(self=None, condition=True, function=None, skip=0, message=None): """Causes a test to exit with a fail. @@ -402,6 +437,7 @@ def fail_test(self=None, condition=True, function=None, skip=0, message=None): return if function is not None: function() + clean_up_ninja_daemon(self, 'fail_test') of = "" desc = "" sep = " " @@ -447,6 +483,7 @@ def no_result(self=None, condition=True, function=None, skip=0): return if function is not None: function() + clean_up_ninja_daemon(self, 'no_result') of = "" desc = "" sep = " " @@ -483,6 +520,7 @@ def pass_test(self=None, condition=True, function=None): return if function is not None: function() + clean_up_ninja_daemon(self, 'pass_test') sys.stderr.write("PASSED\n") sys.exit(0) |