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

Skip to content

Commit 9e36589

Browse files
tonybaloneyzooba
authored andcommitted
bpo-36500: Add --regen option to PCbuild/build.bat so Windows users can regen grammar, opcodes, tokens and symbols (GH-12654)
1 parent 9707e8e commit 9e36589

3 files changed

Lines changed: 243 additions & 1 deletion

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Added an optional "regen" project to the Visual Studio solution that will
2+
regenerate all grammar, tokens, and opcodes.

PCbuild/build.bat

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ echo. automatically by the pythoncore project)
3232
echo. --pgo Build with Profile-Guided Optimization. This flag
3333
echo. overrides -c and -d
3434
echo. --test-marker Enable the test marker within the build.
35+
echo. --regen Regenerate all opcodes, grammar and tokens
3536
echo.
3637
echo.Available flags to avoid building certain modules.
3738
echo.These flags have no effect if '-e' is not given:
@@ -76,7 +77,8 @@ if "%~1"=="-k" (set kill=true) & shift & goto CheckOpts
7677
if "%~1"=="--pgo" (set do_pgo=true) & shift & goto CheckOpts
7778
if "%~1"=="--pgo-job" (set do_pgo=true) & (set pgo_job=%~2) & shift & shift & goto CheckOpts
7879
if "%~1"=="--test-marker" (set UseTestMarker=true) & shift & goto CheckOpts
79-
if "%~1"=="-V" shift & goto :Version
80+
if "%~1"=="-V" shift & goto Version
81+
if "%~1"=="--regen" (set Regen=true) & shift & goto CheckOpts
8082
rem These use the actual property names used by MSBuild. We could just let
8183
rem them in through the environment, but we specify them on the command line
8284
rem anyway for visibility so set defaults after this
@@ -154,9 +156,22 @@ echo on
154156
/p:UseTestMarker=%UseTestMarker% %GITProperty%^
155157
%1 %2 %3 %4 %5 %6 %7 %8 %9
156158

159+
if "%Regen%"=="true" call :Regen
157160
@echo off
158161
exit /b %ERRORLEVEL%
159162

163+
:Regen
164+
echo on
165+
call "%dir%find_msbuild.bat" %MSBUILD%
166+
if not ERRORLEVEL 1 %MSBUILD% "%dir%regen.vcxproj" /t:%target% %parallel% %verbose%^
167+
/p:IncludeExternals=%IncludeExternals%^
168+
/p:Configuration=%conf% /p:Platform=%platf%^
169+
/p:UseTestMarker=%UseTestMarker% %GITProperty%^
170+
%1 %2 %3 %4 %5 %6 %7 %8 %9
171+
172+
@echo off
173+
goto :eof
174+
160175
:Version
161176
rem Display the current build version information
162177
call "%dir%find_msbuild.bat" %MSBUILD%

