Skip to content
This repository has been archived by the owner on Jun 25, 2020. It is now read-only.

Commit

Permalink
Related to #352: more general way of finding version specific clang-f…
Browse files Browse the repository at this point in the history
…ormat and lldb-server executables
  • Loading branch information
eidheim committed Nov 5, 2017
1 parent e85e5b6 commit e931840
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 34 deletions.
15 changes: 0 additions & 15 deletions src/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -207,19 +207,4 @@ void Config::read(const boost::property_tree::ptree &cfg) {
terminal.font=cfg.get<std::string>("terminal.font");

terminal.show_progress=cfg.get<bool>("terminal.show_progress");

terminal.clang_format_command="clang-format";
#ifdef __linux
if(terminal.clang_format_command=="clang-format" &&
!boost::filesystem::exists("/usr/bin/clang-format") && !boost::filesystem::exists("/usr/local/bin/clang-format")) {
auto versions={"5.0", "5", "4.0", "4", "3.9", "3.8", "3.7", "3.6", "3.5"};
for(auto &version: versions) {
auto corrected_command=std::string("/usr/bin/clang-format-")+version;
if(boost::filesystem::exists(corrected_command)) {
terminal.clang_format_command=corrected_command;
break;
}
}
}
#endif
}
1 change: 0 additions & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class Config {

class Terminal {
public:
std::string clang_format_command;
int history_size;
std::string font;
bool show_progress;
Expand Down
22 changes: 6 additions & 16 deletions src/debug_lldb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,17 @@ void log(const char *msg, void *) {
}

Debug::LLDB::LLDB(): state(lldb::StateType::eStateInvalid), buffer_size(131072) {
#ifdef __APPLE__
if(!getenv("LLDB_DEBUGSERVER_PATH")) {
#ifdef __APPLE__
std::string debug_server_path("/usr/local/opt/llvm/bin/debugserver");
if(boost::filesystem::exists(debug_server_path))
setenv("LLDB_DEBUGSERVER_PATH", debug_server_path.c_str(), 0);
}
#elif __linux
if(!getenv("LLDB_DEBUGSERVER_PATH")) {
std::string debug_server_path("/usr/bin/lldb-server");
if(!boost::filesystem::exists(debug_server_path)) {
auto versions={"5.0", "5", "4.0", "4", "3.9", "3.8", "3.7", "3.6", "3.5"};
for(auto &version: versions) {
auto corrected_debug_server_path=debug_server_path+'-'+version;
if(boost::filesystem::exists(corrected_debug_server_path)) {
setenv("LLDB_DEBUGSERVER_PATH", corrected_debug_server_path.c_str(), 0);
break;
}
}
}
}
#else
auto debug_server_path = filesystem::get_executable("lldb-server").string();
if(debug_server_path != "lldb-server")
setenv("LLDB_DEBUGSERVER_PATH", debug_server_path.c_str(), 0);
#endif
}
}

std::tuple<std::vector<std::string>, std::string, std::vector<std::string> > Debug::LLDB::parse_run_arguments(const std::string &command) {
Expand Down
41 changes: 41 additions & 0 deletions src/filesystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,44 @@ boost::filesystem::path filesystem::get_relative_path(const boost::filesystem::p

return relative_path;
}

boost::filesystem::path filesystem::get_executable(const boost::filesystem::path &executable_name) noexcept {
#if defined(__APPLE__) || defined(_WIN32)
return executable_name;
#endif

static std::vector<boost::filesystem::path> bin_paths={"/usr/bin", "/usr/local/bin"};

try {
for(auto &path: bin_paths) {
if(boost::filesystem::exists(path/executable_name))
return executable_name;
}

auto executable_name_str = executable_name.string();
for(auto &path: bin_paths) {
boost::filesystem::path executable;
for(boost::filesystem::directory_iterator it(path), end; it != end; ++it) {
auto it_path = it->path();
auto it_path_filename_str = it_path.filename().string();
if(!it_path_filename_str.empty() && it_path_filename_str.compare(0, executable_name_str.size(), executable_name_str)==0) {
if(it_path > executable &&
((it_path_filename_str.size() > executable_name_str.size() &&
it_path_filename_str[executable_name_str.size()]>='0' &&
it_path_filename_str[executable_name_str.size()]<='9') ||
(it_path_filename_str.size() > executable_name_str.size()+1 &&
it_path_filename_str[executable_name_str.size()]=='-' &&
it_path_filename_str[executable_name_str.size()+1]>='0' &&
it_path_filename_str[executable_name_str.size()+1]<='9')) &&
!boost::filesystem::is_directory(it_path))
executable=it_path;
}
}
if(!executable.empty())
return executable;
}
}
catch(...) {}

return executable_name;
}
5 changes: 4 additions & 1 deletion src/filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ class filesystem {
/// Return path with dot, dot-dot and directory separator elements removed
static boost::filesystem::path get_normal_path(const boost::filesystem::path &path) noexcept;

///Returns empty path on failure
/// Returns empty path on failure
static boost::filesystem::path get_relative_path(const boost::filesystem::path &path, const boost::filesystem::path &base) noexcept;

/// Return executable with latest version in filename on systems that is lacking executable_name symbolic link
static boost::filesystem::path get_executable(const boost::filesystem::path &executable_name) noexcept;
};
#endif // JUCI_FILESYSTEM_H_
4 changes: 3 additions & 1 deletion src/source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ Source::View::View(const boost::filesystem::path &file_path, Glib::RefPtr<Gsv::L
is_bracket_language=true;

format_style=[this](bool continue_without_style_file) {
auto command=Config::get().terminal.clang_format_command+" -output-replacements-xml -assume-filename="+filesystem::escape_argument(this->file_path.string());
static auto clang_format_command = filesystem::get_executable("clang-format").string();

auto command=clang_format_command+" -output-replacements-xml -assume-filename="+filesystem::escape_argument(this->file_path.string());

if(get_buffer()->get_has_selection()) {
Gtk::TextIter start, end;
Expand Down

0 comments on commit e931840

Please sign in to comment.