6 using System.ServiceModel;
8 using SiliconStudio.Assets.Compiler;
9 using SiliconStudio.Assets.Diagnostics;
10 using SiliconStudio.BuildEngine;
11 using SiliconStudio.Core;
12 using SiliconStudio.Core.Extensions;
13 using SiliconStudio.Core.Diagnostics;
14 using SiliconStudio.Core.IO;
15 using SiliconStudio.Core.MicroThreading;
16 using SiliconStudio.Core.Serialization.Assets;
18 using System.Threading;
20 namespace SiliconStudio.Assets.CompilerApp
30 if (packageBuilderOptions == null)
throw new ArgumentNullException(
"packageBuilderOptions");
32 builderOptions = packageBuilderOptions;
39 if (builderOptions.IsValidForSlave())
44 result = BuildSlave();
49 result = BuildMaster();
55 private static void PrepareDatabases()
62 assetLogger =
new RemoteLogForwarder(builderOptions.Logger, builderOptions.LogPipeNames);
63 GlobalLogger.GlobalMessageLogged += assetLogger;
71 AutoCompileProjects = builderOptions.Platform != PlatformType.Windows || builderOptions.ProjectConfiguration !=
"Debug",
72 ExtraCompileProperties = builderOptions.ExtraCompileProperties,
76 var projectSessionResult = PackageSession.Load(builderOptions.PackageFile, sessionLoadParameters);
77 if (projectSessionResult.HasErrors)
79 projectSessionResult.CopyTo(builderOptions.Logger);
80 return BuildResultCode.BuildError;
83 var projectSession = projectSessionResult.Session;
86 var
package = projectSession.LocalPackages.First();
89 var buildProfile = package.Profiles.FirstOrDefault(pair => pair.Name == builderOptions.BuildProfile);
90 if (buildProfile == null)
92 builderOptions.Logger.Error(
"Unable to find profile [{0}] in package [{1}]", builderOptions.BuildProfile, package.FullPath);
93 return BuildResultCode.BuildError;
97 var buildDirectory = builderOptions.BuildDirectory;
98 var outputDirectory = builderOptions.OutputDirectory;
102 assetBuilder.AssetCompiled += RegisterBuildStepProcessedHandler;
112 foreach (var propertyValue
in buildProfile.Properties)
114 context.Properties.Set(propertyValue.Key, propertyValue.Value);
117 var assetBuildResult = assetBuilder.Compile(context);
118 assetBuildResult.CopyTo(builderOptions.Logger);
119 if (assetBuildResult.HasErrors)
120 return BuildResultCode.BuildError;
123 var indexName =
"index." + builderOptions.BuildProfile;
124 builder =
new Builder(buildDirectory, builderOptions.BuildProfile, indexName,
"InputHashes", builderOptions.Logger) { ThreadCount = builderOptions.ThreadCount };
125 builder.MonitorPipeNames.AddRange(builderOptions.MonitorPipeNames);
128 builder.Root.Add(assetBuildResult.BuildSteps);
131 var result = builder.Run(Builder.Mode.Build);
132 builder.WriteIndexFile(
false);
135 var bundlePacker =
new BundlePacker();
136 bundlePacker.Build(builderOptions.Logger, projectSession, buildProfile, indexName, outputDirectory, builder.DisableCompressionIds);
139 GlobalLogger.GlobalMessageLogged -= assetLogger;
140 assetLogger.Dispose();
145 private void RegisterBuildStepProcessedHandler(
object sender,
AssetCompiledArgs e)
152 buildStep.Tag = e.Asset;
153 buildStep.StepProcessed += BuildStepProcessed;
159 var assetItem = (AssetItem)e.
Step.
Tag;
160 var assetRef = assetItem.ToReference();
161 var project = assetItem.Package;
163 if (stepLogger != null)
165 foreach (var message
in stepLogger.Messages.Where(x => x.LogMessage.IsAtLeast(
LogMessageType.Warning)))
167 var assetMessage =
new AssetLogMessage(project, assetRef, message.LogMessage.Type,
AssetMessageCode.InternalCompilerError, assetRef.Location, message.LogMessage.Text)
171 builderOptions.Logger.Log(assetMessage);
174 switch (e.Step.Status)
177 case ResultStatus.NotProcessed:
180 case ResultStatus.Successful:
183 case ResultStatus.Failed:
186 case ResultStatus.Cancelled:
189 case ResultStatus.NotTriggeredWasSuccessful:
192 case ResultStatus.NotTriggeredPrerequisiteFailed:
196 throw new ArgumentOutOfRangeException();
198 e.Step.StepProcessed -= BuildStepProcessed;
205 GlobalLogger.GlobalMessageLogged += logMessage =>
212 processBuilderRemote.ForwardLog(message);
225 VirtualFileSystem.CreateDirectory(
"/data/");
226 VirtualFileSystem.CreateDirectory(
"/data/db/");
229 var namedPipeBinding =
new NetNamedPipeBinding(NetNamedPipeSecurityMode.None) { SendTimeout = TimeSpan.FromSeconds(300.0) };
230 var processBuilderRemote = ChannelFactory<IProcessBuilderRemote>.CreateChannel(namedPipeBinding,
new EndpointAddress(builderOptions.SlavePipe));
234 RegisterRemoteLogger(processBuilderRemote);
239 var status = ResultStatus.NotProcessed;
242 string buildPath = builderOptions.BuildDirectory;
243 string buildProfile = builderOptions.BuildProfile;
245 Builder.SetupBuildPath(buildPath);
247 Logger logger = builderOptions.Logger;
248 MicroThread microthread = scheduler.Add(async () =>
251 Command command = processBuilderRemote.GetCommandToExecute();
255 var inputHashes = FileVersionTracker.GetDefault();
256 var builderContext =
new BuilderContext(buildPath, buildProfile, inputHashes, parameters, 0, null);
258 var commandContext =
new RemoteCommandContext(processBuilderRemote, command, builderContext, logger);
259 IndexFileCommand.MountDatabases(commandContext);
260 command.PreCommand(commandContext);
261 status = await command.DoCommand(commandContext);
262 command.PostCommand(commandContext, status);
265 processBuilderRemote.RegisterResult(commandContext.ResultEntry);
273 lock (scheduler.MicroThreads)
275 if (!scheduler.MicroThreads.Any())
285 builderOptions.Logger.Fatal(microthread.Exception.ToString());
286 return BuildResultCode.BuildError;
290 return BuildResultCode.Successful;
292 return BuildResultCode.BuildError;
298 ((IClientChannel)processBuilderRemote).Close();
309 if (builder != null && builder.IsRunning)
311 builder.CancelBuild();
A BuildStep that can spawn multiple BuildStep. Input and output tracking and merging will be performe...
Virtual abstraction over a file system. It handles access to files, http, packages, path rewrite, etc...
A package assets compiler. Creates the build steps necessary to produce the assets of a package...
Represents an execution context managed by a Scheduler, that can cooperatively yield execution to ano...
GraphicsPlatform
The graphics platform.
A file system implementation for IVirtualFileProvider.
AssetMessageCode
A message code used by AssetLogMessage to identify an error/warning.
IEnumerable< BuildStep > Steps
The template can be applied to an existing Assets.Package.
ResultStatus
Status of a command.
The context used when compiling an asset in a Package.
ListBuildStep BuildSteps
Gets or sets the build steps generated for the build engine. This can be null if LoggerResult.HasErrors is true.
Base implementation for ILogger.
Exception Exception
Gets the exception that was thrown by this MicroThread.
object Tag
A tag property that can contain anything useful for tools based on this build Engine.
static readonly IVirtualFileProvider ApplicationData
The application data file provider.
static MicroThreadLocal< DatabaseFileProvider > DatabaseFileProvider
A Command that reads and/or writes to the index file.
A class that represents a copy of a LogMessage that can be serialized.
LogMessageType
Type of a LogMessage.
PackageBuilder(PackageBuilderOptions packageBuilderOptions)
A base log message used by the logging infrastructure.
AssetCompilerResult Result
The result of the asset compilation.
Provides a specialized LogMessage to give specific information about an asset.
Scheduler that manage a group of cooperating MicroThread.
The class represents the argument of the ItemListCompiler.AssetCompiled event raised by the ItemListC...
bool Cancel()
Cancels this build.
Parameters used for loading a package.