PCbuild/regen.vcxproj

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|ARM">
5+
<Configuration>Debug</Configuration>
6+
<Platform>ARM</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Debug|Win32">
9+
<Configuration>Debug</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="PGInstrument|ARM">
17+
<Configuration>PGInstrument</Configuration>
18+
<Platform>ARM</Platform>
19+
</ProjectConfiguration>
20+
<ProjectConfiguration Include="PGInstrument|Win32">
21+
<Configuration>PGInstrument</Configuration>
22+
<Platform>Win32</Platform>
23+
</ProjectConfiguration>
24+
<ProjectConfiguration Include="PGInstrument|x64">
25+
<Configuration>PGInstrument</Configuration>
26+
<Platform>x64</Platform>
27+
</ProjectConfiguration>
28+
<ProjectConfiguration Include="PGUpdate|ARM">
29+
<Configuration>PGUpdate</Configuration>
30+
<Platform>ARM</Platform>
31+
</ProjectConfiguration>
32+
<ProjectConfiguration Include="PGUpdate|Win32">
33+
<Configuration>PGUpdate</Configuration>
34+
<Platform>Win32</Platform>
35+
</ProjectConfiguration>
36+
<ProjectConfiguration Include="PGUpdate|x64">
37+
<Configuration>PGUpdate</Configuration>
38+
<Platform>x64</Platform>
39+
</ProjectConfiguration>
40+
<ProjectConfiguration Include="Release|ARM">
41+
<Configuration>Release</Configuration>
42+
<Platform>ARM</Platform>
43+
</ProjectConfiguration>
44+
<ProjectConfiguration Include="Release|Win32">
45+
<Configuration>Release</Configuration>
46+
<Platform>Win32</Platform>
47+
</ProjectConfiguration>
48+
<ProjectConfiguration Include="Release|x64">
49+
<Configuration>Release</Configuration>
50+
<Platform>x64</Platform>
51+
</ProjectConfiguration>
52+
</ItemGroup>
53+
<PropertyGroup Label="Globals">
54+
<ProjectGuid>{21CF2108-2CC9-4005-A6ED-B7965ADE3854}</ProjectGuid>
55+
<Keyword>Win32Proj</Keyword>
56+
<RootNamespace>regen</RootNamespace>
57+
<SupportPGO>false</SupportPGO>
58+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
59+
</PropertyGroup>
60+
<Import Project="python.props" />
61+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
62+
<PropertyGroup Label="Configuration">
63+
<ConfigurationType>Utility</ConfigurationType>
64+
<CharacterSet>Unicode</CharacterSet>
65+
</PropertyGroup>
66+
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
67+
<PlatformToolset>v142</PlatformToolset>
68+
</PropertyGroup>
69+
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">
70+
<PlatformToolset>v142</PlatformToolset>
71+
</PropertyGroup>
72+
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
73+
<PlatformToolset>v142</PlatformToolset>
74+
</PropertyGroup>
75+
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
76+
<PlatformToolset>v142</PlatformToolset>
77+
</PropertyGroup>
78+
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">
79+
<PlatformToolset>v142</PlatformToolset>
80+
</PropertyGroup>
81+
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
82+
<PlatformToolset>v142</PlatformToolset>
83+
</PropertyGroup>
84+
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='PGUpdate|x64'">
85+
<PlatformToolset>v142</PlatformToolset>
86+
</PropertyGroup>
87+
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='PGUpdate|ARM'">
88+
<PlatformToolset>v142</PlatformToolset>
89+
</PropertyGroup>
90+
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='PGUpdate|Win32'">
91+
<PlatformToolset>v142</PlatformToolset>
92+
</PropertyGroup>
93+
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='PGInstrument|ARM'">
94+
<PlatformToolset>v142</PlatformToolset>
95+
</PropertyGroup>
96+
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='PGInstrument|x64'">
97+
<PlatformToolset>v142</PlatformToolset>
98+
</PropertyGroup>
99+
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='PGInstrument|Win32'">
100+
<PlatformToolset>v142</PlatformToolset>
101+
</PropertyGroup>
102+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
103+
<ImportGroup Label="ExtensionSettings">
104+
</ImportGroup>
105+
<ImportGroup Label="PropertySheets">
106+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
107+
<Import Project="pyproject.props" />
108+
</ImportGroup>
109+
<PropertyGroup Label="UserMacros" />
110+
<ItemDefinitionGroup>
111+
<ClCompile>
112+
<PreprocessorDefinitions>_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
113+
</ClCompile>
114+
<Link>
115+
<SubSystem>Console</SubSystem>
116+
</Link>
117+
</ItemDefinitionGroup>
118+
<ItemGroup>
119+
<ClCompile Include="..\Programs\_freeze_importlib.c" />
120+
</ItemGroup>
121+
<ItemGroup>
122+
<ProjectReference Include="pythoncore.vcxproj">
123+
<Project>{cf7ac3d1-e2df-41d2-bea6-1e2556cdea26}</Project>
124+
<Private>true</Private>
125+
<ReferenceOutputAssembly>true</ReferenceOutputAssembly>
126+
<CopyLocalSatelliteAssemblies>false</CopyLocalSatelliteAssemblies>
127+
<LinkLibraryDependencies>true</LinkLibraryDependencies>
128+
<UseLibraryDependencyInputs>false</UseLibraryDependencyInputs>
129+
</ProjectReference>
130+
</ItemGroup>
131+
<ItemGroup>
132+
<None Include="..\Grammar\Grammar">
133+
</None>
134+
<None Include="..\Grammar\Tokens">
135+
</None>
136+
<None Include="..\Include\graminit.h">
137+
</None>
138+
<None Include="..\Python\graminit.c">
139+
</None>
140+
<None Include="..\Include\token.h">
141+
</None>
142+
<None Include="..\Include\opcode.h">
143+
</None>
144+
<None Include="..\Include\Python-ast.h">
145+
</None>
146+
<None Include="..\Python\Python-ast.c">
147+
</None>
148+
<None Include="..\Lib\keyword.py">
149+
</None>
150+
<None Include="..\Lib\symbol.py">
151+
</None>
152+
<None Include="..\Doc\library\token-list.inc">
153+
</None>
154+
</ItemGroup>
155+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
156+
<ImportGroup Label="ExtensionTargets">
157+
</ImportGroup>
158+
<Target Name="_RegenGrammar" BeforeTargets="Build">
159+
<!-- Regenerate Include/graminit.h and Python/graminit.c from Grammar/Grammar using pgen-->
160+
<Exec Command="&quot;$(PythonExe)&quot; -m Parser.pgen &quot;$(PySourcePath)Grammar\Grammar&quot; &quot;$(PySourcePath)Grammar\Tokens&quot; &quot;$(IntDir)graminit.h&quot; &quot;$(IntDir)graminit.c&quot;" />
161+
<Copy SourceFiles="$(IntDir)graminit.h" DestinationFiles="$(PySourcePath)Include\graminit.h">
162+
<Output TaskParameter="CopiedFiles" ItemName="_UpdatedH" />
163+
</Copy>
164+
<Copy SourceFiles="$(IntDir)graminit.c" DestinationFiles="$(PySourcePath)Python\graminit.c">
165+
<Output TaskParameter="CopiedFiles" ItemName="_UpdatedC" />
166+
</Copy>
167+
<Warning Text="Grammar updated. You will need to rebuild pythoncore to see the changes." Condition="'@(_UpdatedH)' != '' and '@(_UpdatedC)' != ''" />
168+
</Target>
169+
<Target Name="_RegenAST_H" AfterTargets="_RegenGrammar">
170+
<!-- Regenerate Include/Python-ast.h using Parser/asdl_c.py -h -->
171+
<Exec Command="&quot;$(PythonExe)&quot; &quot;$(PySourcePath)Parser\asdl_c.py&quot; -h &quot;$(IntDir)Python-ast.h&quot; &quot;$(PySourcePath)Parser\Python.asdl&quot;" />
172+
<Copy SourceFiles="$(IntDir)Python-ast.h" DestinationFiles="$(PySourcePath)Include\Python-ast.h">
173+
<Output TaskParameter="CopiedFiles" ItemName="_UpdatedH" />
174+
</Copy>
175+
<Warning Text="Python-ast.h updated. You will need to rebuild pythoncore to see the changes." Condition="'@(_UpdatedH)' != '' and '@(_UpdatedC)' != ''" />
176+
</Target>
177+
<Target Name="_RegenAST_C" AfterTargets="_RegenGrammar">
178+
<!-- Regenerate Python/Python-ast.c using Parser/asdl_c.py -c -->
179+
<Exec Command="&quot;$(PythonExe)&quot; &quot;$(PySourcePath)Parser\asdl_c.py&quot; -c &quot;$(IntDir)Python-ast.c&quot; &quot;$(PySourcePath)Parser\Python.asdl&quot;" />
180+
<Copy SourceFiles="$(IntDir)Python-ast.c" DestinationFiles="$(PySourcePath)Python\Python-ast.c">
181+
<Output TaskParameter="CopiedFiles" ItemName="_UpdatedH" />
182+
</Copy>
183+
<Warning Text="Python-ast.c updated. You will need to rebuild pythoncore to see the changes." Condition="'@(_UpdatedH)' != '' and '@(_UpdatedC)' != ''" />
184+
</Target>
185+
<Target Name="_RegenOpcodes" AfterTargets="_RegenAST_C">
186+
<!-- Regenerate Include/opcode.h from Lib/opcode.py using Tools/scripts/generate_opcode_h.py-->
187+
<Exec Command="&quot;$(PythonExe)&quot; $(PySourcePath)Tools\scripts\generate_opcode_h.py &quot;$(PySourcePath)Lib\opcode.py&quot; &quot;$(IntDir)opcode.h&quot;" />
188+
<Copy SourceFiles="$(IntDir)opcode.h" DestinationFiles="$(PySourcePath)Include\opcode.h">
189+
<Output TaskParameter="CopiedFiles" ItemName="_Updated" />
190+
</Copy>
191+
<Warning Text="Opcodes updated. You will need to rebuild pythoncore to see the changes." Condition="'@(_Updated)' != ''" />
192+
</Target>
193+
<Target Name="_RegenTokens" AfterTargets="_RegenOpcodes">
194+
<!-- Regenerate Doc/library/token-list.inc from Grammar/Tokens using Tools/scripts/generate_token.py-->
195+
<Exec Command="&quot;$(PythonExe)&quot; $(PySourcePath)Tools\scripts\generate_token.py rst &quot;$(PySourcePath)Grammar\Tokens&quot; &quot;$(PySourcePath)Doc\library\token-list.inc&quot;" />
196+
<!-- Regenerate Include/token.h from Grammar/Tokens using Tools/scripts/generate_token.py-->
197+
<Exec Command="&quot;$(PythonExe)&quot; $(PySourcePath)Tools\scripts\generate_token.py h &quot;$(PySourcePath)Grammar\Tokens&quot; &quot;$(PySourcePath)Include\token.h&quot;" />
198+
<!-- Regenerate Parser/token.c from Grammar/Tokens using Tools/scripts/generate_token.py-->
199+
<Exec Command="&quot;$(PythonExe)&quot; $(PySourcePath)Tools\scripts\generate_token.py c &quot;$(PySourcePath)Grammar\Tokens&quot; &quot;$(PySourcePath)Parser\token.c&quot;" />
200+
<!-- Regenerate Lib/token.py from Grammar/Tokens using Tools/scripts/generate_token.py -->
201+
<Exec Command="&quot;$(PythonExe)&quot; $(PySourcePath)Tools\scripts\generate_token.py py &quot;$(PySourcePath)Grammar\Tokens&quot; &quot;$(PySourcePath)Lib\token.py&quot;" />
202+
</Target>
203+
<Target Name="_RegenKeywords" AfterTargets="_RegenTokens">
204+
<!-- Regenerate Lib/keyword.py from Grammar/Grammar and Grammar/Tokens using Parser/pgen-->
205+
<Exec Command="&quot;$(PythonExe)&quot; -m Parser.pgen.keywordgen &quot;$(PySourcePath)Grammar\Grammar&quot; &quot;$(PySourcePath)Grammar\Tokens&quot; &quot;$(IntDir)keyword.py&quot;" />
206+
<Copy SourceFiles="$(IntDir)keyword.py" DestinationFiles="$(PySourcePath)Lib\keyword.py">
207+
<Output TaskParameter="CopiedFiles" ItemName="_Updated" />
208+
</Copy>
209+
<Warning Text="Keywords updated. You will need to rebuild pythoncore to see the changes." Condition="'@(_Updated)' != ''" />
210+
</Target>
211+
<Target Name="_RegenSymbols" AfterTargets="_RegenKeywords">
212+
<!-- Regenerate Lib/symbol.py from Include/graminit.h using Tools/scripts/generate_symbol_py.py-->
213+
<Exec Command="&quot;$(PythonExe)&quot; $(PySourcePath)Tools\scripts\generate_symbol_py.py &quot;$(PySourcePath)Include\graminit.h&quot; &quot;$(PySourcePath)Lib\symbol.py&quot;" />
214+
</Target>
215+
<Target Name="_CleanFiles" BeforeTargets="CoreClean">
216+
<ItemGroup>
217+
<Clean Include="$(IntDir)keyword.py" />
218+
<Clean Include="$(IntDir)opcode.h" />
219+
<Clean Include="$(IntDir)Python-ast.c" />
220+
<Clean Include="$(IntDir)Python-ast.h" />
221+
<Clean Include="$(IntDir)graminit.h.new" />
222+
<Clean Include="$(IntDir)graminit.c.new" />
223+
</ItemGroup>
224+
</Target>
225+
</Project>

0 commit comments

Comments
 (0)