public ConanProject ExtractConanProject(VCProject vcProject, ISettingsService settingsService) { var projectPath = ConanPathHelper.GetNearestConanfilePath(vcProject.ProjectDirectory); if (projectPath == null) { return(null); } var project = new ConanProject { Path = projectPath, }; if (settingsService != null && settingsService.GetConanInstallOnlyActiveConfiguration()) { project.Configurations.Add(ExtractConanConfiguration(settingsService, vcProject.ActiveConfiguration)); } else { foreach (VCConfiguration configuration in vcProject.Configurations) { project.Configurations.Add(ExtractConanConfiguration(settingsService, configuration)); } } return(project); }
public ConanProject ExtractConanProject(VCProject vcProject, ISettingsService settingsService) { var projectPath = ConanPathHelper.GetNearestConanfilePath(vcProject.ProjectDirectory); // TODO: Instead of nearest, use the one added to the project (be explicit) if (projectPath == null) { return(null); } string projectConanConfig = ConanPathHelper.GetNearestConanConfig(vcProject.ProjectDirectory); var project = new ConanProject { Path = projectPath, ConfigFile = projectConanConfig }; if (settingsService != null && settingsService.GetConanInstallOnlyActiveConfiguration()) { project.Configurations.Add(ExtractConanConfiguration(settingsService, vcProject.ActiveConfiguration)); } else { foreach (VCConfiguration configuration in vcProject.Configurations) { project.Configurations.Add(ExtractConanConfiguration(settingsService, configuration)); } } return(project); }
public async Task GeneratorShouldBeInvokedProperly() { var conan = new ConanRunner(ResourceUtils.ConanShim); var project = new ConanProject { Path = ".", InstallPath = "./conan", Configurations = { new ConanConfiguration { Architecture = "x86_64", BuildType = "Debug", CompilerToolset = "v141", CompilerVersion = "15" } } }; using (var process = await conan.Install(project, project.Configurations.Single())) { Assert.Equal("install . -g visual_studio_multi " + "--install-folder ./conan " + "-s arch=x86_64 " + "-s build_type=Debug " + "-s compiler.toolset=v141 " + "-s compiler.version=15 " + "--build missing --update", process.StartInfo.Arguments); } }
private async System.Threading.Tasks.Task InspectAsync(EnvDTE.Project project) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var conanProject = new ConanProject { Path = project.FileName }; await TaskScheduler.Default; var conanRunner = new ConanRunner(_settingsService.LoadSettingFile(conanProject), _conanPath); var process = await conanRunner.Inspect(conanProject); Logger.Log( $"[Conan.VisualStudio] Calling process '{process.StartInfo.FileName}' " + $"with arguments '{process.StartInfo.Arguments}'"); using (var reader = process.StandardOutput) { string line; while ((line = await reader.ReadLineAsync()) != null) { Logger.Log(line); } } }
private async Task InstallDependenciesAsync(ConanRunner conan, ConanProject project) { foreach (var configuration in project.Configurations) { var installPath = configuration.InstallPath; await Task.Run(() => Directory.CreateDirectory(installPath)); var logFilePath = Path.Combine(installPath, $"conan_{Guid.NewGuid().ToString()}.log"); using (var logFile = File.Open(logFilePath, FileMode.Create, FileAccess.Write, FileShare.Read)) using (var logStream = new StreamWriter(logFile)) { ConanGeneratorType generator = _settingsService.GetConanGenerator(); ConanBuildType build = _settingsService.GetConanBuild(); bool update = _settingsService.GetConanUpdate(); var process = await conan.Install(project, configuration, generator, build, update, _errorListService); string message = $"[Conan.VisualStudio] Calling process '{process.StartInfo.FileName}' " + $"with arguments '{process.StartInfo.Arguments}'"; Logger.Log(message); await logStream.WriteLineAsync(message); using (var reader = process.StandardOutput) { string line; while ((line = await reader.ReadLineAsync()) != null) { await logStream.WriteLineAsync(line); Logger.Log(line); } } var exitCode = await process.WaitForExitAsync(); if (exitCode != 0) { message = $"Conan has returned exit code '{exitCode}' " + $"while processing configuration '{configuration}'. " + $"Please check file '{logFilePath}' for details."; Logger.Log(message); await logStream.WriteLineAsync(message); _errorListService.WriteError(message, logFilePath); return; } else { message = $"[Conan.VisualStudio] Conan has succsessfully installed configuration '{configuration}'"; Logger.Log(message); await logStream.WriteLineAsync(message); _errorListService.WriteMessage(message); } } } }
private Task RunCommand(string conanPath, ConanProject project) { var vcProject = Mock.Of <VCProject>(); Mock.Get(vcProject).Setup(x => x.Name).Returns("TestProject"); var commandService = Mock.Of <IMenuCommandService>(); _dialogService.Setup(x => x.ShowOkCancel(It.IsAny <string>())).Returns(true); var projectService = new Mock <IVcProjectService>(); projectService.Setup(x => x.GetActiveProject()).Returns(vcProject); projectService.Setup(x => x.ExtractConanProject(It.IsAny <VCProject>())).ReturnsAsync(project); var settingsService = new Mock <ISettingsService>(); settingsService.Setup(x => x.GetConanExecutablePath()).Returns(conanPath); var command = new AddConanDepends( commandService, _dialogService.Object, projectService.Object, settingsService.Object); return(command.MenuItemCallback()); }
/// <summary> /// Try and load a project-level conan-vs-settings.json file /// </summary> /// <param name="project">Project</param> /// <returns>ConanSettings with overrides or null</returns> public ConanSettings LoadSettingFile(ConanProject project) { var projectDir = Path.GetDirectoryName(project.Path); var settingFileName = "conan-vs-settings.json"; var settingPath = Path.Combine(projectDir, settingFileName); if (!File.Exists(settingPath)) { return(null); } var conanSettings = JsonConvert.DeserializeObject <ConanSettings>(File.ReadAllText(settingPath)); return(conanSettings as ConanSettings); }
public async Task <ConanProject> ExtractConanProject(VCProject vcProject) { var projectPath = await ConanPathHelper.GetNearestConanfilePath(vcProject.ProjectDirectory); var project = new ConanProject { Path = projectPath, InstallPath = Path.Combine(projectPath, "conan") }; foreach (VCConfiguration configuration in vcProject.Configurations) { project.Configurations.Add(ExtractConanConfiguration(configuration)); } return(project); }
private async Task InstallDependencies(ConanRunner conan, ConanProject project) { var installPath = project.InstallPath; await Task.Run(() => Directory.CreateDirectory(installPath)); var logFilePath = Path.Combine(installPath, "conan.log"); using (var logFile = File.Open(logFilePath, FileMode.Create, FileAccess.Write, FileShare.Read)) using (var logStream = new StreamWriter(logFile)) { foreach (var configuration in project.Configurations) { var process = await conan.Install(project, configuration); await logStream.WriteLineAsync( $"[Conan.VisualStudio] Calling process '{process.StartInfo.FileName}' " + $"with arguments '{process.StartInfo.Arguments}'"); using (var reader = process.StandardOutput) { string line; while ((line = await reader.ReadLineAsync()) != null) { await logStream.WriteLineAsync(line); } } var exitCode = await process.WaitForExitAsync(); if (exitCode != 0) { _dialogService.ShowPluginError( $"Conan has returned exit code '{exitCode}' " + $"while processing configuration '{configuration}'. " + $"Please check file '{logFilePath}' for details."); return; } } _dialogService.ShowInfo("Conan dependencies have been installed successfully."); } }
private async void Inspect(EnvDTE.Project project) { var conanProject = new ConanProject { Path = project.FileName }; var process = await _conanRunner.Inspect(conanProject); Logger.Log( $"[Conan.VisualStudio] Calling process '{process.StartInfo.FileName}' " + $"with arguments '{process.StartInfo.Arguments}'"); using (var reader = process.StandardOutput) { string line; while ((line = await reader.ReadLineAsync()) != null) { Logger.Log(line); } } }
private async Task <bool> InstallDependenciesAsync(ConanRunner conan, ConanProject project) { foreach (var configuration in project.Configurations) { var installPath = configuration.InstallPath; await Task.Run(() => Directory.CreateDirectory(installPath)); var logFilePath = Path.Combine(installPath, $"conan_{Guid.NewGuid().ToString()}.log"); using (var logFile = File.Open(logFilePath, FileMode.Create, FileAccess.Write, FileShare.Read)) using (var logStream = new StreamWriter(logFile)) { ConanGeneratorType generator = _settingsService.GetConanGenerator(); ConanBuildType build = _settingsService.GetConanBuild(); bool update = _settingsService.GetConanUpdate(); ProcessStartInfo process = null; try { // Run 'conan --version' for log purposes process = conan.Version(); int exitCode = await Utils.RunProcessAsync(process, logStream); if (exitCode != 0) { string message = "Cannot get Conan version, check that the " + "executable is pointing to a valid one"; Logger.Log(message); await logStream.WriteLineAsync(message); _errorListService.WriteError(message, logFilePath); } // Run the install process = conan.Install(project, configuration, generator, build, update, _errorListService); exitCode = await Utils.RunProcessAsync(process, logStream); if (exitCode != 0) { string message = $"Conan has returned exit code '{exitCode}' " + $"while processing configuration '{configuration}'. " + $"Please check file '{logFilePath}' for details."; Logger.Log(message); await logStream.WriteLineAsync(message); _errorListService.WriteError(message, logFilePath); return(false); } else { string message = $"[Conan.VisualStudio] Conan has succsessfully " + $"installed configuration '{configuration}'"; Logger.Log(message); await logStream.WriteLineAsync(message); _errorListService.WriteMessage(message); } } catch (System.ComponentModel.Win32Exception e) { string message = $"[Conan.VisualStudio] Unhandled error running '{process.FileName}'" + $": {e.Message}. Check log file '{logFilePath}' for details"; Logger.Log(message); await logStream.WriteLineAsync(message); _errorListService.WriteError(message); return(false); } } } return(true); }