Skip to content

Commit 9a627e8

Browse files
stinosdpgeorge
authored andcommitted
windows/msvc: Implement automatic qstr generation using makeqstrdefs.
Note this still needs some work: currently all source files are always preprocessed no matter which one actually changed, moreover that happens file by file without any parallellism so builds are painstakingly slow.
1 parent 61b560f commit 9a627e8

1 file changed

Lines changed: 52 additions & 11 deletions

File tree

windows/msvc/genhdr.targets

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,74 @@
33

44
<Import Project="paths.props" Condition="'$(PyPathsIncluded)' != 'True'"/>
55

6-
<!--Generate qstrdefs.h and mpversion.h similar to what is done in py/py.mk-->
7-
<Target Name="GenerateHeaders" DependsOnTargets="MakeQstrData;MakeVersionHdr">
6+
<!--Generate qstrdefs.h and mpversion.h similar to what is done in py/mkrules.mk-->
7+
<Target Name="GenerateHeaders" DependsOnTargets="MakeVersionHdr;MakeQstrData">
88
</Target>
99

1010
<PropertyGroup>
1111
<DestDir>$(PyBuildDir)genhdr\</DestDir>
1212
<PySrcDir>$(PyBaseDir)py\</PySrcDir>
13+
<QstrDefs>$(PyBaseDir)unix\qstrdefsport.h</QstrDefs>
14+
<QstrDefsCollected>$(DestDir)qstrdefscollected.h</QstrDefsCollected>
15+
<QstrGen>$(DestDir)qstrdefs.generated.h</QstrGen>
1316
<PyPython Condition="'$(PyPython)' == ''">python</PyPython>
1417
</PropertyGroup>
1518

19+
<ItemGroup>
20+
<PyQstrSourceFiles Include="@(ClCompile);$(PySrcDir)qstrdefs.h"/>
21+
</ItemGroup>
22+
1623
<Target Name="MakeDestDir">
1724
<MakeDir Directories="$(DestDir)"/>
1825
</Target>
1926

20-
<Target Name="MakeQstrData" DependsOnTargets="MakeDestDir">
27+
<Target Name="MakeQstrDefs" DependsOnTargets="MakeDestDir" Inputs="@(PyQstrSourceFiles)" Outputs="$(QstrDefsCollected)">
28+
<ItemGroup>
29+
<PyIncDirs Include="$(PyIncDirs)"/>
30+
<PreProcDefs Include=" %(ClCompile.PreProcessorDefinitions)"/>
31+
<PyQstrSourceFiles>
32+
<Qstr>$([System.String]::new('%(FullPath)').Replace('$(PyBaseDir)', '$(DestDir)'))</Qstr>
33+
</PyQstrSourceFiles>
34+
<PyQstrSourceFiles>
35+
<Qstr>$([System.IO.Path]::ChangeExtension('%(Qstr)', '.qstr'))</Qstr>
36+
<PreProc>$([System.IO.Path]::ChangeExtension('%(Qstr)', '.pp'))</PreProc>
37+
<QstrDir>$([System.IO.Path]::GetDirectoryName('%(Qstr)'))</QstrDir>
38+
<PreProcOnly>$([System.String]::new('%(FileName)').Contains('qstrdefs'))</PreProcOnly>
39+
</PyQstrSourceFiles>
40+
</ItemGroup>
2141
<PropertyGroup>
22-
<PreProc>$(DestDir)qstrdefs.preprocessed.h</PreProc>
23-
<QstrDefs>$(PyBaseDir)unix\qstrdefsport.h</QstrDefs>
24-
<DestFile>$(DestDir)qstrdefs.generated.h</DestFile>
25-
<TmpFile>$(DestFile).tmp</TmpFile>
42+
2643
</PropertyGroup>
44+
45+
<!-- Preprocess and pass to makeqstrdefs if needed, else just copy -->
46+
<MakeDir Directories="@(PyQstrSourceFiles->'%(QstrDir)')"/>
47+
<Touch Files="$(QstrGen)" AlwaysCreate="true"/>
48+
49+
<Exec Command="cl /nologo /I@(PyIncDirs, ' /I') /D@(PreProcDefs, ' /D') /Fi%(PyQstrSourceFiles.PreProc) /P %(PyQstrSourceFiles.Identity)"/>
50+
<Exec Command="$(PyPython) $(PySrcDir)makeqstrdefs.py -s -o %(PyQstrSourceFiles.Qstr) %(PyQstrSourceFiles.PreProc)" Condition="'%(PyQstrSourceFiles.PreProcOnly)' != 'True'"/>
51+
<Copy SourceFiles="%(PyQstrSourceFiles.PreProc)" DestinationFiles="%(PyQstrSourceFiles.Qstr)" Condition="'%(PyQstrSourceFiles.PreProcOnly)' == 'True'"/>
52+
53+
<!-- Collect all output (where qstrdefs file(s) have priority over autogenerated ones), then
54+
filter out lines which definitely aren't qstr definitions so we don't end up with a huge (> 10mb) filesize -->
55+
<ReadLinesFromFile File="%(PyQstrSourceFiles.Qstr)" Condition="'%(PyQstrSourceFiles.PreProcOnly)' == 'True'">
56+
<Output TaskParameter="Lines" ItemName="PreProcLines"/>
57+
</ReadLinesFromFile>
58+
<ReadLinesFromFile File="%(PyQstrSourceFiles.Qstr)">
59+
<Output TaskParameter="Lines" ItemName="PreProcLines"/>
60+
</ReadLinesFromFile>
2761
<ItemGroup>
28-
<PyIncDirs Include="$(PyIncDirs)"/>
62+
<QStrLines Include="@(PreProcLines)" Condition="$([System.String]::new('%(Identity)').Contains('Q'))"/>
2963
</ItemGroup>
30-
<Exec Command="cl /nologo /I@(PyIncDirs, ' /I') /Fi$(PreProc) /P $(PySrcDir)qstrdefs.h"/>
31-
<Exec Command="$(PyPython) $(PySrcDir)makeqstrdata.py $(PreProc) $(QstrDefs) > $(TmpFile)"/>
32-
<MSBuild Projects="$(MSBuildThisFileFullPath)" Targets="CopyFileIfDifferent" Properties="SourceFile=$(TmpFile);DestFile=$(DestFile)"/>
64+
65+
<WriteLinesToFile Lines="@(QStrLines)" File="$(QstrDefsCollected)" Overwrite="true"/>
66+
</Target>
67+
68+
<Target Name="MakeQstrData" DependsOnTargets="MakeQstrDefs">
69+
<PropertyGroup>
70+
<TmpFile>$(DestFile).tmp</TmpFile>
71+
</PropertyGroup>
72+
<Exec Command="$(PyPython) $(PySrcDir)makeqstrdata.py $(QstrDefs) $(QstrDefsCollected) > $(TmpFile)"/>
73+
<MSBuild Projects="$(MSBuildThisFileFullPath)" Targets="CopyFileIfDifferent" Properties="SourceFile=$(TmpFile);DestFile=$(QstrGen)"/>
3374
</Target>
3475

3576
<Target Name="MakeVersionHdr" DependsOnTargets="MakeDestDir">

0 commit comments

Comments
 (0)