Merge pull request #577 from tfarina/structs

structs not classes.
diff --git a/RELEASING b/RELEASING
index 4d2e46a..faa04a2 100644
--- a/RELEASING
+++ b/RELEASING
@@ -5,6 +5,6 @@
 3. fix version number in src/version.cc (it will likely conflict in the above)
 4. fix version in doc/manual.asciidoc
 5. rebuild manual, put in place on website
-6. commit, tag, push
+6. commit, tag, push (don't forget to push --tags)
 7. construct release notes from prior notes
    credits: git shortlog -s --no-merges REV..
diff --git a/bootstrap.py b/bootstrap.py
index 0f6aa59..cff10ba 100755
--- a/bootstrap.py
+++ b/bootstrap.py
@@ -33,7 +33,6 @@
                   help='enable verbose build',)
 parser.add_option('--x64', action='store_true',
                   help='force 64-bit build (Windows)',)
-# TODO: make this --platform to match configure.py.
 parser.add_option('--platform',
                   help='target platform (' + '/'.join(platform_helper.platforms()) + ')',
                   choices=platform_helper.platforms())
diff --git a/configure.py b/configure.py
index 1284deb..7c90e66 100755
--- a/configure.py
+++ b/configure.py
@@ -65,6 +65,9 @@
 n.comment('It is generated by ' + os.path.basename(__file__) + '.')
 n.newline()
 
+n.variable('ninja_required_version', '1.3')
+n.newline()
+
 n.comment('The arguments passed to configure.py, for rerunning it.')
 n.variable('configure_args', ' '.join(sys.argv[1:]))
 env_keys = set(['CXX', 'AR', 'CFLAGS', 'LDFLAGS'])
diff --git a/platform_helper.py b/platform_helper.py
index cd7298b..97827c3 100644
--- a/platform_helper.py
+++ b/platform_helper.py
@@ -18,7 +18,8 @@
 import sys
 
 def platforms():
-    return ['linux', 'freebsd', 'openbsd', 'solaris', 'sunos5', 'mingw', 'msvc']
+    return ['linux', 'darwin', 'freebsd', 'openbsd', 'solaris', 'sunos5',
+            'mingw', 'msvc']
 
 class Platform( object ):
     def __init__( self, platform):
diff --git a/src/build_log.h b/src/build_log.h
index 231bfd9..6eae89f 100644
--- a/src/build_log.h
+++ b/src/build_log.h
@@ -15,7 +15,6 @@
 #ifndef NINJA_BUILD_LOG_H_
 #define NINJA_BUILD_LOG_H_
 
-#include <map>
 #include <string>
 #include <stdio.h>
 using namespace std;
diff --git a/src/build_test.cc b/src/build_test.cc
index 68a5142..90c328a 100644
--- a/src/build_test.cc
+++ b/src/build_test.cc
@@ -24,6 +24,26 @@
 // to create Nodes and Edges.
 struct PlanTest : public StateTestWithBuiltinRules {
   Plan plan_;
+
+  /// Because FindWork does not return Edges in any sort of predictable order,
+  // provide a means to get available Edges in order and in a format which is
+  // easy to write tests around.
+  void FindWorkSorted(deque<Edge*>* ret, int count) {
+    struct CompareEdgesByOutput {
+      static bool cmp(const Edge* a, const Edge* b) {
+        return a->outputs_[0]->path() < b->outputs_[0]->path();
+      }
+    };
+
+    for (int i = 0; i < count; ++i) {
+      ASSERT_TRUE(plan_.more_to_do());
+      Edge* edge = plan_.FindWork();
+      ASSERT_TRUE(edge);
+      ret->push_back(edge);
+    }
+    ASSERT_FALSE(plan_.FindWork());
+    sort(ret->begin(), ret->end(), CompareEdgesByOutput::cmp);
+  }
 };
 
 TEST_F(PlanTest, Basic) {
@@ -251,27 +271,21 @@
   EXPECT_TRUE(plan_.AddTarget(GetNode("allTheThings"), &err));
   ASSERT_EQ("", err);
 
-  // Grab the first 4 edges, out1 out2 outb1 outb2
   deque<Edge*> edges;
+  FindWorkSorted(&edges, 5);
+
   for (int i = 0; i < 4; ++i) {
-    ASSERT_TRUE(plan_.more_to_do());
-    Edge* edge = plan_.FindWork();
-    ASSERT_TRUE(edge);
+    Edge *edge = edges[i];
     ASSERT_EQ("in",  edge->inputs_[0]->path());
     string base_name(i < 2 ? "out" : "outb");
     ASSERT_EQ(base_name + string(1, '1' + (i % 2)), edge->outputs_[0]->path());
-    edges.push_back(edge);
   }
 
   // outb3 is exempt because it has an empty pool
-  ASSERT_TRUE(plan_.more_to_do());
-  Edge* edge = plan_.FindWork();
+  Edge* edge = edges[4];
   ASSERT_TRUE(edge);
   ASSERT_EQ("in",  edge->inputs_[0]->path());
   ASSERT_EQ("outb3", edge->outputs_[0]->path());
-  edges.push_back(edge);
-
-  ASSERT_FALSE(plan_.FindWork());
 
   // finish out1
   plan_.EdgeFinished(edges.front());
@@ -293,11 +307,11 @@
     plan_.EdgeFinished(*it);
   }
 
