mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-25 09:05:10 +00:00
Remove unused fs code.
This commit is contained in:
parent
fdb562bb42
commit
96bba583c9
@ -195,7 +195,6 @@ target_sources(ccls PRIVATE
|
||||
src/message_handler.cc
|
||||
src/platform_posix.cc
|
||||
src/platform_win.cc
|
||||
src/platform.cc
|
||||
src/port.cc
|
||||
src/position.cc
|
||||
src/project.cc
|
||||
|
@ -97,13 +97,13 @@ long long GetCurrentTimeInMilliseconds() {
|
||||
struct ActiveThread {
|
||||
ActiveThread(ImportPipelineStatus* status)
|
||||
: status_(status) {
|
||||
if (g_config->progressReportFrequencyMs < 0)
|
||||
if (g_config && g_config->progressReportFrequencyMs < 0)
|
||||
return;
|
||||
|
||||
++status_->num_active_threads;
|
||||
}
|
||||
~ActiveThread() {
|
||||
if (g_config->progressReportFrequencyMs < 0)
|
||||
if (g_config && g_config->progressReportFrequencyMs < 0)
|
||||
return;
|
||||
|
||||
--status_->num_active_threads;
|
||||
@ -122,7 +122,7 @@ struct ActiveThread {
|
||||
out.params.activeThreads = status_->num_active_threads;
|
||||
|
||||
// Ignore this progress update if the last update was too recent.
|
||||
if (g_config->progressReportFrequencyMs != 0) {
|
||||
if (g_config && g_config->progressReportFrequencyMs != 0) {
|
||||
// Make sure we output a status update if queue lengths are zero.
|
||||
bool all_zero =
|
||||
out.params.indexRequestCount == 0 && out.params.doIdMapCount == 0 &&
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "cache_manager.h"
|
||||
#include "diagnostics_engine.h"
|
||||
#include "filesystem.hh"
|
||||
#include "import_pipeline.h"
|
||||
#include "include_complete.h"
|
||||
#include "message_handler.h"
|
||||
@ -504,9 +505,9 @@ struct Handler_Initialize : BaseMessageHandler<In_InitializeRequest> {
|
||||
config->projectRoot = project_path;
|
||||
// Create two cache directories for files inside and outside of the
|
||||
// project.
|
||||
MakeDirectoryRecursive(config->cacheDirectory +
|
||||
fs::create_directories(config->cacheDirectory +
|
||||
EscapeFileName(config->projectRoot));
|
||||
MakeDirectoryRecursive(config->cacheDirectory + '@' +
|
||||
fs::create_directories(config->cacheDirectory + '@' +
|
||||
EscapeFileName(config->projectRoot));
|
||||
|
||||
g_config = std::move(config);
|
||||
|
@ -1,96 +0,0 @@
|
||||
#include "platform.h"
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <iterator>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
|
||||
// See http://stackoverflow.com/a/236803
|
||||
template <typename Out>
|
||||
void Split(const std::string& s, char delim, Out result) {
|
||||
std::stringstream ss;
|
||||
ss.str(s);
|
||||
std::string item;
|
||||
while (std::getline(ss, item, delim)) {
|
||||
if (!item.empty())
|
||||
*(result++) = item;
|
||||
}
|
||||
}
|
||||
std::vector<std::string> Split(const std::string& s, char delim) {
|
||||
std::vector<std::string> elems;
|
||||
Split(s, delim, std::back_inserter(elems));
|
||||
return elems;
|
||||
}
|
||||
|
||||
std::string Join(const std::vector<std::string>& entries,
|
||||
char delim,
|
||||
size_t end) {
|
||||
std::string result;
|
||||
bool first = true;
|
||||
for (size_t i = 0; i < end; ++i) {
|
||||
if (!first)
|
||||
result += delim;
|
||||
first = false;
|
||||
result += entries[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
PlatformMutex::~PlatformMutex() = default;
|
||||
|
||||
PlatformScopedMutexLock::~PlatformScopedMutexLock() = default;
|
||||
|
||||
PlatformSharedMemory::~PlatformSharedMemory() = default;
|
||||
|
||||
void MakeDirectoryRecursive(std::string path) {
|
||||
path = NormalizePath(path);
|
||||
|
||||
if (TryMakeDirectory(path))
|
||||
return;
|
||||
|
||||
std::string prefix = "";
|
||||
if (path[0] == '/')
|
||||
prefix = "/";
|
||||
|
||||
std::vector<std::string> components = Split(path, '/');
|
||||
|
||||
// Find first parent directory which doesn't exist.
|
||||
int first_success = -1;
|
||||
for (size_t j = 0; j < components.size(); ++j) {
|
||||
size_t i = components.size() - j;
|
||||
if (TryMakeDirectory(prefix + Join(components, '/', i))) {
|
||||
first_success = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (first_success == -1) {
|
||||
LOG_S(FATAL) << "Failed to make any parent directory for " << path;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Make all child directories.
|
||||
for (size_t i = first_success + 1; i <= components.size(); ++i) {
|
||||
if (TryMakeDirectory(prefix + Join(components, '/', i)) == false) {
|
||||
LOG_S(FATAL) << "Failed making directory for " << path
|
||||
<< " even after creating parent directories";
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_SUITE("Platform") {
|
||||
TEST_CASE("Split strings") {
|
||||
std::vector<std::string> actual = Split("/a/b/c/", '/');
|
||||
std::vector<std::string> expected{"a", "b", "c"};
|
||||
REQUIRE(actual == expected);
|
||||
}
|
||||
}
|
@ -7,46 +7,18 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct PlatformMutex {
|
||||
virtual ~PlatformMutex();
|
||||
};
|
||||
struct PlatformScopedMutexLock {
|
||||
virtual ~PlatformScopedMutexLock();
|
||||
};
|
||||
struct PlatformSharedMemory {
|
||||
virtual ~PlatformSharedMemory();
|
||||
void* data;
|
||||
size_t capacity;
|
||||
std::string name;
|
||||
};
|
||||
|
||||
void PlatformInit();
|
||||
|
||||
std::string GetExecutablePath();
|
||||
std::string GetWorkingDirectory();
|
||||
std::string NormalizePath(const std::string& path);
|
||||
// Creates a directory at |path|. Creates directories recursively if needed.
|
||||
void MakeDirectoryRecursive(std::string path);
|
||||
// Tries to create the directory given by |absolute_path|. Returns true if
|
||||
// successful or if the directory already exists. Returns false otherwise. This
|
||||
// does not attempt to recursively create directories.
|
||||
bool TryMakeDirectory(const std::string& absolute_path);
|
||||
|
||||
void SetCurrentThreadName(const std::string& thread_name);
|
||||
|
||||
std::optional<int64_t> GetLastModificationTime(const std::string& absolute_path);
|
||||
|
||||
void MoveFileTo(const std::string& destination, const std::string& source);
|
||||
void CopyFileTo(const std::string& destination, const std::string& source);
|
||||
|
||||
bool IsSymLink(const std::string& path);
|
||||
|
||||
// Free any unused memory and return it to the system.
|
||||
void FreeUnusedMemory();
|
||||
|
||||
// If true objective-c index tests will be run.
|
||||
bool RunObjectiveCIndexTests();
|
||||
|
||||
// Stop self and wait for SIGCONT.
|
||||
void TraceMe();
|
||||
|
||||
|
@ -150,29 +150,11 @@ std::string GetExecutablePath() {
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string GetWorkingDirectory() {
|
||||
char result[FILENAME_MAX];
|
||||
if (!getcwd(result, sizeof(result)))
|
||||
return "";
|
||||
std::string working_dir = std::string(result, strlen(result));
|
||||
EnsureEndsInSlash(working_dir);
|
||||
return working_dir;
|
||||
}
|
||||
|
||||
std::string NormalizePath(const std::string& path) {
|
||||
std::optional<std::string> resolved = RealPathNotExpandSymlink(path);
|
||||
return resolved ? *resolved : path;
|
||||
}
|
||||
|
||||
bool TryMakeDirectory(const std::string& absolute_path) {
|
||||
const mode_t kMode = 0777; // UNIX style permissions
|
||||
if (mkdir(absolute_path.c_str(), kMode) == -1) {
|
||||
// Success if the directory exists.
|
||||
return errno == EEXIST;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void SetCurrentThreadName(const std::string& thread_name) {
|
||||
loguru::set_thread_name(thread_name.c_str());
|
||||
#if defined(__APPLE__)
|
||||
@ -206,73 +188,12 @@ std::optional<int64_t> GetLastModificationTime(const std::string& absolute_path)
|
||||
return buf.st_mtime;
|
||||
}
|
||||
|
||||
void MoveFileTo(const std::string& dest, const std::string& source) {
|
||||
// TODO/FIXME - do a real move.
|
||||
CopyFileTo(dest, source);
|
||||
}
|
||||
|
||||
// See http://stackoverflow.com/q/13198627
|
||||
void CopyFileTo(const std::string& dest, const std::string& source) {
|
||||
int fd_from = open(source.c_str(), O_RDONLY);
|
||||
if (fd_from < 0)
|
||||
return;
|
||||
|
||||
int fd_to = open(dest.c_str(), O_WRONLY | O_CREAT, 0666);
|
||||
if (fd_to < 0)
|
||||
goto out_error;
|
||||
|
||||
char buf[4096];
|
||||
ssize_t nread;
|
||||
while (nread = read(fd_from, buf, sizeof buf), nread > 0) {
|
||||
char* out_ptr = buf;
|
||||
ssize_t nwritten;
|
||||
|
||||
do {
|
||||
nwritten = write(fd_to, out_ptr, nread);
|
||||
|
||||
if (nwritten >= 0) {
|
||||
nread -= nwritten;
|
||||
out_ptr += nwritten;
|
||||
} else if (errno != EINTR)
|
||||
goto out_error;
|
||||
} while (nread > 0);
|
||||
}
|
||||
|
||||
if (nread == 0) {
|
||||
if (close(fd_to) < 0) {
|
||||
fd_to = -1;
|
||||
goto out_error;
|
||||
}
|
||||
close(fd_from);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
out_error:
|
||||
close(fd_from);
|
||||
if (fd_to >= 0)
|
||||
close(fd_to);
|
||||
}
|
||||
|
||||
bool IsSymLink(const std::string& path) {
|
||||
struct stat buf;
|
||||
return lstat(path.c_str(), &buf) == 0 && S_ISLNK(buf.st_mode);
|
||||
}
|
||||
|
||||
void FreeUnusedMemory() {
|
||||
#if defined(__GLIBC__)
|
||||
malloc_trim(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool RunObjectiveCIndexTests() {
|
||||
#if defined(__APPLE__)
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void TraceMe() {
|
||||
// If the environment variable is defined, wait for a debugger.
|
||||
// In gdb, you need to invoke `signal SIGCONT` if you want ccls to continue
|
||||
|
@ -34,13 +34,6 @@ std::string GetExecutablePath() {
|
||||
return NormalizePath(result);
|
||||
}
|
||||
|
||||
// See http://stackoverflow.com/a/19535628
|
||||
std::string GetWorkingDirectory() {
|
||||
char result[MAX_PATH];
|
||||
std::string binary_path(result, GetModuleFileName(NULL, result, MAX_PATH));
|
||||
return binary_path.substr(0, binary_path.find_last_of("\\/") + 1);
|
||||
}
|
||||
|
||||
std::string NormalizePath(const std::string& path) {
|
||||
DWORD retval = 0;
|
||||
TCHAR buffer[MAX_PATH] = TEXT("");
|
||||
@ -57,14 +50,6 @@ std::string NormalizePath(const std::string& path) {
|
||||
return result;
|
||||
}
|
||||
|
||||
bool TryMakeDirectory(const std::string& absolute_path) {
|
||||
if (_mkdir(absolute_path.c_str()) == -1) {
|
||||
// Success if the directory exists.
|
||||
return errno == EEXIST;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// See https://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx
|
||||
const DWORD MS_VC_EXCEPTION = 0x406D1388;
|
||||
#pragma pack(push, 8)
|
||||
@ -117,24 +102,8 @@ std::optional<int64_t> GetLastModificationTime(const std::string& absolute_path)
|
||||
return buf.st_mtime;
|
||||
}
|
||||
|
||||
void MoveFileTo(const std::string& destination, const std::string& source) {
|
||||
MoveFile(source.c_str(), destination.c_str());
|
||||
}
|
||||
|
||||
void CopyFileTo(const std::string& destination, const std::string& source) {
|
||||
CopyFile(source.c_str(), destination.c_str(), false /*failIfExists*/);
|
||||
}
|
||||
|
||||
bool IsSymLink(const std::string& path) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void FreeUnusedMemory() {}
|
||||
|
||||
bool RunObjectiveCIndexTests() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO Wait for debugger to attach
|
||||
void TraceMe() {}
|
||||
|
||||
|
@ -224,11 +224,11 @@ bool RunIndexTests(const std::string& filter_path, bool enable_update) {
|
||||
bool is_fail_allowed = false;
|
||||
|
||||
if (EndsWithAny(path, {".m", ".mm"})) {
|
||||
if (!RunObjectiveCIndexTests()) {
|
||||
#ifndef __APPLE__
|
||||
std::cout << "Skipping \"" << path << "\" since this platform does not "
|
||||
<< "support running Objective-C tests." << std::endl;
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
// objective-c tests are often not updated right away. do not bring down
|
||||
// CI if they fail.
|
||||
|
Loading…
Reference in New Issue
Block a user