-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
lxmonika.targets
88 lines (87 loc) · 3.88 KB
/
lxmonika.targets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="MonikaAppendDetails" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<ItemList ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" />
<AddQuotes ParameterType="System.Boolean" Required="true" />
<OutputItemList ParameterType="Microsoft.Build.Framework.ITaskItem[]" Output="true" />
</ParameterGroup>
<Task>
<Using Namespace="System.Diagnostics" />
<Code Type="Fragment" Language="cs"><![CDATA[
const string metadataName = "PreprocessorDefinitions";
string toAppend = "";
void Append(string varName, string value)
{
toAppend += AddQuotes ? $";{varName}=\"{value}\"" : $";{varName}={value}";
}
string Run(string command)
{
var p = new Process();
p.StartInfo = new ProcessStartInfo("git", command);
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.Start();
p.WaitForExit();
return p.StandardOutput.ReadToEnd().Trim();
}
void AppendRun(string varName, string command)
{
Append(varName, Run(command));
}
if (Run("branch --show-current") == "master")
{
AppendRun("MONIKA_BUILD_NUMBER", "rev-list --count master");
}
else
{
var mergeBase = Run("merge-base refs/remotes/origin/master HEAD");
var masterCount = Run($"rev-list --count {mergeBase}");
var divergeCount = Run($"rev-list --count {mergeBase}..HEAD");
if (AddQuotes)
{
Append("MONIKA_BUILD_NUMBER", $"{masterCount}+{divergeCount}");
}
else
{
// The build number is interpreted as an integer literal for resources.
Append("MONIKA_BUILD_NUMBER", $"{masterCount}");
}
}
AppendRun("MONIKA_BUILD_TAG", "describe --broken --dirty --all");
AppendRun("MONIKA_BUILD_HASH", "rev-parse --short HEAD");
AppendRun("MONIKA_BUILD_ORIGIN", "remote get-url origin");
foreach (var item in ItemList)
{
var cur = item.GetMetadata(metadataName);
item.SetMetadata(metadataName, $"{toAppend};{cur}");
}
OutputItemList = ItemList;
]]></Code>
</Task>
</UsingTask>
<Target Name="MonikaAppendDetailsToClCompileItems" BeforeTargets="Build;CL;BeforeClCompile">
<ItemGroup>
<ClCompileCopy Include="@(ClCompile)" />
<ClCompile Remove="@(ClCompile)" />
<ResourceCompileCopy Include="@(ResourceCompile)" />
<ResourceCompile Remove="@(ResourceCompile)" />
</ItemGroup>
<MonikaAppendDetails ItemList="@(ClCompileCopy)" AddQuotes="true">
<Output ItemName="ClCompile" TaskParameter="OutputItemList" />
</MonikaAppendDetails>
<MonikaAppendDetails ItemList="@(ResourceCompileCopy)" AddQuotes="false">
<Output ItemName="ResourceCompile" TaskParameter="OutputItemList" />
</MonikaAppendDetails>
<ItemGroup>
<ClCompileCopy Remove="@(ClCompileCopy)" />
<ResourceCompileCopy Remove="@(ResourceCompileCopy)" />
</ItemGroup>
</Target>
<Target Name="MonikaFixToolPaths" Condition="$(MaTargetPlatformVersion) != ''"
BeforeTargets="Manifest;ResourceCompile;TestSign">
<PropertyGroup>
<RCToolPath>$([System.String]::Copy('$(RCToolPath)').Replace('$(MaTargetPlatformVersion)','$(MaLatestTargetPlatformVersion)'))</RCToolPath>
<DriverSignToolPath>$([System.String]::Copy('$(DriverSignToolPath)').Replace('$(MaTargetPlatformVersion)','$(MaLatestTargetPlatformVersion)'))</DriverSignToolPath>
</PropertyGroup>
</Target>
</Project>