micropython/windows/msvc/genhdr.targets

80 lines
3.8 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="GenerateHeaders">
<Import Project="env.props" Condition="$(PyEnvIncluded)!=True"/>
<Target Name="GenerateHeaders" DependsOnTargets="MakeQstrData;MakeVersionHeader">
</Target>
<PropertyGroup>
<DestDir>$(PyBuildDir)genhdr\</DestDir>
</PropertyGroup>
<Target Name="MakeDestDir">
<MakeDir Directories="$(DestDir)"/>
</Target>
<!--see py/py.mk under #qstr data-->
<Target Name="MakeQstrData" DependsOnTargets="MakeDestDir">
<PropertyGroup>
<PySrcDir>$(PyBaseDir)py\</PySrcDir>
<PreProc>$(DestDir)qstrdefs.preprocessed.h</PreProc>
<QstrDefs>$(PyBaseDir)unix\qstrdefsport.h</QstrDefs>
<DestFile>$(DestDir)qstrdefs.generated.h</DestFile>
<TmpFile>$(DestFile).tmp</TmpFile>
</PropertyGroup>
<ItemGroup>
<PyIncDirs Include="$(PyIncDirs)"/>
</ItemGroup>
<Exec Command="cl /nologo /I@(PyIncDirs, ' /I') /Fi$(PreProc) /P $(PySrcDir)qstrdefs.h"/>
<Exec Command="python $(PySrcDir)makeqstrdata.py $(PreProc) $(QstrDefs) > $(TmpFile)"/>
<MSBuild Projects="$(MSBuildThisFileFullPath)" Targets="CopyFileIfDifferent" Properties="SourceFile=$(TmpFile);DestFile=$(DestFile)"/>
</Target>
<!--see py/py-version.sh-->
<Target Name="GetGitState">
<Exec Command="git describe --dirty --always" ConsoleToMSBuild="true" IgnoreExitCode="true">
<Output TaskParameter="ConsoleOutput" PropertyName="GitTag" />
</Exec>
<Exec Command="git rev-parse --short HEAD 2>NUL || echo unknown" ConsoleToMSBuild="true" IgnoreExitCode="true">
<Output TaskParameter="ConsoleOutput" PropertyName="GitHash" />
</Exec>
<Exec Command="git diff --no-ext-diff --quiet --exit-code 2>NUL || echo 0" ConsoleToMSBuild="true" IgnoreExitCode="true">
<Output TaskParameter="ConsoleOutput" PropertyName="GitFilesAreClean" />
</Exec>
<Exec Command="git diff-index --cached --quiet HEAD -- 2>NUL || echo 0" ConsoleToMSBuild="true" IgnoreExitCode="true" Condition="'$(GitFilesAreClean)'==''">
<Output TaskParameter="ConsoleOutput" PropertyName="GitFilesAreClean" />
</Exec>
</Target>
<Target Name="MakeVersionHeader" DependsOnTargets="MakeDestDir;GetGitState">
<PropertyGroup Condition="'$(GitFilesAreClean)'=='0'">
<GitHash>$(GitHash)-dirty</GitHash>
</PropertyGroup>
<PropertyGroup>
<DestFile>$(DestDir)py-version.h</DestFile>
<TmpFile>$(DestFile).tmp</TmpFile>
</PropertyGroup>
<ItemGroup>
<Lines Include="// This file was generated by $([System.IO.Path]::GetFileName(`$(MsBuildThisFile)`))"/>
<Lines Include="#define MICROPY_GIT_TAG &quot;$(GitTag)&quot;"/>
<Lines Include="#define MICROPY_GIT_HASH &quot;$(GitHash)&quot;"/>
<Lines Include="#define MICROPY_BUILD_DATE &quot;$([System.DateTime]::Now.ToString(`yyyy-MM-dd`))&quot;"/>
</ItemGroup>
<WriteLinesToFile Lines="@(Lines)" File="$(TmpFile)" Overwrite="true"/>
<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">
<Output TaskParameter="ExitCode" PropertyName="FilesDiffer" />
</Exec>
<Copy SourceFiles="$(SourceFile)" DestinationFiles="$(DestFile)" Condition="'$(FilesDiffer)'!='0'"/>
</Target>
</Project>