static int Main(string[] args)
{
var consoleParams = new ConsoleParameters(args);
if (consoleParams.VerboseOutput)
EnableConsoleDebugLog();
var root = Kernel.Root;
// Binding UI interfaces
root.Bind<IUserOutput>().To<ConsoleUserInterface>().InSingletonScope();
root.Bind<IParameters>().ToConstant(consoleParams).InSingletonScope();
// Binding special directories
var suiteRoot = new LocalFileSystemDirectory(Environment.CurrentDirectory);
root.Bind<IFileSystemDirectory>()
.ToConstant(suiteRoot)
.WhenTargetHas<SuiteRootAttribute>();
root.Bind<IFileSystemDirectory>()
.ToConstant(suiteRoot.GetChildDirectory("target", createIfMissing: true))
.WhenTargetHas<TargetRootAttribute>();
// Binding core services
Kernel.RegisterCoreBindings();
// Binding default cache
var cacheDir = new Lazy<IFileSystemDirectory>(() =>
suiteRoot.GetChildDirectory("cache", createIfMissing: true)
.GetChildDirectory(root.Get<Suite>().ActiveGoal.Name, createIfMissing: true));
root.Bind<Lazy<IFileSystemDirectory>>()
.ToConstant(cacheDir)
.WhenTargetHas<CacheRootAttribute>();
root.Bind<IBuildCache>().To<FileBuildCache>();
// Loading fix plugins
var pluginLoader = root.Get<IPluginLoader>();
foreach (var module in GetOrderedModuleList(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Bari.Plugins.*.dll"))
pluginLoader.Load(module);
// Initializing builder store
Kernel.InitializeBuilderStore();
// Initializing the cache cleaner
root.Bind<ICleanExtension>().ToConstant(new CacheCleaner(cacheDir, root.Get<IBuilderEnumerator>(), () => root.Get<ISoftCleanPredicates>()));
var process = root.Get<MainProcess>();
try
{
if (process.Run())
return 0;
else
return 1;
}
catch (Exception ex)
{
var output = root.Get<IUserOutput>();
output.Error(ex.ToString());
return 2;
}
}