mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-22 15:45:08 +00:00
Inject -resource-dir automatically.
This commit is contained in:
parent
0d091b69cf
commit
58f2107714
@ -501,7 +501,7 @@ struct Index_DoIdMap {
|
|||||||
perf(perf),
|
perf(perf),
|
||||||
is_interactive(is_interactive),
|
is_interactive(is_interactive),
|
||||||
write_to_disk(write_to_disk) {
|
write_to_disk(write_to_disk) {
|
||||||
assert(this->current);
|
assert(this->current);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1367,6 +1367,19 @@ bool QueryDbMainLoop(Config* config,
|
|||||||
EnsureEndsInSlash(config->cacheDirectory);
|
EnsureEndsInSlash(config->cacheDirectory);
|
||||||
MakeDirectoryRecursive(config->cacheDirectory);
|
MakeDirectoryRecursive(config->cacheDirectory);
|
||||||
|
|
||||||
|
// Ensure there is a resource directory.
|
||||||
|
if (config->resourceDirectory.empty()) {
|
||||||
|
config->resourceDirectory = GetWorkingDirectory();
|
||||||
|
#if defined(_WIN32)
|
||||||
|
config->resourceDirectory +=
|
||||||
|
std::string("../../clang_resource_dir/");
|
||||||
|
#else
|
||||||
|
config->resourceDirectory += std::string("../clang_resource_dir/");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
config->resourceDirectory = NormalizePath(config->resourceDirectory);
|
||||||
|
LOG_S(INFO) << "Using -resource-dir=" << config->resourceDirectory;
|
||||||
|
|
||||||
// Set project root.
|
// Set project root.
|
||||||
config->projectRoot =
|
config->projectRoot =
|
||||||
NormalizePath(request->params.rootUri->GetPath());
|
NormalizePath(request->params.rootUri->GetPath());
|
||||||
@ -1391,7 +1404,8 @@ bool QueryDbMainLoop(Config* config,
|
|||||||
Timer time;
|
Timer time;
|
||||||
|
|
||||||
// Open up / load the project.
|
// Open up / load the project.
|
||||||
project->Load(config->extraClangArguments, project_path);
|
project->Load(config->extraClangArguments, project_path,
|
||||||
|
config->resourceDirectory);
|
||||||
time.ResetAndPrint("[perf] Loaded compilation entries (" +
|
time.ResetAndPrint("[perf] Loaded compilation entries (" +
|
||||||
std::to_string(project->entries.size()) +
|
std::to_string(project->entries.size()) +
|
||||||
" files)");
|
" files)");
|
||||||
|
@ -9,6 +9,9 @@ struct Config {
|
|||||||
std::string projectRoot;
|
std::string projectRoot;
|
||||||
// Cache directory for indexed files.
|
// Cache directory for indexed files.
|
||||||
std::string cacheDirectory;
|
std::string cacheDirectory;
|
||||||
|
// Value to use for clang -resource-dir if not present in
|
||||||
|
// compile_commands.json.
|
||||||
|
std::string resourceDirectory;
|
||||||
|
|
||||||
std::vector<std::string> extraClangArguments;
|
std::vector<std::string> extraClangArguments;
|
||||||
|
|
||||||
@ -64,6 +67,7 @@ struct Config {
|
|||||||
};
|
};
|
||||||
MAKE_REFLECT_STRUCT(Config,
|
MAKE_REFLECT_STRUCT(Config,
|
||||||
cacheDirectory,
|
cacheDirectory,
|
||||||
|
resourceDirectory,
|
||||||
|
|
||||||
extraClangArguments,
|
extraClangArguments,
|
||||||
|
|
||||||
|
@ -10,11 +10,9 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
|
|
||||||
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -132,7 +130,8 @@ void PlatformInit() {
|
|||||||
// See http://stackoverflow.com/a/19535628
|
// See http://stackoverflow.com/a/19535628
|
||||||
std::string GetWorkingDirectory() {
|
std::string GetWorkingDirectory() {
|
||||||
char result[MAX_PATH];
|
char result[MAX_PATH];
|
||||||
return std::string(result, GetModuleFileName(NULL, result, MAX_PATH));
|
std::string binary_path(result, GetModuleFileName(NULL, result, MAX_PATH));
|
||||||
|
return binary_path.substr(0, binary_path.find_last_of("\\/") + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string NormalizePath(const std::string& path) {
|
std::string NormalizePath(const std::string& path) {
|
||||||
|
@ -40,6 +40,7 @@ struct ProjectConfig {
|
|||||||
std::unordered_set<std::string> angle_dirs;
|
std::unordered_set<std::string> angle_dirs;
|
||||||
std::vector<std::string> extra_flags;
|
std::vector<std::string> extra_flags;
|
||||||
std::string project_dir;
|
std::string project_dir;
|
||||||
|
std::string resource_dir;
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: See
|
// TODO: See
|
||||||
@ -185,9 +186,10 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry(
|
|||||||
result.args.push_back("-std=c++11");
|
result.args.push_back("-std=c++11");
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Add
|
// Add -resource-dir so clang can correctly resolve system includes like
|
||||||
// "-resource-dir=/home/jdufault/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../clang_includes",
|
// <cstddef>
|
||||||
// we can extract this from build dir.
|
if (!AnyStartsWith(result.args, "-resource-dir"))
|
||||||
|
result.args.push_back("-resource-dir=" + config->resource_dir);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -312,11 +314,13 @@ int ComputeGuessScore(const std::string& a, const std::string& b) {
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void Project::Load(const std::vector<std::string>& extra_flags,
|
void Project::Load(const std::vector<std::string>& extra_flags,
|
||||||
const std::string& directory) {
|
const std::string& directory,
|
||||||
|
const std::string& resource_directory) {
|
||||||
// Load data.
|
// Load data.
|
||||||
ProjectConfig config;
|
ProjectConfig config;
|
||||||
config.extra_flags = extra_flags;
|
config.extra_flags = extra_flags;
|
||||||
config.project_dir = directory;
|
config.project_dir = directory;
|
||||||
|
config.resource_dir = resource_directory;
|
||||||
entries = LoadCompilationEntriesFromDirectory(&config);
|
entries = LoadCompilationEntriesFromDirectory(&config);
|
||||||
|
|
||||||
// Cleanup / postprocess include directories.
|
// Cleanup / postprocess include directories.
|
||||||
@ -393,6 +397,7 @@ void CheckFlags(const std::string& directory,
|
|||||||
|
|
||||||
ProjectConfig config;
|
ProjectConfig config;
|
||||||
config.project_dir = "/w/c/s/";
|
config.project_dir = "/w/c/s/";
|
||||||
|
config.resource_dir = "/w/resource_dir/";
|
||||||
|
|
||||||
CompileCommandsEntry entry;
|
CompileCommandsEntry entry;
|
||||||
entry.directory = directory;
|
entry.directory = directory;
|
||||||
@ -424,13 +429,16 @@ void CheckFlags(std::vector<std::string> raw,
|
|||||||
TEST_CASE("strip meta-compiler invocations") {
|
TEST_CASE("strip meta-compiler invocations") {
|
||||||
CheckFlags(
|
CheckFlags(
|
||||||
/* raw */ {"clang", "-lstdc++", "myfile.cc"},
|
/* raw */ {"clang", "-lstdc++", "myfile.cc"},
|
||||||
/* expected */ {"clang", "-lstdc++", "myfile.cc", "-xc++", "-std=c++11"});
|
/* expected */ {"clang", "-lstdc++", "myfile.cc", "-xc++", "-std=c++11",
|
||||||
|
"-resource-dir=/w/resource_dir/"});
|
||||||
|
|
||||||
CheckFlags(/* raw */ {"goma", "clang"},
|
CheckFlags(/* raw */ {"goma", "clang"},
|
||||||
/* expected */ {"clang", "-xc++", "-std=c++11"});
|
/* expected */ {"clang", "-xc++", "-std=c++11",
|
||||||
|
"-resource-dir=/w/resource_dir/"});
|
||||||
|
|
||||||
CheckFlags(/* raw */ {"goma", "clang", "--foo"},
|
CheckFlags(/* raw */ {"goma", "clang", "--foo"},
|
||||||
/* expected */ {"clang", "--foo", "-xc++", "-std=c++11"});
|
/* expected */ {"clang", "--foo", "-xc++", "-std=c++11",
|
||||||
|
"-resource-dir=/w/resource_dir/"});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks flag parsing for a random chromium file in comparison to what
|
// Checks flag parsing for a random chromium file in comparison to what
|
||||||
@ -773,7 +781,8 @@ TEST_CASE("ycm") {
|
|||||||
"debian_jessie_amd64-sysroot",
|
"debian_jessie_amd64-sysroot",
|
||||||
"-fno-exceptions",
|
"-fno-exceptions",
|
||||||
"-fvisibility-inlines-hidden",
|
"-fvisibility-inlines-hidden",
|
||||||
"-xc++"});
|
"-xc++",
|
||||||
|
"-resource-dir=/w/resource_dir/"});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks flag parsing for an example chromium file.
|
// Checks flag parsing for an example chromium file.
|
||||||
@ -1090,7 +1099,8 @@ TEST_CASE("chromium") {
|
|||||||
"debian_jessie_amd64-sysroot",
|
"debian_jessie_amd64-sysroot",
|
||||||
"-fno-exceptions",
|
"-fno-exceptions",
|
||||||
"-fvisibility-inlines-hidden",
|
"-fvisibility-inlines-hidden",
|
||||||
"-xc++"});
|
"-xc++",
|
||||||
|
"-resource-dir=/w/resource_dir/"});
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Directory extraction") {
|
TEST_CASE("Directory extraction") {
|
||||||
|
@ -36,7 +36,8 @@ struct Project {
|
|||||||
// all *.cpp, *.cc, *.h, and *.hpp files will be used. clang arguments can be
|
// all *.cpp, *.cc, *.h, and *.hpp files will be used. clang arguments can be
|
||||||
// specified in a clang_args file located inside of |directory|.
|
// specified in a clang_args file located inside of |directory|.
|
||||||
void Load(const std::vector<std::string>& extra_flags,
|
void Load(const std::vector<std::string>& extra_flags,
|
||||||
const std::string& directory);
|
const std::string& directory,
|
||||||
|
const std::string& resource_directory);
|
||||||
|
|
||||||
// Lookup the CompilationEntry for |filename|. If no entry was found this
|
// Lookup the CompilationEntry for |filename|. If no entry was found this
|
||||||
// will infer one based on existing project structure.
|
// will infer one based on existing project structure.
|
||||||
|
Loading…
Reference in New Issue
Block a user