summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/build.cc1
-rw-r--r--src/clean.cc41
-rw-r--r--src/disk_interface.cc59
-rw-r--r--src/disk_interface.h9
-rw-r--r--src/graph.cc1
-rw-r--r--src/ninja.h10
-rw-r--r--src/ninja_jumble.cc47
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 13927fe..51bdd8b 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) {