private static bool BuildDepsSequential(ModulesOrder modulesOrder, BuildInfoStorage buildStorage, List <Dep> modulesToBuild, ModuleBuilder builder) { var built = 1; for (var i = 0; i < modulesOrder.BuildOrder.Count - 1; i++) { var dep = modulesOrder.BuildOrder[i]; if (NoNeedToBuild(dep, modulesToBuild)) { buildStorage.AddBuiltModule(dep, modulesOrder.CurrentCommitHashes); continue; } ConsoleWriter.Shared.WriteProgress($"{dep.ToBuildString(),-49} {$"{built}/{modulesToBuild.Count}",10}"); try { if (!builder.Build(dep)) { buildStorage.Save(); return(false); } } catch (Exception) { buildStorage.Save(); throw; } buildStorage.AddBuiltModule(dep, modulesOrder.CurrentCommitHashes); built++; } buildStorage.Save(); Log.LogDebug("msbuild time: " + new TimeSpan(ModuleBuilder.TotalMsbuildTime)); return(true); }
private static bool BuildDepsParallel(ModulesOrder modulesOrder, BuildInfoStorage buildStorage, List <Dep> modulesToBuild, ModuleBuilder builder) { var logger = LogManager.GetLogger <ParallelBuilder>(); var graphHelper = new GraphHelper(); var parallelBuilder = new ParallelBuilder(logger, graphHelper); parallelBuilder.Initialize(modulesOrder.ConfigsGraph); var tasks = new List <Task>(); var builtCount = 1; for (var i = 0; i < Helper.MaxDegreeOfParallelism; i++) { tasks.Add( Task.Run( () => { while (true) { var dep = parallelBuilder.TryStartBuild(); if (dep == null) { return; } if (dep.Equals(modulesOrder.BuildOrder.LastOrDefault())) { parallelBuilder.EndBuild(dep); continue; } if (NoNeedToBuild(dep, modulesToBuild)) { parallelBuilder.EndBuild(dep); lock (buildStorage) buildStorage.AddBuiltModule(dep, modulesOrder.CurrentCommitHashes); continue; } ConsoleWriter.Shared.WriteProgress($"{dep.ToBuildString(),-49} {$"{builtCount}/{modulesToBuild.Count}",10}"); var success = builder.Build(dep); parallelBuilder.EndBuild(dep, !success); if (success) { lock (buildStorage) { buildStorage.AddBuiltModule(dep, modulesOrder.CurrentCommitHashes); builtCount++; } } } })); } Task.WaitAll(tasks.ToArray()); buildStorage.Save(); Log.LogDebug("msbuild time: " + new TimeSpan(ModuleBuilder.TotalMsbuildTime)); return(!parallelBuilder.IsFailed); }