-  Edge* final = plan_.FindWork();
-  ASSERT_TRUE(final);
-  ASSERT_EQ("allTheThings", final->outputs_[0]->path());
+  Edge* last = plan_.FindWork();
+  ASSERT_TRUE(last);
+  ASSERT_EQ("allTheThings", last->outputs_[0]->path());
 
-  plan_.EdgeFinished(final);
+  plan_.EdgeFinished(last);
 
   ASSERT_FALSE(plan_.more_to_do());
   ASSERT_FALSE(plan_.FindWork());
@@ -334,25 +348,28 @@
 
   Edge* edge = NULL;
 
-  edge = plan_.FindWork();
-  ASSERT_TRUE(edge);
+  deque<Edge*> initial_edges;
+  FindWorkSorted(&initial_edges, 2);
+
+  edge = initial_edges[1];  // Foo first
   ASSERT_EQ("foo.cpp", edge->outputs_[0]->path());
   plan_.EdgeFinished(edge);
 
   edge = plan_.FindWork();
   ASSERT_TRUE(edge);
+  ASSERT_FALSE(plan_.FindWork());
   ASSERT_EQ("foo.cpp", edge->inputs_[0]->path());
   ASSERT_EQ("foo.cpp", edge->inputs_[1]->path());
   ASSERT_EQ("foo.cpp.obj", edge->outputs_[0]->path());
   plan_.EdgeFinished(edge);
 
-  edge = plan_.FindWork();
-  ASSERT_TRUE(edge);
+  edge = initial_edges[0];  // Now for bar
   ASSERT_EQ("bar.cpp", edge->outputs_[0]->path());
   plan_.EdgeFinished(edge);
 
   edge = plan_.FindWork();
   ASSERT_TRUE(edge);
+  ASSERT_FALSE(plan_.FindWork());
   ASSERT_EQ("bar.cpp", edge->inputs_[0]->path());
   ASSERT_EQ("bar.cpp", edge->inputs_[1]->path());
   ASSERT_EQ("bar.cpp.obj", edge->outputs_[0]->path());
@@ -360,6 +377,7 @@
 
   edge = plan_.FindWork();
   ASSERT_TRUE(edge);
+  ASSERT_FALSE(plan_.FindWork());
   ASSERT_EQ("foo.cpp.obj", edge->inputs_[0]->path());
   ASSERT_EQ("bar.cpp.obj", edge->inputs_[1]->path());
   ASSERT_EQ("libfoo.a", edge->outputs_[0]->path());
@@ -367,6 +385,7 @@
 
   edge = plan_.FindWork();
   ASSERT_TRUE(edge);
+  ASSERT_FALSE(plan_.FindWork());
   ASSERT_EQ("libfoo.a", edge->inputs_[0]->path());
   ASSERT_EQ("all", edge->outputs_[0]->path());
   plan_.EdgeFinished(edge);
diff --git a/src/clean.cc b/src/clean.cc
index 12afb98..5d1974e 100644
--- a/src/clean.cc
+++ b/src/clean.cc
@@ -15,10 +15,7 @@
 #include "clean.h"
 
 #include <assert.h>
-#include <errno.h>
 #include <stdio.h>
-#include <string.h>
-#include <sys/stat.h>
 
 #include "disk_interface.h"
 #include "graph.h"
