Example #1
0
        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);
                }
            }
        }
        protected internal override async Task MenuItemCallback()
        {
            var vcProject = _vcProjectService.GetActiveProject();

            if (vcProject == null)
            {
                _dialogService.ShowPluginError("A C++ project with a conan file must be selected.");
                return;
            }

            if (!_dialogService.ShowOkCancel($"Process conanbuild.txt for '{vcProject.Name}'?\n"))
            {
                return;
            }

            var conanPath = _settingsService.GetConanExecutablePath();

            if (conanPath == null)
            {
                _dialogService.ShowPluginError(
                    "Conan executable path is not set and Conan executable wasn't found automatically. " +
                    "Please set it up in the Tools → Settings → Conan menu.");
                return;
            }

            var conan   = new ConanRunner(conanPath);
            var project = await _vcProjectService.ExtractConanProject(vcProject);

            await InstallDependencies(conan, project);
        }
Example #3
0
        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);
            }
        }
Example #4
0
        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);
                        }
                    }
            }
        }
        public SolutionEventsHandler(VSConanPackage package)
        {
            var settingsService = new VisualStudioSettingsService(package);
            var conanPath       = settingsService.GetConanExecutablePath();

            _conanRunner = new ConanRunner(conanPath);
        }
        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.");
                }
        }
Example #7
0
        public async Task <bool> InstallAsync(IVCProject vcProject)
        {
            var conanPath = _settingsService.GetConanExecutablePath();

            if (conanPath == null || conanPath == "")
            {
                _errorListService.WriteError(
                    "Conan executable path is not set and Conan executable wasn't found automatically. " +
                    "Please set it up in the Tools → Settings → Conan menu.");
                return(false);
            }

            var project = await _vcProjectService.ExtractConanProjectAsync(vcProject, _settingsService);

            if (project == null)
            {
                _errorListService.WriteError("Unable to extract conan project!");
                return(false);
            }
            var conan = new ConanRunner(conanPath);

            return(await InstallDependenciesAsync(conan, project));
        }
Example #8
0
        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);
        }