Browse Source

Fixes #121, #131 and #132. More testing needed, except bugfix commits soon.

merge-requests/365/head
eidheim 10 years ago
parent
commit
606db580d5
  1. 39
      src/cmake.cc
  2. 2
      src/cmake.h
  3. 2
      src/config.cc
  4. 1
      src/config.h
  5. 4
      src/files.h
  6. 2
      src/notebook.cc
  7. 3
      src/source_clang.cc
  8. 15
      src/window.cc

39
src/cmake.cc

@ -33,14 +33,47 @@ CMake::CMake(const boost::filesystem::path &path) {
} }
if(!project_path.empty()) { if(!project_path.empty()) {
if(boost::filesystem::exists(project_path/"CMakeLists.txt") && !boost::filesystem::exists(project_path/"compile_commands.json")) if(!boost::filesystem::exists(get_default_build_path(project_path)/"compile_commands.json"))
create_compile_commands(project_path); create_compile_commands(project_path);
} }
} }
boost::filesystem::path CMake::get_default_build_path(const boost::filesystem::path &path) {
boost::filesystem::path default_build_path=Config::get().terminal.default_build_path;
const std::string path_variable_project_directory_name="<project_directory_name>";
size_t pos=0;
auto default_build_path_string=default_build_path.string();
auto path_filename_string=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=path/default_build_path;
if(!boost::filesystem::exists(default_build_path)) {
boost::system::error_code ec;
boost::filesystem::create_directories(default_build_path, ec);
if(ec) {
Terminal::get().print("Could not create "+default_build_path.string()+": "+ec.message(), true);
return boost::filesystem::path();
}
}
return default_build_path;
}
bool CMake::create_compile_commands(const boost::filesystem::path &path) { bool CMake::create_compile_commands(const boost::filesystem::path &path) {
Dialog::Message message("Creating "+path.string()+"/compile_commands.json"); auto default_build_path=get_default_build_path(path);
auto exit_status=Terminal::get().process(Config::get().terminal.cmake_command+" . -DCMAKE_EXPORT_COMPILE_COMMANDS=ON", path); if(default_build_path.empty())
return false;
Dialog::Message message("Creating "+default_build_path.string()+"/compile_commands.json");
auto exit_status=Terminal::get().process(Config::get().terminal.cmake_command+" "+
path.string()+" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON", default_build_path);
message.hide(); message.hide();
if(exit_status==EXIT_SUCCESS) { if(exit_status==EXIT_SUCCESS) {
#ifdef _WIN32 //Temporary fix to MSYS2's libclang #ifdef _WIN32 //Temporary fix to MSYS2's libclang

2
src/cmake.h

@ -8,6 +8,7 @@ class CMake {
public: public:
CMake(const boost::filesystem::path &path); CMake(const boost::filesystem::path &path);
std::vector<std::pair<boost::filesystem::path, std::vector<std::string> > > get_functions_parameters(const std::string &name); std::vector<std::pair<boost::filesystem::path, std::vector<std::string> > > get_functions_parameters(const std::string &name);
static boost::filesystem::path get_default_build_path(const boost::filesystem::path &path);
static bool create_compile_commands(const boost::filesystem::path &path); static bool create_compile_commands(const boost::filesystem::path &path);
std::vector<boost::filesystem::path> paths; std::vector<boost::filesystem::path> paths;
@ -15,6 +16,7 @@ public:
boost::filesystem::path project_path; boost::filesystem::path project_path;
std::unordered_map<std::string, std::string> variables; std::unordered_map<std::string, std::string> variables;
private: private:
void read_files(); void read_files();
void remove_tabs(); void remove_tabs();
void remove_comments(); void remove_comments();

2
src/config.cc

@ -84,6 +84,8 @@ void Config::retrieve_config() {
window.theme_variant=cfg.get<std::string>("gtk_theme.variant"); window.theme_variant=cfg.get<std::string>("gtk_theme.variant");
window.version = cfg.get<std::string>("version"); window.version = cfg.get<std::string>("version");
window.default_size = {cfg.get<int>("default_window_size.width"), cfg.get<int>("default_window_size.height")}; window.default_size = {cfg.get<int>("default_window_size.width"), cfg.get<int>("default_window_size.height")};
terminal.default_build_path=cfg.get<std::string>("project.default_build_path");
terminal.make_command=cfg.get<std::string>("project.make_command"); terminal.make_command=cfg.get<std::string>("project.make_command");
terminal.cmake_command=cfg.get<std::string>("project.cmake_command"); terminal.cmake_command=cfg.get<std::string>("project.cmake_command");
terminal.history_size=cfg.get<int>("terminal_history_size"); terminal.history_size=cfg.get<int>("terminal_history_size");

1
src/config.h

@ -24,6 +24,7 @@ public:
class Terminal { class Terminal {
public: public:
std::string default_build_path;
std::string cmake_command; std::string cmake_command;
std::string make_command; std::string make_command;
std::string clang_format_command; std::string clang_format_command;

4
src/files.h

@ -2,7 +2,7 @@
#define JUCI_FILES_H_ #define JUCI_FILES_H_
#include <string> #include <string>
#define JUCI_VERSION "1.0.0" #define JUCI_VERSION "1.0.1"
const std::string configjson = const std::string configjson =
"{\n" "{\n"
@ -107,6 +107,8 @@ const std::string configjson =
" \"close_tab\": \"<primary>w\"\n" " \"close_tab\": \"<primary>w\"\n"
" },\n" " },\n"
" \"project\": {\n" " \"project\": {\n"
" \"default_build_path_comment\": \"Use <project_directory_name> to insert the project top level directory name\",\n"
" \"default_build_path\": \"./build\",\n"
#ifdef _WIN32 #ifdef _WIN32
" \"cmake_command\": \"cmake -G\\\"MSYS Makefiles\\\" -DCMAKE_INSTALL_PREFIX="+JUCI_CMAKE_INSTALL_PREFIX+"\",\n" " \"cmake_command\": \"cmake -G\\\"MSYS Makefiles\\\" -DCMAKE_INSTALL_PREFIX="+JUCI_CMAKE_INSTALL_PREFIX+"\",\n"
#else #else

2
src/notebook.cc

@ -110,7 +110,7 @@ void Notebook::open(const boost::filesystem::path &file_path) {
} }
} }
if(language && (language->get_id()=="chdr" || language->get_id()=="cpphdr" || language->get_id()=="c" || language->get_id()=="cpp" || language->get_id()=="objc")) { if(language && (language->get_id()=="chdr" || language->get_id()=="cpphdr" || language->get_id()=="c" || language->get_id()=="cpp" || language->get_id()=="objc")) {
if(boost::filesystem::exists(project_path.string()+"/CMakeLists.txt") && !boost::filesystem::exists(project_path.string()+"/compile_commands.json")) if(boost::filesystem::exists(project_path.string()+"/CMakeLists.txt") && !boost::filesystem::exists(CMake::get_default_build_path(project_path)/"compile_commands.json"))
CMake::create_compile_commands(project_path); CMake::create_compile_commands(project_path);
source_views.emplace_back(new Source::ClangView(file_path, project_path, language)); source_views.emplace_back(new Source::ClangView(file_path, project_path, language));
} }

3
src/source_clang.cc

@ -1,6 +1,7 @@
#include "source_clang.h" #include "source_clang.h"
#include "config.h" #include "config.h"
#include "terminal.h" #include "terminal.h"
#include "cmake.h"
namespace sigc { namespace sigc {
#ifndef SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE #ifndef SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE
@ -178,7 +179,7 @@ void Source::ClangViewParse::soft_reparse() {
} }
std::vector<std::string> Source::ClangViewParse::get_compilation_commands() { std::vector<std::string> Source::ClangViewParse::get_compilation_commands() {
clang::CompilationDatabase db(project_path.string()); clang::CompilationDatabase db(CMake::get_default_build_path(project_path).string());
clang::CompileCommands commands(file_path.string(), db); clang::CompileCommands commands(file_path.string(), db);
std::vector<clang::CompileCommand> cmds = commands.get_commands(); std::vector<clang::CompileCommand> cmds = commands.get_commands();
std::vector<std::string> arguments; std::vector<std::string> arguments;

15
src/window.cc

@ -540,9 +540,16 @@ void Window::set_menu_actions() {
if(cmake.project_path!="") { if(cmake.project_path!="") {
if(executable_path!="") { if(executable_path!="") {
compiling=true; compiling=true;
Terminal::get().print("Compiling and running "+executable_path.string()+"\n");
auto project_path=cmake.project_path; auto project_path=cmake.project_path;
Terminal::get().async_process(Config::get().terminal.make_command, cmake.project_path, [this, executable_path, project_path](int exit_status){ auto default_build_path=CMake::get_default_build_path(project_path);
auto executable_path_string=executable_path.string();
size_t pos=executable_path_string.find(project_path.string());
if(pos!=std::string::npos) {
executable_path_string.replace(pos, project_path.string().size(), default_build_path.string());
executable_path=executable_path_string;
}
Terminal::get().print("Compiling and running "+executable_path.string()+"\n");
Terminal::get().async_process(Config::get().terminal.make_command, default_build_path, [this, executable_path, default_build_path](int exit_status){
compiling=false; compiling=false;
if(exit_status==EXIT_SUCCESS) { if(exit_status==EXIT_SUCCESS) {
auto executable_path_spaces_fixed=executable_path.string(); auto executable_path_spaces_fixed=executable_path.string();
@ -554,7 +561,7 @@ void Window::set_menu_actions() {
} }
last_char=executable_path_spaces_fixed[c]; last_char=executable_path_spaces_fixed[c];
} }
Terminal::get().async_process(executable_path_spaces_fixed, project_path, [this, executable_path](int exit_status){ Terminal::get().async_process(executable_path_spaces_fixed, default_build_path, [this, executable_path](int exit_status){
Terminal::get().async_print(executable_path.string()+" returned: "+std::to_string(exit_status)+'\n'); Terminal::get().async_print(executable_path.string()+" returned: "+std::to_string(exit_status)+'\n');
}); });
} }
@ -581,7 +588,7 @@ void Window::set_menu_actions() {
if(cmake.project_path!="") { if(cmake.project_path!="") {
compiling=true; compiling=true;
Terminal::get().print("Compiling project "+cmake.project_path.string()+"\n"); Terminal::get().print("Compiling project "+cmake.project_path.string()+"\n");
Terminal::get().async_process(Config::get().terminal.make_command, cmake.project_path, [this](int exit_status){ Terminal::get().async_process(Config::get().terminal.make_command, CMake::get_default_build_path(cmake.project_path), [this](int exit_status){
compiling=false; compiling=false;
}); });
} }

Loading…
Cancel
Save