diff options
author | Shinichiro Hamaji <shinichiro.hamaji@gmail.com> | 2015-07-31 15:12:04 +0900 |
---|---|---|
committer | Shinichiro Hamaji <shinichiro.hamaji@gmail.com> | 2015-07-31 15:18:11 +0900 |
commit | 36eeb75372686651a4a99e51581693d222806232 (patch) | |
tree | f634c4eb9764b94890133713476d4069b44f7384 | |
parent | e6ec11817b8d3030690129ea800a50f1272f89a5 (diff) | |
download | android_build_kati-36eeb75372686651a4a99e51581693d222806232.tar.gz android_build_kati-36eeb75372686651a4a99e51581693d222806232.tar.bz2 android_build_kati-36eeb75372686651a4a99e51581693d222806232.zip |
[C++] Use nano seconds for timestamp check
-rw-r--r-- | fileutil.cc | 4 | ||||
-rw-r--r-- | main.cc | 5 | ||||
-rw-r--r-- | ninja.cc | 14 | ||||
-rw-r--r-- | ninja.h | 2 | ||||
-rwxr-xr-x | testcase/ninja_regen.sh | 3 |
5 files changed, 17 insertions, 11 deletions
diff --git a/fileutil.cc b/fileutil.cc index b994f5c..86d66e0 100644 --- a/fileutil.cc +++ b/fileutil.cc @@ -46,7 +46,11 @@ double GetTimestamp(StringPiece filename) { if (stat(filename.as_string().c_str(), &st) < 0) { return -2.0; } +#if defined(__linux__) + return st.st_mtime + st.st_mtim.tv_nsec * 0.001 * 0.001 * 0.001; +#else return st.st_mtime; +#endif } int RunCommand(const string& shell, const string& cmd, bool redirect_stderr, @@ -231,8 +231,9 @@ static int Run(const vector<Symbol>& targets, ClearGlobCache(); } - time_t start_time; - time(&start_time); + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + double start_time = ts.tv_sec + ts.tv_nsec * 0.001 * 0.001 * 0.001; MakefileCacheManager* cache_mgr = NewMakefileCacheManager(); @@ -167,7 +167,7 @@ bool GetDepfileFromCommand(string* cmd, string* out) { class NinjaGenerator { public: NinjaGenerator(const char* ninja_suffix, const char* ninja_dir, Evaluator* ev, - time_t start_time) + double start_time) : ce_(ev), ev_(ev), fp_(NULL), rule_id_(0), start_time_(start_time) { ev_->set_avoid_io(true); shell_ = ev->EvalVar(kShellSym); @@ -709,8 +709,10 @@ class NinjaGenerator { void GenerateStamp() { FILE* fp = fopen(GetStampFilename().c_str(), "wb"); + CHECK(fp); - DumpInt(fp, start_time_); + size_t r = fwrite(&start_time_, sizeof(start_time_), 1, fp); + CHECK(r == 1); unordered_set<string> makefiles; MakefileCacheManager::Get()->GetAllFilenames(&makefiles); @@ -763,7 +765,7 @@ class NinjaGenerator { shared_ptr<string> shell_; map<string, string> used_envs_; string kati_binary_; - time_t start_time_; + double start_time_; }; void GenerateNinja(const char* ninja_suffix, @@ -772,7 +774,7 @@ void GenerateNinja(const char* ninja_suffix, Evaluator* ev, bool build_all_targets, const string& orig_args, - time_t start_time) { + double start_time) { NinjaGenerator ng(ninja_suffix, ninja_dir, ev, start_time); ng.Generate(nodes, build_all_targets, orig_args); } @@ -786,7 +788,9 @@ bool NeedsRegen(const char* ninja_suffix, return true; ScopedFile sfp(fp); - time_t gen_time = LoadInt(fp); + double gen_time; + size_t r = fread(&gen_time, sizeof(gen_time), 1, fp); + CHECK(r == 1); string s, s2; int num_files = LoadInt(fp); @@ -33,7 +33,7 @@ void GenerateNinja(const char* ninja_suffix, Evaluator* ev, bool build_all_targets, const string& orig_args, - time_t start_time); + double start_time); bool NeedsRegen(const char* ninja_suffix, const char* ninja_dir); diff --git a/testcase/ninja_regen.sh b/testcase/ninja_regen.sh index 4ce1072..8c4f411 100755 --- a/testcase/ninja_regen.sh +++ b/testcase/ninja_regen.sh @@ -31,7 +31,6 @@ if [ -e ninja.sh ]; then ./ninja.sh fi -sleep 1 cat <<EOF > Makefile all: echo bar @@ -66,7 +65,6 @@ if [ -e ninja.sh ]; then ./ninja.sh fi -sleep 1 touch PASS.mk ${mk} 2> ${log} if [ -e ninja.sh ]; then @@ -76,7 +74,6 @@ if [ -e ninja.sh ]; then ./ninja.sh fi -sleep 1 touch XXX ${mk} 2> ${log} if [ -e ninja.sh ]; then |