diff --git a/src/deps_log_test.cc b/src/deps_log_test.cc
index 0591736..3b32963 100644
--- a/src/deps_log_test.cc
+++ b/src/deps_log_test.cc
@@ -340,7 +340,8 @@
   // Shorten the file, corrupting the last record.
   struct stat st;
   ASSERT_EQ(0, stat(kTestFilename, &st));
-  ASSERT_EQ(0, truncate(kTestFilename, st.st_size - 2));
+  string err;
+  ASSERT_TRUE(Truncate(kTestFilename, st.st_size - 2, &err));
 
   // Load the file again, add an entry.
   {
diff --git a/src/manifest_parser.cc b/src/manifest_parser.cc
index a581114..3593567 100644
--- a/src/manifest_parser.cc
+++ b/src/manifest_parser.cc
@@ -14,10 +14,8 @@
 
 #include "manifest_parser.h"
 
-#include <assert.h>
-#include <errno.h>
 #include <stdio.h>
-#include <string.h>
+#include <vector>
 
 #include "graph.h"
 #include "metrics.h"
diff --git a/src/manifest_parser.h b/src/manifest_parser.h
index a08e5af..967dfdd 100644
--- a/src/manifest_parser.h
+++ b/src/manifest_parser.h
@@ -16,13 +16,10 @@
 #define NINJA_MANIFEST_PARSER_H_
 
 #include <string>
-#include <vector>
-#include <limits>
 
 using namespace std;
 
 #include "lexer.h"
-#include "string_piece.h"
 
 struct BindingEnv;
 struct EvalString;
diff --git a/src/manifest_parser_test.cc b/src/manifest_parser_test.cc
index be749f2..2638edc 100644
--- a/src/manifest_parser_test.cc
+++ b/src/manifest_parser_test.cc
@@ -14,6 +14,9 @@
 
 #include "manifest_parser.h"
 
+#include <map>
+#include <vector>
+
 #include <gtest/gtest.h>
 
 #include "graph.h"
diff --git a/src/msvc_helper_main-win32.cc b/src/msvc_helper_main-win32.cc
index ef91450..647bb86 100644
--- a/src/msvc_helper_main-win32.cc
+++ b/src/msvc_helper_main-win32.cc
@@ -123,7 +123,7 @@
     output = parser.Parse(output);
     WriteDepFileOrDie(output_filename, parser);
   }
-  printf("%s\n", output.c_str());
+  printf("%s", output.c_str());
 
   return exit_code;
 }
diff --git a/src/ninja.cc b/src/ninja.cc
index 8ba1aa6..b4797ed 100644
--- a/src/ninja.cc
+++ b/src/ninja.cc
@@ -17,8 +17,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <sys/stat.h>
-#include <sys/types.h>
 
 #ifdef _WIN32
 #include "getopt.h"
@@ -35,7 +33,6 @@
 #include "deps_log.h"
 #include "clean.h"
 #include "disk_interface.h"
-#include "edit_distance.h"
 #include "explain.h"
 #include "graph.h"
 #include "graphviz.h"
diff --git a/src/state.h b/src/state.h
index 7e3aead..bde75ff 100644
--- a/src/state.h
+++ b/src/state.h
@@ -16,7 +16,6 @@
 #define NINJA_STATE_H_
 
 #include <map>
-#include <deque>
 #include <set>
 #include <string>
 #include <vector>
diff --git a/src/subprocess-posix.cc b/src/subprocess-posix.cc
index c56d147..339edfe 100644
--- a/src/subprocess-posix.cc
+++ b/src/subprocess-posix.cc
@@ -14,8 +14,6 @@
 
 #include "subprocess.h"
 
-#include <algorithm>
-#include <map>
 #include <assert.h>
 #include <errno.h>
 #include <fcntl.h>
diff --git a/src/version.cc b/src/version.cc
index 8eb2e07..18fa96a 100644
--- a/src/version.cc
+++ b/src/version.cc
@@ -18,7 +18,7 @@
 
 #include "util.h"
 
-const char* kNinjaVersion = "1.2.0.git";
+const char* kNinjaVersion = "1.3.0.git";
 
 void ParseVersion(const string& version, int* major, int* minor) {
   size_t end = version.find('.');
@@ -51,7 +51,3 @@
           kNinjaVersion, version.c_str());
   }
 }
-
-
-
-