mirror of
https://github.com/MaskRay/ccls.git
synced 2025-02-07 17:32:14 +00:00
Do not try to load compile_commands.json if there is a .cquery file.
Also give some better diagnostics for .cquery.
This commit is contained in:
parent
8a7dfb017f
commit
a4496b7430
@ -65,7 +65,7 @@ std::vector<std::string> kPathArgs = {
|
|||||||
// Arguments which always require an absolute path, ie, clang -working-directory
|
// Arguments which always require an absolute path, ie, clang -working-directory
|
||||||
// does not work as expected. Argument processing assumes that this is a subset
|
// does not work as expected. Argument processing assumes that this is a subset
|
||||||
// of kPathArgs.
|
// of kPathArgs.
|
||||||
std::vector<std::string> kNormalizePathArgs = { "--sysroot=" };
|
std::vector<std::string> kNormalizePathArgs = {"--sysroot="};
|
||||||
|
|
||||||
// Arguments whose path arguments should be injected into include dir lookup
|
// Arguments whose path arguments should be injected into include dir lookup
|
||||||
// for #include completion.
|
// for #include completion.
|
||||||
@ -125,7 +125,7 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry(
|
|||||||
// .c .cpp, We take it as a source filename. Others (like ./a/b/goma
|
// .c .cpp, We take it as a source filename. Others (like ./a/b/goma
|
||||||
// clang-4.0) are seen as commands.
|
// clang-4.0) are seen as commands.
|
||||||
((dot = entry.args[i].rfind('.')) == std::string::npos ||
|
((dot = entry.args[i].rfind('.')) == std::string::npos ||
|
||||||
dot + 4 < entry.args[i].size() || isdigit(entry.args[i][dot+1])))
|
dot + 4 < entry.args[i].size() || isdigit(entry.args[i][dot + 1])))
|
||||||
++i;
|
++i;
|
||||||
// Include the compiler in the args.
|
// Include the compiler in the args.
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
@ -248,18 +248,20 @@ std::vector<Project::Entry> LoadFromDirectoryListing(ProjectConfig* config) {
|
|||||||
std::vector<Project::Entry> result;
|
std::vector<Project::Entry> result;
|
||||||
|
|
||||||
std::vector<std::string> args;
|
std::vector<std::string> args;
|
||||||
std::cerr << "Using arguments: ";
|
|
||||||
for (std::string line :
|
for (std::string line :
|
||||||
ReadLinesWithEnding(config->project_dir + "/.cquery")) {
|
ReadLinesWithEnding(config->project_dir + "/.cquery")) {
|
||||||
TrimInPlace(line);
|
TrimInPlace(line);
|
||||||
if (line.empty() || StartsWith(line, "#"))
|
if (line.empty() || StartsWith(line, "#"))
|
||||||
continue;
|
continue;
|
||||||
if (!args.empty())
|
|
||||||
std::cerr << ", ";
|
|
||||||
std::cerr << line;
|
|
||||||
args.push_back(line);
|
args.push_back(line);
|
||||||
}
|
}
|
||||||
std::cerr << std::endl;
|
LOG_IF_S(INFO, !args.empty())
|
||||||
|
<< "Using .cquery arguments " << StringJoin(args);
|
||||||
|
LOG_IF_S(WARNING, !FileExists(config->project_dir + "/.cquery") &&
|
||||||
|
config->extra_flags.empty())
|
||||||
|
<< "cquery has no clang arguments. Considering adding either a "
|
||||||
|
"compile_commands.json or .cquery file. See the cquery README for "
|
||||||
|
"more information.";
|
||||||
|
|
||||||
std::vector<std::string> files = GetFilesInFolder(
|
std::vector<std::string> files = GetFilesInFolder(
|
||||||
config->project_dir, true /*recursive*/, true /*add_folder_to_path*/);
|
config->project_dir, true /*recursive*/, true /*add_folder_to_path*/);
|
||||||
@ -280,6 +282,10 @@ std::vector<Project::Entry> LoadFromDirectoryListing(ProjectConfig* config) {
|
|||||||
std::vector<Project::Entry> LoadCompilationEntriesFromDirectory(
|
std::vector<Project::Entry> LoadCompilationEntriesFromDirectory(
|
||||||
ProjectConfig* config,
|
ProjectConfig* config,
|
||||||
const std::string& opt_compilation_db_dir) {
|
const std::string& opt_compilation_db_dir) {
|
||||||
|
// If there is a .cquery file always load using directory listing.
|
||||||
|
if (FileExists(config->project_dir + "/.cquery"))
|
||||||
|
return LoadFromDirectoryListing(config);
|
||||||
|
|
||||||
// Try to load compile_commands.json, but fallback to a project listing.
|
// Try to load compile_commands.json, but fallback to a project listing.
|
||||||
const auto& compilation_db_dir = opt_compilation_db_dir.empty()
|
const auto& compilation_db_dir = opt_compilation_db_dir.empty()
|
||||||
? config->project_dir
|
? config->project_dir
|
||||||
@ -508,15 +514,16 @@ TEST_SUITE("Project") {
|
|||||||
CheckFlags(
|
CheckFlags(
|
||||||
/* raw */ {"clang", "-lstdc++", "myfile.cc"},
|
/* raw */ {"clang", "-lstdc++", "myfile.cc"},
|
||||||
/* expected */
|
/* expected */
|
||||||
{"clang", "-working-directory", "/dir/", "-xc++", "-std=c++11", "-lstdc++", "myfile.cc",
|
{"clang", "-working-directory", "/dir/", "-xc++", "-std=c++11",
|
||||||
"-resource-dir=/w/resource_dir/", "-Wno-unknown-warning-option",
|
"-lstdc++", "myfile.cc", "-resource-dir=/w/resource_dir/",
|
||||||
"-fparse-all-comments"});
|
"-Wno-unknown-warning-option", "-fparse-all-comments"});
|
||||||
|
|
||||||
CheckFlags(
|
CheckFlags(
|
||||||
/* raw */ {"goma", "clang"},
|
/* raw */ {"goma", "clang"},
|
||||||
/* expected */
|
/* expected */
|
||||||
{"clang", "-working-directory", "/dir/", "-xc++", "-std=c++11", "-resource-dir=/w/resource_dir/",
|
{"clang", "-working-directory", "/dir/", "-xc++", "-std=c++11",
|
||||||
"-Wno-unknown-warning-option", "-fparse-all-comments"});
|
"-resource-dir=/w/resource_dir/", "-Wno-unknown-warning-option",
|
||||||
|
"-fparse-all-comments"});
|
||||||
|
|
||||||
CheckFlags(
|
CheckFlags(
|
||||||
/* raw */ {"goma", "clang", "--foo"},
|
/* raw */ {"goma", "clang", "--foo"},
|
||||||
@ -528,21 +535,22 @@ TEST_SUITE("Project") {
|
|||||||
|
|
||||||
// FIXME: Fix this test.
|
// FIXME: Fix this test.
|
||||||
TEST_CASE("Path in args") {
|
TEST_CASE("Path in args") {
|
||||||
CheckFlags(
|
CheckFlags("/home/user", "/home/user/foo/bar.c",
|
||||||
"/home/user", "/home/user/foo/bar.c",
|
/* raw */ {"cc", "-O0", "foo/bar.c"},
|
||||||
/* raw */ {"cc", "-O0", "foo/bar.c"},
|
/* expected */
|
||||||
/* expected */
|
{"cc", "-working-directory", "/home/user", "-xc", "-std=gnu11",
|
||||||
{"cc", "-working-directory", "/home/user", "-xc", "-std=gnu11", "-O0", "foo/bar.c", "-resource-dir=/w/resource_dir/",
|
"-O0", "foo/bar.c", "-resource-dir=/w/resource_dir/",
|
||||||
"-Wno-unknown-warning-option", "-fparse-all-comments"});
|
"-Wno-unknown-warning-option", "-fparse-all-comments"});
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Implied binary") {
|
TEST_CASE("Implied binary") {
|
||||||
CheckFlags("/home/user", "/home/user/foo/bar.cc",
|
CheckFlags(
|
||||||
/* raw */ {"-DDONT_IGNORE_ME"},
|
"/home/user", "/home/user/foo/bar.cc",
|
||||||
/* expected */
|
/* raw */ {"-DDONT_IGNORE_ME"},
|
||||||
{"clang++", "-working-directory", "/home/user", "-xc++", "-std=c++11", "-DDONT_IGNORE_ME",
|
/* expected */
|
||||||
"-resource-dir=/w/resource_dir/", "-Wno-unknown-warning-option",
|
{"clang++", "-working-directory", "/home/user", "-xc++", "-std=c++11",
|
||||||
"-fparse-all-comments"});
|
"-DDONT_IGNORE_ME", "-resource-dir=/w/resource_dir/",
|
||||||
|
"-Wno-unknown-warning-option", "-fparse-all-comments"});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks flag parsing for a random chromium file in comparison to what
|
// Checks flag parsing for a random chromium file in comparison to what
|
||||||
|
@ -248,6 +248,11 @@ std::istream& SafeGetline(std::istream& is, std::string& t) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FileExists(const std::string& filename) {
|
||||||
|
std::ifstream cache(filename);
|
||||||
|
return cache.is_open();
|
||||||
|
}
|
||||||
|
|
||||||
optional<std::string> ReadContent(const std::string& filename) {
|
optional<std::string> ReadContent(const std::string& filename) {
|
||||||
std::ifstream cache;
|
std::ifstream cache;
|
||||||
cache.open(filename);
|
cache.open(filename);
|
||||||
|
@ -77,6 +77,7 @@ void EnsureEndsInSlash(std::string& path);
|
|||||||
std::string EscapeFileName(std::string path);
|
std::string EscapeFileName(std::string path);
|
||||||
|
|
||||||
// FIXME: Move ReadContent into ICacheManager?
|
// FIXME: Move ReadContent into ICacheManager?
|
||||||
|
bool FileExists(const std::string& filename);
|
||||||
optional<std::string> ReadContent(const std::string& filename);
|
optional<std::string> ReadContent(const std::string& filename);
|
||||||
std::vector<std::string> ReadLinesWithEnding(std::string filename);
|
std::vector<std::string> ReadLinesWithEnding(std::string filename);
|
||||||
std::vector<std::string> ToLines(const std::string& content,
|
std::vector<std::string> ToLines(const std::string& content,
|
||||||
|
Loading…
Reference in New Issue
Block a user