mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-25 09:05:10 +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>
|
||||
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;
|
||||
args.push_back(save.c_str());
|
||||
args.push_back(intern(save));
|
||||
args.push_back("-fsyntax-only");
|
||||
|
||||
// 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")
|
||||
return nullptr;
|
||||
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>();
|
||||
#if LLVM_VERSION_MAJOR >= 10 // rC370122
|
||||
if (!CompilerInvocation::CreateFromArgs(*ci, cc_args, *diags))
|
||||
if (!CompilerInvocation::CreateFromArgs(*ci, *c_args, *diags))
|
||||
#else
|
||||
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
|
||||
return nullptr;
|
||||
|
||||
|
@ -42,7 +42,8 @@ Range fromTokenRangeDefaulted(const clang::SourceManager &sm,
|
||||
|
||||
std::unique_ptr<clang::CompilerInvocation>
|
||||
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);
|
||||
} // namespace ccls
|
||||
|
@ -1277,7 +1277,7 @@ index(SemaManager *manager, WorkingFiles *wfiles, VFS *vfs,
|
||||
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs =
|
||||
llvm::vfs::getRealFileSystem();
|
||||
std::shared_ptr<CompilerInvocation> ci =
|
||||
buildCompilerInvocation(main, args, fs);
|
||||
buildCompilerInvocation(main, args, fs, opt_wdir);
|
||||
// e.g. .s
|
||||
if (!ci)
|
||||
return {};
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <llvm/ADT/DenseMap.h>
|
||||
#include <llvm/ADT/SmallVector.h>
|
||||
#include <llvm/ADT/StringMap.h>
|
||||
#include <llvm/ADT/STLExtras.h>
|
||||
|
||||
namespace llvm {
|
||||
template <> struct DenseMapInfo<ccls::ExtentRef> {
|
||||
|
@ -433,8 +433,8 @@ void *preambleMain(void *manager_) {
|
||||
auto stat_cache = std::make_unique<PreambleStatCache>();
|
||||
IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs =
|
||||
stat_cache->producer(session->fs);
|
||||
if (std::unique_ptr<CompilerInvocation> ci =
|
||||
buildCompilerInvocation(task.path, session->file.args, fs))
|
||||
if (std::unique_ptr<CompilerInvocation> ci = buildCompilerInvocation(
|
||||
task.path, session->file.args, fs, session->file.directory))
|
||||
buildPreamble(*session, *ci, fs, task, std::move(stat_cache));
|
||||
|
||||
if (task.comp_task) {
|
||||
@ -475,8 +475,8 @@ void *completionMain(void *manager_) {
|
||||
std::shared_ptr<PreambleData> preamble = session->getPreamble();
|
||||
IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs =
|
||||
preamble ? preamble->stat_cache->consumer(session->fs) : session->fs;
|
||||
std::unique_ptr<CompilerInvocation> ci =
|
||||
buildCompilerInvocation(task->path, session->file.args, fs);
|
||||
std::unique_ptr<CompilerInvocation> ci = buildCompilerInvocation(
|
||||
task->path, session->file.args, fs, session->file.directory);
|
||||
if (!ci)
|
||||
continue;
|
||||
auto &fOpts = ci->getFrontendOpts();
|
||||
@ -569,8 +569,8 @@ void *diagnosticMain(void *manager_) {
|
||||
std::shared_ptr<PreambleData> preamble = session->getPreamble();
|
||||
IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs =
|
||||
preamble ? preamble->stat_cache->consumer(session->fs) : session->fs;
|
||||
std::unique_ptr<CompilerInvocation> ci =
|
||||
buildCompilerInvocation(task.path, session->file.args, fs);
|
||||
std::unique_ptr<CompilerInvocation> ci = buildCompilerInvocation(
|
||||
task.path, session->file.args, fs, session->file.directory);
|
||||
if (!ci)
|
||||
continue;
|
||||
if (preamble) {
|
||||
|
Loading…
Reference in New Issue
Block a user