public async Task <bool> Restore(IConsole console, IStatusBar statusBar = null) { return(await Task.Factory.StartNew(() => { var exitCode = PlatformSupport.ExecuteShellCommand(DotNetCliService.Instance.Info.Executable, $"restore {Path.GetFileName(Location)}", (s, e) => { if (statusBar != null) { if (!string.IsNullOrWhiteSpace(e.Data)) { Dispatcher.UIThread.InvokeAsync(() => { statusBar.SetText(e.Data.Trim()); }); } } console?.WriteLine(e.Data); }, (s, e) => { if (e.Data != null) { if (console != null) { console.WriteLine(); console.WriteLine(e.Data); } } }, false, CurrentDirectory, false); return exitCode == 0; })); }
private LinkResult Link(IConsole console, IStandardProject superProject, CompileResult compileResult, CompileResult linkResults, string label = "") { var binDirectory = compileResult.Project.GetBinDirectory(superProject); if (!Directory.Exists(binDirectory)) { Directory.CreateDirectory(binDirectory); } var outputLocation = binDirectory; var executable = Path.Combine(outputLocation, compileResult.Project.Name); if (!string.IsNullOrEmpty(label)) { executable += string.Format("-{0}", label); } if (compileResult.Project.Type == ProjectType.StaticLibrary) { executable = Path.Combine(outputLocation, "lib" + compileResult.Project.Name); executable += StaticLibraryExtension; } else { executable += ExecutableExtension; } if (!Directory.Exists(outputLocation)) { Directory.CreateDirectory(outputLocation); } var link = false; foreach (var objectFile in compileResult.ObjectLocations) { if (!System.IO.File.Exists(executable) || (System.IO.File.GetLastWriteTime(objectFile) > System.IO.File.GetLastWriteTime(executable))) { link = true; break; } } if (!link) { foreach (var library in compileResult.LibraryLocations) { if (!System.IO.File.Exists(executable) || (System.IO.File.GetLastWriteTime(library) > System.IO.File.GetLastWriteTime(executable))) { link = true; break; } } } var linkResult = new LinkResult { Executable = executable }; if (link) { _statusBar?.SetText($"Linking: {compileResult.Project.Name}"); console.OverWrite(string.Format("[LL] [{0}]", compileResult.Project.Name)); linkResult = Link(console, superProject, compileResult.Project, compileResult, executable); _statusBar?.ClearText(); } if (linkResult.ExitCode == 0) { if (compileResult.Project.Type == ProjectType.StaticLibrary) { if (compileResult.ObjectLocations.Count > 0) { // This is where we have a libray with just headers. linkResults.LibraryLocations.Add(executable); } } else { superProject.Executable = superProject.Location.MakeRelativePath(linkResult.Executable).ToAvalonPath(); superProject.Save(); console.WriteLine(); Size(console, compileResult.Project, linkResult); linkResults.ExecutableLocations.Add(executable); } } else if (linkResults.ExitCode == 0) { linkResults.ExitCode = linkResult.ExitCode; } return(linkResult); }
public Task <bool> Restore(IConsole console, IStatusBar statusBar = null, bool checkLock = false) { bool restore = !checkLock; if (checkLock) { lock (_restoreLock) { restore = !IsRestored; if (restore) { IsRestored = true; _restoreTaskCompletionSource = new TaskCompletionSource <bool>(); } } } if (restore) { return(Task.Factory.StartNew(() => { statusBar.SetText($"Restoring Packages for solution: {Name}"); var exitCode = PlatformSupport.ExecuteShellCommand(DotNetCliService.Instance.DotNetPath, $"restore /m {Path.GetFileName(Location)}", (s, e) => { if (statusBar != null) { if (!string.IsNullOrWhiteSpace(e.Data)) { Dispatcher.UIThread.InvokeAsync(() => { statusBar.SetText(e.Data.Trim()); }); } } console?.WriteLine(e.Data); }, (s, e) => { if (e.Data != null) { if (console != null) { console.WriteLine(); console.WriteLine(e.Data); } } }, false, CurrentDirectory, false); IsRestored = true; var result = exitCode == 0; _restoreTaskCompletionSource?.SetResult(result); lock (_restoreLock) { _restoreTaskCompletionSource = null; } return result; })); } else { lock (_restoreLock) { if (_restoreTaskCompletionSource != null) { return(_restoreTaskCompletionSource.Task); } else { return(Task.FromResult(true)); } } } }