summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEvan Martin <martine@danga.com>2012-12-30 17:53:57 (GMT)
committerEvan Martin <martine@danga.com>2013-04-08 21:45:06 (GMT)
commit78ed77667671cde08b5ef045226aae3f848b1b40 (patch)
tree80bcd141f6ee0d0a3999f78e6ed44835e66d0279 /src
parent5504c0cb054ecfa1c8cd04fa141f5831560d13f4 (diff)
downloadNinja-78ed77667671cde08b5ef045226aae3f848b1b40.zip
Ninja-78ed77667671cde08b5ef045226aae3f848b1b40.tar.gz
Ninja-78ed77667671cde08b5ef045226aae3f848b1b40.tar.bz2
factor out creation of build directory
Diffstat (limited to 'src')
-rw-r--r--src/ninja.cc37
1 files changed, 21 insertions, 16 deletions
diff --git a/src/ninja.cc b/src/ninja.cc
index 69646e1..da99020 100644
--- a/src/ninja.cc
+++ b/src/ninja.cc
@@ -641,20 +641,13 @@ bool DebugEnable(const string& name, Globals* globals) {
}
}
-bool OpenLog(BuildLog* build_log, Globals* globals,
- DiskInterface* disk_interface) {
- const string build_dir =
- globals->state->bindings_.LookupVariable("builddir");
- const char* kLogPath = ".ninja_log";
- string log_path = kLogPath;
- if (!build_dir.empty()) {
- log_path = build_dir + "/" + kLogPath;
- if (!disk_interface->MakeDirs(log_path) && errno != EEXIST) {
- Error("creating build directory %s: %s",
- build_dir.c_str(), strerror(errno));
- return false;
- }
- }
+/// Open the build log.
+/// @return false on error.
+bool OpenBuildLog(BuildLog* build_log, const string& build_dir,
+ Globals* globals, DiskInterface* disk_interface) {
+ string log_path = ".ninja_log";
+ if (!build_dir.empty())
+ log_path = build_dir + "/" + log_path;
string err;
if (!build_log->Load(log_path, &err)) {
@@ -872,9 +865,21 @@ reload:
if (tool && tool->when == Tool::RUN_AFTER_LOAD)
return tool->func(&globals, argc, argv);
- BuildLog build_log;
RealDiskInterface disk_interface;
- if (!OpenLog(&build_log, &globals, &disk_interface))
+
+ // Create the build dir if it doesn't exist.
+ const string build_dir = globals.state->bindings_.LookupVariable("builddir");
+ if (!build_dir.empty() && !config.dry_run) {
+ if (!disk_interface.MakeDirs(build_dir + "/.") &&
+ errno != EEXIST) {
+ Error("creating build directory %s: %s",
+ build_dir.c_str(), strerror(errno));
+ return 1;
+ }
+ }
+
+ BuildLog build_log;
+ if (!OpenBuildLog(&build_log, build_dir, &globals, &disk_interface))
return 1;
if (!rebuilt_manifest) { // Don't get caught in an infinite loop by a rebuild