5 using System.Reflection;
7 using System.Diagnostics;
8 using SiliconStudio.Core.Diagnostics;
10 namespace SiliconStudio.BuildEngine
14 private static string FormatLog(
LogMessage message)
16 var builder =
new StringBuilder();
17 TimeSpan timestamp = DateTime.Now - Process.GetCurrentProcess().StartTime;
18 builder.Append((timestamp.TotalMilliseconds * 0.001).ToString(
"0.000 "));
19 builder.Append(message.Module);
21 builder.Append(message.Text);
22 return builder.ToString();
25 private static int Main(
string[] args)
27 var exeName = Path.GetFileName(Assembly.GetExecutingAssembly().Location);
33 "Copyright (C) 2011-2013 Silicon Studio Corporation. All Rights Reserved",
34 "Paradox Build Tool - Version: "
38 typeof(
Program).Assembly.GetName().Version.Major,
39 typeof(
Program).Assembly.GetName().Version.Minor,
40 typeof(
Program).Assembly.GetName().Version.Build) + string.Empty,
41 string.Format(
"Usage: {0} [options]* inputfile -o outputfile", exeName),
45 {
"h|help",
"Show this message and exit", v => showHelp = v != null },
46 {
"v|verbose",
"Show more verbose progress logs", v => options.Verbose = v != null },
47 {
"d|debug",
"Show debug logs (imply verbose)", v => options.Debug = v != null },
48 {
"c|clean",
"Clean the command cache, forcing to rebuild everything at the next build.", v => options.BuilderMode = Builder.Mode.Clean },
49 {
"cd|clean-delete",
"Clean the command cache and delete output objects", v => options.BuilderMode = Builder.Mode.CleanAndDelete },
50 {
"b|build-path=",
"Build path", v => options.BuildDirectory = v },
51 {
"mdb|metadata-database=",
"Optional ; indicate the directory containing the Metadata database, if used.", v => {
if (!
string.IsNullOrEmpty(v)) options.MetadataDatabaseDirectory = v; } },
52 {
"o|output-path=",
"Optional ; indicate an output path to copy the built assets in.", v => options.OutputDirectory = v },
53 {
"cfg|config=",
"Configuration name", v => options.Configuration = v },
54 {
"log",
"Enable file logging", v => options.EnableFileLogging = v != null },
55 {
"log-file=",
"Log build in a custom file.", v =>
57 options.EnableFileLogging = v != null;
58 options.CustomLogFileName = v;
60 {
"monitor-pipe=",
"Monitor pipe.", v =>
62 if (!
string.IsNullOrEmpty(v))
63 options.MonitorPipeNames.Add(v);
65 {
"slave=",
"Slave pipe", v => options.SlavePipe = v },
66 {
"s|sourcebase=",
"Optional ; Set the base directory for the source files. Not required if all source paths are absolute", v => options.SourceBaseDirectory = v },
67 {
"a|append",
"If set, the existing asset mappings won't be deleted.", v => options.Append = v != null },
68 {
"t|threads=",
"Number of threads to create. Default value is the number of hardware threads available.", v => options.ThreadCount = int.Parse(v) },
69 {
"p|plugin=",
"Add plugin directory.", v =>
71 if (!
string.IsNullOrEmpty(v))
72 options.Plugins.AddPluginFolder(v);
74 {
"test=",
"Run a test session.", v => options.TestName = v }
80 if (options.SlavePipe == null)
83 GlobalLogger.MessageLogged += consoleLogListener;
87 options.Plugins.AddPluginFolder(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) ??
"",
"BuildPlugins"));
88 options.Plugins.Register();
94 options.InputFiles = p.Parse(args);
97 if (options.SlavePipe == null)
99 if (options.EnableFileLogging)
101 string logFileName = options.CustomLogFileName;
102 if (
string.IsNullOrEmpty(logFileName))
104 string inputName =
"NoInput";
105 if (options.InputFiles.Count > 0)
106 inputName = Path.GetFileNameWithoutExtension(options.InputFiles[0]);
108 logFileName =
"Logs/Build-" + inputName +
"-" + DateTime.Now.ToString(
"yy-MM-dd-HH-mm") +
".txt";
111 string dirName = Path.GetDirectoryName(logFileName);
113 Directory.CreateDirectory(dirName);
116 GlobalLogger.MessageLogged += fileLogListener;
118 options.Logger.Info(
"BuildEngine arguments: " + string.Join(
" ", args));
119 options.Logger.Info(
"Starting builder.");
124 p.WriteOptionDescriptions(Console.Out);
125 exitCode = BuildResultCode.Successful;
127 else if (!
string.IsNullOrEmpty(options.TestName))
130 test.RunTest(options.TestName, options.Logger);
131 exitCode = BuildResultCode.Successful;
135 exitCode = BuildEngineCommands.Build(options);
138 catch (OptionException e)
140 options.Logger.Error(
"{0}", e);
141 exitCode = BuildResultCode.CommandLineError;
145 options.Logger.Error(
"{0}", e);
146 exitCode = BuildResultCode.BuildError;
150 if (fileLogListener != null)
151 fileLogListener.LogWriter.Close();
154 return (
int)exitCode;
System.IO.FileMode FileMode
A LogListener implementation redirecting its output to a TextWriter.
Base implementation for ILogger.
A base log message used by the logging infrastructure.
A LogListener implementation redirecting its output to the default OS console. If console is not supp...