Include file modification time in index

This commit is contained in:
Jacob Dufault 2017-04-19 21:57:44 -07:00
parent 9cb45c0ea0
commit b4fb350140
113 changed files with 173 additions and 6 deletions

View File

@ -1376,6 +1376,8 @@ std::vector<std::unique_ptr<IndexedFile>> Parse(IndexerConfig* config, FileConsu
assert(entry->id_cache.primary_file == entry->path);
entry->path = NormalizePath(entry->path);
entry->id_cache.primary_file = entry->path;
entry->last_modification_time = GetLastModificationTime(entry->path);
}
// TODO: Fix interesting checks.

View File

@ -466,6 +466,8 @@ struct IndexedFile {
IdCache id_cache;
std::string path;
int64_t last_modification_time = 0;
// The content of |path| when it was indexed.
//std::string content;

View File

@ -11,6 +11,8 @@
namespace {
bool gModificationTimeDisabled = false;
// See http://stackoverflow.com/a/236803
template<typename Out>
void Split(const std::string &s, char delim, Out result) {
@ -83,6 +85,15 @@ void MakeDirectoryRecursive(std::string path) {
}
}
void DisableModificationTimeForTest() {
gModificationTimeDisabled = true;
}
bool IsModificationTimeDisabledForTests() {
return gModificationTimeDisabled;
}
TEST_SUITE("Platform");
TEST_CASE("Split strings") {

View File

@ -37,5 +37,10 @@ bool TryMakeDirectory(const std::string& absolute_path);
void SetCurrentThreadName(const std::string& thread_name);
void DisableModificationTimeForTest();
bool IsModificationTimeDisabledForTests();
int64_t GetLastModificationTime(const std::string& absolute_path);
// Returns any clang arguments that are specific to the current platform.
std::vector<std::string> GetPlatformClangArguments();

View File

@ -8,6 +8,9 @@
#include <io.h>
#include <Windows.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <algorithm>
#include <cassert>
#include <iostream>
@ -179,6 +182,29 @@ void SetCurrentThreadName(const std::string& thread_name) {
__except (EXCEPTION_EXECUTE_HANDLER) {}
}
int64_t GetLastModificationTime(const std::string& absolute_path) {
if (IsModificationTimeDisabledForTests())
return 1;
struct _stat buf;
if (_stat(absolute_path.c_str(), &buf) != 0) {
switch (errno) {
case ENOENT:
std::cerr << "GetLastModificationTime: unable to find file " << absolute_path << std::endl;
break;
case EINVAL:
std::cerr << "GetLastModificationTime: invalid param to _stat for file file " << absolute_path << std::endl;
break;
default:
std::cerr << "GetLastModificationTime: unhandled for " << absolute_path << std::endl;
exit(1);
break;
}
}
return buf.st_mtime;
}
std::vector<std::string> GetPlatformClangArguments() {
return {
"-fms-compatibility",

View File

@ -104,9 +104,9 @@ CompilationEntry GetCompilationEntryFromCompileCommandEntry(const CompileCommand
CompilationEntry result;
result.filename = NormalizePath(entry.file);
unsigned int num_args = entry.args.size();
size_t num_args = entry.args.size();
result.args.reserve(num_args);
for (unsigned int j = 0; j < num_args; ++j) {
for (size_t j = 0; j < num_args; ++j) {
std::string arg = entry.args[j];
@ -226,9 +226,9 @@ std::vector<CompilationEntry> LoadCompilationEntriesFromDirectory(const std::str
entry.file = NormalizePath(absolute_filename);
entry.directory = directory;
unsigned int num_args = clang_CompileCommand_getNumArgs(cx_command);
unsigned num_args = clang_CompileCommand_getNumArgs(cx_command);
entry.args.reserve(num_args);
for (int i = 0; i < num_args; ++i)
for (unsigned i = 0; i < num_args; ++i)
entry.args.push_back(clang::ToString(clang_CompileCommand_getArg(cx_command, i)));
result.push_back(GetCompilationEntryFromCompileCommandEntry(entry));

View File

@ -10,6 +10,13 @@ void Reflect(Reader& visitor, int& value) {
void Reflect(Writer& visitor, int& value) {
visitor.Int(value);
}
// int64_t
void Reflect(Reader& visitor, int64_t& value) {
value = visitor.GetInt64();
}
void Reflect(Writer& visitor, int64_t& value) {
visitor.Int64(value);
}
// bool
void Reflect(Reader& visitor, bool& value) {
value = visitor.GetBool();
@ -215,6 +222,7 @@ bool ReflectMemberStart(Writer& visitor, IndexedFile& value) {
template<typename TVisitor>
void Reflect(TVisitor& visitor, IndexedFile& value) {
REFLECT_MEMBER_START();
REFLECT_MEMBER(last_modification_time);
REFLECT_MEMBER(dependencies);
REFLECT_MEMBER(types);
REFLECT_MEMBER(funcs);

View File

@ -102,6 +102,9 @@ void ReflectMemberEnd(TVisitor& visitor, T& value) {
// int
void Reflect(Reader& visitor, int& value);
void Reflect(Writer& visitor, int& value);
// int64_t
void Reflect(Reader& visitor, int64_t& value);
void Reflect(Writer& visitor, int64_t& value);
// bool
void Reflect(Reader& visitor, bool& value);
void Reflect(Writer& visitor, bool& value);

View File

@ -112,6 +112,8 @@ IndexedFile* FindDbForPathEnding(const std::string& path, const std::vector<std:
}
void RunTests() {
DisableModificationTimeForTest();
// TODO: Assert that we need to be on clang >= 3.9.1
bool update_all = false;

View File

@ -1,4 +1,6 @@
/*
OUTPUT:
{}
{
"last_modification_time": 1
}
*/

View File

@ -6,6 +6,7 @@ class Foo;
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@S@Foo",

View File

@ -11,6 +11,7 @@ void foo() {
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@S@Foo",

View File

@ -16,6 +16,7 @@ void foo() {
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@S@Foo",

View File

@ -6,6 +6,7 @@ Foo::Foo() {}
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@S@Foo",

View File

@ -8,6 +8,7 @@ class Foo;
// for comments.
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@S@Foo",

View File

@ -5,6 +5,7 @@ class Foo {
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@S@Foo",

View File

@ -7,6 +7,7 @@ int Foo::foo;
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@S@Foo",

View File

@ -7,6 +7,7 @@ void foo();
// Note: we always use the latest seen ("most local") definition/declaration.
OUTPUT:
{
"last_modification_time": 1,
"funcs": [{
"id": 0,
"usr": "c:@F@foo#",

View File

@ -9,6 +9,7 @@ void Foo::def() {}
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@S@Foo",

View File

@ -6,6 +6,7 @@ enum class Foo {
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@E@Foo",

View File

@ -6,6 +6,7 @@ enum Foo {
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@E@Foo",

View File

@ -6,6 +6,7 @@ enum Foo : int {
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@E@Foo",

View File

@ -8,6 +8,7 @@ Foo x = Foo::A;
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@E@Foo",

View File

@ -11,6 +11,7 @@ Foo<B> b;
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@E@A",

View File

@ -3,6 +3,7 @@ void foo(int a, int b);
/*
OUTPUT:
{
"last_modification_time": 1,
"funcs": [{
"id": 0,
"usr": "c:@F@foo#I#I#",

View File

@ -5,6 +5,7 @@ void foo() {}
/*
OUTPUT:
{
"last_modification_time": 1,
"funcs": [{
"id": 0,
"usr": "c:@F@foo#",

View File

@ -3,6 +3,7 @@ void foo() {}
/*
OUTPUT:
{
"last_modification_time": 1,
"funcs": [{
"id": 0,
"usr": "c:@F@foo#",

View File

@ -4,6 +4,7 @@ class Derived : public Parent {};
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@S@Parent",

View File

@ -15,6 +15,7 @@ class Derived : Base1<3>, Base2<Derived>, Derived1<4>, Derived2<Derived> {};
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@ST>1#Ni@Base1",

View File

@ -6,6 +6,7 @@ class Derived : public MiddleA, public MiddleB {};
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@S@Root",

View File

@ -8,6 +8,7 @@ class Derived : public Root {
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@S@Root",

View File

@ -5,6 +5,7 @@ class IFoo {
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@S@IFoo",

View File

@ -9,6 +9,7 @@ class Foo {
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@S@Foo",

View File

@ -7,6 +7,7 @@ void Foo::foo() {}
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@S@Foo",

View File

@ -5,6 +5,7 @@ class Foo {
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@S@Foo",

View File

@ -8,6 +8,7 @@ enum Foo {
OUTPUT: funky_enum.h
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@E@Foo",
@ -45,9 +46,9 @@ OUTPUT: funky_enum.h
"uses": ["6:1-6:2"]
}]
}
OUTPUT: funky_enum.cc
{
"last_modification_time": 1,
"dependencies": ["C:/Users/jacob/Desktop/superindex/indexer/tests/multi_file/funky_enum.h"],
"types": [{
"id": 0,

View File

@ -7,6 +7,7 @@ void Impl() {
/*
OUTPUT: header.h
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@S@Base",
@ -110,6 +111,7 @@ OUTPUT: header.h
}
OUTPUT: impl.cc
{
"last_modification_time": 1,
"dependencies": ["C:/Users/jacob/Desktop/superindex/indexer/tests/multi_file/header.h"],
"funcs": [{
"id": 0,

View File

@ -7,6 +7,7 @@ void impl() {
/*
OUTPUT: simple_header.h
{
"last_modification_time": 1,
"funcs": [{
"id": 0,
"usr": "c:@F@header#",
@ -17,6 +18,7 @@ OUTPUT: simple_header.h
}
OUTPUT: simple_impl.cc
{
"last_modification_time": 1,
"dependencies": ["C:/Users/jacob/Desktop/superindex/indexer/tests/multi_file/simple_header.h"],
"funcs": [{
"id": 0,

View File

@ -5,6 +5,7 @@ void Buffer::CreateSharedBuffer() {}
/*
OUTPUT: static.h
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@S@Buffer",
@ -26,6 +27,7 @@ OUTPUT: static.h
}
OUTPUT: static.cc
{
"last_modification_time": 1,
"dependencies": ["C:/Users/jacob/Desktop/superindex/indexer/tests/multi_file/static.h"],
"types": [{
"id": 0,

View File

@ -5,6 +5,7 @@ void foo();
/*
OUTPUT:
{
"last_modification_time": 1,
"funcs": [{
"id": 0,
"usr": "c:anonymous_function.cc@aN@F@foo#",

View File

@ -5,6 +5,7 @@ void foo(int a, int b);
/*
OUTPUT:
{
"last_modification_time": 1,
"funcs": [{
"id": 0,
"usr": "c:@N@hello@F@foo#I#I#",

View File

@ -5,6 +5,7 @@ void foo() {}
/*
OUTPUT:
{
"last_modification_time": 1,
"funcs": [{
"id": 0,
"usr": "c:@N@hello@F@foo#",

View File

@ -7,6 +7,7 @@ class Foo {
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@N@hello@S@Foo",

View File

@ -9,6 +9,7 @@ void Foo::foo() {}
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@N@hello@S@Foo",

View File

@ -7,6 +7,7 @@ class Foo {
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@N@hello@S@Foo",

View File

@ -12,6 +12,7 @@ void Runner() {
/*
OUTPUT:
{
"last_modification_time": 1,
"funcs": [{
"id": 0,
"usr": "c:@N@ns@F@Accept#I#",

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -10,6 +10,7 @@ void Foo::Bar(Template<double>&) {}
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@ST>1#T@Template",

View File

@ -17,6 +17,7 @@ namespace ns {
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@N@ns@E@VarType",

View File

@ -14,6 +14,7 @@ namespace ns {
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@N@ns@ST>1#T@Foo",

View File

@ -9,6 +9,7 @@ namespace ns {
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@N@ns@ST>1#T@Foo",

View File

@ -15,6 +15,7 @@ void Template<void>::Foo() {}
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@ST>1#T@Template",

View File

@ -11,6 +11,7 @@ int b = Foo<bool>::foo();
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@ST>1#T@Foo",

View File

@ -12,6 +12,7 @@ int b = Foo<bool>::foo<double>();
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@ST>1#T@Foo",

View File

@ -30,6 +30,7 @@ VarDecl b
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@E@A",

View File

@ -9,6 +9,7 @@ int b = Foo<bool>::var;
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@ST>1#T@Foo",

View File

@ -12,6 +12,7 @@ int b = foo<bool>();
/*
OUTPUT:
{
"last_modification_time": 1,
"funcs": [{
"id": 0,
"usr": "c:template_func_usage_folded_into_one.cc@FT@>1#Tfoo#I#",

View File

@ -7,6 +7,7 @@ Foo<bool> b;
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@ST>1#T@Foo",

View File

@ -30,6 +30,7 @@ UnexposedDecl var
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@E@A",

View File

@ -6,6 +6,7 @@ union vector3 {
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@U@vector3",

View File

@ -6,6 +6,7 @@ union Foo {
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@U@Foo",

View File

@ -14,6 +14,7 @@ void act(Foo*) {
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@U@Foo",

View File

@ -11,6 +11,7 @@ Foo::Foo() {
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@S@Foo",

View File

@ -9,6 +9,7 @@ void caller() {
/*
OUTPUT:
{
"last_modification_time": 1,
"funcs": [{
"id": 0,
"usr": "c:@F@called#b#b#",

View File

@ -14,6 +14,7 @@ void foo() {
// called() is never referenced.
OUTPUT:
{
"last_modification_time": 1,
"funcs": [{
"id": 0,
"usr": "c:@F@called#",

View File

@ -11,6 +11,7 @@ Wrapper caller() {
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@S@Wrapper",

View File

@ -10,6 +10,7 @@ void user() {
/*
OUTPUT:
{
"last_modification_time": 1,
"funcs": [{
"id": 0,
"usr": "c:@F@consume#*v#",

View File

@ -10,6 +10,7 @@ void user() {
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@S@Foo",

View File

@ -6,6 +6,7 @@ void caller() {
/*
OUTPUT:
{
"last_modification_time": 1,
"funcs": [{
"id": 0,
"usr": "c:@F@called#",

View File

@ -10,6 +10,7 @@ void user() {
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@S@Foo",

View File

@ -9,6 +9,7 @@ class Foo {
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@S@Foo",

View File

@ -6,6 +6,7 @@ void usage() {
/*
OUTPUT:
{
"last_modification_time": 1,
"funcs": [{
"id": 0,
"usr": "c:@F@foo#",

View File

@ -9,6 +9,7 @@ void usage() {
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@S@Foo",

View File

@ -9,6 +9,7 @@ void foo() {
/*
OUTPUT:
{
"last_modification_time": 1,
"funcs": [{
"id": 0,
"usr": "c:@FT@>1#Taccept#t0.0#v#",

View File

@ -13,6 +13,7 @@ unique_ptr<S>* return_type() {
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@ST>1#T@unique_ptr",

View File

@ -81,6 +81,7 @@ unique_ptr<S1, S2>* Foo::foo() { return nullptr; }
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@ST>2#T#T@unique_ptr",

View File

@ -8,6 +8,7 @@ static unique_ptr<S> foo;
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@ST>1#T@unique_ptr",

View File

@ -4,6 +4,7 @@ extern T t;
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@S@T",

View File

@ -9,6 +9,7 @@ struct Foo {
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@S@ForwardType",

View File

@ -9,6 +9,7 @@ void Foo() {
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@S@ForwardType",

View File

@ -6,6 +6,7 @@ void foo(ForwardType* f, ImplementedType a) {}
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@S@ForwardType",

View File

@ -11,6 +11,7 @@ void foo(Foo* f, Foo*) {}
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@S@Foo",

View File

@ -3,6 +3,7 @@ void foo(ForwardType*) {}
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@S@ForwardType",

View File

@ -9,6 +9,7 @@ void foo(Type& a0, const Type& a1) {
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@S@Type",

View File

@ -3,6 +3,7 @@ static Type t;
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@S@Type",

View File

@ -20,6 +20,7 @@ static Type* bar() {}
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@S@Type",

View File

@ -12,6 +12,7 @@ void accept3(Foo3*) {}
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@S@Foo",

View File

@ -7,6 +7,7 @@ typedef Foo<Foo1> Foo2;
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@ST>1#T@Foo",

View File

@ -12,6 +12,7 @@ extern Foo foo;
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@S@Foo",

View File

@ -17,6 +17,7 @@ void foo() {
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@S@Foo",

View File

@ -9,6 +9,7 @@ void foo() {
/*
OUTPUT:
{
"last_modification_time": 1,
"funcs": [{
"id": 0,
"usr": "c:@F@called#I#",

View File

@ -10,6 +10,7 @@ void caller() {
/*
OUTPUT:
{
"last_modification_time": 1,
"funcs": [{
"id": 0,
"usr": "c:@F@called#",

View File

@ -20,6 +20,7 @@ void foo() {
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@S@Foo",

View File

@ -11,6 +11,7 @@ void foo() {
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@S@Foo",

View File

@ -10,6 +10,7 @@ const VarType Holder::static_var;
/*
OUTPUT:
{
"last_modification_time": 1,
"types": [{
"id": 0,
"usr": "c:@E@VarType",

View File

@ -6,6 +6,7 @@ void foo() {
/*
OUTPUT:
{
"last_modification_time": 1,
"funcs": [{
"id": 0,
"usr": "c:@F@foo#",

View File

@ -4,6 +4,7 @@ void foo(int a) {
/*
OUTPUT:
{
"last_modification_time": 1,
"funcs": [{
"id": 0,
"usr": "c:@F@foo#I#",

View File

@ -5,6 +5,7 @@ void foo() {
/*
OUTPUT:
{
"last_modification_time": 1,
"funcs": [{
"id": 0,
"usr": "c:@F@foo#",

Some files were not shown because too many files have changed in this diff Show More