Skip to content

Commit

Permalink
Build: use inline task to speed up build
Browse files Browse the repository at this point in the history
Avoid launching CMake when
  • Loading branch information
uxmal committed Feb 15, 2024
1 parent 4c56784 commit 01f9404
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 92 deletions.
86 changes: 0 additions & 86 deletions cmake/CheckGit.cmake

This file was deleted.

4 changes: 0 additions & 4 deletions src/BuildTargets/BuildTargets.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@
<CMake>"$(CMakeVS)"</CMake>
</PropertyGroup>

<Target Name="git_hash">
<Exec Command="$(CMake) $(CMakeArguments) -DGIT_HASH_OUTPUT=$(CustomAssemblyInfoFile) -DTARGET=git_hash -P $(RekoCMake)" />
</Target>

<!-- Builds the whole Reko solution (the ~/src/Reko-decompiler.sln) -->
<Target Name="build_solution">
<Exec Command="$(CMake) $(CMakeArguments) -DTARGET=build_solution -P $(RekoCMake)" />
Expand Down
85 changes: 85 additions & 0 deletions src/BuildTargets/UpdateGitHash.tasks
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--
This inline task asks for the short hash of the current revision,
and compares it to the hash from the previous run. If the hashes
differ, the new hash is injected into an assembly property in a C#
file which is built into Reko.Core.dll. All Reko assemblies that
wish to display the current Git hash do so by referring to the
"GitHash" assembly metadata property.
-->
<UsingTask
TaskName="UpdateGitHash"
TaskFactory="RoslynCodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll" >
<ParameterGroup>
<HashFileName Required="true" />
<TemplateFileName Required="true" />
<OutputFileName Required="true" />
</ParameterGroup>
<Task>
<!-- <Reference Include="System.Xml"/> -->
<Using Namespace="System"/>
<Using Namespace="System.Diagnostics"/>
<Using Namespace="System.IO"/>
<Using Namespace="System.Xml"/>
<Code Type="Fragment" Language="cs">
<![CDATA[

Process p = new Process();
// Redirect the output stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;

p.StartInfo.FileName = "git";
p.StartInfo.Arguments = "rev-parse --short HEAD";
p.Start();
// Read the output stream first and then wait.
string currentHash = p.StandardOutput.ReadToEnd().Trim();
p.WaitForExit();

string oldHash = "";
try {
oldHash = File.ReadAllText(HashFileName) ?? "";
} catch (Exception) {
}
Log.LogMessage(MessageImportance.Normal, $"Current git hash {currentHash}, previous hash: {oldHash}");
if (currentHash == oldHash)
return true;

string fileContents;
try {
fileContents = File.ReadAllText(TemplateFileName);
} catch (Exception ex) {
Log.LogError($"Unable to read template file {TemplateFileName}. {ex.Message}");
return false;
}
fileContents = fileContents.Replace("@GIT_HASH@", currentHash);
Log.LogMessage(MessageImportance.Normal, $"Writing git hash to {OutputFileName}");
File.WriteAllText(OutputFileName, fileContents);
Log.LogMessage(MessageImportance.Normal, $"Writing new hash file to {HashFileName}");
File.WriteAllText(HashFileName, currentHash);
]]>
</Code>
</Task>
</UsingTask>

<!-- This crude task is used for timing indivdual tasks. -->
<UsingTask
TaskName="Klokk"
TaskFactory="RoslynCodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll" >
<ParameterGroup>
</ParameterGroup>
<Task>
<Using Namespace="System"/>
<Using Namespace="System.Diagnostics"/>
<Using Namespace="System.IO"/>
<Using Namespace="System.Xml"/>
<Code Type="Fragment" Language="cs">
<![CDATA[
Log.LogMessage(MessageImportance.High, $"*** Time: {DateTime.UtcNow}");
]]>
</Code>
</Task>
</UsingTask>
</Project>
File renamed without changes.
9 changes: 7 additions & 2 deletions src/Core/Core.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$(ProjectDir)../Drivers/CommonBuildProperties.items" />
<Import Project="$(ProjectDir)../BuildTargets/UpdateGitHash.tasks" />
<!-- <Import Project="$(ProjectDir)../Drivers/ApiTracking.items " /> -->
<PropertyGroup>
<ProjectGuid>{5C315C78-1F97-4B16-81AA-917284969DFE}</ProjectGuid>
Expand Down Expand Up @@ -35,10 +36,14 @@
<Compile Include="$(CustomAssemblyInfoFile)" />
</ItemGroup>


<!-- Regenerates CustomAssemblyInfoFile, if the git hash changed -->
<Target Name="UpdateGitHash" BeforeTargets="CoreCompile">
<MSBuild Projects="$(ProjectDir)..\BuildTargets\BuildTargets.csproj" Properties="Configuration=$(Configuration);Platform=$(Platform);CustomAssemblyInfoFile=$(CustomAssemblyInfoFile)" Targets="git_hash" />
<UpdateGitHash
HashFileName="$(BaseIntermediateOutputPath)githash.txt"
TemplateFileName="$(ProjectDir)AssemblyData.Extra.cs.template"
OutputFileName="$(CustomAssemblyInfoFile)">
</UpdateGitHash>
</Target>


</Project>

0 comments on commit 01f9404

Please sign in to comment.