diff --git a/src/project_build.cpp b/src/project_build.cpp index 933a0d7..d767121 100644 --- a/src/project_build.cpp +++ b/src/project_build.cpp @@ -1,6 +1,7 @@ #include "project_build.hpp" #include "config.hpp" #include "filesystem.hpp" +#include "terminal.hpp" #include #include #include @@ -202,6 +203,27 @@ bool Project::MesonBuild::is_valid() { return true; } +bool Project::CargoBuild::update_default(bool force) { + auto default_build_path = get_default_path(); + if(default_build_path.empty()) + return false; + + boost::system::error_code ec; + if(!boost::filesystem::exists(default_build_path, ec)) { + boost::system::error_code ec; + boost::filesystem::create_directories(default_build_path, ec); + if(ec) { + Terminal::get().print("\e[31mError\e[m: could not create " + filesystem::get_short_path(default_build_path).string() + ": " + ec.message() + "\n", true); + return false; + } + } + return true; +} + +bool Project::CargoBuild::update_debug(bool force) { + return update_default(force); +} + std::string Project::CargoBuild::get_compile_command() { return Config::get().project.cargo_command + " build"; } diff --git a/src/project_build.hpp b/src/project_build.hpp index f1677b6..0ddacf1 100644 --- a/src/project_build.hpp +++ b/src/project_build.hpp @@ -63,9 +63,9 @@ namespace Project { class CargoBuild : public Build { public: boost::filesystem::path get_default_path() override { return project_path / "target" / "debug"; } - bool update_default(bool force = false) override { return true; } + bool update_default(bool force = false) override; boost::filesystem::path get_debug_path() override { return get_default_path(); } - bool update_debug(bool force = false) override { return true; } + bool update_debug(bool force = false) override; std::string get_compile_command() override; boost::filesystem::path get_executable(const boost::filesystem::path &path) override { return get_debug_path() / project_path.filename(); }