From d1f8cfa821337c8d390b2e3e5cb94a5f5b88078a Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Sat, 23 Jul 2022 23:00:57 +0900 Subject: [PATCH] gh-85454: Remove distutils.ccompiler from Tools/c-analyzer --- Tools/c-analyzer/c_parser/preprocessor/__init__.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Tools/c-analyzer/c_parser/preprocessor/__init__.py b/Tools/c-analyzer/c_parser/preprocessor/__init__.py index e38176fee31fac..c154137bf42f0d 100644 --- a/Tools/c-analyzer/c_parser/preprocessor/__init__.py +++ b/Tools/c-analyzer/c_parser/preprocessor/__init__.py @@ -1,7 +1,9 @@ import contextlib -import distutils.ccompiler import logging +import os import os.path +import re +import sys from c_common.fsutil import match_glob as _match_glob from c_common.tables import parse_table as _parse_table @@ -168,9 +170,17 @@ def handling_errors(ignore_exc=None, *, log_err=None): } +def _get_default_compiler(): + if re.match('cygwin.*', sys.platform) is not None: + return 'unix' + if os.name == 'nt': + return 'msvc' + return 'unix' + + def _get_preprocessor(tool): if tool is True: - tool = distutils.ccompiler.get_default_compiler() + tool = _get_default_compiler() preprocess = _COMPILERS.get(tool) if preprocess is None: raise ValueError(f'unsupported tool {tool}')