summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2020-04-23 13:46:22 (GMT)
committerGitHub <noreply@github.com>2020-04-23 13:46:22 (GMT)
commit9e6a1312c1cd04ab37cddd8f3bb9baa7e9a38bc0 (patch)
treeeccfa1521f72ee0f6a8e749f680c595ebbb2e128
parent1221135289306333d11db25ab20cbbd21ceec630 (diff)
downloadcpython-9e6a1312c1cd04ab37cddd8f3bb9baa7e9a38bc0.zip
cpython-9e6a1312c1cd04ab37cddd8f3bb9baa7e9a38bc0.tar.gz
cpython-9e6a1312c1cd04ab37cddd8f3bb9baa7e9a38bc0.tar.bz2
bpo-40370: Use the same compile and link args as the interpreter used in test_peg_generator (GH-19674)
-rw-r--r--Lib/test/test_peg_generator/test_c_parser.py4
-rw-r--r--Tools/peg_generator/pegen/build.py15
2 files changed, 16 insertions, 3 deletions
diff --git a/Lib/test/test_peg_generator/test_c_parser.py b/Lib/test/test_peg_generator/test_c_parser.py
index 6682c90..ceda6d4 100644
--- a/Lib/test/test_peg_generator/test_c_parser.py
+++ b/Lib/test/test_peg_generator/test_c_parser.py
@@ -8,6 +8,7 @@ import sys
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
@@ -23,6 +24,9 @@ with test_tools.imports_under_tool('peg_generator'):
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):
diff --git a/Tools/peg_generator/pegen/build.py b/Tools/peg_generator/pegen/build.py
index bd792d6..6ead947 100644
--- a/Tools/peg_generator/pegen/build.py
+++ b/Tools/peg_generator/pegen/build.py
@@ -2,6 +2,7 @@ import pathlib
import shutil
import tokenize
import sys
+import sysconfig
from typing import Optional, Tuple
@@ -22,6 +23,14 @@ from pegen.tokenizer import Tokenizer
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,
@@ -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 = [
@@ -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})