@@ -425,52 +425,35 @@ def create_compiler_path(xml_generator, compiler_path):
425425 if xml_generator == 'castxml' and compiler_path is None :
426426 if platform .system () == 'Windows' :
427427 # 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' )
437429 # No msvc found; look for mingw
438430 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' )
447432 else :
448433 # OS X or Linux
449434 # 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++' )
458436 # No clang found; use gcc
459437 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++' )
468439
469440 if compiler_path == "" :
470441 compiler_path = None
471442
472443 return compiler_path
473444
474445
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+
475458if __name__ == '__main__' :
476459 print (load_xml_generator_configuration ('xml_generator.cfg' ).__dict__ )
0 commit comments