Skip to content

Commit 180ff51

Browse files
committed
Another attempt at avoiding BuildXL assembly load
1 parent 7dd37d8 commit 180ff51

File tree

4 files changed

+37
-26
lines changed

4 files changed

+37
-26
lines changed

src/Build/BackEnd/BuildManager/BuildManager.cs

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,13 @@ public void BeginBuild(BuildParameters parameters)
562562
#if FEATURE_REPORTFILEACCESSES
563563
if (_buildParameters.ReportFileAccesses)
564564
{
565-
EnableDetouredNodeLauncher();
565+
// To properly report file access, we need to disable the in-proc node which won't be detoured.
566+
_buildParameters.DisableInProcNode = true;
567+
568+
// Node reuse must be disabled as future builds will not be able to listen to events raised by detours.
569+
_buildParameters.EnableNodeReuse = false;
570+
571+
_componentFactories.ReplaceFactory(BuildComponentType.NodeLauncher, DetouredNodeLauncherFactory.CreateComponent);
566572
}
567573
#endif
568574

@@ -717,25 +723,6 @@ void InitializeCaches()
717723
}
718724
}
719725

720-
#if FEATURE_REPORTFILEACCESSES
721-
/// <summary>
722-
/// Configure the build to use I/O tracking for nodes.
723-
/// </summary>
724-
/// <remarks>
725-
/// Must be a separate method to avoid loading the BuildXL assembly when not opted in.
726-
/// </remarks>
727-
private void EnableDetouredNodeLauncher()
728-
{
729-
// To properly report file access, we need to disable the in-proc node which won't be detoured.
730-
_buildParameters.DisableInProcNode = true;
731-
732-
// Node reuse must be disabled as future builds will not be able to listen to events raised by detours.
733-
_buildParameters.EnableNodeReuse = false;
734-
735-
_componentFactories.ReplaceFactory(BuildComponentType.NodeLauncher, DetouredNodeLauncher.CreateComponent);
736-
}
737-
#endif
738-
739726
private static void AttachDebugger()
740727
{
741728
if (Debugger.IsAttached)

src/Build/BackEnd/Components/Communications/DetouredNodeLauncher.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@ internal sealed class DetouredNodeLauncher : INodeLauncher, IBuildComponent
2525

2626
private IFileAccessManager _fileAccessManager;
2727

28-
public static IBuildComponent CreateComponent(BuildComponentType type)
29-
{
30-
ErrorUtilities.VerifyThrowArgumentOutOfRange(type == BuildComponentType.NodeLauncher, nameof(type));
31-
return new DetouredNodeLauncher();
32-
}
33-
3428
public void InitializeComponent(IBuildComponentHost host)
3529
{
3630
_fileAccessManager = (IFileAccessManager)host.GetComponent(BuildComponentType.FileAccessManager);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
#if FEATURE_REPORTFILEACCESSES
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
using Microsoft.Build.Shared;
11+
12+
namespace Microsoft.Build.BackEnd
13+
{
14+
/// <summary>
15+
/// Factory for creating the DetouredNodeLauncher
16+
/// </summary>
17+
/// <remarks>
18+
/// Must be a separate class to avoid loading the BuildXL assemblies when not opted in.
19+
/// </remarks>
20+
internal static class DetouredNodeLauncherFactory
21+
{
22+
public static IBuildComponent CreateComponent(BuildComponentType type)
23+
{
24+
ErrorUtilities.VerifyThrowArgumentOutOfRange(type == BuildComponentType.NodeLauncher, nameof(type));
25+
return new DetouredNodeLauncher();
26+
}
27+
}
28+
}
29+
#endif

src/Build/Microsoft.Build.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@
155155
<Compile Include="BackEnd\Components\ProjectCache\*.cs" />
156156
<Compile Include="BackEnd\Components\Communications\CurrentHost.cs" />
157157
<Compile Include="BackEnd\Components\Communications\DetouredNodeLauncher.cs" />
158+
<Compile Include="BackEnd\Components\Communications\DetouredNodeLauncherFactory.cs" />
158159
<Compile Include="BackEnd\Components\Communications\SerializationContractInitializer.cs" />
159160
<Compile Include="BackEnd\Components\Communications\ServerNodeEndpointOutOfProc.cs" />
160161
<Compile Include="BackEnd\Components\FileAccesses\IFileAccessManager.cs" />

0 commit comments

Comments
 (0)