Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9e6a131

Browse files
authored
bpo-40370: Use the same compile and link args as the interpreter used in test_peg_generator (GH-19674)
1 parent 1221135 commit 9e6a131

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

Lib/test/test_peg_generator/test_c_parser.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from test import test_tools
1010
from test.test_peg_generator.ast_dump import ast_dump
11+
from test import support
1112
from pathlib import PurePath, Path
1213
from typing import Sequence
1314

@@ -23,6 +24,9 @@
2324

2425
class TestCParser(unittest.TestCase):
2526
def setUp(self):
27+
cmd = support.missing_compiler_executable()
28+
if cmd is not None:
29+
self.skipTest('The %r command is not found' % cmd)
2630
self.tmp_path = tempfile.mkdtemp()
2731

2832
def tearDown(self):

Tools/peg_generator/pegen/build.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import shutil
33
import tokenize
44
import sys
5+
import sysconfig
56

67
from typing import Optional, Tuple
78

@@ -22,6 +23,14 @@
2223
MOD_DIR = pathlib.Path(__file__).parent
2324

2425

26+
def get_extra_flags(compiler_flags, compiler_py_flags_nodist):
27+
flags = sysconfig.get_config_var(compiler_flags)
28+
py_flags_nodist = sysconfig.get_config_var(compiler_py_flags_nodist)
29+
if flags is None or py_flags_nodist is None:
30+
return []
31+
return f'{flags} {py_flags_nodist}'.split()
32+
33+
2534
def compile_c_extension(
2635
generated_source_path: str,
2736
build_dir: Optional[str] = None,
@@ -43,9 +52,8 @@ def compile_c_extension(
4352

4453
source_file_path = pathlib.Path(generated_source_path)
4554
extension_name = source_file_path.stem
46-
extra_compile_args = []
47-
if not sys.platform.startswith('win'):
48-
extra_compile_args.append("-std=c99")
55+
extra_compile_args = get_extra_flags('CFLAGS', 'PY_CFLAGS_NODIST')
56+
extra_link_args = get_extra_flags('LDFLAGS', 'PY_LDFLAGS_NODIST')
4957
if keep_asserts:
5058
extra_compile_args.append("-UNDEBUG")
5159
extension = [
@@ -66,6 +74,7 @@ def compile_c_extension(
6674
str(MOD_DIR.parent.parent.parent / "Parser" / "pegen"),
6775
],
6876
extra_compile_args=extra_compile_args,
77+
extra_link_args=extra_link_args,
6978
)
7079
]
7180
dist = Distribution({"name": extension_name, "ext_modules": extension})

0 commit comments

Comments
 (0)