summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvan Martin <martine@danga.com>2011-02-07 19:15:29 (GMT)
committerEvan Martin <martine@danga.com>2011-02-07 19:15:29 (GMT)
commit6c4deb6f192485ac27863cdb0af2b845a5314cd1 (patch)
treeab22dc5710024968a677c1b2eafe199847e7fe8c
parent21a8e95e954fa8b0f77d5e4eaae7e81b5b178d2a (diff)
parentd52238f212c8e5ec914270a599d8e690e6af9265 (diff)
downloadNinja-6c4deb6f192485ac27863cdb0af2b845a5314cd1.zip
Ninja-6c4deb6f192485ac27863cdb0af2b845a5314cd1.tar.gz
Ninja-6c4deb6f192485ac27863cdb0af2b845a5314cd1.tar.bz2
Merge branch 'master' of https://github.com/martine/ninja
-rw-r--r--COPYING202
-rw-r--r--HACKING4
-rw-r--r--README9
-rwxr-xr-xbootstrap.sh23
-rw-r--r--manual.asciidoc2
-rw-r--r--misc/long-slow-build.ninja38
-rw-r--r--misc/ninja-mode.el14
-rwxr-xr-xsrc/browse.py14
-rw-r--r--src/build.cc100
-rw-r--r--src/build.h23
-rw-r--r--src/build_log.cc14
-rw-r--r--src/build_log.h14
-rw-r--r--src/build_log_test.cc14
-rw-r--r--src/build_test.cc14
-rw-r--r--src/eval_env.cc14
-rw-r--r--src/eval_env.h14
-rw-r--r--src/graph.cc17
-rw-r--r--src/graph.h16
-rw-r--r--src/graphviz.h14
-rw-r--r--src/hash_map.h14
-rw-r--r--src/ninja.cc34
-rw-r--r--src/ninja.h14
-rw-r--r--src/ninja_jumble.cc14
-rw-r--r--src/ninja_test.cc14
-rw-r--r--src/parsers.cc14
-rw-r--r--src/parsers.h14
-rw-r--r--src/parsers_test.cc14
-rw-r--r--src/subprocess.cc14
-rw-r--r--src/subprocess.h14
-rw-r--r--src/subprocess_test.cc14
-rw-r--r--src/test.h14
-rw-r--r--src/util.cc14
-rw-r--r--src/util.h14
-rw-r--r--todo2
34 files changed, 741 insertions, 37 deletions
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..131cb1d
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2010
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/HACKING b/HACKING
index 84534e6..ac69256 100644
--- a/HACKING
+++ b/HACKING
@@ -3,8 +3,8 @@ Generating the docs:
./ninja doc
Adjusting build flags:
- Just a hack, but edit config.ninja (which was generated by bootstrap.sh)
- to turn on debugging symbols.
+ It's kind of a hack, but edit config.ninja (which was generated by
+ bootstrap.sh) to turn on debugging symbols.
Test-driven development:
Set your build command to
diff --git a/README b/README
index de7c975..be46134 100644
--- a/README
+++ b/README
@@ -1 +1,8 @@
-See manual.html.
+Ninja is a small build system closest in spirit to Make.
+
+See the manual -- http://martine.github.com/ninja/manual.html or
+manual.asciidoc included in the distribution -- for more background,
+including motivation and build instructions.
+
+Though the code is copyright Google, don't take that as an
+endorsement; I wrote this in my spare time for fun.
diff --git a/bootstrap.sh b/bootstrap.sh
index 637e0d0..5ac9141 100755
--- a/bootstrap.sh
+++ b/bootstrap.sh
@@ -1,5 +1,19 @@
#!/bin/bash
+# Copyright 2011 Google Inc. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
set -e
cat >config.ninja <<EOT
@@ -8,12 +22,15 @@ conf_cflags = -O2
conf_ldflags = -s
# When developing:
# conf_cflags = -g -Wall
-# conf_ldlags = -g -Wall
+# conf_ldlags =
EOT
+
+echo "Building ninja manually..."
srcs=$(ls src/*.cc | grep -v test)
-echo "Building stage 1..."
g++ -Wno-deprecated -o ninja.bootstrap $srcs
-echo "Building final result..."
+
+echo "Building ninja using itself..."
./ninja.bootstrap ninja
rm ninja.bootstrap
+
echo "Done!"
diff --git a/manual.asciidoc b/manual.asciidoc
index f50d276..ac3e74c 100644
--- a/manual.asciidoc
+++ b/manual.asciidoc
@@ -1,5 +1,7 @@
Ninja
=====
+Evan Martin <martine@danga.com>
+
Introduction
------------
diff --git a/misc/long-slow-build.ninja b/misc/long-slow-build.ninja
new file mode 100644
index 0000000..46af6ba
--- /dev/null
+++ b/misc/long-slow-build.ninja
@@ -0,0 +1,38 @@
+# An input file for running a "slow" build.
+# Use like: ninja -f misc/long-slow-build.ninja all
+
+rule sleep
+ command = sleep 1
+ description = SLEEP $out
+
+build 0: sleep README
+build 1: sleep README
+build 2: sleep README
+build 3: sleep README
+build 4: sleep README
+build 5: sleep README
+build 6: sleep README
+build 7: sleep README
+build 8: sleep README
+build 9: sleep README
+build 10: sleep 0
+build 11: sleep 1
+build 12: sleep 2
+build 13: sleep 3
+build 14: sleep 4
+build 15: sleep 5
+build 16: sleep 6
+build 17: sleep 7
+build 18: sleep 8
+build 19: sleep 9
+build 20: sleep 10
+build 21: sleep 11
+build 22: sleep 12
+build 23: sleep 13
+build 24: sleep 14
+build 25: sleep 15
+build 26: sleep 16
+build 27: sleep 17
+build 28: sleep 18
+build 29: sleep 19
+build all: phony 20 21 22 23 24 25 26 27 28 29
diff --git a/misc/ninja-mode.el b/misc/ninja-mode.el
index 0cb740c..82595f0 100644
--- a/misc/ninja-mode.el
+++ b/misc/ninja-mode.el
@@ -1,3 +1,17 @@
+;; Copyright 2011 Google Inc. All Rights Reserved.
+;;
+;; Licensed under the Apache License, Version 2.0 (the "License");
+;; you may not use this file except in compliance with the License.
+;; You may obtain a copy of the License at
+;;
+;; http://www.apache.org/licenses/LICENSE-2.0
+;;
+;; Unless required by applicable law or agreed to in writing, software
+;; distributed under the License is distributed on an "AS IS" BASIS,
+;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+;; See the License for the specific language governing permissions and
+;; limitations under the License.
+
;; Simple emacs mode for editing .ninja files.
;; Just some syntax highlighting for now.
diff --git a/src/browse.py b/src/browse.py
index dd7b5dc..92c7eaa 100755
--- a/src/browse.py
+++ b/src/browse.py
@@ -1,4 +1,18 @@
#!/usr/bin/python
+#
+# Copyright 2001 Google Inc. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
"""Simple web server for browsing dependency graph data.
diff --git a/src/build.cc b/src/build.cc
index 8e567d9..95f20bc 100644
--- a/src/build.cc
+++ b/src/build.cc
@@ -1,3 +1,17 @@
+// Copyright 2011 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
#include "build.h"
#include <stdio.h>
@@ -15,6 +29,8 @@ struct BuildStatus {
// Returns the time the edge took, in ms.
int BuildEdgeFinished(Edge* edge);
+ void PrintStatus(Edge* edge);
+
time_t last_update_;
int finished_edges_, total_edges_;
@@ -22,11 +38,16 @@ struct BuildStatus {
RunningEdgeMap running_edges_;
BuildConfig::Verbosity verbosity_;
+ // Whether we can do fancy terminal control codes.
+ bool smart_terminal_;
};
BuildStatus::BuildStatus()
: last_update_(time(NULL)), finished_edges_(0), total_edges_(0),
- verbosity_(BuildConfig::NORMAL) {}
+ verbosity_(BuildConfig::NORMAL) {
+ const char* term = getenv("TERM");
+ smart_terminal_ = isatty(1) && term && string(term) != "dumb";
+}
void BuildStatus::PlanHasTotalEdges(int total) {
total_edges_ = total;
@@ -37,13 +58,7 @@ void BuildStatus::BuildEdgeStarted(Edge* edge) {
gettimeofday(&now, NULL);
running_edges_.insert(make_pair(edge, now));
- string desc = edge->GetDescription();
- if (verbosity_ != BuildConfig::QUIET) {
- if (verbosity_ != BuildConfig::VERBOSE && !desc.empty())
- printf("%s\n", desc.c_str());
- else
- printf("%s\n", edge->EvaluateCommand().c_str());
- }
+ PrintStatus(edge);
}
int BuildStatus::BuildEdgeFinished(Edge* edge) {
@@ -51,10 +66,18 @@ int BuildStatus::BuildEdgeFinished(Edge* edge) {
gettimeofday(&now, NULL);
++finished_edges_;
- if (now.tv_sec - last_update_ > 5) {
- printf("%.1f%% %d/%d\n", finished_edges_ * 100 / (float)total_edges_,
- finished_edges_, total_edges_);
- last_update_ = now.tv_sec;
+ if (verbosity_ != BuildConfig::QUIET) {
+ if (smart_terminal_ && verbosity_ == BuildConfig::NORMAL) {
+ PrintStatus(edge);
+ if (finished_edges_ == total_edges_)
+ printf("\n");
+ } else {
+ if (now.tv_sec - last_update_ > 5) {
+ printf("%.1f%% %d/%d\n", finished_edges_ * 100 / (float)total_edges_,
+ finished_edges_, total_edges_);
+ last_update_ = now.tv_sec;
+ }
+ }
}
RunningEdgeMap::iterator i = running_edges_.find(edge);
@@ -66,6 +89,33 @@ int BuildStatus::BuildEdgeFinished(Edge* edge) {
return ms;
}
+void BuildStatus::PrintStatus(Edge* edge) {
+ switch (verbosity_) {
+ case BuildConfig::QUIET:
+ return;
+
+ case BuildConfig::VERBOSE:
+ printf("%s\n", edge->EvaluateCommand().c_str());
+ break;
+
+ default: {
+ string to_print = edge->GetDescription();
+ if (to_print.empty() || verbosity_ == BuildConfig::VERBOSE)
+ to_print = edge->EvaluateCommand();
+
+ if (smart_terminal_) {
+ printf("\r[%d/%d] %s\e[K", finished_edges_, total_edges_,
+ to_print.c_str());
+ fflush(stdout);
+ } else {
+ printf("%s\n", to_print.c_str());
+ }
+ }
+ }
+}
+
+Plan::Plan() : command_edges_(0) {}
+
bool Plan::AddTarget(Node* node, string* err) {
vector<Node*> stack;
return AddSubTarget(node, &stack, err);
@@ -93,6 +143,8 @@ bool Plan::AddSubTarget(Node* node, vector<Node*>* stack, string* err) {
if (want_.find(edge) != want_.end())
return true; // We've already enqueued it.
want_.insert(edge);
+ if (!edge->is_phony())
+ ++command_edges_;
stack->push_back(node);
bool awaiting_inputs = false;
@@ -230,12 +282,16 @@ Edge* RealCommandRunner::NextFinishedCommand(bool* success) {
Edge* edge = i->second;
subproc_to_edge_.erase(i);
- if (!*success)
- printf("FAILED: %s\n", edge->EvaluateCommand().c_str());
- if (!subproc->stdout_.buf_.empty())
- printf("%s\n", subproc->stdout_.buf_.c_str());
- if (!subproc->stderr_.buf_.empty())
- printf("%s\n", subproc->stderr_.buf_.c_str());
+ if (!*success ||
+ !subproc->stdout_.buf_.empty() ||
+ !subproc->stderr_.buf_.empty()) {
+ printf("\n%s%s\n", *success ? "" : "FAILED: ",
+ edge->EvaluateCommand().c_str());
+ if (!subproc->stdout_.buf_.empty())
+ printf("%s\n", subproc->stdout_.buf_.c_str());
+ if (!subproc->stderr_.buf_.empty())
+ printf("%s\n", subproc->stderr_.buf_.c_str());
+ }
delete subproc;
return edge;
@@ -302,7 +358,7 @@ bool Builder::Build(string* err) {
return true;
}
- status_->PlanHasTotalEdges(plan_.edge_count());
+ status_->PlanHasTotalEdges(plan_.command_edge_count());
while (plan_.more_to_do()) {
while (command_runner_->CanRunMore()) {
Edge* edge = plan_.FindWork();
@@ -312,7 +368,7 @@ bool Builder::Build(string* err) {
if (!StartEdge(edge, err))
return false;
- if (edge->rule_ == &State::kPhonyRule)
+ if (edge->is_phony())
FinishEdge(edge);
}
@@ -338,7 +394,7 @@ bool Builder::Build(string* err) {
}
bool Builder::StartEdge(Edge* edge, string* err) {
- if (edge->rule_ == &State::kPhonyRule)
+ if (edge->is_phony())
return true;
status_->BuildEdgeStarted(edge);
@@ -370,7 +426,7 @@ void Builder::FinishEdge(Edge* edge) {
}
plan_.EdgeFinished(edge);
- if (edge->rule_ == &State::kPhonyRule)
+ if (edge->is_phony())
return;
int ms = status_->BuildEdgeFinished(edge);
diff --git a/src/build.h b/src/build.h
index a1d6d4c..cf9398e 100644
--- a/src/build.h
+++ b/src/build.h
@@ -1,3 +1,17 @@
+// Copyright 2011 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
#ifndef NINJA_BUILD_H_
#define NINJA_BUILD_H_
@@ -15,6 +29,8 @@ struct State;
// Plan stores the state of a build plan: what we intend to build,
// which steps we're ready to execute.
struct Plan {
+ Plan();
+
// Add a target to our plan (including all its dependencies).
// Returns false if we don't need to build this target; may
// fill in |err| with an error message if there's a problem.
@@ -34,8 +50,8 @@ struct Plan {
// tests.
void EdgeFinished(Edge* edge);
- // Number of edges to run.
- int edge_count() const { return want_.size(); }
+ // Number of edges with commands to run.
+ int command_edge_count() const { return command_edges_; }
private:
bool AddSubTarget(Node* node, vector<Node*>* stack, string* err);
@@ -44,6 +60,9 @@ private:
set<Edge*> want_;
set<Edge*> ready_;
+
+ // Total number of edges that have commands (not phony).
+ int command_edges_;
};
// CommandRunner is an interface that wraps running the build
diff --git a/src/build_log.cc b/src/build_log.cc
index b8a782f..9add945 100644
--- a/src/build_log.cc
+++ b/src/build_log.cc
@@ -1,3 +1,17 @@
+// Copyright 2011 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
#include "build_log.h"
#include <errno.h>
diff --git a/src/build_log.h b/src/build_log.h
index 58a598e..be12d85 100644
--- a/src/build_log.h
+++ b/src/build_log.h
@@ -1,3 +1,17 @@
+// Copyright 2011 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
#include <map>
#include <string>
using namespace std;
diff --git a/src/build_log_test.cc b/src/build_log_test.cc
index 11d5f72..26021d5 100644
--- a/src/build_log_test.cc
+++ b/src/build_log_test.cc
@@ -1,3 +1,17 @@
+// Copyright 2011 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
#include "build_log.h"
#include "test.h"
diff --git a/src/build_test.cc b/src/build_test.cc
index 0c35f8c..7533b44 100644
--- a/src/build_test.cc
+++ b/src/build_test.cc
@@ -1,3 +1,17 @@
+// Copyright 2011 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
#include "build.h"
#include "test.h"
diff --git a/src/eval_env.cc b/src/eval_env.cc
index 172544c..0a53ae5 100644
--- a/src/eval_env.cc
+++ b/src/eval_env.cc
@@ -1,3 +1,17 @@
+// Copyright 2011 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
#include "eval_env.h"
string BindingEnv::LookupVariable(const string& var) {
diff --git a/src/eval_env.h b/src/eval_env.h
index 46fb1f1..fd0e4eb 100644
--- a/src/eval_env.h
+++ b/src/eval_env.h
@@ -1,3 +1,17 @@
+// Copyright 2011 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
#ifndef NINJA_EVAL_ENV_H_
#define NINJA_EVAL_ENV_H_
diff --git a/src/graph.cc b/src/graph.cc
index f73028e..aead200 100644
--- a/src/graph.cc
+++ b/src/graph.cc
@@ -1,3 +1,17 @@
+// Copyright 2011 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
#include "graph.h"
#include <stdio.h>
@@ -170,3 +184,6 @@ void Edge::Dump() {
printf("]\n");
}
+bool Edge::is_phony() const {
+ return rule_ == &State::kPhonyRule;
+}
diff --git a/src/graph.h b/src/graph.h
index 2ebf2e4..f3cfa97 100644
--- a/src/graph.h
+++ b/src/graph.h
@@ -1,3 +1,17 @@
+// Copyright 2011 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
#ifndef NINJA_GRAPH_H_
#define NINJA_GRAPH_H_
@@ -101,6 +115,8 @@ struct Edge {
bool is_order_only(int index) {
return index >= ((int)inputs_.size()) - order_only_deps_;
}
+
+ bool is_phony() const;
};
#endif // NINJA_GRAPH_H_
diff --git a/src/graphviz.h b/src/graphviz.h
index eb9ee25..fd6b58e 100644
--- a/src/graphviz.h
+++ b/src/graphviz.h
@@ -1,3 +1,17 @@
+// Copyright 2011 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
#include <set>
// XXX deinline all this code so we don't need this include
diff --git a/src/hash_map.h b/src/hash_map.h
index 820f773..45a83a9 100644
--- a/src/hash_map.h
+++ b/src/hash_map.h
@@ -1,3 +1,17 @@
+// Copyright 2011 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
#include <ext/hash_map>
using __gnu_cxx::hash_map;
diff --git a/src/ninja.cc b/src/ninja.cc
index 0547013..eb7e41c 100644
--- a/src/ninja.cc
+++ b/src/ninja.cc
@@ -1,9 +1,26 @@
+// Copyright 2011 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
#include "ninja.h"
+#include <errno.h>
#include <getopt.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
#include "build.h"
#include "build_log.h"
@@ -32,7 +49,7 @@ void usage(const BuildConfig& config) {
"usage: ninja [options] target\n"
"\n"
"options:\n"
-" -i FILE specify input build file [default=build.ninja]\n"
+" -f FILE specify input build file [default=build.ninja]\n"
" -j N run N jobs in parallel [default=%d]\n"
" -n dry run (don't run commands but pretend they succeeded)\n"
" -v show all command lines\n"
@@ -144,9 +161,9 @@ int main(int argc, char** argv) {
config.parallelism = GuessParallelism();
int opt;
- while ((opt = getopt_long(argc, argv, "hi:j:nt:v", options, NULL)) != -1) {
+ while ((opt = getopt_long(argc, argv, "f:hj:nt:v", options, NULL)) != -1) {
switch (opt) {
- case 'i':
+ case 'f':
input_file = optarg;
break;
case 'j':
@@ -206,7 +223,16 @@ int main(int argc, char** argv) {
const string build_dir = state.bindings_.LookupVariable("builddir");
const char* kLogPath = ".ninja_log";
- string log_path = build_dir.empty() ? kLogPath : build_dir + "/" + kLogPath;
+ string log_path = kLogPath;
+ if (!build_dir.empty()) {
+ if (mkdir(build_dir.c_str(), 0777) < 0 && errno != EEXIST) {
+ fprintf(stderr, "Error creating build directory %s: %s\n",
+ build_dir.c_str(), strerror(errno));
+ return 1;
+ }
+ log_path = 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());
diff --git a/src/ninja.h b/src/ninja.h
index 26432c3..706cb9c 100644
--- a/src/ninja.h
+++ b/src/ninja.h
@@ -1,3 +1,17 @@
+// Copyright 2011 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
#ifndef NINJA_NINJA_H_
#define NINJA_NINJA_H_
diff --git a/src/ninja_jumble.cc b/src/ninja_jumble.cc
index a1ba219..a935c21 100644
--- a/src/ninja_jumble.cc
+++ b/src/ninja_jumble.cc
@@ -1,3 +1,17 @@
+// Copyright 2011 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
// This file is all the code that used to be in one file.
// TODO: split into modules, delete this file.
diff --git a/src/ninja_test.cc b/src/ninja_test.cc
index 7e8bdc0..7ec77fd 100644
--- a/src/ninja_test.cc
+++ b/src/ninja_test.cc
@@ -1,3 +1,17 @@
+// Copyright 2011 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
#include "ninja.h"
#include <gtest/gtest.h>
diff --git a/src/parsers.cc b/src/parsers.cc
index 8e44a38..2fb2c9a 100644
--- a/src/parsers.cc
+++ b/src/parsers.cc
@@ -1,3 +1,17 @@
+// Copyright 2011 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
#include "parsers.h"
#include <assert.h>
diff --git a/src/parsers.h b/src/parsers.h
index 01f65c0..78865d1 100644
--- a/src/parsers.h
+++ b/src/parsers.h
@@ -1,3 +1,17 @@
+// Copyright 2011 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
#ifndef NINJA_PARSERS_H_
#define NINJA_PARSERS_H_
diff --git a/src/parsers_test.cc b/src/parsers_test.cc
index 7810113..8a1efc5 100644
--- a/src/parsers_test.cc
+++ b/src/parsers_test.cc
@@ -1,3 +1,17 @@
+// Copyright 2011 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
#include "parsers.h"
#include <gtest/gtest.h>
diff --git a/src/subprocess.cc b/src/subprocess.cc
index 168ac10..1043e65 100644
--- a/src/subprocess.cc
+++ b/src/subprocess.cc
@@ -1,3 +1,17 @@
+// Copyright 2011 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
#include "subprocess.h"
#include <algorithm>
diff --git a/src/subprocess.h b/src/subprocess.h
index 2c91f4a..35b7914 100644
--- a/src/subprocess.h
+++ b/src/subprocess.h
@@ -1,3 +1,17 @@
+// Copyright 2011 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
#include <string>
#include <vector>
#include <queue>
diff --git a/src/subprocess_test.cc b/src/subprocess_test.cc
index 51d4a11..4eb878b 100644
--- a/src/subprocess_test.cc
+++ b/src/subprocess_test.cc
@@ -1,3 +1,17 @@
+// Copyright 2011 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
#include "subprocess.h"
#include "test.h"
diff --git a/src/test.h b/src/test.h
index 405f039..bc8dfcc 100644
--- a/src/test.h
+++ b/src/test.h
@@ -1,3 +1,17 @@
+// Copyright 2011 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
#include <gtest/gtest.h>
#include "graph.h"
diff --git a/src/util.cc b/src/util.cc
index 7a1c4e6..2eb4559 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -1,3 +1,17 @@
+// Copyright 2011 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
#include "util.h"
#include <execinfo.h>
diff --git a/src/util.h b/src/util.h
index d0f0815..188528c 100644
--- a/src/util.h
+++ b/src/util.h
@@ -1,4 +1,16 @@
-
+// Copyright 2011 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
// Dump a backtrace to stderr.
// |skip_frames| is how many frames to skip;
diff --git a/todo b/todo
index ccabb85..eb70c06 100644
--- a/todo
+++ b/todo
@@ -27,7 +27,5 @@ the output, just mark it for rebuilding immediately.
adjust to system load dynamically
-progress bar rather than printing commands in series
-
compute etas on builds using logged timing info
how does parallelization fit in?