Skip to content
Permalink
Browse files

[Build] Transformed Xenko.Core.BuildEngine into a .NET Standard assembly

  • Loading branch information
xen2 committed May 23, 2019
1 parent bb504a7 commit 382953c7639a0f767894d5fa72d5d7aa2e0dc06d
@@ -9,10 +9,11 @@
using Xenko.Core.Diagnostics;
using Xenko.Core.MicroThreading;
using System.ServiceModel;
using Xenko.Core.BuildEngine;

namespace Xenko.Core.BuildEngine
namespace Xenko.Core.Assets.CompilerApp
{
internal class BuildThreadMonitor
internal class BuildThreadMonitor : IBuildThreadMonitor
{
/// <summary>
/// This class stores informations relative to a build step, used to build data to send to the clients. It is immutable.
@@ -69,7 +70,7 @@ public override string ToString()

private Thread monitorThread;

internal BuildThreadMonitor(Scheduler scheduler, Guid builderId, string monitorPipeName = Builder.MonitorPipeName)
public BuildThreadMonitor(Scheduler scheduler, Guid builderId, string monitorPipeName = Builder.MonitorPipeName)
{
this.monitorPipeName = monitorPipeName;
this.builderId = builderId;
@@ -81,15 +82,15 @@ internal BuildThreadMonitor(Scheduler scheduler, Guid builderId, string monitorP
stopWatch.Start();
}

internal void RegisterThread(int threadId)
public void RegisterThread(int threadId)
{
lock (threadExecutionIntervals)
{
threadExecutionIntervals.Add(threadId, new List<TimeInterval>());
}
}

internal void RegisterBuildStep(BuildStep buildStep, TimestampLocalLogger logger)
public void RegisterBuildStep(BuildStep buildStep, TimestampLocalLogger logger)
{
lock (buildStepInfosToSend)
{
@@ -117,7 +117,7 @@ public enum Mode
private Scheduler scheduler;

private readonly CommandIOMonitor ioMonitor;
private readonly List<BuildThreadMonitor> threadMonitors = new List<BuildThreadMonitor>();
private readonly List<IBuildThreadMonitor> currentThreadMonitors = new List<IBuildThreadMonitor>();

/// <summary>
/// A map containing results of each commands, indexed by command hashes. When the builder is running, this map if filled with the result of the commands of the current execution.
@@ -297,7 +297,7 @@ private void ScheduleBuildStep(BuilderContext builderContext, BuildStep instigat

buildStep.ExecutionId = microThread.Id;

foreach (var threadMonitor in threadMonitors)
foreach (var threadMonitor in currentThreadMonitors)
{
threadMonitor.RegisterBuildStep(buildStep, buildStepLogger.StepLogger);
}
@@ -422,7 +422,7 @@ public void CancelBuild()

private void RunUntilEnd()
{
foreach (var threadMonitor in threadMonitors)
foreach (var threadMonitor in currentThreadMonitors)
threadMonitor.RegisterThread(Thread.CurrentThread.ManagedThreadId);

while (true)
@@ -479,7 +479,7 @@ public void WriteIndexFile(bool mergeWithCurrentIndexFile)
/// <summary>
/// Runs this instance.
/// </summary>
public BuildResultCode Run(Mode mode, bool writeIndexFile = true, bool enableMonitor = false)
public BuildResultCode Run(Mode mode, bool writeIndexFile = true, List<IBuildThreadMonitor> threadMonitors = null)
{
// When we setup the database ourself we have to take responsibility to close it after
var shouldCloseDatabase = ObjectDatabase == null;
@@ -497,7 +497,14 @@ public BuildResultCode Run(Mode mode, bool writeIndexFile = true, bool enableMon
Cancelled = false;
IsRunning = true;
DisableCompressionIds.Clear();


currentThreadMonitors.Clear();
if (threadMonitors != null)
{
foreach (var threadMonitor in threadMonitors)
currentThreadMonitors.Add(threadMonitor);
}

// Reseting result map
var inputHashes = FileVersionTracker.GetDefault();
{
@@ -506,15 +513,8 @@ public BuildResultCode Run(Mode mode, bool writeIndexFile = true, bool enableMon
resultMap = ObjectDatabase;

scheduler = new Scheduler();
if (enableMonitor)
{
threadMonitors.Add(new BuildThreadMonitor(scheduler, BuilderId));
foreach (var monitorPipeName in MonitorPipeNames)
threadMonitors.Add(new BuildThreadMonitor(scheduler, BuilderId, monitorPipeName));

foreach (var threadMonitor in threadMonitors)
threadMonitor.Start();
}
foreach (var threadMonitor in currentThreadMonitors)
threadMonitor.Start();

// Schedule the build
ScheduleBuildStep(builderContext, null, Root, InitialVariables);
@@ -536,14 +536,14 @@ public BuildResultCode Run(Mode mode, bool writeIndexFile = true, bool enableMon
thread.Join();
}

foreach (var threadMonitor in threadMonitors)
foreach (var threadMonitor in currentThreadMonitors)
threadMonitor.Finish();

foreach (var threadMonitor in threadMonitors)
foreach (var threadMonitor in currentThreadMonitors)
threadMonitor.Join();
}

threadMonitors.Clear();
currentThreadMonitors.Clear();
BuildResultCode result;

if (runMode == Mode.Build)
@@ -67,7 +67,7 @@ private void BuilderThread()
{
builder.Reset();
builder.Root.Add(dynamicBuildStep);
builder.Run(Builder.Mode.Build, true, false);
builder.Run(Builder.Mode.Build, true);
}
}
}
@@ -22,7 +22,7 @@ public enum NotificationType

public MicrothreadNotification() { }

internal MicrothreadNotification(int threadId, long microthreadId, long microthreadJobId, long time, NotificationType type)
public MicrothreadNotification(int threadId, long microthreadId, long microthreadJobId, long time, NotificationType type)
{
ThreadId = threadId;
MicrothreadId = microthreadId;
@@ -0,0 +1,16 @@
// Copyright (c) Xenko contributors (https://xenko.com) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.

using Xenko.Core.Diagnostics;

namespace Xenko.Core.BuildEngine
{
public interface IBuildThreadMonitor
{
void Start();
void RegisterBuildStep(BuildStep buildStep, TimestampLocalLogger stepLogger);
void RegisterThread(int managedThreadId);
void Finish();
void Join();
}
}
@@ -6,11 +6,12 @@
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<XenkoAssemblyProcessor>true</XenkoAssemblyProcessor>
<TargetFramework>$(TargetFrameworkTool)</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
<XenkoAssemblyProcessorOptions>--auto-module-initializer --serialization</XenkoAssemblyProcessorOptions>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="EnvDTE" Version="8.0.1" />
<PackageReference Include="System.ServiceModel.Primitives" Version="4.5.3" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.ServiceModel" />
</ItemGroup>

0 comments on commit 382953c

Please sign in to comment.
You can’t perform that action at this time.