Merge pull request #85 from hughbe/popen-pclose

Add and use platform abstractions for popen and pclose
diff --git a/lib/BuildSystem/BuildSystemFrontend.cpp b/lib/BuildSystem/BuildSystemFrontend.cpp
index 510209b..eef4e3a 100644
--- a/lib/BuildSystem/BuildSystemFrontend.cpp
+++ b/lib/BuildSystem/BuildSystemFrontend.cpp
@@ -26,8 +26,7 @@
 
 #include <atomic>
 #include <memory>
-
-#include <unistd.h>
+#include <thread>
 
 using namespace llbuild;
 using namespace llbuild::basic;
@@ -317,9 +316,9 @@
   }
     
   // Get the number of CPUs to use.
-  long numCPUs = sysconf(_SC_NPROCESSORS_ONLN);
+  unsigned numCPUs = std::thread::hardware_concurrency();
   unsigned numLanes;
-  if (numCPUs < 0) {
+  if (numCPUs == 0) {
     error("<unknown>", {}, "unable to detect number of CPUs");
     numLanes = 1;
   } else {
diff --git a/lib/Commands/BuildEngineCommand.cpp b/lib/Commands/BuildEngineCommand.cpp
index 8f50c2b..6bfe455 100644
--- a/lib/Commands/BuildEngineCommand.cpp
+++ b/lib/Commands/BuildEngineCommand.cpp
@@ -288,21 +288,21 @@
       ackermannUsage();
     } else if (option == "--recompute") {
       if (args.empty()) {
-        fprintf(stderr, "\error: %s: missing argument to '%s'\n\n",
+        fprintf(stderr, "error: %s: missing argument to '%s'\n\n",
                 getProgramName(), option.c_str());
         ackermannUsage();
       }
       char *end;
       recomputeCount = ::strtol(args[0].c_str(), &end, 10);
       if (*end != '\0') {
-        fprintf(stderr, "\error: %s: invalid argument to '%s'\n\n",
+        fprintf(stderr, "error: %s: invalid argument to '%s'\n\n",
                 getProgramName(), option.c_str());
         ackermannUsage();
       }
       args.erase(args.begin());
     } else if (option == "--dump-graph") {
       if (args.empty()) {
-        fprintf(stderr, "\error: %s: missing argument to '%s'\n\n",
+        fprintf(stderr, "error: %s: missing argument to '%s'\n\n",
                 getProgramName(), option.c_str());
         ackermannUsage();
       }
@@ -310,14 +310,14 @@
       args.erase(args.begin());
     } else if (option == "--trace") {
       if (args.empty()) {
-        fprintf(stderr, "\error: %s: missing argument to '%s'\n\n",
+        fprintf(stderr, "error: %s: missing argument to '%s'\n\n",
                 getProgramName(), option.c_str());
         ackermannUsage();
       }
       traceFilename = args[0];
       args.erase(args.begin());
     } else {
-      fprintf(stderr, "\error: %s: invalid option: '%s'\n\n",
+      fprintf(stderr, "error: %s: invalid option: '%s'\n\n",
               getProgramName(), option.c_str());
       ackermannUsage();
     }
diff --git a/lib/Commands/NinjaBuildCommand.cpp b/lib/Commands/NinjaBuildCommand.cpp
index efef371..767d93a 100644
--- a/lib/Commands/NinjaBuildCommand.cpp
+++ b/lib/Commands/NinjaBuildCommand.cpp
@@ -24,6 +24,8 @@
 #include "llbuild/Core/MakefileDepsParser.h"
 #include "llbuild/Ninja/ManifestLoader.h"
 
+#include "llvm/Support/TimeValue.h"
+
 #include "CommandLineStatusOutput.h"
 #include "CommandUtil.h"
 
@@ -43,7 +45,6 @@
 #include <spawn.h>
 #include <unistd.h>
 #include <sys/stat.h>
-#include <sys/time.h>
 #include <sys/wait.h>
 
 using namespace llbuild;
@@ -55,9 +56,8 @@
 }
 
 static uint64_t getTimeInMicroseconds() {
-  struct timeval tv;
-  ::gettimeofday(&tv, nullptr);
-  return tv.tv_sec * 1000000 + tv.tv_usec;
+  llvm::sys::TimeValue now = llvm::sys::TimeValue::now();
+  return now.msec();
 }
 
 static std::string getFormattedString(const char* fmt, va_list ap) {
diff --git a/tests/Unit/lit.cfg b/tests/Unit/lit.cfg
index e94cdb8..47113f0 100644
--- a/tests/Unit/lit.cfg
+++ b/tests/Unit/lit.cfg
@@ -35,6 +35,9 @@
 if 'TEMP' in os.environ:
     config.environment['TEMP'] = os.environ['TEMP']
 
+# Define the folder that contains the dlls created during the build.
+config.shlibdir = llbuild_obj_root
+
 # Win32 seeks DLLs along %PATH%.
 if sys.platform in ['win32', 'cygwin'] and os.path.isdir(config.shlibdir):
     config.environment['PATH'] = os.path.pathsep.join((