Another attempt at avoiding BuildXL assembly load

This commit is contained in:
David Federman 2023-08-31 10:35:02 -07:00
Родитель 7dd37d80ae
Коммит 180ff519a8
4 изменённых файлов: 37 добавлений и 26 удалений

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

@ -562,7 +562,13 @@ namespace Microsoft.Build.Execution
#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
@ -717,25 +723,6 @@ namespace Microsoft.Build.Execution
}
}
#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)

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

@ -25,12 +25,6 @@ namespace Microsoft.Build.BackEnd
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);

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

@ -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

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

@ -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" />