From 66311e11a735b9e45d99f25748958468f0ac8ee8 Mon Sep 17 00:00:00 2001 From: Gunhan Gulsoy Date: Tue, 26 Nov 2019 17:10:02 -0800 Subject: [PATCH] Handle and print information about CalledProcessError raised by the subprocess.check_output call in def_file_filter PiperOrigin-RevId: 282668493 Change-Id: I260701c8c99ca84abaee26e09f0613e0cae06e7f --- .../def_file_filter/def_file_filter.py.tpl | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/tensorflow/tools/def_file_filter/def_file_filter.py.tpl b/tensorflow/tools/def_file_filter/def_file_filter.py.tpl index 7702dda1647..f894c000ddc 100644 --- a/tensorflow/tools/def_file_filter/def_file_filter.py.tpl +++ b/tensorflow/tools/def_file_filter/def_file_filter.py.tpl @@ -41,7 +41,6 @@ import tempfile # External tools we use that come with visual studio sdk UNDNAME = "%{undname_bin_path}" DUMPBIN_CMD = "\"{}\" /SYMBOLS".format("%{dumpbin_bin_path}") -GREP_CMD = "| grep External" # Exclude if matched EXCLUDE_RE = re.compile(r"RTTI|deleting destructor|::internal::") @@ -113,19 +112,32 @@ def get_symbols(path_to_lib, re_filter): path_to_lib: String that is path (execpath) to target .lib file. re_filter: String that is regex filter for filtering symbols from .lib. """ - sym_found = subprocess.check_output("{} {} {}".format(DUMPBIN_CMD, path_to_lib, GREP_CMD), shell=True) - sym_found = sym_found.decode() + try: + full_output = subprocess.check_output( + "{} {}".format(DUMPBIN_CMD, path_to_lib), + stderr=subprocess.STDOUT, shell=True) + except subprocess.CalledProcessError as e: + print("Getting symbol list using dumpbin failed with code %d:" % ( + e.returncode)) + print("\t\tFailing command: %s" % (e.cmd)) + print("\t\tOutput: %s" % (e.output)) + print("\t\tError details: %s" % (e)) + raise e + + # Convert to normal string from bytes type. + full_output = full_output.decode() + + # Split and filter the list + sym_split = [x for x in full_output.split("\r\n") + if "External" in x] + # Example symbol line: # 954 00000000 SECT2BD notype () External | ?IsSequence@swig@tensorflow@@YA_NPEAU_object@@@Z (bool __cdecl tensorflow::swig::IsSequence(struct _object *)) - # Split lines with `External` since each line must have the string. - sym_split = sym_found.split("External") sym_filtered = [] re_filter_comp = re.compile(r"{}".format(re_filter)) # Filter out symbol from the split line (`sym_split` in the for loop below). - # Sample line: - # " | ?NewProfiler@tfprof@tensorflow@@YA_NPEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0@Z (bool __cdecl tensorflow::tfprof::NewProfiler(class std::basic_string,class std::allocator > const *,class std::basic_string,class std::allocator > const *))" - sym_line_filter = r"\s+\| (.*) \(.*" + sym_line_filter = r".*\s+\| (.*) \(.*" for sym_line in sym_split: if re_filter_comp.search(sym_line):