1<?xml version="1.0" encoding="utf-8"?>
2<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3  <ItemGroup>
4    <_PegenSources Include="$(PySourcePath)Grammar\python.gram;$(PySourcePath)Grammar\Tokens" />
5    <_PegenOutputs Include="$(PySourcePath)Parser\parser.c" />
6    <_ASTSources Include="$(PySourcePath)Parser\Python.asdl" />
7    <_ASTOutputs Include="$(PySourcePath)Include\internal\pycore_ast.h">
8      <Argument>-H</Argument>
9    </_ASTOutputs>
10    <_ASTOutputs Include="$(PySourcePath)Include\internal\pycore_ast_state.h">
11      <Argument>-I</Argument>
12    </_ASTOutputs>
13    <_ASTOutputs Include="$(PySourcePath)Python\Python-ast.c">
14      <Argument>-C</Argument>
15    </_ASTOutputs>
16    <_OpcodeSources Include="$(PySourcePath)Tools\scripts\generate_opcode_h.py;$(PySourcePath)Lib\opcode.py" />
17    <_OpcodeOutputs Include="$(PySourcePath)Include\opcode.h;$(PySourcePath)Include\internal\pycore_opcode.h;$(PySourcePath)Python\opcode_targets.h" />
18    <_TokenSources Include="$(PySourcePath)Grammar\Tokens" />
19    <_TokenOutputs Include="$(PySourcePath)Doc\library\token-list.inc">
20      <Format>rst</Format>
21    </_TokenOutputs>
22    <_TokenOutputs Include="$(PySourcePath)Include\token.h">
23      <Format>h</Format>
24    </_TokenOutputs>
25    <_TokenOutputs Include="$(PySourcePath)Parser\token.c">
26      <Format>c</Format>
27    </_TokenOutputs>
28    <_TokenOutputs Include="$(PySourcePath)Lib\token.py">
29      <Format>py</Format>
30    </_TokenOutputs>
31    <_KeywordSources Include="$(PySourcePath)Grammar\python.gram;$(PySourcePath)Grammar\Tokens" />
32    <_KeywordOutputs Include="$(PySourcePath)Lib\keyword.py" />
33  </ItemGroup>
34
35  <Target Name="_TouchRegenSources" Condition="$(ForceRegen) == 'true'">
36    <Message Text="Touching source files to force regeneration" Importance="high" />
37    <Touch Files="@(_PegenSources);@(_ASTSources);@(_OpcodeSources);@(_TokenSources);@(_KeywordOutputs)"
38           AlwaysCreate="False" />
39  </Target>
40
41  <Target Name="_RegenPegen"
42          Inputs="@(_PegenSources)" Outputs="@(_PegenOutputs)"
43          DependsOnTargets="FindPythonForBuild">
44    <Message Text="Regenerate @(_PegenOutputs->'%(Filename)%(Extension)',' ')" Importance="high" />
45    <!-- Specify python.gram with POSIX-like path because the argument gets written into the file verbatim -->
46    <Exec Command="set PYTHONPATH=Tools\peg_generator%0D%0A$(PythonForBuild) -m pegen -q c ./Grammar/python.gram Grammar\Tokens -o Parser\parser.c"
47          WorkingDirectory="$(PySourcePath)" />
48  </Target>
49
50  <Target Name="_RegenAST_H"
51          Inputs="@(_ASTSources)" Outputs="@(_ASTOutputs)"
52          DependsOnTargets="FindPythonForBuild">
53    <Message Text="Regenerate @(_ASTOutputs->'%(Filename)%(Extension)',' ')" Importance="high" />
54    <Exec Command="$(PythonForBuild) Parser\asdl_c.py Parser\Python.asdl @(_ASTOutputs->'%(Argument) &quot;%(Identity)&quot;',' ')"
55          WorkingDirectory="$(PySourcePath)" />
56  </Target>
57
58  <Target Name="_RegenOpcodes"
59          Inputs="@(_OpcodeSources)" Outputs="@(_OpcodeOutputs)"
60          DependsOnTargets="FindPythonForBuild">
61    <Message Text="Regenerate @(_OpcodeOutputs->'%(Filename)%(Extension)',' ')" Importance="high" />
62    <Exec Command="$(PythonForBuild) Tools\scripts\generate_opcode_h.py Lib\opcode.py Include\opcode.h Include\internal\pycore_opcode.h"
63          WorkingDirectory="$(PySourcePath)" />
64    <Exec Command="$(PythonForBuild) Python\makeopcodetargets.py Python\opcode_targets.h"
65          WorkingDirectory="$(PySourcePath)" />
66  </Target>
67
68  <Target Name="_RegenTokens"
69          Inputs="@(_TokenSources)" Outputs="@(_TokenOutputs)"
70          DependsOnTargets="FindPythonForBuild">
71    <Message Text="Regenerate @(_TokenOutputs->'%(Filename)%(Extension)',' ')" Importance="high" />
72    <Exec Command="$(PythonForBuild) Tools\scripts\generate_token.py %(_TokenOutputs.Format) Grammar\Tokens &quot;%(_TokenOutputs.Identity)&quot;"
73          WorkingDirectory="$(PySourcePath)" />
74    <Touch Files="@(_TokenOutputs)" />
75  </Target>
76
77  <Target Name="_RegenKeywords"
78          Inputs="@(_KeywordSources)" Outputs="@(_KeywordOutputs)"
79          DependsOnTargets="FindPythonForBuild">
80    <Message Text="Regenerate @(_KeywordOutputs->'%(Filename)%(Extension)',' ')" Importance="high" />
81    <Exec Command="set PYTHONPATH=Tools\peg_generator%0D%0A$(PythonForBuild) -m pegen.keywordgen Grammar\python.gram Grammar\Tokens Lib\keyword.py"
82          WorkingDirectory="$(PySourcePath)" />
83  </Target>
84
85  <Target Name="Regen"
86          Condition="$(Configuration) != 'PGUpdate'"
87          DependsOnTargets="_TouchRegenSources;_RegenPegen;_RegenAST_H;_RegenOpcodes;_RegenTokens;_RegenKeywords">
88    <Message Text="Generated sources are up to date" Importance="high" />
89  </Target>
90
91
92  <ItemGroup>
93    <_TestFrozenSources Include="$(PySourcePath)Programs\freeze_test_frozenmain.py;
94                                 $(PySourcePath)Programs\test_frozenmain.py;
95                                 @(_OpcodeOutputs)" />
96    <_TestFrozenOutputs Include="$(PySourcePath)Programs\test_frozenmain.h" />
97    <_LicenseSources Include="$(PySourcePath)LICENSE;
98                              $(PySourcePath)PC\crtlicense.txt;
99                              $(bz2Dir)LICENSE;
100                              $(opensslOutDir)LICENSE;
101                              $(libffiDir)LICENSE;" />
102    <_LicenseSources Include="$(tcltkDir)tcllicense.terms;
103                              $(tcltkDir)tklicense.terms;
104                              $(tcltkDir)tixlicense.terms" Condition="$(IncludeTkinter)" />
105  </ItemGroup>
106
107  <Target Name="_RegenTestFrozenmain" Inputs="@(_TestFrozenSources)" Outputs="@(_TestFrozenOutputs)"
108          Condition="($(Platform) == 'Win32' or $(Platform) == 'x64') and
109                     $(Configuration) != 'PGInstrument' and $(Configuration) != 'PGUpdate'">
110    <Message Text="Regenerate @(_TestFrozenOutputs->'%(Filename)%(Extension)', ' ')" Importance="high" />
111    <Exec Command='setlocal%0D%0Aset PYTHONPATH=$(PySourcePath)Lib%0D%0A"$(PythonExe)" Programs\freeze_test_frozenmain.py Programs\test_frozenmain.h'
112          WorkingDirectory="$(PySourcePath)" />
113  </Target>
114
115  <Target Name="_RegenLicense">
116    <ItemGroup>
117      <_Text1 Include="@(_LicenseSources)">
118        <Content Condition="Exists(%(FullPath))">$([System.IO.File]::ReadAllText(%(FullPath)))</Content>
119      </_Text1>
120      <_Text Include="@(_Text1->'%(Content)')" />
121    </ItemGroup>
122
123    <WriteLinesToFile File="$(OutDir)LICENSE.txt" Overwrite="true" Lines="@(_Text)" />
124    <Warning Text="License file %(_LicenseSources.FullPath) is missing"
125             Condition="!Exists(@(_LicenseSources))" />
126    <Message Text="Wrote $(OutDir)LICENSE.txt" Importance="high" />
127  </Target>
128
129  <Target Name="PostBuildRegen" DependsOnTargets="_RegenTestFrozenmain;_RegenLicense" />
130</Project>
131