Skip to content

Commit

Permalink
experimental/filesystem -> LLVM/Support/FileSystem.h; sparsepp -> Den…
Browse files Browse the repository at this point in the history
…seMap
  • Loading branch information
MaskRay committed May 13, 2018
1 parent d3a36a4 commit f145c44
Show file tree
Hide file tree
Showing 15 changed files with 116 additions and 110 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
[submodule "third_party/doctest"]
path = third_party/doctest
url = https://github.com/onqtam/doctest
[submodule "third_party/sparsepp"]
path = third_party/sparsepp
url = https://github.com/greg7mdp/sparsepp
[submodule "third_party/loguru"]
path = third_party/loguru
url = https://github.com/emilk/loguru
18 changes: 4 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,9 @@ if(NOT SYSTEM_CLANG)
target_compile_options(ccls PRIVATE -nostdinc++ -cxx-isystem ${CLANG_ROOT}/include/c++/v1)
if(${CMAKE_SYSTEM_NAME} STREQUAL Linux)
# Don't use -stdlib=libc++ because while ccls is linked with libc++, bundled clang+llvm require libstdc++
target_link_libraries(ccls PRIVATE -L${CLANG_ROOT}/lib c++ c++experimental c++abi)
else()
# FreeBSD uses system libcxxrt.a and does not need libc++abi.
target_link_libraries(ccls PRIVATE -stdlib=libc++ -L${CLANG_ROOT}/lib c++experimental)
target_link_libraries(ccls PRIVATE -L${CLANG_ROOT}/lib c++ c++abi)

# FreeBSD defaults to -stdlib=libc++ and uses system libcxxrt.a
endif()
endif()

Expand All @@ -121,25 +120,17 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL Darwin)
target_link_libraries(ccls PRIVATE -lc++experimental)

elseif(${CMAKE_SYSTEM_NAME} STREQUAL Linux)
if(NOT CLANG_USE_BUNDLED_LIBC++)
target_link_libraries(ccls PRIVATE -lstdc++fs)
endif()
# loguru calls dladdr
target_link_libraries(ccls PRIVATE ${CMAKE_DL_LIBS})

elseif(${CMAKE_SYSTEM_NAME} STREQUAL FreeBSD)
# loguru::stacktrace_as_stdstring calls backtrace_symbols
# sparsepp/spp_memory.h uses libkvm
# src/platform_posix.cc uses libthr
find_package(Backtrace REQUIRED)
target_link_libraries(ccls PRIVATE ${Backtrace_LIBRARIES} kvm thr)
target_link_libraries(ccls PRIVATE ${Backtrace_LIBRARIES} thr)
if(SYSTEM_CLANG)
target_link_libraries(ccls PRIVATE c++experimental)
endif()

elseif(${CMAKE_SYSTEM_NAME} STREQUAL Windows)
# sparsepp/spp_memory.h uses LibPsapi
target_link_libraries(ccls PRIVATE Psapi)
endif()

### Definitions
Expand All @@ -156,7 +147,6 @@ target_include_directories(ccls PRIVATE
src
third_party
third_party/rapidjson/include
third_party/sparsepp
third_party/loguru
third_party/doctest)

