mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-22 07:35:08 +00:00
Support an optional compilation database dir at initialization
This commit is contained in:
parent
6f6cd4ea7f
commit
3cee3cb775
@ -1462,10 +1462,6 @@ bool QueryDbMainLoop(Config* config,
|
||||
LOG_S(FATAL) << "Exiting; no cache directory";
|
||||
exit(1);
|
||||
}
|
||||
// Make sure compile commands directory is valid.
|
||||
if (config->compileCommandsDirectory.empty()) {
|
||||
config->compileCommandsDirectory = project_path;
|
||||
}
|
||||
|
||||
config->cacheDirectory = NormalizePath(config->cacheDirectory);
|
||||
EnsureEndsInSlash(config->cacheDirectory);
|
||||
@ -1571,8 +1567,9 @@ bool QueryDbMainLoop(Config* config,
|
||||
Timer time;
|
||||
|
||||
// Open up / load the project.
|
||||
project->Load(config->extraClangArguments, config->compileCommandsDirectory,
|
||||
config->resourceDirectory);
|
||||
project->Load(config->extraClangArguments,
|
||||
config->compilationDatabaseDirectory,
|
||||
project_path, config->resourceDirectory);
|
||||
time.ResetAndPrint("[perf] Loaded compilation entries (" +
|
||||
std::to_string(project->entries.size()) +
|
||||
" files)");
|
||||
|
@ -8,7 +8,7 @@ struct Config {
|
||||
// Root directory of the project. **Not serialized**
|
||||
std::string projectRoot;
|
||||
// Location of compile_commands.json.
|
||||
std::string compileCommandsDirectory;
|
||||
std::string compilationDatabaseDirectory;
|
||||
// Cache directory for indexed files.
|
||||
std::string cacheDirectory;
|
||||
// Value to use for clang -resource-dir if not present in
|
||||
@ -72,7 +72,7 @@ struct Config {
|
||||
bool enableSnippetInsertion = true;
|
||||
};
|
||||
MAKE_REFLECT_STRUCT(Config,
|
||||
compileCommandsDirectory,
|
||||
compilationDatabaseDirectory,
|
||||
cacheDirectory,
|
||||
resourceDirectory,
|
||||
|
||||
@ -101,4 +101,4 @@ MAKE_REFLECT_STRUCT(Config,
|
||||
codeLensOnLocalVariables,
|
||||
|
||||
clientVersion,
|
||||
enableSnippetInsertion);
|
||||
enableSnippetInsertion);
|
||||
|
@ -229,15 +229,19 @@ std::vector<Project::Entry> LoadFromDirectoryListing(ProjectConfig* config) {
|
||||
}
|
||||
|
||||
std::vector<Project::Entry> LoadCompilationEntriesFromDirectory(
|
||||
ProjectConfig* config) {
|
||||
ProjectConfig* config,
|
||||
const std::string& compilationDatabaseDirectory) {
|
||||
// Try to load compile_commands.json, but fallback to a project listing.
|
||||
const auto& compilationDbDir = compilationDatabaseDirectory.empty()
|
||||
? config->project_dir
|
||||
: compilationDatabaseDirectory;
|
||||
LOG_S(INFO) << "Trying to load compile_commands.json";
|
||||
CXCompilationDatabase_Error cx_db_load_error;
|
||||
CXCompilationDatabase cx_db = clang_CompilationDatabase_fromDirectory(
|
||||
config->project_dir.c_str(), &cx_db_load_error);
|
||||
compilationDbDir.c_str(), &cx_db_load_error);
|
||||
if (cx_db_load_error == CXCompilationDatabase_CanNotLoadDatabase) {
|
||||
LOG_S(INFO) << "Unable to load compile_commands.json located at \""
|
||||
<< config->project_dir
|
||||
<< compilationDbDir
|
||||
<< "\"; using directory listing instead.";
|
||||
return LoadFromDirectoryListing(config);
|
||||
}
|
||||
@ -339,14 +343,16 @@ int ComputeGuessScore(const std::string& a, const std::string& b) {
|
||||
} // namespace
|
||||
|
||||
void Project::Load(const std::vector<std::string>& extra_flags,
|
||||
const std::string& directory,
|
||||
const std::string& compilationDatabaseDirectory,
|
||||
const std::string& rootDirectory,
|
||||
const std::string& resource_directory) {
|
||||
// Load data.
|
||||
ProjectConfig config;
|
||||
config.extra_flags = extra_flags;
|
||||
config.project_dir = directory;
|
||||
config.project_dir = rootDirectory;
|
||||
config.resource_dir = resource_directory;
|
||||
entries = LoadCompilationEntriesFromDirectory(&config);
|
||||
entries = LoadCompilationEntriesFromDirectory(&config,
|
||||
compilationDatabaseDirectory);
|
||||
|
||||
// Cleanup / postprocess include directories.
|
||||
quote_include_directories.assign(config.quote_dirs.begin(),
|
||||
|
@ -31,12 +31,15 @@ struct Project {
|
||||
|
||||
// Loads a project for the given |directory|.
|
||||
//
|
||||
// If |directory| contains a compile_commands.json file, that will be used to
|
||||
// discover all files and args. Otherwise, a recursive directory listing of
|
||||
// all *.cpp, *.cc, *.h, and *.hpp files will be used. clang arguments can be
|
||||
// specified in a clang_args file located inside of |directory|.
|
||||
// If |compilationDatabaseDirectory| is not empty, the compile_commands.json
|
||||
// file in it will be used to discover all files and args. If it's empty and
|
||||
// |directory| contains a compile_commands.json file, that one will be used
|
||||
// instead. Otherwise, a recursive directory listing of all *.cpp, *.cc, *.h,
|
||||
// and *.hpp files will be used. clang arguments can be specified in a
|
||||
// clang_args file located inside of |directory|.
|
||||
void Load(const std::vector<std::string>& extra_flags,
|
||||
const std::string& directory,
|
||||
const std::string& compilationDatabaseDirectory,
|
||||
const std::string& rootDirectory,
|
||||
const std::string& resource_directory);
|
||||
|
||||
// Lookup the CompilationEntry for |filename|. If no entry was found this
|
||||
|
Loading…
Reference in New Issue
Block a user