mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-26 01:21:57 +00:00
Move default resource directory computation to utils.
This will be used by the test system as well.
This commit is contained in:
parent
883f886d2a
commit
d23de3a9fb
@ -5,9 +5,6 @@
|
||||
|
||||
#include <loguru.hpp>
|
||||
|
||||
#define _STRINGIFY(x) #x
|
||||
#define ENSURE_STRING_MACRO_ARGUMENT(x) _STRINGIFY(x)
|
||||
|
||||
namespace {
|
||||
struct Ipc_InitializeRequest : public IpcMessage<Ipc_InitializeRequest> {
|
||||
const static IpcId kIpcId = IpcId::Initialize;
|
||||
@ -88,19 +85,8 @@ struct InitializeHandler : BaseMessageHandler<Ipc_InitializeRequest> {
|
||||
EnsureEndsInSlash(config->cacheDirectory);
|
||||
|
||||
// Ensure there is a resource directory.
|
||||
if (config->resourceDirectory.empty()) {
|
||||
std::string defaultResourceDirectory = std::string(
|
||||
ENSURE_STRING_MACRO_ARGUMENT(DEFAULT_RESOURCE_DIRECTORY));
|
||||
if (defaultResourceDirectory.find("..") != std::string::npos) {
|
||||
std::string executablePath = GetExecutablePath();
|
||||
size_t pos = executablePath.find_last_of('/');
|
||||
config->resourceDirectory = executablePath.substr(0, pos + 1);
|
||||
config->resourceDirectory += defaultResourceDirectory;
|
||||
} else {
|
||||
config->resourceDirectory = defaultResourceDirectory;
|
||||
}
|
||||
}
|
||||
config->resourceDirectory = NormalizePath(config->resourceDirectory);
|
||||
if (config->resourceDirectory.empty())
|
||||
config->resourceDirectory = GetDefaultResourceDirectory();
|
||||
LOG_S(INFO) << "Using -resource-dir=" << config->resourceDirectory;
|
||||
|
||||
// Send initialization before starting indexers, so we don't send a
|
||||
|
19
src/utils.cc
19
src/utils.cc
@ -19,6 +19,9 @@
|
||||
#include <sparsepp/spp_memory.h>
|
||||
#endif
|
||||
|
||||
#define _STRINGIFY(x) #x
|
||||
#define ENSURE_STRING_MACRO_ARGUMENT(x) _STRINGIFY(x)
|
||||
|
||||
// See http://stackoverflow.com/a/217605
|
||||
void TrimStart(std::string& s) {
|
||||
s.erase(s.begin(),
|
||||
@ -377,3 +380,19 @@ std::string FormatMicroseconds(long long microseconds) {
|
||||
|
||||
return std::to_string(milliseconds) + "." + std::to_string(remaining) + "ms";
|
||||
}
|
||||
|
||||
std::string GetDefaultResourceDirectory() {
|
||||
std::string result;
|
||||
|
||||
std::string resource_directory = std::string(ENSURE_STRING_MACRO_ARGUMENT(DEFAULT_RESOURCE_DIRECTORY));
|
||||
if (resource_directory.find("..") != std::string::npos) {
|
||||
std::string executable_path = GetExecutablePath();
|
||||
size_t pos = executable_path.find_last_of('/');
|
||||
result = executable_path.substr(0, pos + 1);
|
||||
result += resource_directory;
|
||||
} else {
|
||||
result = resource_directory;
|
||||
}
|
||||
|
||||
return NormalizePath(result);
|
||||
}
|
@ -162,3 +162,5 @@ inline void hash_combine(std::size_t& seed, const T& v, Rest... rest) {
|
||||
float GetProcessMemoryUsedInMb();
|
||||
|
||||
std::string FormatMicroseconds(long long microseconds);
|
||||
|
||||
std::string GetDefaultResourceDirectory();
|
Loading…
Reference in New Issue
Block a user