Skip to content

Instantly share code, notes, and snippets.

@naveen521kk
Last active March 24, 2022 13:48
Show Gist options
  • Save naveen521kk/5abd86a900d621b30aa5bedb6b442023 to your computer and use it in GitHub Desktop.
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.
# 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