Expand Down
1 change: 1 addition & 0 deletions cmake/FindClang.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ set(_Clang_REQUIRED_VARS Clang_LIBRARY Clang_INCLUDE_DIR Clang_EXECUTABLE

_Clang_find_library(Clang_LIBRARY clang)
_Clang_find_add_library(clangDriver)
_Clang_find_add_library(clangBasic)
_Clang_find_add_library(LLVMOption)
_Clang_find_add_library(LLVMSupport)
_Clang_find_add_library(LLVMDemangle)
Expand Down
9 changes: 6 additions & 3 deletions src/clang_complete.cc
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include "clang_complete.h"

#include "clang_utils.h"
#include "filesystem.hh"
#include "platform.h"
#include "timer.h"

#include "filesystem.hh"
using namespace llvm;

#include <loguru.hpp>

#include <algorithm>
Expand All @@ -29,8 +31,9 @@ unsigned Flags() {
}

std::string StripFileType(const std::string& path) {
fs::path p(path);
return p.parent_path() / p.stem();
SmallString<128> Ret;
sys::path::append(Ret, sys::path::parent_path(path), sys::path::stem(path));
return Ret.str();
}

unsigned GetCompletionPriority(const CXCompletionString& str,
Expand Down
11 changes: 8 additions & 3 deletions src/clang_utils.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include "clang_utils.h"

#include "filesystem.hh"
#include "platform.h"

#include "filesystem.hh"
using namespace llvm;

namespace {

lsRange GetLsRangeForFixIt(const CXSourceRange& range) {
Expand Down Expand Up @@ -115,8 +117,11 @@ std::string FileName(CXFile file) {
// clang_getFileName return values may contain ..
ret = NormalizePath(ToString(clang_getFileName(file)));
// Resolve /usr/include/c++/7.3.0 symlink.
if (!StartsWith(ret, g_config->projectRoot))
ret = fs::canonical(ret);
if (!StartsWith(ret, g_config->projectRoot)) {
SmallString<256> dest;
sys::fs::real_path(ret, dest);
ret = dest.str();
}
return ret;
}

Expand Down
50 changes: 26 additions & 24 deletions src/filesystem.cc
Original file line number Diff line number Diff line change
@@ -1,40 +1,42 @@
#include "filesystem.hh"
using namespace llvm;

#include "utils.h"

#include <queue>
#include <utility>

static void GetFilesInFolderHelper(
std::string folder,
bool recursive,
std::string output_prefix,
const std::function<void(const std::string&)>& handler) {
std::queue<std::pair<fs::path, fs::path>> q;
q.emplace(fs::path(folder), fs::path(output_prefix));
while (!q.empty()) {
try {
for (auto it = fs::directory_iterator(q.front().first);
it != fs::directory_iterator(); ++it) {
auto path = it->path();
std::string filename = path.filename();
if (filename[0] != '.' || filename == ".ccls") {
fs::file_status status = it->symlink_status();
if (fs::is_regular_file(status))
handler(q.front().second / filename);
else if (fs::is_directory(status) || fs::is_symlink(status)) {
if (recursive) {
std::string child_dir = q.front().second / filename;
if (fs::is_directory(status))
q.push(make_pair(path, child_dir));
}
}
}
std::error_code ec;
if (recursive)
for (sys::fs::recursive_directory_iterator I(folder, ec), E; I != E && !ec;
I.increment(ec)) {
std::string path = I->path(), filename = sys::path::filename(path);
if (filename[0] != '.' || filename == ".ccls") {
SmallString<256> Path;
if (output_prefix.size()) {
sys::path::append(Path, output_prefix, path);
handler(Path.str());
} else
handler(path);
}
}
else
for (sys::fs::directory_iterator I(folder, ec), E; I != E && !ec;
I.increment(ec)) {
std::string path = I->path(), filename = sys::path::filename(path);
if (filename[0] != '.' || filename == ".ccls") {
SmallString<256> Path;
if (output_prefix.size()) {
sys::path::append(Path, output_prefix, path);
handler(Path.str());
} else
handler(path);
}
} catch (fs::filesystem_error&) {
}
q.pop();
}
}

void GetFilesInFolder(std::string folder,
Expand Down
6 changes: 3 additions & 3 deletions src/filesystem.hh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#pragma once

#include <experimental/filesystem>
#include <llvm/Support/FileSystem.h>
#include <llvm/Support/Path.h>

#include <functional>
#include <string>

namespace fs = std::experimental::filesystem;

void GetFilesInFolder(std::string folder,
bool recursive,
bool add_folder_to_path,
Expand Down
12 changes: 7 additions & 5 deletions src/messages/initialize.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "cache_manager.h"
#include "diagnostics_engine.h"
#include "filesystem.hh"
#include "import_pipeline.h"
#include "include_complete.h"
#include "message_handler.h"
Expand All @@ -11,6 +10,9 @@
#include "timer.h"
#include "working_files.h"

#include "filesystem.hh"
using namespace llvm;

#include <loguru.hpp>

#include <iostream>
Expand Down Expand Up @@ -492,10 +494,10 @@ struct Handler_Initialize : BaseMessageHandler<In_InitializeRequest> {
config->projectRoot = project_path;
// Create two cache directories for files inside and outside of the
// project.
fs::create_directories(config->cacheDirectory +
EscapeFileName(config->projectRoot));
fs::create_directories(config->cacheDirectory + '@' +
EscapeFileName(config->projectRoot));
sys::fs::create_directories(config->cacheDirectory +
EscapeFileName(config->projectRoot));
sys::fs::create_directories(config->cacheDirectory + '@' +
EscapeFileName(config->projectRoot));

g_config = std::move(config);
Timer time;
Expand Down
Loading

0 comments on commit f145c44

Please sign in to comment.