mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-22 07:35:08 +00:00
When clang is in CL mode, it ignores the working-directory option, so it
must be added
This commit is contained in:
parent
dce86b1362
commit
4c9ed62469
@ -96,9 +96,10 @@ Range fromTokenRangeDefaulted(const SourceManager &sm, const LangOptions &lang,
|
|||||||
|
|
||||||
std::unique_ptr<CompilerInvocation>
|
std::unique_ptr<CompilerInvocation>
|
||||||
buildCompilerInvocation(const std::string &main, std::vector<const char *> args,
|
buildCompilerInvocation(const std::string &main, std::vector<const char *> args,
|
||||||
IntrusiveRefCntPtr<llvm::vfs::FileSystem> vfs) {
|
IntrusiveRefCntPtr<llvm::vfs::FileSystem> vfs,
|
||||||
|
const std::string &working_dir) {
|
||||||
std::string save = "-resource-dir=" + g_config->clang.resourceDir;
|
std::string save = "-resource-dir=" + g_config->clang.resourceDir;
|
||||||
args.push_back(save.c_str());
|
args.push_back(intern(save));
|
||||||
args.push_back("-fsyntax-only");
|
args.push_back("-fsyntax-only");
|
||||||
|
|
||||||
// Similar to clang/tools/driver/driver.cpp:insertTargetAndModeArgs but don't
|
// Similar to clang/tools/driver/driver.cpp:insertTargetAndModeArgs but don't
|
||||||
@ -146,12 +147,14 @@ buildCompilerInvocation(const std::string &main, std::vector<const char *> args,
|
|||||||
if (StringRef(cmd.getCreator().getName()) != "clang")
|
if (StringRef(cmd.getCreator().getName()) != "clang")
|
||||||
return nullptr;
|
return nullptr;
|
||||||
const llvm::opt::ArgStringList &cc_args = cmd.getArguments();
|
const llvm::opt::ArgStringList &cc_args = cmd.getArguments();
|
||||||
|
auto c_args = const_cast<llvm::opt::ArgStringList *>(&cc_args);
|
||||||
|
c_args->append({intern("-working-directory=" + working_dir)});
|
||||||
auto ci = std::make_unique<CompilerInvocation>();
|
auto ci = std::make_unique<CompilerInvocation>();
|
||||||
#if LLVM_VERSION_MAJOR >= 10 // rC370122
|
#if LLVM_VERSION_MAJOR >= 10 // rC370122
|
||||||
if (!CompilerInvocation::CreateFromArgs(*ci, cc_args, *diags))
|
if (!CompilerInvocation::CreateFromArgs(*ci, *c_args, *diags))
|
||||||
#else
|
#else
|
||||||
if (!CompilerInvocation::CreateFromArgs(
|
if (!CompilerInvocation::CreateFromArgs(
|
||||||
*ci, cc_args.data(), cc_args.data() + cc_args.size(), *diags))
|
*ci, c_args->data(), c_args->data() + c_args->size(), *diags))
|
||||||
#endif
|
#endif
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
@ -42,7 +42,8 @@ Range fromTokenRangeDefaulted(const clang::SourceManager &sm,
|
|||||||
|
|
||||||
std::unique_ptr<clang::CompilerInvocation>
|
std::unique_ptr<clang::CompilerInvocation>
|
||||||
buildCompilerInvocation(const std::string &main, std::vector<const char *> args,
|
buildCompilerInvocation(const std::string &main, std::vector<const char *> args,
|
||||||
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS);
|
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
|
||||||
|
const std::string &working_dir);
|
||||||
|
|
||||||
const char *clangBuiltinTypeName(int);
|
const char *clangBuiltinTypeName(int);
|
||||||
} // namespace ccls
|
} // namespace ccls
|
||||||
|
@ -1277,7 +1277,7 @@ index(SemaManager *manager, WorkingFiles *wfiles, VFS *vfs,
|
|||||||
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs =
|
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs =
|
||||||
llvm::vfs::getRealFileSystem();
|
llvm::vfs::getRealFileSystem();
|
||||||
std::shared_ptr<CompilerInvocation> ci =
|
std::shared_ptr<CompilerInvocation> ci =
|
||||||
buildCompilerInvocation(main, args, fs);
|
buildCompilerInvocation(main, args, fs, opt_wdir);
|
||||||
// e.g. .s
|
// e.g. .s
|
||||||
if (!ci)
|
if (!ci)
|
||||||
return {};
|
return {};
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include <llvm/ADT/DenseMap.h>
|
#include <llvm/ADT/DenseMap.h>
|
||||||
#include <llvm/ADT/SmallVector.h>
|
#include <llvm/ADT/SmallVector.h>
|
||||||
#include <llvm/ADT/StringMap.h>
|
#include <llvm/ADT/StringMap.h>
|
||||||
|
#include <llvm/ADT/STLExtras.h>
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
template <> struct DenseMapInfo<ccls::ExtentRef> {
|
template <> struct DenseMapInfo<ccls::ExtentRef> {
|
||||||
|
@ -433,8 +433,8 @@ void *preambleMain(void *manager_) {
|
|||||||
auto stat_cache = std::make_unique<PreambleStatCache>();
|
auto stat_cache = std::make_unique<PreambleStatCache>();
|
||||||
IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs =
|
IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs =
|
||||||
stat_cache->producer(session->fs);
|
stat_cache->producer(session->fs);
|
||||||
if (std::unique_ptr<CompilerInvocation> ci =
|
if (std::unique_ptr<CompilerInvocation> ci = buildCompilerInvocation(
|
||||||
buildCompilerInvocation(task.path, session->file.args, fs))
|
task.path, session->file.args, fs, session->file.directory))
|
||||||
buildPreamble(*session, *ci, fs, task, std::move(stat_cache));
|
buildPreamble(*session, *ci, fs, task, std::move(stat_cache));
|
||||||
|
|
||||||
if (task.comp_task) {
|
if (task.comp_task) {
|
||||||
@ -475,8 +475,8 @@ void *completionMain(void *manager_) {
|
|||||||
std::shared_ptr<PreambleData> preamble = session->getPreamble();
|
std::shared_ptr<PreambleData> preamble = session->getPreamble();
|
||||||
IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs =
|
IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs =
|
||||||
preamble ? preamble->stat_cache->consumer(session->fs) : session->fs;
|
preamble ? preamble->stat_cache->consumer(session->fs) : session->fs;
|
||||||
std::unique_ptr<CompilerInvocation> ci =
|
std::unique_ptr<CompilerInvocation> ci = buildCompilerInvocation(
|
||||||
buildCompilerInvocation(task->path, session->file.args, fs);
|
task->path, session->file.args, fs, session->file.directory);
|
||||||
if (!ci)
|
if (!ci)
|
||||||
continue;
|
continue;
|
||||||
auto &fOpts = ci->getFrontendOpts();
|
auto &fOpts = ci->getFrontendOpts();
|
||||||
@ -569,8 +569,8 @@ void *diagnosticMain(void *manager_) {
|
|||||||
std::shared_ptr<PreambleData> preamble = session->getPreamble();
|
std::shared_ptr<PreambleData> preamble = session->getPreamble();
|
||||||
IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs =
|
IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs =
|
||||||
preamble ? preamble->stat_cache->consumer(session->fs) : session->fs;
|
preamble ? preamble->stat_cache->consumer(session->fs) : session->fs;
|
||||||
std::unique_ptr<CompilerInvocation> ci =
|
std::unique_ptr<CompilerInvocation> ci = buildCompilerInvocation(
|
||||||
buildCompilerInvocation(task.path, session->file.args, fs);
|
task.path, session->file.args, fs, session->file.directory);
|
||||||
if (!ci)
|
if (!ci)
|
||||||
continue;
|
continue;
|
||||||
if (preamble) {
|
if (preamble) {
|
||||||
|
Loading…
Reference in New Issue
Block a user