Merge pull request #142 from ddunbar/rdar31633275

[BuildSystem] Lift errors out of frontend API.
diff --git a/examples/c-api/buildsystem/main.c b/examples/c-api/buildsystem/main.c
index cbfeedb..6814632 100644
--- a/examples/c-api/buildsystem/main.c
+++ b/examples/c-api/buildsystem/main.c
@@ -220,9 +220,13 @@
   // Build the default target, twice.
   llb_data_t key = { 0, NULL };
   printf("initial build:\n");
-  llb_buildsystem_build(system, &key);
+  if (!llb_buildsystem_build(system, &key)) {
+    printf("build had command failures\n");
+  }
   printf("second build:\n");
-  llb_buildsystem_build(system, &key);
+  if (!llb_buildsystem_build(system, &key)) {
+    printf("build had command failures\n");
+  }    
 
   // Destroy the build system.
   llb_buildsystem_destroy(system);
diff --git a/lib/BuildSystem/BuildSystemFrontend.cpp b/lib/BuildSystem/BuildSystemFrontend.cpp
index fa2afb8..9bc3cc1 100644
--- a/lib/BuildSystem/BuildSystemFrontend.cpp
+++ b/lib/BuildSystem/BuildSystemFrontend.cpp
@@ -520,13 +520,9 @@
   if (!buildSystem->build(targetToBuild))
     return false;
 
-  // If there were failed commands, report the count and return an error.
-  if (delegate.getNumFailedCommands()) {
-    getDelegate().error("build had " + Twine(delegate.getNumFailedCommands()) +
-                        " command failures");
-    return false;
-  }
-
-  // Otherwise, return an error only if there were unspecified errors.
-  return delegate.getNumErrors() == 0;
+  // The build was successful if there were no failed commands or unspecified
+  // errors.
+  //
+  // It is the job of the client to report a summary, if desired.
+  return delegate.getNumFailedCommands() == 0 && delegate.getNumErrors() == 0;
 }
diff --git a/lib/Commands/BuildSystemCommand.cpp b/lib/Commands/BuildSystemCommand.cpp
index 9e90fcc..1a122ee 100644
--- a/lib/Commands/BuildSystemCommand.cpp
+++ b/lib/Commands/BuildSystemCommand.cpp
@@ -546,6 +546,12 @@
   BasicBuildSystemFrontendDelegate delegate(sourceMgr, invocation);
   BuildSystemFrontend frontend(delegate, invocation);
   if (!frontend.build(targetToBuild)) {
+    // If there were failed commands, report the count and return an error.
+    if (delegate.getNumFailedCommands()) {
+      delegate.error("build had " + Twine(delegate.getNumFailedCommands()) +
+                     " command failures");
+    }
+
     return 1;
   }
 
diff --git a/tests/Examples/buildsystem-capi.llbuild b/tests/Examples/buildsystem-capi.llbuild
index 71945ea..fbf4b59 100644
--- a/tests/Examples/buildsystem-capi.llbuild
+++ b/tests/Examples/buildsystem-capi.llbuild
@@ -15,11 +15,11 @@
 # CHECK: command_finished: <fancy-thing>
 # CHECK: command_started: <error> -- FAILING-COMMAND
 # CHECK: had_command_failure
-# CHECK: <unknown>:0: error: build had 1 command failure
+# CHECK: build had command failures
 #
 # CHECK: second build:
 # CHECK: command_started: <error> -- FAILING-COMMAND
-# CHECK: <unknown>:0: error: build had 1 command failure
+# CHECK: build had command failures
 
 client:
   name: basic