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

Commit e931840

Browse files
committedNov 5, 2017
Related to #352: more general way of finding version specific clang-format and lldb-server executables
1 parent e85e5b6 commit e931840

File tree

6 files changed

+54
-34
lines changed

6 files changed

+54
-34
lines changed
 

‎src/config.cc

-15
Original file line numberDiff line numberDiff line change
@@ -207,19 +207,4 @@ void Config::read(const boost::property_tree::ptree &cfg) {
207207
terminal.font=cfg.get<std::string>("terminal.font");
208208

209209
terminal.show_progress=cfg.get<bool>("terminal.show_progress");
210-
211-
terminal.clang_format_command="clang-format";
212-
#ifdef __linux
213-
if(terminal.clang_format_command=="clang-format" &&
214-
!boost::filesystem::exists("/usr/bin/clang-format") && !boost::filesystem::exists("/usr/local/bin/clang-format")) {
215-
auto versions={"5.0", "5", "4.0", "4", "3.9", "3.8", "3.7", "3.6", "3.5"};
216-
for(auto &version: versions) {
217-
auto corrected_command=std::string("/usr/bin/clang-format-")+version;
218-
if(boost::filesystem::exists(corrected_command)) {
219-
terminal.clang_format_command=corrected_command;
220-
break;
221-
}
222-
}
223-
}
224-
#endif
225210
}

‎src/config.h

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class Config {
2525

2626
class Terminal {
2727
public:
28-
std::string clang_format_command;
2928
int history_size;
3029
std::string font;
3130
bool show_progress;

‎src/debug_lldb.cc

+6-16
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,17 @@ void log(const char *msg, void *) {
1717
}
1818

1919
Debug::LLDB::LLDB(): state(lldb::StateType::eStateInvalid), buffer_size(131072) {
20-
#ifdef __APPLE__
2120
if(!getenv("LLDB_DEBUGSERVER_PATH")) {
21+
#ifdef __APPLE__
2222
std::string debug_server_path("/usr/local/opt/llvm/bin/debugserver");
2323
if(boost::filesystem::exists(debug_server_path))
2424
setenv("LLDB_DEBUGSERVER_PATH", debug_server_path.c_str(), 0);
25-
}
26-
#elif __linux
27-
if(!getenv("LLDB_DEBUGSERVER_PATH")) {
28-
std::string debug_server_path("/usr/bin/lldb-server");
29-
if(!boost::filesystem::exists(debug_server_path)) {
30-
auto versions={"5.0", "5", "4.0", "4", "3.9", "3.8", "3.7", "3.6", "3.5"};
31-
for(auto &version: versions) {
32-
auto corrected_debug_server_path=debug_server_path+'-'+version;
33-
if(boost::filesystem::exists(corrected_debug_server_path)) {
34-
setenv("LLDB_DEBUGSERVER_PATH", corrected_debug_server_path.c_str(), 0);
35-
break;
36-
}
37-
}
38-
}
39-
}
25+
#else
26+
auto debug_server_path = filesystem::get_executable("lldb-server").string();
27+
if(debug_server_path != "lldb-server")
28+
setenv("LLDB_DEBUGSERVER_PATH", debug_server_path.c_str(), 0);
4029
#endif
30+
}
4131
}
4232

4333
std::tuple<std::vector<std::string>, std::string, std::vector<std::string> > Debug::LLDB::parse_run_arguments(const std::string &command) {

‎src/filesystem.cc

+41
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,44 @@ boost::filesystem::path filesystem::get_relative_path(const boost::filesystem::p
173173

174174
return relative_path;
175175
}
176+
177+
boost::filesystem::path filesystem::get_executable(const boost::filesystem::path &executable_name) noexcept {
178+
#if defined(__APPLE__) || defined(_WIN32)
179+
return executable_name;
180+
#endif
181+
182+
static std::vector<boost::filesystem::path> bin_paths={"/usr/bin", "/usr/local/bin"};
183+
184+
try {
185+
for(auto &path: bin_paths) {
186+
if(boost::filesystem::exists(path/executable_name))
187+
return executable_name;
188+
}
189+
190+
auto executable_name_str = executable_name.string();
191+
for(auto &path: bin_paths) {
192+
boost::filesystem::path executable;
193+
for(boost::filesystem::directory_iterator it(path), end; it != end; ++it) {
194+
auto it_path = it->path();
195+
auto it_path_filename_str = it_path.filename().string();
196+
if(!it_path_filename_str.empty() && it_path_filename_str.compare(0, executable_name_str.size(), executable_name_str)==0) {
197+
if(it_path > executable &&
198+
((it_path_filename_str.size() > executable_name_str.size() &&
199+
it_path_filename_str[executable_name_str.size()]>='0' &&
200+
it_path_filename_str[executable_name_str.size()]<='9') ||
201+
(it_path_filename_str.size() > executable_name_str.size()+1 &&
202+
it_path_filename_str[executable_name_str.size()]=='-' &&
203+
it_path_filename_str[executable_name_str.size()+1]>='0' &&
204+
it_path_filename_str[executable_name_str.size()+1]<='9')) &&
205+
!boost::filesystem::is_directory(it_path))
206+
executable=it_path;
207+
}
208+
}
209+
if(!executable.empty())
210+
return executable;
211+
}
212+
}
213+
catch(...) {}
214+
215+
return executable_name;
216+
}

‎src/filesystem.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ class filesystem {
2929
/// Return path with dot, dot-dot and directory separator elements removed
3030
static boost::filesystem::path get_normal_path(const boost::filesystem::path &path) noexcept;
3131

32-
///Returns empty path on failure
32+
/// Returns empty path on failure
3333
static boost::filesystem::path get_relative_path(const boost::filesystem::path &path, const boost::filesystem::path &base) noexcept;
34+
35+
/// Return executable with latest version in filename on systems that is lacking executable_name symbolic link
36+
static boost::filesystem::path get_executable(const boost::filesystem::path &executable_name) noexcept;
3437
};
3538
#endif // JUCI_FILESYSTEM_H_

‎src/source.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ Source::View::View(const boost::filesystem::path &file_path, Glib::RefPtr<Gsv::L
165165
is_bracket_language=true;
166166

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

170172
if(get_buffer()->get_has_selection()) {
171173
Gtk::TextIter start, end;

0 commit comments

Comments
 (0)
This repository has been archived.