|
|
|
@ -2,6 +2,7 @@ |
|
|
|
#include "config.h" |
|
|
|
#include "config.h" |
|
|
|
#include "terminal.h" |
|
|
|
#include "terminal.h" |
|
|
|
#include "filesystem.h" |
|
|
|
#include "filesystem.h" |
|
|
|
|
|
|
|
#include "directories.h" |
|
|
|
#include <fstream> |
|
|
|
#include <fstream> |
|
|
|
#include "menu.h" |
|
|
|
#include "menu.h" |
|
|
|
#include "notebook.h" |
|
|
|
#include "notebook.h" |
|
|
|
@ -9,15 +10,26 @@ |
|
|
|
#include "debug_clang.h" |
|
|
|
#include "debug_clang.h" |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boost::filesystem::path Project::debug_last_stop_file_path; |
|
|
|
std::unordered_map<std::string, std::string> Project::run_arguments; |
|
|
|
std::unordered_map<std::string, std::string> Project::run_arguments; |
|
|
|
std::unordered_map<std::string, std::string> Project::debug_run_arguments; |
|
|
|
std::unordered_map<std::string, std::string> Project::debug_run_arguments; |
|
|
|
std::atomic<bool> Project::compiling; |
|
|
|
std::atomic<bool> Project::compiling(false); |
|
|
|
std::atomic<bool> Project::debugging; |
|
|
|
std::atomic<bool> Project::debugging(false); |
|
|
|
std::pair<boost::filesystem::path, std::pair<int, int> > Project::debug_stop; |
|
|
|
std::pair<boost::filesystem::path, std::pair<int, int> > Project::debug_stop; |
|
|
|
boost::filesystem::path Project::debug_last_stop_file_path; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<Project::Language> Project::current_language; |
|
|
|
std::unique_ptr<Project::Language> Project::current_language; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Project::save_files(const boost::filesystem::path &path) { |
|
|
|
|
|
|
|
if(Notebook::get().get_current_page()==-1) |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
for(int c=0;c<Notebook::get().size();c++) { |
|
|
|
|
|
|
|
auto view=Notebook::get().get_view(c); |
|
|
|
|
|
|
|
if(view->get_buffer()->get_modified()) { |
|
|
|
|
|
|
|
if(filesystem::file_in_path(view->file_path, path)) |
|
|
|
|
|
|
|
Notebook::get().save(c); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Project::debug_update_status(const std::string &debug_status) { |
|
|
|
void Project::debug_update_status(const std::string &debug_status) { |
|
|
|
if(debug_status.empty()) |
|
|
|
if(debug_status.empty()) |
|
|
|
debug_status_label().set_text(""); |
|
|
|
debug_status_label().set_text(""); |
|
|
|
@ -74,39 +86,29 @@ std::unique_ptr<Project::Language> Project::get_language() { |
|
|
|
return std::unique_ptr<Project::Language>(new Project::Clang()); |
|
|
|
return std::unique_ptr<Project::Language>(new Project::Clang()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<CMake> Project::Clang::get_cmake() { |
|
|
|
Project::Language::Language() { |
|
|
|
boost::filesystem::path path; |
|
|
|
|
|
|
|
if(Notebook::get().get_current_page()!=-1) |
|
|
|
if(Notebook::get().get_current_page()!=-1) |
|
|
|
path=Notebook::get().get_current_view()->file_path.parent_path(); |
|
|
|
build=get_build(Notebook::get().get_current_view()->file_path); |
|
|
|
else |
|
|
|
else |
|
|
|
path=Directories::get().current_path; |
|
|
|
build=get_build(Directories::get().path); |
|
|
|
if(path.empty()) |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
auto cmake=std::unique_ptr<CMake>(new CMake(path)); |
|
|
|
|
|
|
|
if(cmake->project_path.empty()) |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
if(!CMake::create_default_build(cmake->project_path)) |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
return cmake; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::pair<std::string, std::string> Project::Clang::get_run_arguments() { |
|
|
|
std::pair<std::string, std::string> Project::Clang::get_run_arguments() { |
|
|
|
auto cmake=get_cmake(); |
|
|
|
if(build->get_default_build_path().empty() || !build->update_default_build()) |
|
|
|
if(!cmake) |
|
|
|
|
|
|
|
return {"", ""}; |
|
|
|
return {"", ""}; |
|
|
|
|
|
|
|
|
|
|
|
auto project_path=cmake->project_path.string(); |
|
|
|
auto project_path=build->project_path.string(); |
|
|
|
auto run_arguments_it=run_arguments.find(project_path); |
|
|
|
auto run_arguments_it=run_arguments.find(project_path); |
|
|
|
std::string arguments; |
|
|
|
std::string arguments; |
|
|
|
if(run_arguments_it!=run_arguments.end()) |
|
|
|
if(run_arguments_it!=run_arguments.end()) |
|
|
|
arguments=run_arguments_it->second; |
|
|
|
arguments=run_arguments_it->second; |
|
|
|
|
|
|
|
|
|
|
|
if(arguments.empty()) { |
|
|
|
if(arguments.empty()) { |
|
|
|
auto executable=cmake->get_executable(Notebook::get().get_current_page()!=-1?Notebook::get().get_current_view()->file_path:"").string(); |
|
|
|
auto executable=build->get_executable(Notebook::get().get_current_page()!=-1?Notebook::get().get_current_view()->file_path:"").string(); |
|
|
|
|
|
|
|
|
|
|
|
if(executable!="") { |
|
|
|
if(executable!="") { |
|
|
|
auto project_path=cmake->project_path; |
|
|
|
auto project_path=build->project_path; |
|
|
|
auto build_path=CMake::get_default_build_path(project_path); |
|
|
|
auto build_path=build->get_default_build_path(); |
|
|
|
if(!build_path.empty()) { |
|
|
|
if(!build_path.empty()) { |
|
|
|
size_t pos=executable.find(project_path.string()); |
|
|
|
size_t pos=executable.find(project_path.string()); |
|
|
|
if(pos!=std::string::npos) |
|
|
|
if(pos!=std::string::npos) |
|
|
|
@ -115,34 +117,33 @@ std::pair<std::string, std::string> Project::Clang::get_run_arguments() { |
|
|
|
arguments=filesystem::escape_argument(executable); |
|
|
|
arguments=filesystem::escape_argument(executable); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
arguments=filesystem::escape_argument(CMake::get_default_build_path(cmake->project_path)); |
|
|
|
arguments=filesystem::escape_argument(build->get_default_build_path()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return {project_path, arguments}; |
|
|
|
return {project_path, arguments}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Project::Clang::compile() {
|
|
|
|
void Project::Clang::compile() {
|
|
|
|
auto cmake=get_cmake(); |
|
|
|
if(build->get_default_build_path().empty() || !build->update_default_build()) |
|
|
|
if(!cmake) |
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
auto default_build_path=CMake::get_default_build_path(cmake->project_path); |
|
|
|
auto default_build_path=build->get_default_build_path(); |
|
|
|
if(default_build_path.empty()) |
|
|
|
if(default_build_path.empty()) |
|
|
|
return; |
|
|
|
return; |
|
|
|
compiling=true; |
|
|
|
compiling=true; |
|
|
|
Terminal::get().print("Compiling project "+cmake->project_path.string()+"\n"); |
|
|
|
Terminal::get().print("Compiling project "+build->project_path.string()+"\n"); |
|
|
|
Terminal::get().async_process(Config::get().project.make_command, default_build_path, [this](int exit_status) { |
|
|
|
Terminal::get().async_process(Config::get().project.make_command, default_build_path, [this](int exit_status) { |
|
|
|
compiling=false; |
|
|
|
compiling=false; |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Project::Clang::compile_and_run() { |
|
|
|
void Project::Clang::compile_and_run() { |
|
|
|
auto cmake=get_cmake(); |
|
|
|
if(build->get_default_build_path().empty() || !build->update_default_build()) |
|
|
|
if(!cmake) |
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
auto project_path=cmake->project_path; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto default_build_path=CMake::get_default_build_path(project_path); |
|
|
|
auto project_path=build->project_path; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto default_build_path=build->get_default_build_path(); |
|
|
|
if(default_build_path.empty()) |
|
|
|
if(default_build_path.empty()) |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
@ -152,11 +153,9 @@ void Project::Clang::compile_and_run() { |
|
|
|
arguments=run_arguments_it->second; |
|
|
|
arguments=run_arguments_it->second; |
|
|
|
|
|
|
|
|
|
|
|
if(arguments.empty()) { |
|
|
|
if(arguments.empty()) { |
|
|
|
arguments=cmake->get_executable(Notebook::get().get_current_page()!=-1?Notebook::get().get_current_view()->file_path:"").string(); |
|
|
|
arguments=build->get_executable(Notebook::get().get_current_page()!=-1?Notebook::get().get_current_view()->file_path:"").string(); |
|
|
|
if(arguments.empty()) { |
|
|
|
if(arguments.empty()) { |
|
|
|
Terminal::get().print("Could not find add_executable in the following paths:\n"); |
|
|
|
Terminal::get().print("Warning: could not find executable.\n"); |
|
|
|
for(auto &path: cmake->paths) |
|
|
|
|
|
|
|
Terminal::get().print(" "+path.string()+"\n"); |
|
|
|
|
|
|
|
Terminal::get().print("Solution: either use Project Set Run Arguments, or open a source file within a directory where add_executable is set.\n", true); |
|
|
|
Terminal::get().print("Solution: either use Project Set Run Arguments, or open a source file within a directory where add_executable is set.\n", true); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -180,22 +179,21 @@ void Project::Clang::compile_and_run() { |
|
|
|
|
|
|
|
|
|
|
|
#ifdef JUCI_ENABLE_DEBUG |
|
|
|
#ifdef JUCI_ENABLE_DEBUG |
|
|
|
std::pair<std::string, std::string> Project::Clang::debug_get_run_arguments() { |
|
|
|
std::pair<std::string, std::string> Project::Clang::debug_get_run_arguments() { |
|
|
|
auto cmake=get_cmake(); |
|
|
|
if(build->get_default_build_path().empty() || !build->update_default_build()) |
|
|
|
if(!cmake) |
|
|
|
|
|
|
|
return {"", ""}; |
|
|
|
return {"", ""}; |
|
|
|
|
|
|
|
|
|
|
|
auto project_path=cmake->project_path.string(); |
|
|
|
auto project_path=build->project_path.string(); |
|
|
|
auto run_arguments_it=debug_run_arguments.find(project_path); |
|
|
|
auto run_arguments_it=debug_run_arguments.find(project_path); |
|
|
|
std::string arguments; |
|
|
|
std::string arguments; |
|
|
|
if(run_arguments_it!=debug_run_arguments.end()) |
|
|
|
if(run_arguments_it!=debug_run_arguments.end()) |
|
|
|
arguments=run_arguments_it->second; |
|
|
|
arguments=run_arguments_it->second; |
|
|
|
|
|
|
|
|
|
|
|
if(arguments.empty()) { |
|
|
|
if(arguments.empty()) { |
|
|
|
auto executable=cmake->get_executable(Notebook::get().get_current_page()!=-1?Notebook::get().get_current_view()->file_path:"").string(); |
|
|
|
auto executable=build->get_executable(Notebook::get().get_current_page()!=-1?Notebook::get().get_current_view()->file_path:"").string(); |
|
|
|
|
|
|
|
|
|
|
|
if(executable!="") { |
|
|
|
if(executable!="") { |
|
|
|
auto project_path=cmake->project_path; |
|
|
|
auto project_path=build->project_path; |
|
|
|
auto build_path=CMake::get_debug_build_path(project_path); |
|
|
|
auto build_path=build->get_debug_build_path(); |
|
|
|
if(!build_path.empty()) { |
|
|
|
if(!build_path.empty()) { |
|
|
|
size_t pos=executable.find(project_path.string()); |
|
|
|
size_t pos=executable.find(project_path.string()); |
|
|
|
if(pos!=std::string::npos) |
|
|
|
if(pos!=std::string::npos) |
|
|
|
@ -204,22 +202,21 @@ std::pair<std::string, std::string> Project::Clang::debug_get_run_arguments() { |
|
|
|
arguments=filesystem::escape_argument(executable); |
|
|
|
arguments=filesystem::escape_argument(executable); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
arguments=filesystem::escape_argument(CMake::get_debug_build_path(cmake->project_path)); |
|
|
|
arguments=filesystem::escape_argument(build->get_debug_build_path()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return {project_path, arguments}; |
|
|
|
return {project_path, arguments}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Project::Clang::debug_start() { |
|
|
|
void Project::Clang::debug_start() { |
|
|
|
auto cmake=get_cmake(); |
|
|
|
if(build->get_default_build_path().empty() || !build->update_default_build()) |
|
|
|
if(!cmake) |
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
auto project_path=cmake->project_path; |
|
|
|
auto project_path=build->project_path; |
|
|
|
|
|
|
|
|
|
|
|
auto debug_build_path=CMake::get_debug_build_path(project_path); |
|
|
|
auto debug_build_path=build->get_debug_build_path(); |
|
|
|
if(debug_build_path.empty()) |
|
|
|
if(debug_build_path.empty()) |
|
|
|
return; |
|
|
|
return; |
|
|
|
if(!CMake::create_debug_build(project_path)) |
|
|
|
if(!build->update_debug_build()) |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
auto run_arguments_it=debug_run_arguments.find(project_path.string()); |
|
|
|
auto run_arguments_it=debug_run_arguments.find(project_path.string()); |
|
|
|
@ -228,11 +225,9 @@ void Project::Clang::debug_start() { |
|
|
|
run_arguments=run_arguments_it->second; |
|
|
|
run_arguments=run_arguments_it->second; |
|
|
|
|
|
|
|
|
|
|
|
if(run_arguments.empty()) { |
|
|
|
if(run_arguments.empty()) { |
|
|
|
run_arguments=cmake->get_executable(Notebook::get().get_current_page()!=-1?Notebook::get().get_current_view()->file_path:"").string(); |
|
|
|
run_arguments=build->get_executable(Notebook::get().get_current_page()!=-1?Notebook::get().get_current_view()->file_path:"").string(); |
|
|
|
if(run_arguments.empty()) { |
|
|
|
if(run_arguments.empty()) { |
|
|
|
Terminal::get().print("Could not find add_executable in the following paths:\n"); |
|
|
|
Terminal::get().print("Warning: could not find executable.\n"); |
|
|
|
for(auto &path: cmake->paths) |
|
|
|
|
|
|
|
Terminal::get().print(" "+path.string()+"\n"); |
|
|
|
|
|
|
|
Terminal::get().print("Solution: either use Debug Set Run Arguments, or open a source file within a directory where add_executable is set.\n", true); |
|
|
|
Terminal::get().print("Solution: either use Debug Set Run Arguments, or open a source file within a directory where add_executable is set.\n", true); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -245,7 +240,7 @@ void Project::Clang::debug_start() { |
|
|
|
auto breakpoints=std::make_shared<std::vector<std::pair<boost::filesystem::path, int> > >(); |
|
|
|
auto breakpoints=std::make_shared<std::vector<std::pair<boost::filesystem::path, int> > >(); |
|
|
|
for(int c=0;c<Notebook::get().size();c++) { |
|
|
|
for(int c=0;c<Notebook::get().size();c++) { |
|
|
|
auto view=Notebook::get().get_view(c); |
|
|
|
auto view=Notebook::get().get_view(c); |
|
|
|
if(project_path==view->project_path) { |
|
|
|
if(filesystem::file_in_path(view->file_path, project_path)) { |
|
|
|
auto iter=view->get_buffer()->begin(); |
|
|
|
auto iter=view->get_buffer()->begin(); |
|
|
|
if(view->get_source_buffer()->get_source_marks_at_iter(iter, "debug_breakpoint").size()>0) |
|
|
|
if(view->get_source_buffer()->get_source_marks_at_iter(iter, "debug_breakpoint").size()>0) |
|
|
|
breakpoints->emplace_back(view->file_path, iter.get_line()+1); |
|
|
|
breakpoints->emplace_back(view->file_path, iter.get_line()+1); |
|
|
|
|