Skip to content

Commit

Permalink
Enable PipelineLogger in Windows builds
Browse files Browse the repository at this point in the history
Fix script bug that prevents using logger
  • Loading branch information
ChadNedzlek authored May 9, 2019
2 parents 15bd597 + 95ad036 commit f15f32d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
10 changes: 5 additions & 5 deletions eng/common/tools.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ function InitializeBuildTool() {
ExitWithExitCode 1
}

$buildTool = @{ Path = Join-Path $dotnetRoot "dotnet.exe"; Command = "msbuild" }
$buildTool = @{ Path = Join-Path $dotnetRoot "dotnet.exe"; Command = "msbuild"; Tool = "dotnet"; Framework = "netcoreapp2.1" }
} elseif ($msbuildEngine -eq "vs") {
try {
$msbuildPath = InitializeVisualStudioMSBuild -install:$restore
Expand All @@ -367,7 +367,7 @@ function InitializeBuildTool() {
ExitWithExitCode 1
}

$buildTool = @{ Path = $msbuildPath; Command = "" }
$buildTool = @{ Path = $msbuildPath; Command = ""; Tool = "vs"; Framework = "net472" }
} else {
Write-Host "Unexpected value of -msbuildEngine: '$msbuildEngine'." -ForegroundColor Red
ExitWithExitCode 1
Expand Down Expand Up @@ -478,11 +478,11 @@ function Stop-Processes() {
# Terminates the script if the build fails.
#
function MSBuild() {
if ($pipelinesLog -and $msbuildEngine) {
if ($pipelinesLog) {
$buildTool = InitializeBuildTool
$toolsetBuildProject = InitializeToolset
$tf = if ($msbuildEngine -eq "dotnet") { "netcoreapp2.1" } else { "net472" }
$path = Split-Path -parent $toolsetBuildProject
$path = Join-Path $path "$tf\Microsoft.DotNet.Arcade.Sdk.dll"
$path = Join-Path $path (Join-Path $buildTool.Framework "Microsoft.DotNet.Arcade.Sdk.dll")
$args += "/logger:$path"
}

Expand Down
20 changes: 11 additions & 9 deletions src/Microsoft.DotNet.Arcade.Sdk/src/PipelinesLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

Expand All @@ -23,7 +20,7 @@ public sealed class PipelinesLogger : ILogger
private readonly MessageBuilder _builder = new MessageBuilder();
private readonly Dictionary<BuildEventContext, Guid> _buildEventContextMap = new Dictionary<BuildEventContext, Guid>(BuildEventContextComparer.Instance);
private readonly Dictionary<Guid, ProjectInfo> _projectInfoMap = new Dictionary<Guid, ProjectInfo>();
private readonly Dictionary<Guid, string> _targetsMap = new Dictionary<Guid, string>();
private readonly Dictionary<BuildEventContext, string> _targetsMap = new Dictionary<BuildEventContext, string>();
private readonly HashSet<Guid> _detailedLoggedSet = new HashSet<Guid>();
private readonly HttpClient _http = new HttpClient();
private HashSet<string> _ignoredTargets;
Expand Down Expand Up @@ -67,6 +64,9 @@ public void Initialize(IEventSource eventSource)
eventSource.ProjectFinished += OnProjectFinished;
eventSource.ProjectStarted += OnProjectStarted;
}

eventSource.ProjectStarted += RecordTargets;
eventSource.ProjectFinished += ReportToAnalytics;
}

public void Shutdown()
Expand Down Expand Up @@ -178,8 +178,6 @@ private void OnWarningRaised(object sender, BuildWarningEventArgs e) =>

private void OnProjectFinished(object sender, ProjectFinishedEventArgs e)
{
ReportToAnalytics(e);

if (!_buildEventContextMap.TryGetValue(e.BuildEventContext, out Guid projectId) ||
!_projectInfoMap.TryGetValue(projectId, out ProjectInfo projectInfo))
{
Expand Down Expand Up @@ -257,7 +255,12 @@ string getName()
}
}

private void ReportToAnalytics(ProjectFinishedEventArgs projectFinished)
private void RecordTargets(object sender, ProjectStartedEventArgs e)
{
_targetsMap[e.BuildEventContext] = e.TargetNames;
}

private void ReportToAnalytics(object sender, ProjectFinishedEventArgs projectFinished)
{
try
{
Expand All @@ -276,8 +279,7 @@ private void ReportToAnalytics(ProjectFinishedEventArgs projectFinished)
return;
}

if (!_buildEventContextMap.TryGetValue(projectFinished.BuildEventContext, out var id) ||
!_targetsMap.TryGetValue(id, out var targets))
if (!_targetsMap.TryGetValue(projectFinished.BuildEventContext, out var targets))
{
targets = "--";
}
Expand Down

0 comments on commit f15f32d

Please sign in to comment.