aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fileutil.cc4
-rw-r--r--main.cc5
-rw-r--r--ninja.cc14
-rw-r--r--ninja.h2
-rwxr-xr-xtestcase/ninja_regen.sh3
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,
diff --git a/main.cc b/main.cc
index 9a9f173..c1f3fa7 100644
--- a/main.cc
+++ b/main.cc
@@ -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();
diff --git a/ninja.cc b/ninja.cc
index d2e9828..ccdb99b 100644
--- a/ninja.cc
+++ b/ninja.cc
@@ -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);
diff --git a/ninja.h b/ninja.h
index d7f9e32..6a92617 100644
--- a/ninja.h
+++ b/ninja.h
@@ -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