summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Misc/NEWS.d/next/Build/2021-11-25-13-53-36.bpo-45866.ZH1W8N.rst4
-rw-r--r--Parser/pegen/parse.c2
-rw-r--r--Tools/peg_generator/pegen/c_generator.py4
-rw-r--r--Tools/peg_generator/pegen/grammar_parser.py2
-rw-r--r--Tools/peg_generator/pegen/python_generator.py4
5 files changed, 12 insertions, 4 deletions
diff --git a/Misc/NEWS.d/next/Build/2021-11-25-13-53-36.bpo-45866.ZH1W8N.rst b/Misc/NEWS.d/next/Build/2021-11-25-13-53-36.bpo-45866.ZH1W8N.rst
new file mode 100644
index 0000000..efa046d
--- /dev/null
+++ b/Misc/NEWS.d/next/Build/2021-11-25-13-53-36.bpo-45866.ZH1W8N.rst
@@ -0,0 +1,4 @@
+``make regen-all`` now produces the same output when run from a directory
+other than the source tree: when building Python out of the source tree.
+pegen now strips directory of the "generated by pygen from <FILENAME" header
+Patch by Victor Stinner.
diff --git a/Parser/pegen/parse.c b/Parser/pegen/parse.c
index 611257d..b80e27f 100644
--- a/Parser/pegen/parse.c
+++ b/Parser/pegen/parse.c
@@ -1,4 +1,4 @@
-// @generated by pegen.py from ./Grammar/python.gram
+// @generated by pegen.py from python.gram
#include "pegen.h"
#if defined(Py_DEBUG) && defined(Py_BUILD_CORE)
diff --git a/Tools/peg_generator/pegen/c_generator.py b/Tools/peg_generator/pegen/c_generator.py
index b5836f6..fe79717 100644
--- a/Tools/peg_generator/pegen/c_generator.py
+++ b/Tools/peg_generator/pegen/c_generator.py
@@ -1,5 +1,6 @@
import ast
from dataclasses import field, dataclass
+import os.path
import re
from typing import Any, Dict, IO, Optional, List, Text, Tuple, Set
from enum import Enum
@@ -379,7 +380,8 @@ class CParserGenerator(ParserGenerator, GrammarVisitor):
def generate(self, filename: str) -> None:
self.collect_todo()
- self.print(f"// @generated by pegen.py from {filename}")
+ basename = os.path.basename(filename)
+ self.print(f"// @generated by pegen.py from {basename}")
header = self.grammar.metas.get("header", EXTENSION_PREFIX)
if header:
self.print(header.rstrip("\n"))
diff --git a/Tools/peg_generator/pegen/grammar_parser.py b/Tools/peg_generator/pegen/grammar_parser.py
index c784cfd..50a2153 100644
--- a/Tools/peg_generator/pegen/grammar_parser.py
+++ b/Tools/peg_generator/pegen/grammar_parser.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python3.8
-# @generated by pegen from ./Tools/peg_generator/pegen/metagrammar.gram
+# @generated by pegen from metagrammar.gram
import ast
import sys
diff --git a/Tools/peg_generator/pegen/python_generator.py b/Tools/peg_generator/pegen/python_generator.py
index b786de7..530cf11 100644
--- a/Tools/peg_generator/pegen/python_generator.py
+++ b/Tools/peg_generator/pegen/python_generator.py
@@ -1,3 +1,4 @@
+import os.path
import token
from typing import Any, Dict, Optional, IO, Text, Tuple
@@ -142,7 +143,8 @@ class PythonParserGenerator(ParserGenerator, GrammarVisitor):
def generate(self, filename: str) -> None:
header = self.grammar.metas.get("header", MODULE_PREFIX)
if header is not None:
- self.print(header.rstrip("\n").format(filename=filename))
+ basename = os.path.basename(filename)
+ self.print(header.rstrip("\n").format(filename=basename))
subheader = self.grammar.metas.get("subheader", "")
if subheader:
self.print(subheader.format(filename=filename))