Skip to content

Commit

Permalink
Another attempt at avoiding BuildXL assembly load
Browse files Browse the repository at this point in the history
  • Loading branch information
dfederm committed Aug 31, 2023
1 parent 7dd37d8 commit 180ff51
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 26 deletions.
27 changes: 7 additions & 20 deletions src/Build/BackEnd/BuildManager/BuildManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,13 @@ public void BeginBuild(BuildParameters parameters)
#if FEATURE_REPORTFILEACCESSES
if (_buildParameters.ReportFileAccesses)
{
EnableDetouredNodeLauncher();
// To properly report file access, we need to disable the in-proc node which won't be detoured.
_buildParameters.DisableInProcNode = true;

// Node reuse must be disabled as future builds will not be able to listen to events raised by detours.
_buildParameters.EnableNodeReuse = false;

_componentFactories.ReplaceFactory(BuildComponentType.NodeLauncher, DetouredNodeLauncherFactory.CreateComponent);
}
#endif

Expand Down Expand Up @@ -717,25 +723,6 @@ void InitializeCaches()
}
}

#if FEATURE_REPORTFILEACCESSES
/// <summary>
/// Configure the build to use I/O tracking for nodes.
/// </summary>
/// <remarks>
/// Must be a separate method to avoid loading the BuildXL assembly when not opted in.
/// </remarks>
private void EnableDetouredNodeLauncher()
{
// To properly report file access, we need to disable the in-proc node which won't be detoured.
_buildParameters.DisableInProcNode = true;

// Node reuse must be disabled as future builds will not be able to listen to events raised by detours.
_buildParameters.EnableNodeReuse = false;

_componentFactories.ReplaceFactory(BuildComponentType.NodeLauncher, DetouredNodeLauncher.CreateComponent);
}
#endif

private static void AttachDebugger()
{
if (Debugger.IsAttached)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ internal sealed class DetouredNodeLauncher : INodeLauncher, IBuildComponent

private IFileAccessManager _fileAccessManager;

public static IBuildComponent CreateComponent(BuildComponentType type)
{
ErrorUtilities.VerifyThrowArgumentOutOfRange(type == BuildComponentType.NodeLauncher, nameof(type));
return new DetouredNodeLauncher();
}

public void InitializeComponent(IBuildComponentHost host)
{
_fileAccessManager = (IFileAccessManager)host.GetComponent(BuildComponentType.FileAccessManager);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#if FEATURE_REPORTFILEACCESSES
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Build.Shared;

namespace Microsoft.Build.BackEnd
{
/// <summary>
/// Factory for creating the DetouredNodeLauncher
/// </summary>
/// <remarks>
/// Must be a separate class to avoid loading the BuildXL assemblies when not opted in.
/// </remarks>
internal static class DetouredNodeLauncherFactory
{
public static IBuildComponent CreateComponent(BuildComponentType type)
{
ErrorUtilities.VerifyThrowArgumentOutOfRange(type == BuildComponentType.NodeLauncher, nameof(type));
return new DetouredNodeLauncher();
}
}
}
#endif
1 change: 1 addition & 0 deletions src/Build/Microsoft.Build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
<Compile Include="BackEnd\Components\ProjectCache\*.cs" />
<Compile Include="BackEnd\Components\Communications\CurrentHost.cs" />
<Compile Include="BackEnd\Components\Communications\DetouredNodeLauncher.cs" />
<Compile Include="BackEnd\Components\Communications\DetouredNodeLauncherFactory.cs" />
<Compile Include="BackEnd\Components\Communications\SerializationContractInitializer.cs" />
<Compile Include="BackEnd\Components\Communications\ServerNodeEndpointOutOfProc.cs" />
<Compile Include="BackEnd\Components\FileAccesses\IFileAccessManager.cs" />
Expand Down

0 comments on commit 180ff51

Please sign in to comment.