Skip to content

Commit

Permalink
Avoid preloading extension types during build
Browse files Browse the repository at this point in the history
  • Loading branch information
glopesdev committed Jul 8, 2024
1 parent 7fd1893 commit 2d9db3c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Bonsai.Core/Expressions/IncludeWorkflowBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace Bonsai.Expressions
public sealed class IncludeWorkflowBuilder : VariableArgumentExpressionBuilder, IGroupWorkflowBuilder, INamedElement, IRequireBuildContext
{
const char AssemblySeparator = ':';
internal const string BuildUriPrefix = "::build:";
const string DefaultSerializerPropertyName = "Property";
static readonly XElement[] EmptyProperties = new XElement[0];
static readonly XmlSerializerNamespaces DefaultSerializerNamespaces = GetXmlSerializerNamespaces();
Expand Down Expand Up @@ -104,7 +105,7 @@ public override Range<int> ArgumentRange
{
if (workflow == null)
{
try { EnsureWorkflow(); }
try { EnsureWorkflow(null); }
catch (Exception) { }
}
return base.ArgumentRange;
Expand All @@ -119,7 +120,7 @@ IBuildContext IRequireBuildContext.BuildContext
buildContext = value;
if (buildContext != null)
{
EnsureWorkflow();
EnsureWorkflow(buildContext);
InternalXmlProperties = null;
}
}
Expand Down Expand Up @@ -352,7 +353,7 @@ internal static Stream GetWorkflowStream(string path, bool embeddedResource)
}
}

void EnsureWorkflow()
void EnsureWorkflow(IBuildContext buildContext)
{
var context = buildContext;
while (context != null)
Expand All @@ -376,12 +377,13 @@ void EnsureWorkflow()
else
{
var embeddedResource = IsEmbeddedResourcePath(path);
var baseUri = buildContext != null ? $"{BuildUriPrefix}{path}" : path;
var lastWriteTime = embeddedResource ? DateTime.MaxValue : File.GetLastWriteTime(path);
if (workflow == null || lastWriteTime > writeTime)
{
var properties = workflow != null ? GetXmlProperties() : InternalXmlProperties;
using (var stream = GetWorkflowStream(path, embeddedResource))
using (var reader = XmlReader.Create(stream))
using (var reader = XmlReader.Create(stream, null, baseUri))
{
reader.MoveToContent();
var serializer = new XmlSerializer(typeof(WorkflowBuilder), reader.NamespaceURI);
Expand Down
1 change: 1 addition & 0 deletions Bonsai.Core/WorkflowBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,7 @@ static void WriteXmlAttributes(
}
else if (includeWorkflow &&
reader.GetAttribute(nameof(IncludeWorkflowBuilder.Path)) is string path &&
!reader.BaseURI.StartsWith(IncludeWorkflowBuilder.BuildUriPrefix) &&
visitedWorkflows.Add(path))
{
// we don't want to fail in most cases while reading nested metadata, as this
Expand Down

0 comments on commit 2d9db3c

Please sign in to comment.