8000 msvc: Use single build target for dealing with generated files · micropython/micropython@ffc96a9 · GitHub
[go: up one dir, main page]

Skip to content

Commit ffc96a9

Browse files
committed
msvc: Use single build target for dealing with generated files
Remove some duplication in the code for generating qstrdefs.generated.h and py-version.h
1 parent fbfd355 commit ffc96a9

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

windows/msvc/genhdr.targets

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
</Target>
88

99
<PropertyGroup>
10-
<SrcDir>$(PyBaseDir)py\</SrcDir>
1110
<DestDir>$(PyBuildDir)genhdr\</DestDir>
1211
</PropertyGroup>
1312

@@ -18,19 +17,18 @@
1817
<!--see py/py.mk under #qstr data-->
1918
<Target Name="MakeQstrData" DependsOnTargets="MakeDestDir">
2019
<PropertyGroup>
20+
<PySrcDir>$(PyBaseDir)py\</PySrcDir>
2121
<PreProc>$(DestDir)qstrdefs.preprocessed.h</PreProc>
2222
<QstrDefs>$(PyBaseDir)unix\qstrdefsport.h</QstrDefs>
2323
<DestFile>$(DestDir)qstrdefs.generated.h</DestFile>
24+
<TmpFile>$(DestFile).tmp</TmpFile>
2425
</PropertyGroup>
2526
<ItemGroup>
2627
<PyIncDirs Include="$(PyIncDirs)"/>
2728
</ItemGroup>
28-
<Exec Command="cl /nologo /I@(PyIncDirs, ' /I') /Fi$(PreProc) /P $(SrcDir)qstrdefs.h"/>
29-
<Exec Command="python $(SrcDir)makeqstrdata.py $(PreProc) $(QstrDefs) > $(DestFile).tmp"/>
30-
<Exec Command="fc /B $(DestFile).tmp $(DestFile) > NUL 2>&amp;1" IgnoreExitCode="true">
31-
<Output TaskParameter="ExitCode" PropertyName="FilesDiffer" />
32-
</Exec>
33-
<Copy SourceFiles="$(DestFile).tmp" DestinationFiles="$(DestFile)" Condition="'$(FilesDiffer)'!='0'"/>
29+
<Exec Command="cl /nologo /I@(PyIncDirs, ' /I') /Fi$(PreProc) /P $(PySrcDir)qstrdefs.h"/>
30+
<Exec Command="python $(PySrcDir)makeqstrdata.py $(PreProc) $(QstrDefs) > $(TmpFile)"/>
31+
<MSBuild Projects="$(MSBuildThisFileFullPath)" Targets="CopyFileIfDifferent" Properties="SourceFile=$(TmpFile);DestFile=$(DestFile)"/>
3432
</Target>
3533

3634
<!--see py/py-version.sh-->
@@ -55,18 +53,27 @@
5553
</PropertyGroup>
5654
<PropertyGroup>
5755
<DestFile>$(DestDir)py-version.h</DestFile>
56+
<TmpFile>$(DestFile).tmp</TmpFile>
5857
</PropertyGroup>
5958
<ItemGroup>
6059
<Lines Include="// This file was generated by $([System.IO.Path]::GetFileName(`$(MsBuildThisFile)`))"/>
6160
<Lines Include="#define MICROPY_GIT_TAG &quot;$(GitTag)&quot;"/>
6261
<Lines Include="#define MICROPY_GIT_HASH &quot;$(GitHash)&quot;"/>
6362
<Lines Include="#define MICROPY_BUILD_DATE &quot;$([System.DateTime]::Now.ToString(`yyyy-MM-dd`))&quot;"/>
6463
</ItemGroup>
65-
<WriteLinesToFile Lines="@(Lines)" File="$(DestFile).tmp" Overwrite="true"/>
66-
<Exec Command="fc /B $(DestFile).tmp $(DestFile) > NUL 2>&amp;1" IgnoreExitCode="true">
64+
<WriteLinesToFile Lines="@(Lines)" File="$(TmpFile)" Overwrite="true"/>
65+
<MSBuild Projects="$(MSBuildThisFileFullPath)" Targets="CopyFileIfDifferent" Properties="SourceFile=$(TmpFile);DestFile=$(DestFile)"/>
66+
</Target>
67+
68+
<!--Copies SourceFile to DestFile only if SourceFile's content differs from DestFile's.
69+
We use this to 'touch' the generated files only when they are really newer
70+
so a build is only triggered if the generated content actually changed,
71+
and not just because the file date changed since the last build-->
72+
<Target Name="CopyFileIfDifferent">
73+
<Exec Command="fc /B $(SourceFile) $(DestFile) > NUL 2>&amp;1" IgnoreExitCode="true">
6774
<Output TaskParameter="ExitCode" PropertyName="FilesDiffer" />
6875
</Exec>
69-
<Copy SourceFiles="$(DestFile).tmp" DestinationFiles="$(DestFile)" Condition="'$(FilesDiffer)'!='0'"/>
76+
<Copy SourceFiles="$(SourceFile)" DestinationFiles="$(DestFile)" Condition="'$(FilesDiffer)'!='0'"/>
7077
</Target>
7178

7279
</Project>

0 commit comments

Comments
 (0)
0