Skip to content

Commit

Permalink
Merge pull request #179 from mgorny/no-which
Browse files Browse the repository at this point in the history
Use `shutil.which()` to get compiler path
  • Loading branch information
iMichka authored Apr 16, 2024
2 parents f57ddbb + 08f5353 commit 5090a61
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions src/pygccxml/parser/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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__)

0 comments on commit 5090a61

Please sign in to comment.