mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-21 23:25:07 +00:00
Specify nullptr for source_filename in clang_parseTranslationUnit2 so that we do not need to strip main source filename from args
This commit is contained in:
parent
bf2aaf470e
commit
2b54296992
@ -96,7 +96,7 @@ are skipped. Here's an example:
|
||||
|
||||
```
|
||||
# Language
|
||||
-xc++
|
||||
clang++
|
||||
-std=c++11
|
||||
|
||||
# Includes
|
||||
|
@ -27,7 +27,7 @@ std::unique_ptr<ClangTranslationUnit> ClangTranslationUnit::Create(
|
||||
|
||||
CXTranslationUnit cx_tu;
|
||||
CXErrorCode error_code = clang_parseTranslationUnit2FullArgv(
|
||||
index->cx_index, filepath.c_str(), args.data(), (int)args.size(),
|
||||
index->cx_index, nullptr, args.data(), (int)args.size(),
|
||||
unsaved_files.data(), (unsigned)unsaved_files.size(), flags, &cx_tu);
|
||||
|
||||
switch (error_code) {
|
||||
|
@ -53,9 +53,6 @@ static std::vector<std::string> kBlacklistMulti = {
|
||||
// Blacklisted flags which are always removed from the command line.
|
||||
static std::vector<std::string> kBlacklist = {
|
||||
"-c", "-MP", "-MD", "-MMD", "--fcolor-diagnostics",
|
||||
|
||||
// This strips path-like args but is a bit hacky.
|
||||
"/", "..",
|
||||
};
|
||||
|
||||
// Arguments which are followed by a potentially relative path. We need to make
|
||||
@ -117,10 +114,6 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry(
|
||||
return NormalizePathWithTestOptOut(entry.directory + "/" + path);
|
||||
};
|
||||
|
||||
// Do not include path.
|
||||
if (result.filename == cleanup_maybe_relative_path(arg))
|
||||
continue;
|
||||
|
||||
// If blacklist skip.
|
||||
if (!next_flag_is_path) {
|
||||
if (StartsWithAny(arg, kBlacklistMulti)) {
|
||||
@ -174,14 +167,6 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry(
|
||||
for (const auto& flag : config->extra_flags)
|
||||
result.args.push_back(flag);
|
||||
|
||||
// Clang does not have good hueristics for determining source language, we
|
||||
// should explicitly specify it.
|
||||
if (!AnyStartsWith(result.args, "-x")) {
|
||||
if (IsCFile(entry.file))
|
||||
result.args.push_back("-xc");
|
||||
else
|
||||
result.args.push_back("-xc++");
|
||||
}
|
||||
if (!AnyStartsWith(result.args, "-std=")) {
|
||||
if (IsCFile(entry.file))
|
||||
result.args.push_back("-std=c11");
|
||||
@ -221,6 +206,7 @@ std::vector<Project::Entry> LoadFromDirectoryListing(ProjectConfig* config) {
|
||||
CompileCommandsEntry e;
|
||||
e.file = NormalizePathWithTestOptOut(file);
|
||||
e.args = args;
|
||||
e.args.push_back(e.file);
|
||||
result.push_back(GetCompilationEntryFromCompileCommandEntry(config, e));
|
||||
}
|
||||
}
|
||||
@ -463,15 +449,15 @@ TEST_SUITE("Project") {
|
||||
TEST_CASE("strip meta-compiler invocations") {
|
||||
CheckFlags(
|
||||
/* raw */ {"clang", "-lstdc++", "myfile.cc"},
|
||||
/* expected */ {"clang", "-lstdc++", "myfile.cc", "-xc++", "-std=c++11",
|
||||
/* expected */ {"clang", "-lstdc++", "myfile.cc", "-std=c++11",
|
||||
"-resource-dir=/w/resource_dir/"});
|
||||
|
||||
CheckFlags(/* raw */ {"goma", "clang"},
|
||||
/* expected */ {"clang", "-xc++", "-std=c++11",
|
||||
/* expected */ {"clang", "-std=c++11",
|
||||
"-resource-dir=/w/resource_dir/"});
|
||||
|
||||
CheckFlags(/* raw */ {"goma", "clang", "--foo"},
|
||||
/* expected */ {"clang", "--foo", "-xc++", "-std=c++11",
|
||||
/* expected */ {"clang", "--foo", "-std=c++11",
|
||||
"-resource-dir=/w/resource_dir/"});
|
||||
}
|
||||
|
||||
@ -481,7 +467,7 @@ TEST_SUITE("Project") {
|
||||
"/home/user", "/home/user/foo/bar.c",
|
||||
/* raw */ {"cc", "-O0", "foo/bar.c"},
|
||||
/* expected */
|
||||
{"cc", "-O0", "-xc", "-std=c11", "-resource-dir=/w/resource_dir/"});
|
||||
{"cc", "-O0", "foo/bar.c", "-std=c11", "-resource-dir=/w/resource_dir/"});
|
||||
}
|
||||
|
||||
// Checks flag parsing for a random chromium file in comparison to what
|
||||
@ -825,7 +811,7 @@ TEST_SUITE("Project") {
|
||||
"debian_jessie_amd64-sysroot",
|
||||
"-fno-exceptions",
|
||||
"-fvisibility-inlines-hidden",
|
||||
"-xc++",
|
||||
"../../ash/login/ui/lock_screen_sanity_unittest.cc",
|
||||
"-resource-dir=/w/resource_dir/"});
|
||||
}
|
||||
|
||||
@ -994,7 +980,8 @@ TEST_SUITE("Project") {
|
||||
"-isystem../../buildtools/third_party/libc++abi/trunk/include",
|
||||
"--sysroot=../../build/linux/debian_jessie_amd64-sysroot",
|
||||
"-fno-exceptions",
|
||||
"-fvisibility-inlines-hidden"},
|
||||
"-fvisibility-inlines-hidden",
|
||||
"../../apps/app_lifetime_monitor.cc"},
|
||||
|
||||
/* expected */
|
||||
{"../../third_party/llvm-build/Release+Asserts/bin/clang++",
|
||||
@ -1144,7 +1131,7 @@ TEST_SUITE("Project") {
|
||||
"debian_jessie_amd64-sysroot",
|
||||
"-fno-exceptions",
|
||||
"-fvisibility-inlines-hidden",
|
||||
"-xc++",
|
||||
"../../apps/app_lifetime_monitor.cc",
|
||||
"-resource-dir=/w/resource_dir/"});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user