From a662b0a2da4154616ac4ec9c77729b49a9907a3c Mon Sep 17 00:00:00 2001 From: eidheim Date: Sat, 19 Mar 2016 13:48:20 +0100 Subject: [PATCH] Getting default/debug path cleanup --- src/cmake.cc | 57 ++-------------------------------------- src/cmake.h | 6 ++--- src/project_build.cc | 62 +++++++++++++++++++++++++++++++++++++------- src/project_build.h | 6 ++--- 4 files changed, 59 insertions(+), 72 deletions(-) diff --git a/src/cmake.cc b/src/cmake.cc index 4b4150c..01e372c 100644 --- a/src/cmake.cc +++ b/src/cmake.cc @@ -33,65 +33,13 @@ CMake::CMake(const boost::filesystem::path &path) { } } -boost::filesystem::path CMake::get_default_build_path() { - boost::filesystem::path default_build_path=Config::get().project.default_build_path; - - const std::string path_variable_project_directory_name=""; - size_t pos=0; - auto default_build_path_string=default_build_path.string(); - auto path_filename_string=project_path.filename().string(); - while((pos=default_build_path_string.find(path_variable_project_directory_name, pos))!=std::string::npos) { - default_build_path_string.replace(pos, path_variable_project_directory_name.size(), path_filename_string); - pos+=path_filename_string.size(); - } - if(pos!=0) - default_build_path=default_build_path_string; - - if(default_build_path.is_relative()) - default_build_path=project_path/default_build_path; - - return default_build_path; -} - -boost::filesystem::path CMake::get_debug_build_path() { - boost::filesystem::path debug_build_path=Config::get().project.debug_build_path; - - const std::string path_variable_project_directory_name=""; - size_t pos=0; - auto debug_build_path_string=debug_build_path.string(); - auto path_filename_string=project_path.filename().string(); - while((pos=debug_build_path_string.find(path_variable_project_directory_name, pos))!=std::string::npos) { - debug_build_path_string.replace(pos, path_variable_project_directory_name.size(), path_filename_string); - pos+=path_filename_string.size(); - } - if(pos!=0) - debug_build_path=debug_build_path_string; - - const std::string path_variable_default_build_path=""; - pos=0; - debug_build_path_string=debug_build_path.string(); - auto default_build_path=Config::get().project.default_build_path; - while((pos=debug_build_path_string.find(path_variable_default_build_path, pos))!=std::string::npos) { - debug_build_path_string.replace(pos, path_variable_default_build_path.size(), default_build_path); - pos+=default_build_path.size(); - } - if(pos!=0) - debug_build_path=debug_build_path_string; - - if(debug_build_path.is_relative()) - debug_build_path=project_path/debug_build_path; - - return debug_build_path; -} - -bool CMake::update_default_build(bool force) { +bool CMake::update_default_build(const boost::filesystem::path &default_build_path, bool force) { if(project_path.empty()) return false; if(!boost::filesystem::exists(project_path/"CMakeLists.txt")) return false; - auto default_build_path=get_default_build_path(); if(default_build_path.empty()) return false; if(!boost::filesystem::exists(default_build_path)) { @@ -131,14 +79,13 @@ bool CMake::update_default_build(bool force) { return false; } -bool CMake::update_debug_build(bool force) { +bool CMake::update_debug_build(const boost::filesystem::path &debug_build_path, bool force) { if(project_path.empty()) return false; if(!boost::filesystem::exists(project_path/"CMakeLists.txt")) return false; - auto debug_build_path=get_debug_build_path(); if(debug_build_path.empty()) return false; if(!boost::filesystem::exists(debug_build_path)) { diff --git a/src/cmake.h b/src/cmake.h index eb282db..004688d 100644 --- a/src/cmake.h +++ b/src/cmake.h @@ -11,10 +11,8 @@ public: boost::filesystem::path project_path; std::vector paths; - boost::filesystem::path get_default_build_path(); - boost::filesystem::path get_debug_build_path(); - bool update_default_build(bool force=false); - bool update_debug_build(bool force=false); + bool update_default_build(const boost::filesystem::path &default_build_path, bool force=false); + bool update_debug_build(const boost::filesystem::path &debug_build_path, bool force=false); boost::filesystem::path get_executable(const boost::filesystem::path &file_path); diff --git a/src/project_build.cc b/src/project_build.cc index 5da6b64..534742b 100644 --- a/src/project_build.cc +++ b/src/project_build.cc @@ -1,27 +1,71 @@ #include "project_build.h" +#include "config.h" std::unique_ptr Project::get_build(const boost::filesystem::path &path) { return std::unique_ptr(new CMake(path)); } -Project::CMake::CMake(const boost::filesystem::path &path) : Project::Build(), cmake(path) { - project_path=cmake.project_path; +boost::filesystem::path Project::Build::get_default_build_path() { + boost::filesystem::path default_build_path=Config::get().project.default_build_path; + + const std::string path_variable_project_directory_name=""; + size_t pos=0; + auto default_build_path_string=default_build_path.string(); + auto path_filename_string=project_path.filename().string(); + while((pos=default_build_path_string.find(path_variable_project_directory_name, pos))!=std::string::npos) { + default_build_path_string.replace(pos, path_variable_project_directory_name.size(), path_filename_string); + pos+=path_filename_string.size(); + } + if(pos!=0) + default_build_path=default_build_path_string; + + if(default_build_path.is_relative()) + default_build_path=project_path/default_build_path; + + return default_build_path; } -boost::filesystem::path Project::CMake::get_default_build_path() { - return cmake.get_default_build_path(); +boost::filesystem::path Project::Build::get_debug_build_path() { + boost::filesystem::path debug_build_path=Config::get().project.debug_build_path; + + const std::string path_variable_project_directory_name=""; + size_t pos=0; + auto debug_build_path_string=debug_build_path.string(); + auto path_filename_string=project_path.filename().string(); + while((pos=debug_build_path_string.find(path_variable_project_directory_name, pos))!=std::string::npos) { + debug_build_path_string.replace(pos, path_variable_project_directory_name.size(), path_filename_string); + pos+=path_filename_string.size(); + } + if(pos!=0) + debug_build_path=debug_build_path_string; + + const std::string path_variable_default_build_path=""; + pos=0; + debug_build_path_string=debug_build_path.string(); + auto default_build_path=Config::get().project.default_build_path; + while((pos=debug_build_path_string.find(path_variable_default_build_path, pos))!=std::string::npos) { + debug_build_path_string.replace(pos, path_variable_default_build_path.size(), default_build_path); + pos+=default_build_path.size(); + } + if(pos!=0) + debug_build_path=debug_build_path_string; + + if(debug_build_path.is_relative()) + debug_build_path=project_path/debug_build_path; + + return debug_build_path; } -bool Project::CMake::update_default_build(bool force) { - return cmake.update_default_build(force); +Project::CMake::CMake(const boost::filesystem::path &path) : Project::Build(), cmake(path) { + project_path=cmake.project_path; } -boost::filesystem::path Project::CMake::get_debug_build_path() { - return cmake.get_debug_build_path(); +bool Project::CMake::update_default_build(bool force) { + return cmake.update_default_build(get_default_build_path(), force); } bool Project::CMake::update_debug_build(bool force) { - return cmake.update_debug_build(force); + return cmake.update_debug_build(get_debug_build_path(), force); } boost::filesystem::path Project::CMake::get_executable(const boost::filesystem::path &path) { diff --git a/src/project_build.h b/src/project_build.h index ffd36cb..ea12926 100644 --- a/src/project_build.h +++ b/src/project_build.h @@ -12,9 +12,9 @@ namespace Project { boost::filesystem::path project_path; - virtual boost::filesystem::path get_default_build_path() {return boost::filesystem::path();} + boost::filesystem::path get_default_build_path(); virtual bool update_default_build(bool force=false) {return false;} - virtual boost::filesystem::path get_debug_build_path() {return boost::filesystem::path();} + boost::filesystem::path get_debug_build_path(); virtual bool update_debug_build(bool force=false) {return false;} virtual boost::filesystem::path get_executable(const boost::filesystem::path &path) {return boost::filesystem::path();} @@ -25,9 +25,7 @@ namespace Project { public: CMake(const boost::filesystem::path &path); - boost::filesystem::path get_default_build_path() override; bool update_default_build(bool force=false) override; - boost::filesystem::path get_debug_build_path() override; bool update_debug_build(bool force=false) override; boost::filesystem::path get_executable(const boost::filesystem::path &path) override;