Skip to content

Commit 92abec7

Browse files
committed
Merged PR 722035: Added an environment variable that contain list of loaded plugin capabilities for every process pips
Added [BUILDXL]LOADED_PLUGIN_CAPABILITIES to pip env vars which lists the capabilities (supported message types) of the currently loaded plugins
1 parent 93b674a commit 92abec7

File tree

4 files changed

+52
-7
lines changed

4 files changed

+52
-7
lines changed

Public/Src/Engine/ProcessPipExecutor/PluginEndpoints.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4+
using System.Collections.Generic;
45
using System.IO;
56
using System.Threading.Tasks;
67
using BuildXL.Pips.Operations;
@@ -27,6 +28,17 @@ public class PluginEndpoints
2728
/// </summary>
2829
public SandboxedProcessInfo ProcessInfo { get; set; }
2930

31+
/// <summary>
32+
/// Gets a list of the plugin message types that the loaded plugins can handle
33+
/// </summary>
34+
public HashSet<PluginMessageType> LoadedPluginSupportedMessageTypes
35+
{
36+
get
37+
{
38+
return m_pluginManager?.GetSupportedMessageTypesOfLoadedPlugins() ?? new HashSet<PluginMessageType>();
39+
}
40+
}
41+
3042
/// <summary>
3143
/// Creates a wrapper to pass relevant information to PluginManager
3244
/// </summary>

Public/Src/Engine/ProcessPipExecutor/SandboxedProcessPipExecutor.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2969,6 +2969,14 @@ private IBuildParameters PrepareEnvironmentVariables()
29692969
}
29702970
}
29712971

2972+
if (m_pluginEP != null)
2973+
{
2974+
environmentVariables = environmentVariables.Override(new[]
2975+
{
2976+
new KeyValuePair<string, string>(PluginConstants.PluginCapabilitiesEnvVar, string.Join(",", m_pluginEP.LoadedPluginSupportedMessageTypes.Select(m => m.ToString())))
2977+
});
2978+
}
2979+
29722980
return environmentVariables;
29732981
}
29742982

Public/Src/Utilities/Plugin/Plugin.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,21 @@
1313

1414
namespace BuildXL.Plugin
1515
{
16+
/// <nodoc />
17+
public static class PluginConstants
18+
{
19+
/// <summary>
20+
/// Name of the environment variable listing the capabilities of the currently loaded plugins
21+
/// </summary>
22+
public const string PluginCapabilitiesEnvVar = "[BUILDXL]LOADED_PLUGIN_CAPABILITIES";
23+
}
24+
1625
/// <nodoc />
1726
public class Plugin : IPlugin
1827
{
1928
private readonly TaskSourceSlim<Unit> m_startCompletionTaskSoure;
2029
private bool m_disposed = false;
30+
2131
/// <nodoc />
2232
public string FilePath { get; }
2333
/// <nodoc />

Public/Src/Utilities/Plugin/PluginManager.cs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,21 @@ public bool CanHandleMessage(PluginMessageType messageType)
106106
return m_pluginHandlers.TryGet(messageType, out _);
107107
}
108108

109+
/// <nodoc />
110+
public HashSet<PluginMessageType> GetSupportedMessageTypesOfLoadedPlugins()
111+
{
112+
HashSet<PluginMessageType> result = new HashSet<PluginMessageType>();
113+
foreach (PluginMessageType messageType in Enum.GetValues(typeof(PluginMessageType)).Cast<PluginMessageType>())
114+
{
115+
if (CanHandleMessage(messageType))
116+
{
117+
result.Add(messageType);
118+
}
119+
}
120+
121+
return result;
122+
}
123+
109124
/// <nodoc />
110125
private void EnsurePluginLoaded(IPlugin plugin)
111126
{
@@ -133,7 +148,7 @@ private async Task<Possible<T>> CallWithEnsurePluginLoadedWrapperAsync<T>(Plugin
133148
}
134149
catch(Exception e)
135150
{
136-
Tracing.Logger.Log.PluginManagerLogMessage(m_loggingContext, $"grpc call with type {messageType.ToString()} failed with {e}");
151+
Tracing.Logger.Log.PluginManagerLogMessage(m_loggingContext, $"Grpc call with type {messageType.ToString()} failed with {e}");
137152
return new Failure<T>(defaultReturnValue);
138153
}
139154
}
@@ -145,7 +160,7 @@ private async Task<Possible<IPlugin>> CreatePluginAsync(PluginCreationArgument p
145160
{
146161
if (!File.Exists(pluinCreationArgument.PluginPath) && pluinCreationArgument.RunInSeparateProcess)
147162
{
148-
Tracing.Logger.Log.PluginManagerLogMessage(m_loggingContext, $"Can't Load plugin because {pluinCreationArgument.PluginPath} doesn't exist");
163+
Tracing.Logger.Log.PluginManagerLogMessage(m_loggingContext, $"Can't load plugin because {pluinCreationArgument.PluginPath} doesn't exist");
149164
new Failure<IPlugin>(null);
150165
}
151166

@@ -190,7 +205,7 @@ public async Task<Possible<LogParseResult>> LogParseAsync(string message, bool i
190205
var messageType = PluginMessageType.ParseLogMessage;
191206
if (!m_pluginHandlers.TryGet(messageType, out plugin))
192207
{
193-
return new Failure<string>($"no plugin is available to handle {messageType}");
208+
return new Failure<string>($"No plugin is available to handle {messageType}");
194209
}
195210

196211
return await CallWithEnsurePluginLoadedWrapperAsync(
@@ -211,7 +226,7 @@ public async Task<Possible<ProcessResultMessageResponse>> ProcessResultAsync(str
211226
var messageType = PluginMessageType.ProcessResult;
212227
if (!m_pluginHandlers.TryGet(messageType, out plugin))
213228
{
214-
return new Failure<string>($"no plugin is available to handle {messageType}");
229+
return new Failure<string>($"No plugin is available to handle {messageType}");
215230
}
216231

217232
return await CallWithEnsurePluginLoadedWrapperAsync(
@@ -274,15 +289,15 @@ public async Task<Possible<IPlugin>> GetOrCreateAsync(PluginCreationArgument sta
274289
}
275290
else
276291
{
277-
Tracing.Logger.Log.PluginManagerErrorMessage(m_loggingContext, $"Two plugins({plugin.FilePath} and {alreadyRegisteredPlugin.FilePath}) can hanlde {pluginMessageType} that we don't suuport this scenario");
292+
Tracing.Logger.Log.PluginManagerErrorMessage(m_loggingContext, $"Two plugins ({plugin.FilePath} and {alreadyRegisteredPlugin.FilePath}) can handle {pluginMessageType}. This scenario is not currently supported.");
278293
}
279294
}
280-
Tracing.Logger.Log.PluginManagerLogMessage(m_loggingContext, $"Supported Messagey Type for {plugin.Name} is {string.Join(",", messageType.Result)}");
295+
Tracing.Logger.Log.PluginManagerLogMessage(m_loggingContext, $"Supported message types for {plugin.Name} is {string.Join(",", messageType.Result)}");
281296
plugin.SupportedMessageType = messageType.Result;
282297
}
283298
else
284299
{
285-
Tracing.Logger.Log.PluginManagerLogMessage(m_loggingContext, $"Can't get supported message tyep for {plugin.Name}");
300+
Tracing.Logger.Log.PluginManagerLogMessage(m_loggingContext, $"Can't get supported message types for {plugin.Name}");
286301
}
287302

288303
return creationResult;

0 commit comments

Comments
 (0)