genhdr.targets 4.67 KB
Newer Older
stijn's avatar
stijn committed
1
2
3
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="GenerateHeaders">

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

6
7
  <!--Generate qstrdefs.h and mpversion.h similar to what is done in py/mkrules.mk-->
  <Target Name="GenerateHeaders" DependsOnTargets="MakeVersionHdr;MakeQstrData">
stijn's avatar
stijn committed
8
9
10
  </Target>

  <PropertyGroup>
11
    <DestDir>$(PyBuildDir)genhdr\</DestDir>
12
    <PySrcDir>$(PyBaseDir)py\</PySrcDir>
13
14
15
    <QstrDefs>$(PyBaseDir)unix\qstrdefsport.h</QstrDefs>
    <QstrDefsCollected>$(DestDir)qstrdefscollected.h</QstrDefsCollected>
    <QstrGen>$(DestDir)qstrdefs.generated.h</QstrGen>
16
    <PyPython Condition="'$(PyPython)' == ''">python</PyPython>
stijn's avatar
stijn committed
17
18
  </PropertyGroup>

19
20
21
22
  <ItemGroup>
    <PyQstrSourceFiles Include="@(ClCompile);$(PySrcDir)qstrdefs.h"/>
  </ItemGroup>

stijn's avatar
stijn committed
23
24
25
26
  <Target Name="MakeDestDir">
    <MakeDir Directories="$(DestDir)"/>
  </Target>

27
28
29
30
31
32
33
34
35
36
37
38
39
40
  <Target Name="MakeQstrDefs" DependsOnTargets="MakeDestDir" Inputs="@(PyQstrSourceFiles)" Outputs="$(QstrDefsCollected)">
    <ItemGroup>
      <PyIncDirs Include="$(PyIncDirs)"/>
      <PreProcDefs Include=" %(ClCompile.PreProcessorDefinitions)"/>
      <PyQstrSourceFiles>
        <Qstr>$([System.String]::new('%(FullPath)').Replace('$(PyBaseDir)', '$(DestDir)'))</Qstr>
      </PyQstrSourceFiles>
      <PyQstrSourceFiles>
        <Qstr>$([System.IO.Path]::ChangeExtension('%(Qstr)', '.qstr'))</Qstr>
        <PreProc>$([System.IO.Path]::ChangeExtension('%(Qstr)', '.pp'))</PreProc>
        <QstrDir>$([System.IO.Path]::GetDirectoryName('%(Qstr)'))</QstrDir>
        <PreProcOnly>$([System.String]::new('%(FileName)').Contains('qstrdefs'))</PreProcOnly>
      </PyQstrSourceFiles>
    </ItemGroup>
stijn's avatar
stijn committed
41
    <PropertyGroup>
42

stijn's avatar
stijn committed
43
    </PropertyGroup>
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

    <!-- Preprocess and pass to makeqstrdefs if needed, else just copy -->
    <MakeDir Directories="@(PyQstrSourceFiles->'%(QstrDir)')"/>
    <Touch Files="$(QstrGen)" AlwaysCreate="true"/>

    <Exec Command="cl /nologo /I@(PyIncDirs, ' /I') /D@(PreProcDefs, ' /D') /Fi%(PyQstrSourceFiles.PreProc) /P %(PyQstrSourceFiles.Identity)"/>
    <Exec Command="$(PyPython) $(PySrcDir)makeqstrdefs.py -s -o %(PyQstrSourceFiles.Qstr) %(PyQstrSourceFiles.PreProc)" Condition="'%(PyQstrSourceFiles.PreProcOnly)' != 'True'"/>
    <Copy SourceFiles="%(PyQstrSourceFiles.PreProc)" DestinationFiles="%(PyQstrSourceFiles.Qstr)" Condition="'%(PyQstrSourceFiles.PreProcOnly)' == 'True'"/>

    <!-- Collect all output (where qstrdefs file(s) have priority over autogenerated ones), then
         filter out lines which definitely aren't qstr definitions so we don't end up with a huge (> 10mb) filesize -->
    <ReadLinesFromFile File="%(PyQstrSourceFiles.Qstr)" Condition="'%(PyQstrSourceFiles.PreProcOnly)' == 'True'">
      <Output TaskParameter="Lines" ItemName="PreProcLines"/>
    </ReadLinesFromFile>
    <ReadLinesFromFile File="%(PyQstrSourceFiles.Qstr)">
      <Output TaskParameter="Lines" ItemName="PreProcLines"/>
    </ReadLinesFromFile>
61
    <ItemGroup>
62
      <QStrLines Include="@(PreProcLines)" Condition="$([System.String]::new('%(Identity)').Contains('Q'))"/>
63
    </ItemGroup>
64
65
66
67
68
69
70
71
72
73

    <WriteLinesToFile Lines="@(QStrLines)" File="$(QstrDefsCollected)" Overwrite="true"/>
  </Target>

  <Target Name="MakeQstrData" DependsOnTargets="MakeQstrDefs">
    <PropertyGroup>
      <TmpFile>$(DestFile).tmp</TmpFile>
    </PropertyGroup>
    <Exec Command="$(PyPython) $(PySrcDir)makeqstrdata.py $(QstrDefs) $(QstrDefsCollected) > $(TmpFile)"/>
    <MSBuild Projects="$(MSBuildThisFileFullPath)" Targets="CopyFileIfDifferent" Properties="SourceFile=$(TmpFile);DestFile=$(QstrGen)"/>
stijn's avatar
stijn committed
74
75
  </Target>

76
  <Target Name="MakeVersionHdr" DependsOnTargets="MakeDestDir">
stijn's avatar
stijn committed
77
    <PropertyGroup>
78
      <DestFile>$(DestDir)mpversion.h</DestFile>
79
      <TmpFile>$(DestFile).tmp</TmpFile>
stijn's avatar
stijn committed
80
    </PropertyGroup>
81
    <Exec Command="$(PyPython) $(PySrcDir)makeversionhdr.py $(TmpFile)"/>
82
83
84
85
86
87
88
89
90
    <MSBuild Projects="$(MSBuildThisFileFullPath)" Targets="CopyFileIfDifferent" Properties="SourceFile=$(TmpFile);DestFile=$(DestFile)"/>
  </Target>

  <!--Copies SourceFile to DestFile only if SourceFile's content differs from DestFile's.
      We use this to 'touch' the generated files only when they are really newer
      so a build is only triggered if the generated content actually changed,
      and not just because the file date changed since the last build-->
  <Target Name="CopyFileIfDifferent">
    <Exec Command="fc /B $(SourceFile) $(DestFile) > NUL 2>&amp;1" IgnoreExitCode="true">
91
92
      <Output TaskParameter="ExitCode" PropertyName="FilesDiffer" />
    </Exec>
93
    <Copy SourceFiles="$(SourceFile)" DestinationFiles="$(DestFile)" Condition="'$(FilesDiffer)'!='0'"/>
stijn's avatar
stijn committed
94
95
96
  </Target>

</Project>