Skip to content

Use shutil.which() to get compiler path #179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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__)
Loading