From 231206b0b512d8850976fba3f9f16fc7c3872ebc Mon Sep 17 00:00:00 2001 From: Evan Martin Date: Thu, 3 Feb 2011 21:36:01 -0800 Subject: use builddir for log file --- .gitignore | 1 - manual.asciidoc | 13 +++++++++++++ src/ninja.cc | 9 ++++++--- todo | 2 -- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index ab7d326..31d4bc1 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,3 @@ TAGS /README.html /config.ninja /manual.html -.ninja_log diff --git a/manual.asciidoc b/manual.asciidoc index fd18200..f50d276 100644 --- a/manual.asciidoc +++ b/manual.asciidoc @@ -251,6 +251,19 @@ statement to the rule (for example, if the rule needs "the file extension of the first input"), pass that through as an extra variable, like how `cflags` is passed above. +The Ninja log +~~~~~~~~~~~~~ + +For each built file, Ninja keeps a log of the command used to build +it. Using this log Ninja can know when an existing output was built +with a different command line than the build files specify (i.e., the +command line changed) and knows to rebuild the file. + +The log file is kept in the build root in a file called `.ninja_log`. +If you provide a variable named `builddir` in the outermost scope, +`.ninja_log` will be kept in that directory instead. + + Generating Ninja files ---------------------- diff --git a/src/ninja.cc b/src/ninja.cc index 6e441b6..0547013 100644 --- a/src/ninja.cc +++ b/src/ninja.cc @@ -204,13 +204,16 @@ int main(int argc, char** argv) { build_log.SetConfig(&config); state.build_log_ = &build_log; + const string build_dir = state.bindings_.LookupVariable("builddir"); const char* kLogPath = ".ninja_log"; - if (!build_log.Load(kLogPath, &err)) { - fprintf(stderr, "error loading build log: %s\n", err.c_str()); + string log_path = build_dir.empty() ? kLogPath : build_dir + "/" + kLogPath; + if (!build_log.Load(log_path.c_str(), &err)) { + fprintf(stderr, "error loading build log %s: %s\n", + log_path.c_str(), err.c_str()); return 1; } - if (!build_log.OpenForWrite(kLogPath, &err)) { + if (!build_log.OpenForWrite(log_path.c_str(), &err)) { fprintf(stderr, "error opening build log: %s\n", err.c_str()); return 1; } diff --git a/todo b/todo index 0164d20..a702cf0 100644 --- a/todo +++ b/todo @@ -7,8 +7,6 @@ website, contact info delete halfway-built output files when interrupted -put ninja_log somewhere useful and document it - frosting ======== -- cgit v0.12