From 8284194db01b6f0a9804272c852b5b91707b3ebd Mon Sep 17 00:00:00 2001 From: eidheim Date: Sat, 5 Sep 2020 09:57:16 +0200 Subject: [PATCH] Build messages are now shown while build is created/updated --- src/cmake.cpp | 33 +++++++++++++++++++++++++-------- src/meson.cpp | 37 +++++++++++++++++++++++++------------ 2 files changed, 50 insertions(+), 20 deletions(-) diff --git a/src/cmake.cpp b/src/cmake.cpp index bdfd55e..5ae3f00 100644 --- a/src/cmake.cpp +++ b/src/cmake.cpp @@ -7,6 +7,7 @@ #include "utility.hpp" #include #include +#include #include CMake::CMake(const boost::filesystem::path &path) { @@ -60,10 +61,19 @@ bool CMake::update_default_build(const boost::filesystem::path &default_build_pa auto compile_commands_path = default_build_path / "compile_commands.json"; Dialog::Message message("Creating/updating default build"); - auto exit_status = Terminal::get().process(Config::get().project.cmake.command + ' ' + - filesystem::escape_argument(project_path.string()) + " -DCMAKE_EXPORT_COMPILE_COMMANDS=ON", default_build_path); + std::promise promise; + Terminal::get().async_process(Config::get().project.cmake.command + ' ' + filesystem::escape_argument(project_path.string()) + " -DCMAKE_EXPORT_COMPILE_COMMANDS=ON", + default_build_path, + [&promise](int exit_status) { + promise.set_value(exit_status); + }); + auto future = promise.get_future(); + while(future.wait_for(std::chrono::milliseconds(10)) != std::future_status::ready) { + while(Gtk::Main::events_pending()) + Gtk::Main::iteration(); + } message.hide(); - if(exit_status == 0) { + if(future.get() == 0) { #ifdef _WIN32 //Temporary fix to MSYS2's libclang auto compile_commands_file = filesystem::read(compile_commands_path); auto replace_drive = [&compile_commands_file](const std::string ¶m) { @@ -103,12 +113,19 @@ bool CMake::update_debug_build(const boost::filesystem::path &debug_build_path, return true; Dialog::Message message("Creating/updating debug build"); - auto exit_status = Terminal::get().process(Config::get().project.cmake.command + ' ' + - filesystem::escape_argument(project_path.string()) + " -DCMAKE_BUILD_TYPE=Debug", debug_build_path); + std::promise promise; + Terminal::get().async_process(Config::get().project.cmake.command + ' ' + filesystem::escape_argument(project_path.string()) + " -DCMAKE_BUILD_TYPE=Debug", + debug_build_path, + [&promise](int exit_status) { + promise.set_value(exit_status); + }); + auto future = promise.get_future(); + while(future.wait_for(std::chrono::milliseconds(10)) != std::future_status::ready) { + while(Gtk::Main::events_pending()) + Gtk::Main::iteration(); + } message.hide(); - if(exit_status == 0) - return true; - return false; + return future.get() == 0; } boost::filesystem::path CMake::get_executable(const boost::filesystem::path &build_path, const boost::filesystem::path &file_path) { diff --git a/src/meson.cpp b/src/meson.cpp index c9faeb5..278e3ed 100644 --- a/src/meson.cpp +++ b/src/meson.cpp @@ -7,6 +7,7 @@ #include "utility.hpp" #include #include +#include #include Meson::Meson(const boost::filesystem::path &path) { @@ -60,13 +61,19 @@ bool Meson::update_default_build(const boost::filesystem::path &default_build_pa return true; Dialog::Message message("Creating/updating default build"); - auto exit_status = Terminal::get().process(Config::get().project.meson.command + ' ' + - (compile_commands_exists ? "--internal regenerate " : "") + - "--buildtype plain " + filesystem::escape_argument(project_path.string()), default_build_path); + std::promise promise; + Terminal::get().async_process(Config::get().project.meson.command + ' ' + (compile_commands_exists ? "--internal regenerate " : "") + "--buildtype plain " + filesystem::escape_argument(project_path.string()), + default_build_path, + [&promise](int exit_status) { + promise.set_value(exit_status); + }); + auto future = promise.get_future(); + while(future.wait_for(std::chrono::milliseconds(10)) != std::future_status::ready) { + while(Gtk::Main::events_pending()) + Gtk::Main::iteration(); + } message.hide(); - if(exit_status == 0) - return true; - return false; + return future.get() == 0; } bool Meson::update_debug_build(const boost::filesystem::path &debug_build_path, bool force) { @@ -88,13 +95,19 @@ bool Meson::update_debug_build(const boost::filesystem::path &debug_build_path, return true; Dialog::Message message("Creating/updating debug build"); - auto exit_status = Terminal::get().process(Config::get().project.meson.command + ' ' + - (compile_commands_exists ? "--internal regenerate " : "") + - "--buildtype debug " + filesystem::escape_argument(project_path.string()), debug_build_path); + std::promise promise; + Terminal::get().async_process(Config::get().project.meson.command + ' ' + (compile_commands_exists ? "--internal regenerate " : "") + "--buildtype debug " + filesystem::escape_argument(project_path.string()), + debug_build_path, + [&promise](int exit_status) { + promise.set_value(exit_status); + }); + auto future = promise.get_future(); + while(future.wait_for(std::chrono::milliseconds(10)) != std::future_status::ready) { + while(Gtk::Main::events_pending()) + Gtk::Main::iteration(); + } message.hide(); - if(exit_status == 0) - return true; - return false; + return future.get() == 0; } boost::filesystem::path Meson::get_executable(const boost::filesystem::path &build_path, const boost::filesystem::path &file_path) {