Skip to content

Commit 5601321

Browse files
authored
bpo-33717: pythoninfo: add CC --version (#7290)
Get the version of the C compiler.
1 parent 110bc01 commit 5601321

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Lib/test/pythoninfo.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,34 @@ def collect_test_support(info_add):
489489
call_func(info_add, 'test_support.python_is_optimized', support, 'python_is_optimized')
490490

491491

492+
def collect_cc(info_add):
493+
import subprocess
494+
import sysconfig
495+
496+
CC = sysconfig.get_config_var('CC')
497+
if not CC:
498+
return
499+
500+
try:
501+
import shlex
502+
args = shlex.split(CC)
503+
except ImportError:
504+
args = CC.split()
505+
args.append('--version')
506+
proc = subprocess.Popen(args,
507+
stdout=subprocess.PIPE,
508+
stderr=subprocess.STDOUT,
509+
universal_newlines=True)
510+
stdout = proc.communicate()[0]
511+
if proc.returncode:
512+
# CC --version failed: ignore error
513+
return
514+
515+
text = stdout.splitlines()[0]
516+
text = normalize_text(text)
517+
info_add('CC.version', text)
518+
519+
492520
def collect_info(info):
493521
error = False
494522
info_add = info.add
@@ -515,6 +543,7 @@ def collect_info(info):
515543
collect_decimal,
516544
collect_testcapi,
517545
collect_resource,
546+
collect_cc,
518547

519548
# Collecting from tests should be last as they have side effects.
520549
collect_test_socket,

0 commit comments

Comments
 (0)