|
11 | 11 | import os |
12 | 12 | import copy |
13 | 13 | import platform |
| 14 | +import shutil |
14 | 15 | import subprocess |
15 | 16 | import warnings |
16 | 17 | # In py3, ConfigParser was renamed to the more-standard configparser. |
@@ -129,16 +130,12 @@ def compiler(self, compiler): |
129 | 130 |
|
130 | 131 | @property |
131 | 132 | def xml_generator(self): |
132 | | - """get xml_generator (gccxml or castxml)""" |
| 133 | + """get xml_generator""" |
133 | 134 | return self.__xml_generator |
134 | 135 |
|
135 | 136 | @xml_generator.setter |
136 | 137 | def xml_generator(self, xml_generator): |
137 | | - """set xml_generator (gccxml or castxml)""" |
138 | | - if "real" in xml_generator: |
139 | | - # Support for gccxml.real from newer gccxml package |
140 | | - # Can be removed once gccxml support is dropped. |
141 | | - xml_generator = "gccxml" |
| 138 | + """set xml_generator""" |
142 | 139 | self.__xml_generator = xml_generator |
143 | 140 |
|
144 | 141 | @property |
@@ -241,9 +238,8 @@ def raise_on_wrong_settings(self): |
241 | 238 | self.__ensure_dir_exists(self.working_directory, 'working directory') |
242 | 239 | for idir in self.include_paths: |
243 | 240 | self.__ensure_dir_exists(idir, 'include directory') |
244 | | - if self.__xml_generator not in ["castxml", "gccxml"]: |
245 | | - msg = ('xml_generator("%s") should either be ' + |
246 | | - '"castxml" or "gccxml".') % self.xml_generator |
| 241 | + if self.__xml_generator != "castxml": |
| 242 | + msg = f"xml_generator ({self.xml_generator}) can only be 'castxml'" |
247 | 243 | raise RuntimeError(msg) |
248 | 244 |
|
249 | 245 |
|
@@ -456,35 +452,20 @@ def create_compiler_path(xml_generator, compiler_path): |
456 | 452 | if xml_generator == 'castxml' and compiler_path is None: |
457 | 453 | if platform.system() == 'Windows': |
458 | 454 | # Look for msvc |
459 | | - compiler_path = __get_first_compiler_in_path('where', 'cl') |
| 455 | + compiler_path = shutil.which('cl') |
460 | 456 | # No msvc found; look for mingw |
461 | | - if compiler_path == '': |
462 | | - compiler_path = __get_first_compiler_in_path('where', 'mingw') |
| 457 | + if compiler_path is None: |
| 458 | + compiler_path = shutil.which('mingw') |
463 | 459 | else: |
464 | 460 | # OS X or Linux |
465 | 461 | # Look for clang first, then gcc |
466 | | - compiler_path = __get_first_compiler_in_path('which', 'clang++') |
| 462 | + compiler_path = shutil.which('clang++') |
467 | 463 | # No clang found; use gcc |
468 | | - if compiler_path == '': |
469 | | - compiler_path = __get_first_compiler_in_path('which', 'c++') |
470 | | - |
471 | | - if compiler_path == "": |
472 | | - compiler_path = None |
| 464 | + if compiler_path is None: |
| 465 | + compiler_path = shutil.which('c++') |
473 | 466 |
|
474 | 467 | return compiler_path |
475 | 468 |
|
476 | 469 |
|
477 | | -def __get_first_compiler_in_path(command, compiler_name): |
478 | | - p = subprocess.Popen( |
479 | | - [command, compiler_name], |
480 | | - stdout=subprocess.PIPE, |
481 | | - stderr=subprocess.PIPE) |
482 | | - path = p.stdout.read().decode("utf-8").rstrip().split("\r\n")[0].rstrip() |
483 | | - p.wait() |
484 | | - p.stdout.close() |
485 | | - p.stderr.close() |
486 | | - return path |
487 | | - |
488 | | - |
489 | 470 | if __name__ == '__main__': |
490 | 471 | print(load_xml_generator_configuration('xml_generator.cfg').__dict__) |
0 commit comments