diff --git a/src/pygccxml/parser/config.py b/src/pygccxml/parser/config.py index 1032b54e..4fe4a6a0 100644 --- a/src/pygccxml/parser/config.py +++ b/src/pygccxml/parser/config.py @@ -11,6 +11,7 @@ import os import copy import platform +import shutil import subprocess import warnings # In py3, ConfigParser was renamed to the more-standard configparser. @@ -451,35 +452,20 @@ def create_compiler_path(xml_generator, compiler_path): if xml_generator == 'castxml' and compiler_path is None: if platform.system() == 'Windows': # Look for msvc - compiler_path = __get_first_compiler_in_path('where', 'cl') + compiler_path = shutil.which('cl') # No msvc found; look for mingw - if compiler_path == '': - compiler_path = __get_first_compiler_in_path('where', 'mingw') + if compiler_path is None: + compiler_path = shutil.which('mingw') else: # OS X or Linux # Look for clang first, then gcc - compiler_path = __get_first_compiler_in_path('which', 'clang++') + compiler_path = shutil.which('clang++') # No clang found; use gcc - if compiler_path == '': - compiler_path = __get_first_compiler_in_path('which', 'c++') - - if compiler_path == "": - compiler_path = None + if compiler_path is None: + compiler_path = shutil.which('c++') return compiler_path -def __get_first_compiler_in_path(command, compiler_name): - p = subprocess.Popen( - [command, compiler_name], - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - path = p.stdout.read().decode("utf-8").rstrip().split("\r\n")[0].rstrip() - p.wait() - p.stdout.close() - p.stderr.close() - return path - - if __name__ == '__main__': print(load_xml_generator_configuration('xml_generator.cfg').__dict__)