summaryrefslogtreecommitdiffstats
path: root/src/ninja.cc
diff options
context:
space:
mode:
authorEvan Martin <martine@danga.com>2012-08-07 20:58:55 (GMT)
committerEvan Martin <martine@danga.com>2012-08-07 21:03:00 (GMT)
commitcc222d3f6ba769fd800b1dfdb1699fbb84516c7b (patch)
tree99f395a2f120ffbdd1d1390c8e5d6205d346354f /src/ninja.cc
parent645165bca247558f94d5f47cf7795c463e81d83a (diff)
downloadNinja-cc222d3f6ba769fd800b1dfdb1699fbb84516c7b.zip
Ninja-cc222d3f6ba769fd800b1dfdb1699fbb84516c7b.tar.gz
Ninja-cc222d3f6ba769fd800b1dfdb1699fbb84516c7b.tar.bz2
use DiskInterface to create the build directory
Fixes issue #392 (didn't handle creating nested build dirs right). Moves MakeDir out of util.h; all code should go through DiskInterface to simplify testing. Moves ownership of the DiskInterface into the client of the Builder, which also allows removing some code that reached inside the object as well as a minor leak.
Diffstat (limited to 'src/ninja.cc')
-rw-r--r--src/ninja.cc19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/ninja.cc b/src/ninja.cc
index 778eb53..d212579 100644
--- a/src/ninja.cc
+++ b/src/ninja.cc
@@ -32,6 +32,7 @@
#include "build.h"
#include "build_log.h"
#include "clean.h"
+#include "disk_interface.h"
#include "edit_distance.h"
#include "explain.h"
#include "graph.h"
@@ -66,6 +67,8 @@ struct Globals {
BuildConfig config;
/// Loaded state (rules, nodes). This is a pointer so it can be reset.
State* state;
+ /// Functions for interacting with the disk.
+ RealDiskInterface disk_interface;
};
/// Print usage information.
@@ -122,16 +125,16 @@ struct RealFileReader : public ManifestParser::FileReader {
/// Rebuild the build manifest, if necessary.
/// Returns true if the manifest was rebuilt.
-bool RebuildManifest(State* state, const BuildConfig& config,
- const char* input_file, string* err) {
+bool RebuildManifest(Globals* globals, const char* input_file, string* err) {
string path = input_file;
if (!CanonicalizePath(&path, err))
return false;
- Node* node = state->LookupNode(path);
+ Node* node = globals->state->LookupNode(path);
if (!node)
return false;
- Builder manifest_builder(state, config);
+ Builder manifest_builder(globals->state, globals->config,
+ &globals->disk_interface);
if (!manifest_builder.AddTarget(node, err))
return false;
@@ -579,7 +582,7 @@ int RunBuild(Globals* globals, int argc, char** argv) {
return 1;
}
- Builder builder(globals->state, globals->config);
+ Builder builder(globals->state, globals->config, &globals->disk_interface);
for (size_t i = 0; i < targets.size(); ++i) {
if (!builder.AddTarget(targets[i], &err)) {
if (!err.empty()) {
@@ -745,12 +748,12 @@ reload:
const char* kLogPath = ".ninja_log";
string log_path = kLogPath;
if (!build_dir.empty()) {
- if (MakeDir(build_dir) < 0 && errno != EEXIST) {
+ log_path = build_dir + "/" + kLogPath;
+ if (globals.disk_interface.MakeDirs(log_path) < 0 && errno != EEXIST) {
Error("creating build directory %s: %s",
build_dir.c_str(), strerror(errno));
return 1;
}
- log_path = build_dir + "/" + kLogPath;
}
if (!build_log.Load(log_path, &err)) {
@@ -765,7 +768,7 @@ reload:
if (!rebuilt_manifest) { // Don't get caught in an infinite loop by a rebuild
// target that is never up to date.
- if (RebuildManifest(globals.state, globals.config, input_file, &err)) {
+ if (RebuildManifest(&globals, input_file, &err)) {
rebuilt_manifest = true;
globals.ResetState();
goto reload;