4 using System.Collections.Generic;
7 using System.Runtime.CompilerServices;
11 using System.Reflection;
13 using System.Diagnostics;
15 using SiliconStudio.BuildEngine;
16 using SiliconStudio.Core;
17 using SiliconStudio.Core.Diagnostics;
18 using SiliconStudio.Paradox.Assets.Model;
19 using SiliconStudio.Paradox.Assets.SpriteFont;
20 using SiliconStudio.Paradox.Effects.Modules;
21 using SiliconStudio.Paradox.Graphics;
23 namespace SiliconStudio.Assets.CompilerApp
27 private static Stopwatch clock;
28 private static string FormatLog(
ILogMessage message)
32 var builder =
new StringBuilder();
33 builder.Append(message.Module);
35 builder.Append(message.Type.ToString().ToLowerInvariant()).Append(
" ");
36 builder.Append((clock.ElapsedMilliseconds * 0.001).ToString(
"0.000"));
37 builder.Append(
"s: ");
38 builder.Append(message.Text);
39 return builder.ToString();
42 private static int Main(
string[] args)
44 clock = Stopwatch.StartNew();
47 RuntimeHelpers.RunModuleConstructor(typeof(
MaterialKeys).Module.ModuleHandle);
48 RuntimeHelpers.RunModuleConstructor(typeof(
SpriteFontAsset).Module.ModuleHandle);
49 RuntimeHelpers.RunModuleConstructor(typeof(
ModelAsset).Module.ModuleHandle);
61 Paradox.Physics.PhysicsEngine.InitializeConverters();
63 var exeName = Path.GetFileName(Assembly.GetExecutingAssembly().Location);
69 "Copyright (C) 2011-2014 Silicon Studio Corporation. All Rights Reserved",
70 "Paradox Build Tool - Version: "
74 typeof(
Program).Assembly.GetName().Version.Major,
75 typeof(
Program).Assembly.GetName().Version.Minor,
76 typeof(
Program).Assembly.GetName().Version.Build) + string.Empty,
77 string.Format(
"Usage: {0} inputPackageFile [options]* -b buildPath", exeName),
81 {
"h|help",
"Show this message and exit", v => showHelp = v != null },
82 {
"v|verbose",
"Show more verbose progress logs", v => options.Verbose = v != null },
83 {
"d|debug",
"Show debug logs (imply verbose)", v => options.Debug = v != null },
84 {
"log",
"Enable file logging", v => options.EnableFileLogging = v != null },
85 {
"p|profile=",
"Profile name", v => options.BuildProfile = v },
86 {
"project-configuration=",
"Project configuration", v => options.ProjectConfiguration = v },
89 {
"solution-file=",
"Solution File Name", v => options.SolutionFile = v },
90 {
"package-id=",
"Package Id from the solution file", v => options.PackageId = Guid.Parse(v) },
91 {
"package-file=",
"Input Package File Name", v => options.PackageFile = v },
92 {
"o|output-path=",
"Output path", v => options.OutputDirectory = v },
93 {
"b|build-path=",
"Build path", v => options.BuildDirectory = v },
94 {
"log-file=",
"Log build in a custom file.", v =>
96 options.EnableFileLogging = v != null;
97 options.CustomLogFileName = v;
99 {
"log-pipe=",
"Log pipe.", v =>
101 if (!
string.IsNullOrEmpty(v))
102 options.LogPipeNames.Add(v);
104 {
"monitor-pipe=",
"Monitor pipe.", v =>
106 if (!
string.IsNullOrEmpty(v))
107 options.MonitorPipeNames.Add(v);
109 {
"slave=",
"Slave pipe", v => options.SlavePipe = v },
110 {
"t|threads=",
"Number of threads to create. Default value is the number of hardware threads available.", v => options.ThreadCount = int.Parse(v) },
111 {
"test=",
"Run a test session.", v => options.TestName = v },
112 {
"property:",
"Properties. Format is name1=value1;name2=value2", v =>
114 if (!
string.IsNullOrEmpty(v))
116 foreach (var nameValue
in v.Split(
new [] {
';' }, StringSplitOptions.RemoveEmptyEntries))
118 var equalIndex = nameValue.IndexOf(
'=');
119 if (equalIndex == -1)
120 throw new OptionException(
"Expect name1=value1;name2=value2 format.",
"property");
122 options.Properties.Add(nameValue.Substring(0, equalIndex), nameValue.Substring(equalIndex + 1));
127 {
"compile-property:",
"Compile properties. Format is name1=value1;name2=value2", v =>
129 if (!
string.IsNullOrEmpty(v))
131 if (options.ExtraCompileProperties == null)
132 options.ExtraCompileProperties =
new Dictionary<string, string>();
134 foreach (var nameValue
in v.Split(
new [] {
';' }, StringSplitOptions.RemoveEmptyEntries))
136 var equalIndex = nameValue.IndexOf(
'=');
137 if (equalIndex == -1)
138 throw new OptionException(
"Expect name1=value1;name2=value2 format.",
"property");
140 options.ExtraCompileProperties.Add(nameValue.Substring(0, equalIndex), nameValue.Substring(equalIndex + 1));
150 if (options.SlavePipe == null)
152 var consoleLogListener =
new ConsoleLogListener { TextFormatter = FormatLog, LogMode = ConsoleLogMode.Always };
153 GlobalLogger.GlobalMessageLogged += consoleLogListener;
160 var unexpectedArgs = p.Parse(args);
161 if (unexpectedArgs.Any())
163 throw new OptionException(
"Unexpected arguments [{0}]".ToFormat(
string.Join(
", ", unexpectedArgs)),
"args");
167 options.ValidateOptions();
169 catch (ArgumentException ex)
171 throw new OptionException(ex.Message, ex.ParamName);
175 if (options.SlavePipe == null)
177 if (options.EnableFileLogging)
179 string logFileName = options.CustomLogFileName;
180 if (
string.IsNullOrEmpty(logFileName))
182 string inputName = Path.GetFileNameWithoutExtension(options.PackageFile);
183 logFileName =
"Logs/Build-" + inputName +
"-" + DateTime.Now.ToString(
"yy-MM-dd-HH-mm") +
".txt";
186 string dirName = Path.GetDirectoryName(logFileName);
188 Directory.CreateDirectory(dirName);
191 GlobalLogger.GlobalMessageLogged += fileLogListener;
193 options.Logger.Info(
"BuildEngine arguments: " + string.Join(
" ", args));
194 options.Logger.Info(
"Starting builder.");
199 p.WriteOptionDescriptions(Console.Out);
200 exitCode = BuildResultCode.Successful;
202 else if (!
string.IsNullOrEmpty(options.TestName))
205 test.RunTest(options.TestName, options.Logger);
206 exitCode = BuildResultCode.Successful;
211 Console.CancelKeyPress += (_, e) => e.Cancel = builder.Cancel();
212 exitCode = builder.Build();
215 catch (OptionException e)
217 options.Logger.Error(
"Command option '{0}': {1}", e.OptionName, e.Message);
218 exitCode = BuildResultCode.CommandLineError;
222 options.Logger.Error(
"Unhandled exception: {0}", e, e.Message);
223 exitCode = BuildResultCode.BuildError;
227 if (fileLogListener != null)
228 fileLogListener.LogWriter.Close();
231 return (
int)exitCode;
PlatformType
Describes the platform operating system.
static Logger GetLogger(string module)
Gets the GlobalLogger associated to the specified module.
GraphicsPlatform
The graphics platform.
System.IO.FileMode FileMode
A LogListener implementation redirecting its output to a TextWriter.
The base interface for log messages used by the logging infrastructure.
A logger that redirect messages to a global handler and handle instantiated MapModuleNameToLogger.
A LogListener implementation redirecting its output to the default OS console. If console is not supp...