From f5780776683185ea062932a4878db430fd201be2 Mon Sep 17 00:00:00 2001 From: TunaCici <36923239+TunaCici@users.noreply.github.com> Date: Wed, 2 Oct 2024 19:42:06 +0300 Subject: [PATCH] tools: handle different python sh versions - ensure that 'RunningCommand' object is returned by checking the version of the 'sh' module. - use '_return_cmd=True' for sh versions 2.x. Signed-off-by: Tuna Cici --- common.py | 9 ++++++++- test.py | 17 ++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/common.py b/common.py index e6ce8bed..efc4df6d 100644 --- a/common.py +++ b/common.py @@ -66,7 +66,14 @@ def _init_build_directory(config, initialised, directory, tute_directory, output tute_dir = "-DTUTORIAL_DIR=" + os.path.basename(tute_directory) args = ['-G', 'Ninja'] + config_dict[config] + [tute_dir] + \ ["-C", "../projects/sel4-tutorials/settings.cmake"] - return sh.cmake(args + [tute_directory], _cwd=directory, _out=output, _err=output) + result = None + if sh.__version__.startswith("1"): + result = sh.cmake(args + [tute_directory], _cwd=directory, _out=output, + _err=output) + else: + result = sh.cmake(args + [tute_directory], _cwd=directory, _out=output, + _err=output, _return_cmd=True) + return result def _init_tute_directory(config, tut, solution, task, directory, output=None): diff --git a/test.py b/test.py index 12c6e046..f5702b91 100755 --- a/test.py +++ b/test.py @@ -40,17 +40,28 @@ def print_pexpect_failure(failure): def run_single_test_iteration(build_dir, solution, logfile): # Build - result = sh.ninja(_out=logfile, _cwd=build_dir) + result = None + if sh.__version__.startswith("1"): + result = sh.ninja(_out=logfile, _cwd=build_dir) + else: + result = sh.ninja(_out=logfile, _cwd=build_dir, _return_cmd=True) if result.exit_code != 0: logging.error("Failed to build. Not deleting build directory %s" % build_dir) sys.exit(1) check = sh.Command(os.path.join(build_dir, "check")) if solution: - result = check(_out=logfile, _cwd=build_dir) + if sh.__version__.startswith("1"): + result = check(_out=logfile, _cwd=build_dir) + else: + result = check(_out=logfile, _cwd=build_dir, _return_cmd=True) else: # We check the start state if not solution - result = check("--start", _out=logfile, _cwd=build_dir) + if sh.__version__.startswith("1"): + result = check("--start", _out=logfile, _cwd=build_dir) + else: + result = check("--start", _out=logfile, _cwd=build_dir, + _return_cmd=True) for proc in psutil.process_iter(): if "qemu" in proc.name(): proc.kill()