diff options
author | Evan Martin <martine@danga.com> | 2011-08-25 15:02:51 (GMT) |
---|---|---|
committer | Evan Martin <martine@danga.com> | 2011-08-25 15:02:51 (GMT) |
commit | a87f4979c94d18daf35f9b0ff8391aaa3e6a5274 (patch) | |
tree | b23d15af98aa65f06ba0f9c38b78ec3a6c403cc1 /src | |
parent | 210ca80b06c57994851fcfdebf7f3d767c41427b (diff) | |
parent | 16761d7c766e0bed31e7648e3c5f2ce67c3aca52 (diff) | |
download | Ninja-a87f4979c94d18daf35f9b0ff8391aaa3e6a5274.zip Ninja-a87f4979c94d18daf35f9b0ff8391aaa3e6a5274.tar.gz Ninja-a87f4979c94d18daf35f9b0ff8391aaa3e6a5274.tar.bz2 |
Merge pull request #86 from tfarina/real-disk-interface
Move RealDiskInterface class to disk_interface.h.
Diffstat (limited to 'src')
-rw-r--r-- | src/build.cc | 1 | ||||
-rw-r--r-- | src/clean.cc | 41 | ||||
-rw-r--r-- | src/disk_interface.cc | 59 | ||||
-rw-r--r-- | src/disk_interface.h | 9 | ||||
-rw-r--r-- | src/graph.cc | 1 | ||||
-rw-r--r-- | src/ninja.h | 10 | ||||
-rw-r--r-- | src/ninja_jumble.cc | 47 |
7 files changed, 90 insertions, 78 deletions
diff --git a/src/build.cc b/src/build.cc index f967538..1c8a4fa 100644 --- a/src/build.cc +++ b/src/build.cc @@ -25,6 +25,7 @@ #endif #include "build_log.h" +#include "disk_interface.h" #include "graph.h" #include "ninja.h" #include "subprocess.h" diff --git a/src/clean.cc b/src/clean.cc index d6436ad..31641d2 100644 --- a/src/clean.cc +++ b/src/clean.cc @@ -14,37 +14,36 @@ #include "clean.h" -#include "graph.h" -#include "ninja.h" -#include "util.h" -#include "build.h" - -#include <stdio.h> +#include <assert.h> #include <errno.h> +#include <stdio.h> #include <string.h> #include <sys/stat.h> -#include <assert.h> + +#include "build.h" +#include "disk_interface.h" +#include "graph.h" +#include "ninja.h" +#include "util.h" Cleaner::Cleaner(State* state, const BuildConfig& config) - : state_(state) - , config_(config) - , removed_() - , cleaned_files_count_(0) - , disk_interface_(new RealDiskInterface) - , status_(0) -{ + : state_(state), + config_(config), + removed_(), + cleaned_files_count_(0), + disk_interface_(new RealDiskInterface), + status_(0) { } Cleaner::Cleaner(State* state, const BuildConfig& config, DiskInterface* disk_interface) - : state_(state) - , config_(config) - , removed_() - , cleaned_files_count_(0) - , disk_interface_(disk_interface) - , status_(0) -{ + : state_(state), + config_(config), + removed_(), + cleaned_files_count_(0), + disk_interface_(disk_interface), + status_(0) { } int Cleaner::RemoveFile(const string& path) { diff --git a/src/disk_interface.cc b/src/disk_interface.cc index 70564d7..6404bd5 100644 --- a/src/disk_interface.cc +++ b/src/disk_interface.cc @@ -14,6 +14,13 @@ #include "disk_interface.h" +#include <errno.h> +#include <stdio.h> +#include <string.h> +#include <sys/stat.h> + +#include "util.h" + namespace { std::string DirName(const std::string& path) { @@ -33,6 +40,8 @@ std::string DirName(const std::string& path) { } // namespace +// DiskInterface --------------------------------------------------------------- + bool DiskInterface::MakeDirs(const std::string& path) { std::string dir = DirName(path); if (dir.empty()) @@ -49,3 +58,53 @@ bool DiskInterface::MakeDirs(const std::string& path) { return false; return MakeDir(dir); } + +// RealDiskInterface ----------------------------------------------------------- + +int RealDiskInterface::Stat(const std::string& path) { + struct stat st; + if (stat(path.c_str(), &st) < 0) { + if (errno == ENOENT) { + return 0; + } else { + Error("stat(%s): %s", path.c_str(), strerror(errno)); + return -1; + } + } + + return st.st_mtime; + return true; +} + +bool RealDiskInterface::MakeDir(const std::string& path) { + if (::MakeDir(path) < 0) { + Error("mkdir(%s): %s", path.c_str(), strerror(errno)); + return false; + } + return true; +} + +std::string RealDiskInterface::ReadFile(const std::string& path, + std::string* err) { + std::string contents; + int ret = ::ReadFile(path, &contents, err); + if (ret == -ENOENT) { + // Swallow ENOENT. + err->clear(); + } + return contents; +} + +int RealDiskInterface::RemoveFile(const std::string& path) { + if (remove(path.c_str()) < 0) { + switch (errno) { + case ENOENT: + return 1; + default: + Error("remove(%s): %s", path.c_str(), strerror(errno)); + return -1; + } + } else { + return 0; + } +} diff --git a/src/disk_interface.h b/src/disk_interface.h index b8d9786..9efcfce 100644 --- a/src/disk_interface.h +++ b/src/disk_interface.h @@ -46,4 +46,13 @@ struct DiskInterface { bool MakeDirs(const std::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); +}; + #endif // NINJA_DISK_INTERFACE_H_ diff --git a/src/graph.cc b/src/graph.cc index 0f687ea..5517f17 100644 --- a/src/graph.cc +++ b/src/graph.cc @@ -17,6 +17,7 @@ #include <stdio.h> #include "build_log.h" +#include "disk_interface.h" #include "ninja.h" #include "parsers.h" #include "util.h" diff --git a/src/ninja.h b/src/ninja.h index 1e797b6..4953711 100644 --- a/src/ninja.h +++ b/src/ninja.h @@ -23,7 +23,6 @@ #include <string> #include <vector> -#include "disk_interface.h" #include "eval_env.h" #include "stat_cache.h" @@ -34,15 +33,6 @@ struct FileStat; struct Node; struct Rule; -/// Implementation of DiskInterface that actually hits the disk. -struct RealDiskInterface : public DiskInterface { - virtual ~RealDiskInterface() {} - virtual int Stat(const string& path); - virtual bool MakeDir(const string& path); - virtual string ReadFile(const string& path, string* err); - virtual int RemoveFile(const string& path); -}; - /// Global state (file status, loaded rules) for a single run. struct State { State(); diff --git a/src/ninja_jumble.cc b/src/ninja_jumble.cc index f3b726a..e5cdf29 100644 --- a/src/ninja_jumble.cc +++ b/src/ninja_jumble.cc @@ -26,53 +26,6 @@ #include "graph.h" #include "util.h" -int RealDiskInterface::Stat(const string& path) { - struct stat st; - if (stat(path.c_str(), &st) < 0) { - if (errno == ENOENT) { - return 0; - } else { - Error("stat(%s): %s", path.c_str(), strerror(errno)); - return -1; - } - } - - return st.st_mtime; - return true; -} - -string RealDiskInterface::ReadFile(const string& path, string* err) { - string contents; - int ret = ::ReadFile(path, &contents, err); - if (ret == -ENOENT) { - // Swallow ENOENT. - err->clear(); - } - return contents; -} - -bool RealDiskInterface::MakeDir(const string& path) { - if (::MakeDir(path) < 0) { - Error("mkdir(%s): %s", path.c_str(), strerror(errno)); - return false; - } - return true; -} - -int RealDiskInterface::RemoveFile(const string& path) { - if (remove(path.c_str()) < 0) { - switch (errno) { - case ENOENT: - return 1; - default: - Error("remove(%s): %s", path.c_str(), strerror(errno)); - return -1; - } - } else { - return 0; - } -} - const Rule State::kPhonyRule("phony"); State::State() : build_log_(NULL) { |