diff options
author | Evan Martin <martine@danga.com> | 2012-01-05 17:24:30 (GMT) |
---|---|---|
committer | Evan Martin <martine@danga.com> | 2012-01-05 17:24:30 (GMT) |
commit | 499d3e9ea1776e5f59ef722bc82188f46fce3a9d (patch) | |
tree | 5447d244788b4bf50290de14b8d07d020360dd1a /src | |
parent | dc3ffcdd4c840a697cdbc71f2c0121908977af9a (diff) | |
download | Ninja-499d3e9ea1776e5f59ef722bc82188f46fce3a9d.zip Ninja-499d3e9ea1776e5f59ef722bc82188f46fce3a9d.tar.gz Ninja-499d3e9ea1776e5f59ef722bc82188f46fce3a9d.tar.bz2 |
convert all time_t to a new TimeStamp type
Diffstat (limited to 'src')
-rw-r--r-- | src/build.cc | 10 | ||||
-rw-r--r-- | src/build_log.cc | 4 | ||||
-rw-r--r-- | src/build_log.h | 5 | ||||
-rw-r--r-- | src/disk_interface.cc | 6 | ||||
-rw-r--r-- | src/disk_interface.h | 21 | ||||
-rw-r--r-- | src/disk_interface_test.cc | 8 | ||||
-rw-r--r-- | src/graph.cc | 9 | ||||
-rw-r--r-- | src/graph.h | 8 | ||||
-rw-r--r-- | src/test.cc | 2 | ||||
-rw-r--r-- | src/test.h | 2 | ||||
-rw-r--r-- | src/timestamp.h | 24 |
11 files changed, 64 insertions, 35 deletions
diff --git a/src/build.cc b/src/build.cc index 4b54561..61439cc 100644 --- a/src/build.cc +++ b/src/build.cc @@ -321,7 +321,7 @@ void Plan::CleanNode(BuildLog* build_log, Node* node) { end = (*ei)->inputs_.end() - (*ei)->order_only_deps_; if (find_if(begin, end, mem_fun(&Node::dirty)) == end) { // Recompute most_recent_input and command. - time_t most_recent_input = 1; + TimeStamp most_recent_input = 1; for (vector<Node*>::iterator ni = begin; ni != end; ++ni) if ((*ni)->mtime() > most_recent_input) most_recent_input = (*ni)->mtime(); @@ -569,7 +569,7 @@ bool Builder::StartEdge(Edge* edge, string* err) { } void Builder::FinishEdge(Edge* edge, bool success, const string& output) { - time_t restat_mtime = 0; + TimeStamp restat_mtime = 0; if (success) { if (edge->rule().restat()) { @@ -578,7 +578,7 @@ void Builder::FinishEdge(Edge* edge, bool success, const string& output) { for (vector<Node*>::iterator i = edge->outputs_.begin(); i != edge->outputs_.end(); ++i) { if ((*i)->exists()) { - time_t new_mtime = disk_interface_->Stat((*i)->path()); + TimeStamp new_mtime = disk_interface_->Stat((*i)->path()); if ((*i)->mtime() == new_mtime) { // The rule command did not change the output. Propagate the clean // state through the build graph. @@ -593,7 +593,7 @@ void Builder::FinishEdge(Edge* edge, bool success, const string& output) { // (existing) non-order-only input or the depfile. for (vector<Node*>::iterator i = edge->inputs_.begin(); i != edge->inputs_.end() - edge->order_only_deps_; ++i) { - time_t input_mtime = disk_interface_->Stat((*i)->path()); + TimeStamp input_mtime = disk_interface_->Stat((*i)->path()); if (input_mtime == 0) { restat_mtime = 0; break; @@ -603,7 +603,7 @@ void Builder::FinishEdge(Edge* edge, bool success, const string& output) { } if (restat_mtime != 0 && !edge->rule().depfile().empty()) { - time_t depfile_mtime = disk_interface_->Stat(edge->EvaluateDepFile()); + TimeStamp depfile_mtime = disk_interface_->Stat(edge->EvaluateDepFile()); if (depfile_mtime == 0) restat_mtime = 0; else if (depfile_mtime > restat_mtime) diff --git a/src/build_log.cc b/src/build_log.cc index 501b15b..b564137 100644 --- a/src/build_log.cc +++ b/src/build_log.cc @@ -73,7 +73,7 @@ bool BuildLog::OpenForWrite(const string& path, string* err) { } void BuildLog::RecordCommand(Edge* edge, int start_time, int end_time, - time_t restat_mtime) { + TimeStamp restat_mtime) { const string command = edge->EvaluateCommand(); for (vector<Node*>::iterator out = edge->outputs_.begin(); out != edge->outputs_.end(); ++out) { @@ -133,7 +133,7 @@ bool BuildLog::Load(const string& path, string* err) { *end = 0; int start_time = 0, end_time = 0; - time_t restat_mtime = 0; + TimeStamp restat_mtime = 0; start_time = atoi(start); start = end + 1; diff --git a/src/build_log.h b/src/build_log.h index 51cbe5e..3e27eee 100644 --- a/src/build_log.h +++ b/src/build_log.h @@ -20,6 +20,7 @@ using namespace std; #include "hash_map.h" +#include "timestamp.h" struct BuildConfig; struct Edge; @@ -39,7 +40,7 @@ struct BuildLog { void SetConfig(BuildConfig* config) { config_ = config; } bool OpenForWrite(const string& path, string* err); void RecordCommand(Edge* edge, int start_time, int end_time, - time_t restat_mtime = 0); + TimeStamp restat_mtime = 0); void Close(); /// Load the on-disk log. @@ -50,7 +51,7 @@ struct BuildLog { string command; int start_time; int end_time; - time_t restat_mtime; + TimeStamp restat_mtime; // Used by tests. bool operator==(const LogEntry& o) { diff --git a/src/disk_interface.cc b/src/disk_interface.cc index dec3836..0944643 100644 --- a/src/disk_interface.cc +++ b/src/disk_interface.cc @@ -50,7 +50,7 @@ bool DiskInterface::MakeDirs(const std::string& path) { std::string dir = DirName(path); if (dir.empty()) return true; // Reached root; assume it's there. - int mtime = Stat(dir); + TimeStamp mtime = Stat(dir); if (mtime < 0) return false; // Error. if (mtime > 0) @@ -65,7 +65,7 @@ bool DiskInterface::MakeDirs(const std::string& path) { // RealDiskInterface ----------------------------------------------------------- -int RealDiskInterface::Stat(const std::string& path) { +TimeStamp RealDiskInterface::Stat(const std::string& path) { #ifdef WIN32 WIN32_FILE_ATTRIBUTE_DATA attrs; if (!GetFileAttributesEx(path.c_str(), GetFileExInfoStandard, &attrs)) { @@ -84,7 +84,7 @@ int RealDiskInterface::Stat(const std::string& path) { ((uint64_t)filetime.dwLowDateTime); mtime /= 1000000000LL / 100; // 100ns -> s. mtime -= 12622770400LL; // 1600 epoch -> 2000 epoch (subtract 400 years). - return (int)mtime; + return (TimeStamp)mtime; #else struct stat st; if (stat(path.c_str(), &st) < 0) { diff --git a/src/disk_interface.h b/src/disk_interface.h index 9efcfce..b0fed3d 100644 --- a/src/disk_interface.h +++ b/src/disk_interface.h @@ -16,6 +16,9 @@ #define NINJA_DISK_INTERFACE_H_ #include <string> +using namespace std; + +#include "timestamp.h" /// Interface for accessing the disk. /// @@ -26,33 +29,33 @@ struct DiskInterface { /// stat() a file, returning the mtime, or 0 if missing and -1 on /// other errors. - virtual int Stat(const std::string& path) = 0; + virtual TimeStamp Stat(const string& path) = 0; /// Create a directory, returning false on failure. - virtual bool MakeDir(const std::string& path) = 0; + virtual bool MakeDir(const string& path) = 0; /// Read a file to a string. Fill in |err| on error. - virtual std::string ReadFile(const std::string& path, std::string* err) = 0; + virtual string ReadFile(const string& path, string* err) = 0; /// Remove the file named @a path. It behaves like 'rm -f path' so no errors /// are reported if it does not exists. /// @returns 0 if the file has been removed, /// 1 if the file does not exist, and /// -1 if an error occurs. - virtual int RemoveFile(const std::string& path) = 0; + virtual int RemoveFile(const string& path) = 0; /// Create all the parent directories for path; like mkdir -p /// `basename path`. - bool MakeDirs(const std::string& path); + bool MakeDirs(const string& path); }; /// Implementation of DiskInterface that actually hits the disk. struct RealDiskInterface : public DiskInterface { virtual ~RealDiskInterface() {} - virtual int Stat(const std::string& path); - virtual bool MakeDir(const std::string& path); - virtual std::string ReadFile(const std::string& path, std::string* err); - virtual int RemoveFile(const std::string& path); + virtual TimeStamp Stat(const string& path); + virtual bool MakeDir(const string& path); + virtual string ReadFile(const string& path, string* err); + virtual int RemoveFile(const string& path); }; #endif // NINJA_DISK_INTERFACE_H_ diff --git a/src/disk_interface_test.cc b/src/disk_interface_test.cc index 3bb8067..c431e75 100644 --- a/src/disk_interface_test.cc +++ b/src/disk_interface_test.cc @@ -168,7 +168,7 @@ TEST_F(DiskInterfaceTest, RemoveFile) { struct StatTest : public StateTestWithBuiltinRules, public DiskInterface { // DiskInterface implementation. - virtual int Stat(const string& path); + virtual TimeStamp Stat(const string& path); virtual bool MakeDir(const string& path) { assert(false); return false; @@ -182,13 +182,13 @@ struct StatTest : public StateTestWithBuiltinRules, return 0; } - map<string, time_t> mtimes_; + map<string, TimeStamp> mtimes_; vector<string> stats_; }; -int StatTest::Stat(const string& path) { +TimeStamp StatTest::Stat(const string& path) { stats_.push_back(path); - map<string, time_t>::iterator i = mtimes_.find(path); + map<string, TimeStamp>::iterator i = mtimes_.find(path); if (i == mtimes_.end()) return 0; // File not found. return i->second; diff --git a/src/graph.cc b/src/graph.cc index ed7097b..eb107f2 100644 --- a/src/graph.cc +++ b/src/graph.cc @@ -40,7 +40,7 @@ bool Edge::RecomputeDirty(State* state, DiskInterface* disk_interface, } // Visit all inputs; we're dirty if any of the inputs are dirty. - time_t most_recent_input = 1; + TimeStamp most_recent_input = 1; for (vector<Node*>::iterator i = inputs_.begin(); i != inputs_.end(); ++i) { if ((*i)->StatIfNecessary(disk_interface)) { if (Edge* edge = (*i)->in_edge()) { @@ -103,11 +103,12 @@ bool Edge::RecomputeDirty(State* state, DiskInterface* disk_interface, return true; } -bool Edge::RecomputeOutputDirty(BuildLog* build_log, time_t most_recent_input, +bool Edge::RecomputeOutputDirty(BuildLog* build_log, + TimeStamp most_recent_input, const string& command, Node* output) { if (is_phony()) { - // Phony edges don't write any output. - // Outputs are only dirty if there are no inputs and we're missing the output. + // Phony edges don't write any output. Outputs are only dirty if + // there are no inputs and we're missing the output. return inputs_.empty() && !output->exists(); } diff --git a/src/graph.h b/src/graph.h index 0514c0c..6ba82b9 100644 --- a/src/graph.h +++ b/src/graph.h @@ -20,9 +20,9 @@ using namespace std; #include "eval_env.h" +#include "timestamp.h" struct DiskInterface; - struct Edge; /// Information about a node in the dependency graph: the file, whether @@ -62,7 +62,7 @@ struct Node { } const string& path() const { return path_; } - time_t mtime() const { return mtime_; } + TimeStamp mtime() const { return mtime_; } bool dirty() const { return dirty_; } void set_dirty(bool dirty) { dirty_ = dirty; } @@ -80,7 +80,7 @@ private: /// -1: file hasn't been examined /// 0: we looked, and file doesn't exist /// >0: actual file's mtime - time_t mtime_; + TimeStamp mtime_; /// Dirty is true when the underlying file is out-of-date. /// But note that Edge::outputs_ready_ is also used in judging which @@ -141,7 +141,7 @@ struct Edge { /// Recompute whether a given single output should be marked dirty. /// Returns true if so. - bool RecomputeOutputDirty(BuildLog* build_log, time_t most_recent_input, + bool RecomputeOutputDirty(BuildLog* build_log, TimeStamp most_recent_input, const string& command, Node* output); /// Return true if all inputs' in-edges are ready. diff --git a/src/test.cc b/src/test.cc index e8ea621..925a6cb 100644 --- a/src/test.cc +++ b/src/test.cc @@ -41,7 +41,7 @@ void VirtualFileSystem::Create(const string& path, int time, files_[path].contents = contents; } -int VirtualFileSystem::Stat(const string& path) { +TimeStamp VirtualFileSystem::Stat(const string& path) { FileMap::iterator i = files_.find(path); if (i != files_.end()) return i->second.mtime; @@ -43,7 +43,7 @@ struct VirtualFileSystem : public DiskInterface { void Create(const string& path, int time, const string& contents); // DiskInterface - virtual int Stat(const string& path); + virtual TimeStamp Stat(const string& path); virtual bool MakeDir(const string& path); virtual string ReadFile(const string& path, string* err); virtual int RemoveFile(const string& path); diff --git a/src/timestamp.h b/src/timestamp.h new file mode 100644 index 0000000..cee7ba8 --- /dev/null +++ b/src/timestamp.h @@ -0,0 +1,24 @@ +// Copyright 2011 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef NINJA_TIMESTAMP_H_ +#define NINJA_TIMESTAMP_H_ + +// When considering file modification times we only care to compare +// them against one another -- we never convert them to an absolute +// real time. On POSIX we use time_t (seconds since epoch) and on +// Windows we use a different value. Both fit in an int. +typedef int TimeStamp; + +#endif // NINJA_TIMESTAMP_H_ |