Browse Source

Preserve dependencies across multiple index runs.

pull/2/head
Jacob Dufault 8 years ago
parent
commit
1f6da81009
  1. 13
      src/command_line.cc
  2. 12
      src/file_consumer.cc
  3. 6
      src/indexer.cc
  4. 4
      src/indexer.h
  5. 7
      src/project.cc
  6. 3
      src/project.h
  7. 2
      src/test.cc

13
src/command_line.cc

@ -895,8 +895,8 @@ bool IndexMain_DoIndex(IndexerConfig* config,
dep_index_request.args = index_request->args;
queue_do_index->PriorityEnqueue(std::move(dep_index_request));
}
project->UpdateFileState(index_request->path, old_index->import_file, old_index->last_modification_time);
project->UpdateFileState(index_request->path, old_index->import_file, old_index->dependencies, old_index->last_modification_time);
Index_DoIdMap response(nullptr, std::move(old_index));
queue_do_id_map->Enqueue(std::move(response));
@ -913,11 +913,13 @@ bool IndexMain_DoIndex(IndexerConfig* config,
// Parse request and send a response.
std::string import_file = index_request->path;
std::vector<std::string> import_dependencies;
// Skip index if file modification time didn't change.
optional<Project::Entry> entry = project->FindCompilationEntryForFile(index_request->path);
if (entry && entry->last_modification_time) {
import_file = entry->import_file;
import_dependencies = entry->import_dependencies;
int64_t modification_time = GetLastModificationTime(index_request->path);
if (modification_time == *entry->last_modification_time) {
@ -926,13 +928,16 @@ bool IndexMain_DoIndex(IndexerConfig* config,
}
}
std::vector<std::unique_ptr<IndexedFile>> indexes = Parse(config, file_consumer_shared, index_request->path, import_file, index_request->args);
std::vector<std::unique_ptr<IndexedFile>> indexes = Parse(
config, file_consumer_shared,
index_request->path, import_file, import_dependencies,
index_request->args);
time.ResetAndPrint("Parsing/indexing " + index_request->path);
for (auto& current_index : indexes) {
std::cerr << "Got index for " << current_index->path << std::endl;
project->UpdateFileState(current_index->path, current_index->import_file, current_index->last_modification_time);
project->UpdateFileState(current_index->path, current_index->import_file, current_index->dependencies, current_index->last_modification_time);
std::unique_ptr<IndexedFile> old_index = LoadCachedFile(config, current_index->path);
time.ResetAndPrint("Loading cached index");

12
src/file_consumer.cc

@ -50,6 +50,16 @@ IndexedFile* FileConsumer::TryConsumeFile(CXFile file, bool* is_first_ownership)
}
IndexedFile* FileConsumer::ForceLocal(CXFile file) {
// Try to fetch the file using the normal system, which will insert the file
// usage into global storage.
{
bool is_first;
IndexedFile* cache = TryConsumeFile(file, &is_first);
if (cache)
return cache;
}
// It's already been taken before, just create a local copy.
CXFileUniqueID file_id;
if (clang_getFileUniqueID(file, &file_id) != 0) {
std::cerr << "Could not get unique file id for " << FileName(file) << std::endl;
@ -57,7 +67,7 @@ IndexedFile* FileConsumer::ForceLocal(CXFile file) {
}
auto it = local_.find(file_id);
if (it == local_.end())
if (it == local_.end() || !it->second)
local_[file_id] = MakeUnique<IndexedFile>(FileName(file));
assert(local_.find(file_id) != local_.end());
return local_[file_id].get();

6
src/indexer.cc

@ -1337,7 +1337,8 @@ void indexEntityReference(CXClientData client_data,
std::vector<std::unique_ptr<IndexedFile>> Parse(
IndexerConfig* config, FileConsumer::SharedState* file_consumer_shared,
std::string desired_index_file, std::string import_file, std::vector<std::string> args,
std::string desired_index_file, std::string import_file, const std::vector<std::string>& existing_dependencies,
std::vector<std::string> args,
bool dump_ast) {
if (!config->enableIndexing)
@ -1391,6 +1392,9 @@ std::vector<std::unique_ptr<IndexedFile>> Parse(
entry->last_modification_time = GetLastModificationTime(entry->path);
entry->import_file = import_file;
if (entry->path == import_file && !existing_dependencies.empty())
AddRange(&entry->dependencies, existing_dependencies);
}
// TODO: Fix interesting checks.

4
src/indexer.h

@ -502,8 +502,10 @@ struct IndexedFile {
// |import_file| is the cc file which is what gets passed to clang.
// |desired_index_file| is the (h or cc) file which has actually changed.
// |dependencies| are the existing dependencies of |import_file| if this is a reparse.
std::vector<std::unique_ptr<IndexedFile>> Parse(
IndexerConfig* config, FileConsumer::SharedState* file_consumer_shared,
std::string desired_index_file, std::string import_file, std::vector<std::string> args,
std::string desired_index_file, std::string import_file, const std::vector<std::string>& existing_dependencies,
std::vector<std::string> args,
bool dump_ast = false);
void IndexInit();

7
src/project.cc

@ -259,7 +259,7 @@ optional<Project::Entry> Project::FindCompilationEntryForFile(const std::string&
return nullopt;
}
void Project::UpdateFileState(const std::string& filename, const std::string& import_file, uint64_t modification_time) {
void Project::UpdateFileState(const std::string& filename, const std::string& import_file, const std::vector<std::string>& import_dependencies, uint64_t modification_time) {
{
// TODO: There might be a lot of thread contention here.
std::lock_guard<std::mutex> lock(entries_modification_mutex_);
@ -267,6 +267,7 @@ void Project::UpdateFileState(const std::string& filename, const std::string& im
if (it != absolute_path_to_entry_index_.end()) {
auto& entry = entries[it->second];
entry.import_file = import_file;
entry.import_dependencies = import_dependencies;
entry.last_modification_time = modification_time;
return;
}
@ -277,10 +278,12 @@ void Project::UpdateFileState(const std::string& filename, const std::string& im
Project::Entry entry;
entry.filename = filename;
if (import_entry)
if (import_entry) {
entry.args = import_entry->args;
}
entry.import_file = import_file;
entry.import_dependencies = import_dependencies;
entry.last_modification_time = modification_time;
// TODO: There might be a lot of thread contention here.

3
src/project.h

@ -16,6 +16,7 @@ struct Project {
std::vector<std::string> args;
std::string import_file;
std::vector<std::string> import_dependencies;
optional<uint64_t> last_modification_time;
};
@ -35,6 +36,6 @@ struct Project {
optional<Entry> FindCompilationEntryForFile(const std::string& filename);
// Update the modification time for the given filename. This is thread-safe.
void UpdateFileState(const std::string& filename, const std::string& import_file, uint64_t modification_time);
void UpdateFileState(const std::string& filename, const std::string& import_file, const std::vector<std::string>& import_dependencies, uint64_t modification_time);
};

2
src/test.cc

@ -139,7 +139,7 @@ void RunTests() {
std::cout << "[START] " << path << std::endl;
std::vector<std::unique_ptr<IndexedFile>> dbs = Parse(
&config, &file_consumer_shared,
path, path,
path, path, {},
{
"-xc++",
"-std=c++11",

Loading…
Cancel
Save