Skip to content

Commit

Permalink
bpo-40370: Use the same compile and link args as the interpreter used…
Browse files Browse the repository at this point in the history
… in test_peg_generator (pythonGH-19674)
  • Loading branch information
pablogsal authored Apr 23, 2020
1 parent 1221135 commit 9e6a131
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Lib/test/test_peg_generator/test_c_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from test import test_tools
from test.test_peg_generator.ast_dump import ast_dump
from test import support
from pathlib import PurePath, Path
from typing import Sequence

Expand All @@ -23,6 +24,9 @@

class TestCParser(unittest.TestCase):
def setUp(self):
cmd = support.missing_compiler_executable()
if cmd is not None:
self.skipTest('The %r command is not found' % cmd)
self.tmp_path = tempfile.mkdtemp()

def tearDown(self):
Expand Down
15 changes: 12 additions & 3 deletions Tools/peg_generator/pegen/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import shutil
import tokenize
import sys
import sysconfig

from typing import Optional, Tuple

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


def get_extra_flags(compiler_flags, compiler_py_flags_nodist):
flags = sysconfig.get_config_var(compiler_flags)
py_flags_nodist = sysconfig.get_config_var(compiler_py_flags_nodist)
if flags is None or py_flags_nodist is None:
return []
return f'{flags} {py_flags_nodist}'.split()


def compile_c_extension(
generated_source_path: str,
build_dir: Optional[str] = None,
Expand All @@ -43,9 +52,8 @@ def compile_c_extension(

source_file_path = pathlib.Path(generated_source_path)
extension_name = source_file_path.stem
extra_compile_args = []
if not sys.platform.startswith('win'):
extra_compile_args.append("-std=c99")
extra_compile_args = get_extra_flags('CFLAGS', 'PY_CFLAGS_NODIST')
extra_link_args = get_extra_flags('LDFLAGS', 'PY_LDFLAGS_NODIST')
if keep_asserts:
extra_compile_args.append("-UNDEBUG")
extension = [
Expand All @@ -66,6 +74,7 @@ def compile_c_extension(
str(MOD_DIR.parent.parent.parent / "Parser" / "pegen"),
],
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
)
]
dist = Distribution({"name": extension_name, "ext_modules": extension})
Expand Down

0 comments on commit 9e6a131

Please sign in to comment.