Browse Source

Now makes sure build directory is created before building and debugging rust programs

merge-requests/404/merge
eidheim 5 years ago
parent
commit
218f98f9c2
  1. 22
      src/project_build.cpp
  2. 4
      src/project_build.hpp

22
src/project_build.cpp

@ -1,6 +1,7 @@
#include "project_build.hpp" #include "project_build.hpp"
#include "config.hpp" #include "config.hpp"
#include "filesystem.hpp" #include "filesystem.hpp"
#include "terminal.hpp"
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <boost/property_tree/json_parser.hpp> #include <boost/property_tree/json_parser.hpp>
#include <regex> #include <regex>
@ -202,6 +203,27 @@ bool Project::MesonBuild::is_valid() {
return true; 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() { std::string Project::CargoBuild::get_compile_command() {
return Config::get().project.cargo_command + " build"; return Config::get().project.cargo_command + " build";
} }

4
src/project_build.hpp

@ -63,9 +63,9 @@ namespace Project {
class CargoBuild : public Build { class CargoBuild : public Build {
public: public:
boost::filesystem::path get_default_path() override { return project_path / "target" / "debug"; } 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(); } 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; std::string get_compile_command() override;
boost::filesystem::path get_executable(const boost::filesystem::path &path) override { return get_debug_path() / project_path.filename(); } boost::filesystem::path get_executable(const boost::filesystem::path &path) override { return get_debug_path() / project_path.filename(); }

Loading…
Cancel
Save