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; })); }
public async Task <bool> Build(IConsole console, IProject project, string label = "", IEnumerable <string> definitions = null) { return(await Task.Factory.StartNew(() => { string lastLine = string.Empty; var exitCode = PlatformSupport.ExecuteShellCommand(Path.Combine(BinDirectory, "dotnet" + Platform.ExecutableExtension), "build", (s, e) => { console.WriteLine(e.Data); if (!string.IsNullOrEmpty(e.Data)) { lastLine = e.Data; } }, (s, e) => { if (e.Data != null) { console.WriteLine(); console.WriteLine(e.Data); } }, false, project.CurrentDirectory, false); if (exitCode == 0 && lastLine.StartsWith($" {project.Name} -> ")) { project.Executable = lastLine.Substring($" {project.Name} -> ".Length); } ; return exitCode == 0; })); }
public override CompileResult Compile(IConsole console, IStandardProject superProject, IStandardProject project, ISourceFile file, string outputFile) { var result = new CompileResult(); string commandName = file.Extension == ".cpp" ? CPPExecutable : CCExecutable; var fileArguments = string.Empty; if (file.Extension == ".cpp") { fileArguments = "-x c++ -fno-use-cxa-atexit"; } var arguments = string.Format("{0} {1} {2} -o{3} -MMD -MP", fileArguments, GetCompilerArguments(superProject, project, file), file.Location, outputFile); result.ExitCode = PlatformSupport.ExecuteShellCommand(commandName, arguments, (s, e) => console.WriteLine(e.Data), (s, e) => { if (e.Data != null) { console.WriteLine(); console.WriteLine(e.Data); } }, false, file.CurrentDirectory, false); //console.WriteLine(Path.GetFileNameWithoutExtension(commandName) + " " + arguments); return(result); }
public Task <bool> Build(IConsole console, IProject project, string label = "", IEnumerable <string> definitions = null) { console.WriteLine($"Build Started - {project.Name}"); //Make sure tools are available if (!PlatformSupport.CheckExecutableAvailability("tsc")) { //TypeScript compiler missing console.WriteLine("The TypeScript compiler `tsc` is not available on your path. Please install it with `npm install -g typescript`"); //Check if they're also missing Node if (!PlatformSupport.CheckExecutableAvailability("node")) { console.WriteLine("You seem to be missing Node.js. Please install Node.js and TypeScript globally."); } console.WriteLine("Build failed."); return(Task.FromResult(false)); //Fail build } var tscVersionResult = PlatformSupport.ExecuteShellCommand("tsc", "-v"); //Run build console.WriteLine($"Using TypeScript compiler {tscVersionResult.Output}"); console.WriteLine($"TypeScript compile started..."); var compileExitCode = PlatformSupport.ExecuteShellCommand("tsc", $"-p {project.CurrentDirectory}", (s, a) => console.WriteLine(a.Data)); if (compileExitCode != 0) { console.WriteLine($"Build completed with code {compileExitCode}"); } else { console.WriteLine("Build completed successfully."); } return(Task.FromResult(compileExitCode == 0)); }
public async Task <bool> Build(IConsole console, IProject project, string label = "", IEnumerable <string> definitions = null) { return(await Task.Factory.StartNew(() => { var settings = SettingsBase.GetSettings <DotNetToolchainSettings>(); var exitCode = PlatformSupport.ExecuteShellCommand(settings.DotNetPath, "build", (s, e) => { console.WriteLine(e.Data); if (!string.IsNullOrEmpty(e.Data)) { if (e.Data.StartsWith($" {project.Name} -> ")) { project.Executable = e.Data.Substring($" {project.Name} -> ".Length); } } }, (s, e) => { if (e.Data != null) { console.WriteLine(); console.WriteLine(e.Data); } }, false, project.CurrentDirectory, false); return exitCode == 0; })); }
public override ProcessResult Size(IConsole console, IStandardProject project, LinkResult linkResult) { var result = new ProcessResult(); result.ExitCode = PlatformSupport.ExecuteShellCommand(SizeExecutable, linkResult.Executable, (s, e) => console.WriteLine(e.Data), (s, e) => console.WriteLine(e.Data), false, string.Empty, false, RunWithSystemPaths); return(result); }
public async Task <ProcessResult> ObjCopy(IConsole console, IProject project, LinkResult linkResult, AssemblyFormat format) { var result = new ProcessResult(); var commandName = Path.Combine(BinDirectory, $"{SizePrefix}objcopy" + Platform.ExecutableExtension); if (PlatformSupport.CheckExecutableAvailability(commandName, BinDirectory)) { string formatArg = "binary"; switch (format) { case AssemblyFormat.Binary: formatArg = "binary"; break; case AssemblyFormat.IntelHex: formatArg = "ihex"; break; } string outputExtension = ".bin"; switch (format) { case AssemblyFormat.Binary: outputExtension = ".bin"; break; case AssemblyFormat.IntelHex: outputExtension = ".hex"; break; case AssemblyFormat.Elf32: outputExtension = ".elf"; break; } var arguments = $"-O {formatArg} {linkResult.Executable} {Path.GetDirectoryName(linkResult.Executable)}{Platform.DirectorySeperator}{Path.GetFileNameWithoutExtension(linkResult.Executable)}{outputExtension}"; console.WriteLine($"Converting to {format.ToString()}"); result.ExitCode = PlatformSupport.ExecuteShellCommand(commandName, arguments, (s, e) => console.WriteLine(e.Data), (s, e) => console.WriteLine(e.Data), false, string.Empty, false); } else { console.WriteLine("Unable to find tool (" + commandName + ") check project compiler settings."); result.ExitCode = -1; } return(result); }
public override CompileResult Compile(IConsole console, IStandardProject superProject, IStandardProject project, ISourceFile file, string outputFile) { var result = new CompileResult(); var settings = superProject.GetToolchainSettingsIfExists <GccToolchainSettings>().CompileSettings; string commandName = file.Extension == ".cpp" ? CPPExecutable : CCExecutable; var fileArguments = string.Empty; if (file.Extension.ToLower() == ".cpp" || (settings != null && settings.CompileExtensions.Select(ext => "." + ext.ToLower()).Contains(file.Extension.ToLower()))) { fileArguments = "-x c++ -fno-use-cxa-atexit"; } if (file.Extension.ToLower() == ".s" || (settings != null && settings.AssembleExtensions.Select(ext => "." + ext.ToLower()).Contains(file.Extension.ToLower()))) { fileArguments = "-x assembler-with-cpp"; } var environment = superProject.GetEnvironmentVariables().AppendRange(Platform.EnvironmentVariables); var arguments = ""; if (!string.IsNullOrWhiteSpace(SysRoot)) { arguments = string.Format("{0} {1} {2} -o{3} -MMD -MP --sysroot=\"{4}\"", fileArguments, GetCompilerArguments(superProject, project, file), file.Location, outputFile, SysRoot).ExpandVariables(environment); } else { arguments = string.Format("{0} {1} {2} -o{3} -MMD -MP", fileArguments, GetCompilerArguments(superProject, project, file), file.Location, outputFile).ExpandVariables(environment); } result.ExitCode = PlatformSupport.ExecuteShellCommand(commandName, arguments, (s, e) => console.WriteLine(e.Data), (s, e) => { if (e.Data != null) { ParseOutputForErrors(result.Diagnostics, file, e.Data); console.WriteLine(); console.WriteLine(e.Data); } }, false, "", false, RunWithSystemPaths, ExtraPaths); if (Studio.DebugMode) { console.WriteLine(Path.GetFileNameWithoutExtension(commandName) + " " + arguments); } return(result); }
public async Task Clean(IConsole console, IProject project) { await Task.Factory.StartNew(() => { var exitCode = PlatformSupport.ExecuteShellCommand(Path.Combine(BinDirectory, "dotnet" + Platform.ExecutableExtension), "clean", (s, e) => console.WriteLine(e.Data), (s, e) => { if (e.Data != null) { console.WriteLine(); console.WriteLine(e.Data); } }, false, project.CurrentDirectory, false); }); }
public async Task Clean(IConsole console, IProject project) { await Task.Factory.StartNew(() => { console.Write($"Cleaning Project: {project.Name}..."); var exitCode = PlatformSupport.ExecuteShellCommand(DotNetCliService.Instance.DotNetPath, "clean /nologo", (s, e) => console.WriteLine(e.Data), (s, e) => { if (e.Data != null) { console.WriteLine(); console.WriteLine(e.Data); } }, false, project.CurrentDirectory, false); }); console.WriteLine("Done."); }
private int ExecuteCommand(IConsole console, IProject project, string command, string args) { var environment = project.GetEnvironmentVariables().AppendRange(Platform.EnvironmentVariables); command = command.ExpandVariables(environment); args = args.ExpandVariables(environment); console.WriteLine($"[CMD] {command} {args}"); var exitCode = PlatformSupport.ExecuteShellCommand(command, args, (s, e) => { console.WriteLine(e.Data); }, (s, ee) => { if (ee.Data != null) { console.WriteLine(ee.Data); } }, false, project.CurrentDirectory, true, true, project.ToolChain?.BinDirectory); return(exitCode); }
private async Task <int> ExecuteCommand(IConsole console, IProject project, string command, string args) { var environment = project.GetEnvironmentVariables().AppendRange(Platform.EnvironmentVariables); if (command.Contains('{') && command.Contains('}') && command.Contains('?')) { var index = command.IndexOf("{?") + 1; var indexEnd = command.IndexOf('}'); var packageInfo = PackageManager.ParseUrl(command.Substring(index, indexEnd - index)); await PackageManager.EnsurePackage(packageInfo.package, packageInfo.version, console); var directory = PackageManager.GetPackageDirectory(packageInfo.package, packageInfo.version); command = command.Remove(index - 1, indexEnd - index + 2); command = command.Insert(index - 1, directory); } command = command.ExpandVariables(environment); args = args.ExpandVariables(environment); console.WriteLine($"[CMD] {command} {args}"); var exitCode = PlatformSupport.ExecuteShellCommand(command, args, (s, e) => { console.WriteLine(e.Data); }, (s, ee) => { if (ee.Data != null) { console.WriteLine(ee.Data); } }, false, project.CurrentDirectory, true, true, project.ToolChain?.BinDirectory); return(exitCode); }
public async Task Clean(IConsole console, IProject project) { await Task.Factory.StartNew(() => { var settings = SettingsBase.GetSettings <DotNetToolchainSettings>(); if (string.IsNullOrEmpty(settings.DotNetPath)) { console.WriteLine("Please configure the location of the dotnet runtime and sdk."); return; } var exitCode = PlatformSupport.ExecuteShellCommand(settings.DotNetPath, "clean", (s, e) => console.WriteLine(e.Data), (s, e) => { if (e.Data != null) { console.WriteLine(); console.WriteLine(e.Data); } }, false, project.CurrentDirectory, false); }); }
private static string ResolveShimVersion() { var settings = SettingsBase.GetSettings <DotNetToolchainSettings>(); bool inHostSection = false; string result = string.Empty; var exitCode = PlatformSupport.ExecuteShellCommand(settings.DotNetPath, "--info", (s, e) => { if (!string.IsNullOrEmpty(e.Data)) { if (inHostSection) { if (e.Data.Trim().StartsWith("Version")) { var parts = e.Data.Split(':'); if (parts.Length >= 2) { result = parts[1].Trim(); } } } else { if (e.Data.Trim().StartsWith("Microsoft .NET Core Shared Framework Host")) { inHostSection = true; } } } }, (s, e) => { }, false, "", false); return(result); }
public async Task <bool> BuildAsync(IConsole console, IProject project, string label = "", IEnumerable <string> definitions = null) { var diagnosticEntries = new Dictionary <string, List <Diagnostic> >(); var errorList = IoC.Get <IErrorList>(); errorList.Remove(this); var result = await Task.Factory.StartNew(() => { var exitCode = PlatformSupport.ExecuteShellCommand(DotNetCliService.Instance.Info.Executable, $"build {Path.GetFileName(project.Location)}", (s, e) => { console.WriteLine(e.Data); ParseOutputForErrors(diagnosticEntries, e.Data); }, (s, e) => { if (e.Data != null) { console.WriteLine(); console.WriteLine(e.Data); ParseOutputForErrors(diagnosticEntries, e.Data); } }, false, project.CurrentDirectory, false); return(exitCode == 0); }); foreach (var key in diagnosticEntries.Keys) { errorList.Create(this, key, DiagnosticSourceKind.Build, diagnosticEntries[key].ToImmutableArray()); } return(result); }
public Task RestoreAsync(string workingDirectory, string arguments = null, Action onFailure = null) { return(Task.Factory.StartNew(() => { _console.WriteLine($"Begin dotnet restore in '{workingDirectory}'"); var restoreLock = _locks.GetOrAdd(workingDirectory, new object()); lock (restoreLock) { ShellExecuteResult?exitStatus = null; //_eventEmitter.RestoreStarted(workingDirectory); _semaphore.Wait(); try { // A successful restore will update the project lock file which is monitored // by the dotnet project system which eventually update the Roslyn model exitStatus = PlatformSupport.ExecuteShellCommand(Path.Combine(workingDirectory, _dotnetPath), $"restore {arguments}");// updateEnvironment: RemoveMSBuildEnvironmentVariables); } finally { _semaphore.Release(); _locks.TryRemove(workingDirectory, out _); //_eventEmitter.RestoreFinished(workingDirectory, exitStatus.Succeeded); if (exitStatus?.ExitCode != 0 && onFailure != null) { onFailure(); } _console.WriteLine($"Finish restoring project {workingDirectory}. Exit code {exitStatus}"); } } })); }
protected override void OnRun(DebuggerStartInfo startInfo) { var settings = _project.GetDebuggerSettings <RemoteGdbSettings>(); var environment = _project.GetEnvironmentVariables().AppendRange(Platform.EnvironmentVariables); console.Clear(); var preInitCommand = settings.PreInitCommand?.Trim().ExpandVariables(environment); var preInitCommandArguments = settings.PreInitCommandArgs?.Trim().ExpandVariables(environment); var postInitCommand = settings.PostInitCommand?.Trim().ExpandVariables(environment); var postInitCommandArguments = settings.PostInitCommandArgs?.Trim().ExpandVariables(environment); if (!string.IsNullOrEmpty(preInitCommand)) { console.WriteLine("[Remote GDB] - Starting GDB Server..."); var gdbServerStartInfo = new ProcessStartInfo { Arguments = preInitCommandArguments ?? "", FileName = preInitCommand, WorkingDirectory = _project.CurrentDirectory, // Hide console window RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false, CreateNoWindow = true }; Task.Run(() => { using (var process = Process.Start(gdbServerStartInfo)) { _gdbServerProcess = process; process.OutputDataReceived += (sender, e) => { console.WriteLine("[GDB Server] - " + e.Data); }; process.ErrorDataReceived += (sender, e) => { if (!string.IsNullOrEmpty(e.Data)) { console.WriteLine("[GDB Server] - " + e.Data); } }; process.BeginOutputReadLine(); process.BeginErrorReadLine(); process.WaitForExit(); Dispose(); console.WriteLine("[GDB Server] - GDB Server Closed."); _gdbServerProcess = null; } }); TargetExited += (sender, e) => { _gdbServerProcess?.Kill(); _gdbServerProcess = null; }; } base.OnRun(startInfo); Task.Factory.StartNew(async() => { await Task.Delay(250); if (!string.IsNullOrEmpty(postInitCommand)) { var console = IoC.Get <IConsole>(); var exitCode = PlatformSupport.ExecuteShellCommand(postInitCommand, postInitCommandArguments, (s, e) => { console.WriteLine(e.Data); }, (s, ee) => { if (ee.Data != null) { console.WriteLine(ee.Data); } }, false, _project.CurrentDirectory, false); } }); }
public SemanticVersion GetVersion(string workingDirectory = null) { var shellResult = PlatformSupport.ExecuteShellCommand(Path.Combine(workingDirectory, _dotnetPath), "--version"); return(SemanticVersion.Parse(shellResult.Output)); }
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)); } } } }
public override LinkResult Link(IConsole console, IStandardProject superProject, IStandardProject project, CompileResult assemblies, string outputPath) { var result = new LinkResult(); string commandName = project.Type == ProjectType.StaticLibrary ? ARExecutable : LDExecutable; var objectArguments = string.Empty; foreach (var obj in assemblies.ObjectLocations) { objectArguments += obj + " "; } var libs = string.Empty; foreach (var lib in assemblies.LibraryLocations) { libs += lib + " "; } var outputDir = Path.GetDirectoryName(outputPath); if (!Directory.Exists(outputDir)) { Directory.CreateDirectory(outputDir); } var outputName = Path.GetFileName(outputPath); if (project.Type == ProjectType.StaticLibrary) { outputName = Path.GetFileName(outputPath); } var executable = Path.Combine(outputDir, outputName); var linkedLibraries = string.Empty; foreach (var libraryPath in project.StaticLibraries) { var relativePath = Path.GetDirectoryName(libraryPath); var libName = Path.GetFileNameWithoutExtension(libraryPath).Substring(3); linkedLibraries += string.Format("-L\"{0}\" -l{1} ", relativePath, libName); } string libraryPaths = string.Empty; var linkerScripts = string.Empty; if (project.Type == ProjectType.Executable) { var settings = project.GetToolchainSettings <GccToolchainSettings>(); foreach (var libraryPath in settings.LinkSettings.LinkedLibraries) { libraryPaths += $"-Wl,--library-path={Path.Combine(project.CurrentDirectory, Path.GetDirectoryName(libraryPath)).ToPlatformPath()} "; var libName = Path.GetFileName(libraryPath); linkedLibraries += string.Format($"-Wl,--library=:{libName} "); } foreach (var script in settings.LinkSettings.LinkerScripts) { linkerScripts += $"-Wl,-T\"{Path.Combine(project.CurrentDirectory, script)}\" "; } foreach (var lib in settings.LinkSettings.SystemLibraries) { linkedLibraries += $"-l{lib} "; } } foreach (var lib in project.BuiltinLibraries) { linkedLibraries += $"-l{lib} "; } linkedLibraries += GetBaseLibraryArguments(superProject); string arguments = string.Empty; if (project.Type == ProjectType.StaticLibrary) { arguments = string.Format("rvs {0} {1}", executable, objectArguments); } else { var environment = superProject.GetEnvironmentVariables().AppendRange(Platform.EnvironmentVariables); arguments = string.Format("{0} {1} -o{2} {3} {4} -Wl,--start-group {5} {6} -Wl,--end-group", GetLinkerArguments(superProject, project).ExpandVariables(environment), linkerScripts, executable, objectArguments, libraryPaths, linkedLibraries, libs); } result.ExitCode = PlatformSupport.ExecuteShellCommand(commandName, arguments, (s, e) => { if (e.Data != null) { console.WriteLine(e.Data); } }, (s, e) => { if (e.Data != null && !e.Data.Contains("creating")) { console.WriteLine(e.Data); } }, false, project.Solution.CurrentDirectory, false, RunWithSystemPaths); if (Shell.DebugMode) { console.WriteLine(Path.GetFileNameWithoutExtension(commandName) + " " + arguments); } if (result.ExitCode == 0) { result.Executable = executable; } return(result); }