@@ -425,52 +425,35 @@ def create_compiler_path(xml_generator, compiler_path):
425
425
if xml_generator == 'castxml' and compiler_path is None :
426
426
if platform .system () == 'Windows' :
427
427
# Look for msvc
428
- p = subprocess .Popen (
429
- ['where' , 'cl' ],
430
- stdout = subprocess .PIPE ,
431
- stderr = subprocess .PIPE )
432
- # Fix where cl error. In cmake environment there are more then one Visual Studio path are found.
433
- compiler_path = p .stdout .read ().decode ("utf-8" ).rstrip ().split ("\r \n " )[0 ].rstrip ()
434
- p .wait ()
435
- p .stdout .close ()
436
- p .stderr .close ()
428
+ compiler_path = __get_first_compiler_in_path ('where' , 'cl' )
437
429
# No msvc found; look for mingw
438
430
if compiler_path == '' :
439
- p = subprocess .Popen (
440
- ['where' , 'mingw' ],
441
- stdout = subprocess .PIPE ,
442
- stderr = subprocess .PIPE )
443
- compiler_path = p .stdout .read ().decode ("utf-8" ).rstrip ()
444
- p .wait ()
445
- p .stdout .close ()
446
- p .stderr .close ()
431
+ compiler_path = __get_first_compiler_in_path ('where' , 'mingw' )
447
432
else :
448
433
# OS X or Linux
449
434
# Look for clang first, then gcc
450
- p = subprocess .Popen (
451
- ['which' , 'clang++' ],
452
- stdout = subprocess .PIPE ,
453
- stderr = subprocess .PIPE )
454
- compiler_path = p .stdout .read ().decode ("utf-8" ).rstrip ()
455
- p .wait ()
456
- p .stdout .close ()
457
- p .stderr .close ()
435
+ compiler_path = __get_first_compiler_in_path ('which' , 'clang++' )
458
436
# No clang found; use gcc
459
437
if compiler_path == '' :
460
- p = subprocess .Popen (
461
- ['which' , 'c++' ],
462
- stdout = subprocess .PIPE ,
463
- stderr = subprocess .PIPE )
464
- compiler_path = p .stdout .read ().decode ("utf-8" ).rstrip ()
465
- p .wait ()
466
- p .stdout .close ()
467
- p .stderr .close ()
438
+ compiler_path = __get_first_compiler_in_path ('which' , 'c++' )
468
439
469
440
if compiler_path == "" :
470
441
compiler_path = None
471
442
472
443
return compiler_path
473
444
474
445
446
+ def __get_first_compiler_in_path (command , compiler_name ):
447
+ p = subprocess .Popen (
448
+ [command , compiler_name ],
449
+ stdout = subprocess .PIPE ,
450
+ stderr = subprocess .PIPE )
451
+ path = p .stdout .read ().decode ("utf-8" ).rstrip ().split ("\r \n " )[0 ].rstrip ()
452
+ p .wait ()
453
+ p .stdout .close ()
454
+ p .stderr .close ()
455
+ return path
456
+
457
+
475
458
if __name__ == '__main__' :
476
459
print (load_xml_generator_configuration ('xml_generator.cfg' ).__dict__ )
0 commit comments