add support for converting log to structured log format

This commit is contained in:
Andrew Stanton-Nurse 2017-05-17 10:26:11 -07:00
Родитель 6dd120f709
Коммит 2ad1d7b29b
4 изменённых файлов: 36 добавлений и 1 удалений

Просмотреть файл

@ -6,6 +6,8 @@
-->
<TargetFramework>netcoreapp1.0</TargetFramework>
<StructuredLoggerVersion>1.0.130</StructuredLoggerVersion>
<!--
We want to ensure these properties do not flow into sub-builds.
This group of properties should be specified in RemoveProperties when an MSBuild task is used.
@ -35,6 +37,10 @@
environment variable to compile for .NET Framework on xplat without installing Mono.
-->
<PackageReference Include="NETFrameworkReferenceAssemblies" Version="$(NetFxVersion)" Condition="'$(NetFxVersion)'!=''" />
<!-- MSBuild Structured Logger, which we use to optimize the binary log at the end (optionally) -->
<PackageReference Include="Microsoft.Build.Logging.StructuredLogger" Version="$(StructuredLoggerVersion)" />
<!-- Additional package references required to make other targets work should be kept in the files where those targets are defined -->
</ItemGroup>
@ -55,6 +61,7 @@
<Import Project="targets\KoreBuild.Common.targets" />
<Import Project="targets\KoreBuild.SolutionItems.targets" Condition="'$(DisableDefaultItems)' != 'true'" />
<Import Project="targets\KoreBuild.SolutionBuild.targets" Condition="'$(DisableDefaultTargets)' != 'true'" />
<Import Project="targets\KoreBuild.StructuredLogging.targets" />
<Import Project="$(RepositoryRoot)build\repo.targets" Condition="Exists('$(RepositoryRoot)build\repo.targets')" />
</Project>

Просмотреть файл

@ -123,4 +123,20 @@ if (!(Test-Path $msbuildArtifactsDir))
$msBuildArguments | Out-File -Encoding ASCII -FilePath $msBuildResponseFile
__exec dotnet restore /p:PreflightRestore=true "$makeFileProj"
__exec dotnet msbuild `@"$msBuildResponseFile"
try {
__exec dotnet msbuild `@"$msBuildResponseFile"
} finally {
# If the structured logger is enabled, replay the binary log to a structured log and remove the binary log
# (can't do this in MSBuild because MSBuild logs the log, for obvious reasons)
if ($env:KOREBUILD_WRITE_STRUCTURED_LOG -eq "true") {
# Open to suggestions for a cleaner way to do this...
$r = [regex]"!StructuredLoggerVersion:([^!]*)!"
$m = $r.Match((dotnet build $makeFileProj /t:GetStructuredLoggerVersion /p:DisableDefaultTargets=true))
$StructuredLoggerPath = "$env:USERPROFILE\.nuget\packages\microsoft.build.logging.structuredlogger\$($m.Groups[1].Value)\lib\netstandard1.5\StructuredLogger.dll"
$structuredLogPath = [IO.Path]::ChangeExtension($msbuildLogFilePath, ".buildlog")
Write-Host "Building structured log..."
__exec dotnet msbuild $msbuildLogFilePath /noconlog /logger:"StructuredLogger,$StructuredLoggerPath;$StructuredLogPath" /noautoresponse
}
}

Просмотреть файл

@ -153,3 +153,10 @@ echo -e "$msbuild_args" >> $msbuildResponseFile
__exec dotnet restore /p:PreflightRestore=true /p:NetFxVersion=$netfxversion "$makeFileProj"
__exec dotnet msbuild @"$msbuildResponseFile"
if [ "$KOREBUILD_WRITE_STRUCTURED_LOG" == "true" ]; then
structuredLoggerVersion=$(dotnet build $makeFileProj /t:GetStructuredLoggerVersion /p:DisableDefaultTargets=true | grep "\!StructuredLoggerVersion" | sed 's/ *!StructuredLoggerVersion:\([^!]*\)!/\1/g')
structuredLogFile=${msbuildLogFile//.binlog/.buildlog}
structuredLoggerPath=$HOME/.nuget/packages/microsoft.build.logging.structuredlogger/$structuredLoggerVersion/lib/netstandard1.5/StructuredLogger.dll
__exec dotnet msbuild $msbuildLogFile /noconlog /logger:"StructuredLogger,$structuredLoggerPath;$structuredLogFile" /noautoresponse
fi

Просмотреть файл

@ -0,0 +1,5 @@
<Project>
<Target Name="GetStructuredLoggerVersion">
<Message Text="!StructuredLoggerVersion:$(StructuredLoggerVersion)!" Importance="high" />
</Target>
</Project>