Last active
March 24, 2022 13:48
-
-
Save naveen521kk/5abd86a900d621b30aa5bedb6b442023 to your computer and use it in GitHub Desktop.
A program to check if the compiler passed is a Mingw-w64 based compiler.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A program to check if the compiler passed | |
# is a Mingw-w64 based compiler. | |
import os | |
import subprocess | |
import argparse | |
import sys | |
def is_mingw(CC): | |
if sys.platform != 'win32': | |
# Let's check only if we are in Windows | |
return False | |
# Check if the compiler in VS | |
if os.path.basename(CC) in ['cl', 'cl.exe']: | |
return False | |
try: | |
com = subprocess.run( | |
[CC, '--version'], check=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True | |
) | |
except FileNotFoundError: | |
return False | |
if com.returncode != 0: | |
# Both gcc and clang compilers from mingw should understand that argument | |
# and should return a status code of 0. | |
return False | |
out, err = com.stdout, com.stderr | |
if 'clang' in out or 'Clang' in out: | |
# Check it's not clang-cl wrapper | |
if 'CL.EXE COMPATIBILITY' in out: | |
return False | |
return True | |
if 'gcc.exe' in out: | |
return True | |
return False | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser( | |
description='Check if the compiler passed in a mingw based compiler.') | |
parser.add_argument('compiler', help='path to the compiler to check.') | |
args = parser.parse_args() | |
CC = args.compiler | |
print(is_mingw(CC)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment