Giacomo Travaglini has submitted this change. (
https://gem5-review.googlesource.com/c/public/gem5/+/28847 )
Change subject: scons: Add readCommandWithReturn helper
......................................................................
scons: Add readCommandWithReturn helper
In this way it will be possible to reliably catch any error
in the command execution which is not raising an exception
to Popen.
Change-Id: I4dc15648423f9bb8e8a470d97291dbd065c48eba
Signed-off-by: Giacomo Travaglini <giacomo.travagl...@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/28847
Reviewed-by: Jason Lowe-Power <power...@gmail.com>
Maintainer: Jason Lowe-Power <power...@gmail.com>
Tested-by: kokoro <noreply+kok...@google.com>
---
M src/python/m5/util/__init__.py
1 file changed, 26 insertions(+), 6 deletions(-)
Approvals:
Jason Lowe-Power: Looks good to me, approved; Looks good to me, approved
kokoro: Regressions pass
diff --git a/src/python/m5/util/__init__.py b/src/python/m5/util/__init__.py
index 98a7a08..c59f40a 100644
--- a/src/python/m5/util/__init__.py
+++ b/src/python/m5/util/__init__.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2016 ARM Limited
+# Copyright (c) 2016, 2020 ARM Limited
# All rights reserved.
#
# The license below extends only to copyright in the software and shall
@@ -177,9 +177,16 @@
line += item
print(line)
-def readCommand(cmd, **kwargs):
- """run the command cmd, read the results and return them
- this is sorta like `cmd` in shell"""
+def readCommandWithReturn(cmd, **kwargs):
+ """
+ run the command cmd, read the results and return them
+ this is sorta like `cmd` in shell
+
+ :param cmd: command to run with Popen
+ :type cmd: string, list
+ :returns: pair consisting on Popen retcode and the command stdout
+ :rtype: (int, string)
+ """
from subprocess import Popen, PIPE, STDOUT
if isinstance(cmd, str):
@@ -196,10 +203,23 @@
subp = Popen(cmd, **kwargs)
except Exception as e:
if no_exception:
- return exception
+ return -1, exception
raise
- return subp.communicate()[0].decode('utf-8')
+ output = subp.communicate()[0].decode('utf-8')
+ return subp.returncode, output
+
+def readCommand(cmd, **kwargs):
+ """
+ run the command cmd, read the results and return them
+ this is sorta like `cmd` in shell
+
+ :param cmd: command to run with Popen
+ :type cmd: string, list
+ :returns: command stdout
+ :rtype: string
+ """
+ return readCommandWithReturn(cmd, **kwargs)[1]
def makeDir(path):
"""Make a directory if it doesn't exist. If the path does exist,
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/28847
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: release-staging-v20.0.0.0
Gerrit-Change-Id: I4dc15648423f9bb8e8a470d97291dbd065c48eba
Gerrit-Change-Number: 28847
Gerrit-PatchSet: 4
Gerrit-Owner: Giacomo Travaglini <giacomo.travagl...@arm.com>
Gerrit-Reviewer: Bobby R. Bruce <bbr...@ucdavis.edu>
Gerrit-Reviewer: Gabe Black <gabebl...@google.com>
Gerrit-Reviewer: Giacomo Travaglini <giacomo.travagl...@arm.com>
Gerrit-Reviewer: Jason Lowe-Power <power...@gmail.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s