Skip to content

Commit

Permalink
Detect MSVC without relying on compiler filename
Browse files Browse the repository at this point in the history
Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com>
  • Loading branch information
bensze01 authored and gilles-peskine-arm committed May 20, 2021
1 parent b32966d commit fa6bf1e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions scripts/mbedtls_dev/c_build_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def generate_c_file(c_file,
}
''')

_cc_is_msvc = None #pylint: disable=invalid-name
def get_c_expression_values(
cast_to, printf_format,
expressions,
Expand Down Expand Up @@ -128,11 +129,20 @@ def get_c_expression_values(
)
c_file.close()
cc = os.getenv('CC', 'cc')
cc_is_msvc = os.path.split(cc)[1].lower() in ('cl', 'cl.exe')
cmd = [cc]

global _cc_is_msvc #pylint: disable=global-statement,invalid-name
if _cc_is_msvc is None:
proc = subprocess.Popen(cmd,
stdout=subprocess.DEVNULL,
stderr=subprocess.PIPE,
universal_newlines=True)
_cc_is_msvc = 'Microsoft (R) C/C++ Optimizing Compiler' in \
proc.communicate()[1]

cmd += ['-I' + dir for dir in include_path]
# MSVC has deprecated using -o to specify the output file.
output_opt = '-Fe' if cc_is_msvc else '-o'
output_opt = '-Fe' if _cc_is_msvc else '-o'
cmd += [output_opt + exe_name]
subprocess.check_call(cmd + [c_name])
if keep_c:
Expand Down

0 comments on commit fa6bf1e

Please sign in to comment.