Cleanup: Build file.cc as part of util library.

Looks like in the transition it was forgotten to be moved to the new
location.

As an effect of this change it was discovered that file.cc had an
dependency back on blaze_util.cc (from client binary for die/pdie functions).

In order to fix that dependency we have had to move die/pdie functions into
util library (added errors.(cc|h)) for this.

Tested on Linux with the following command lines:

$ ./compile.sh
$ ./output/bazel build //src/main/cpp:all
$ ./output/bazel build //src:bazel
$ ./bootstrap_test.sh all

--
Change-Id: I70fb1b6189dc5af31f816332d76efe380ef26302
MOS_MIGRATED_REVID=90987514
diff --git a/src/main/cpp/BUILD b/src/main/cpp/BUILD
index 2681792..0e31cdb 100644
--- a/src/main/cpp/BUILD
+++ b/src/main/cpp/BUILD
@@ -1,11 +1,15 @@
 cc_library(
     name = "util",
     srcs = [
+        "util/errors.cc",
+        "util/file.cc",
         "util/numbers.cc",
         "util/port.cc",
         "util/strings.cc",
     ],
     hdrs = [
+        "util/errors.h",
+        "util/file.h",
         "util/numbers.h",
         "util/port.h",
         "util/strings.h",
@@ -40,7 +44,6 @@
         "blaze_startup_options_common.cc",
         "blaze_util.cc",
         "option_processor.cc",
-        "util/file.cc",
         ":blaze_util_os",
     ],
     copts = [
diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc
index 547a6a5..f324c95 100644
--- a/src/main/cpp/blaze.cc
+++ b/src/main/cpp/blaze.cc
@@ -58,6 +58,7 @@
 #include "blaze_util.h"
 #include "blaze_util_platform.h"
 #include "option_processor.h"
+#include "util/errors.h"
 #include "util/file.h"
 #include "util/md5.h"
 #include "util/numbers.h"
@@ -67,6 +68,8 @@
 #include "archive_entry.h"
 
 using blaze_util::Md5Digest;
+using blaze_util::die;
+using blaze_util::pdie;
 using std::set;
 using std::vector;
 
diff --git a/src/main/cpp/blaze_util.cc b/src/main/cpp/blaze_util.cc
index 782c87a..4f67533 100644
--- a/src/main/cpp/blaze_util.cc
+++ b/src/main/cpp/blaze_util.cc
@@ -29,33 +29,17 @@
 #include <unistd.h>
 #include <sstream>
 
+#include "util/errors.h"
 #include "util/file.h"
 #include "util/numbers.h"
 #include "util/strings.h"
 
+using blaze_util::die;
+using blaze_util::pdie;
 using std::vector;
 
 namespace blaze {
 
-void die(const int exit_status, const char *format, ...) {
-  va_list ap;
-  va_start(ap, format);
-  vfprintf(stderr, format, ap);
-  va_end(ap);
-  fputc('\n', stderr);
-  exit(exit_status);
-}
-
-void pdie(const int exit_status, const char *format, ...) {
-  fprintf(stderr, "Error: ");
-  va_list ap;
-  va_start(ap, format);
-  vfprintf(stderr, format, ap);
-  va_end(ap);
-  fprintf(stderr, ": %s\n", strerror(errno));
-  exit(exit_status);
-}
-
 string GetUserName() {
   const char *user = getenv("USER");
   if (user && user[0] != '\0') return user;
diff --git a/src/main/cpp/blaze_util.h b/src/main/cpp/blaze_util.h
index d4a8410..071200c 100644
--- a/src/main/cpp/blaze_util.h
+++ b/src/main/cpp/blaze_util.h
@@ -36,13 +36,6 @@
 
 using std::string;
 
-// Prints the specified error message and exits nonzero.
-void die(const int exit_status, const char *format, ...) ATTRIBUTE_NORETURN
-    PRINTF_ATTRIBUTE(2, 3);
-// Prints "Error: <formatted-message>: <strerror(errno)>\n",  and exits nonzero.
-void pdie(const int exit_status, const char *format, ...) ATTRIBUTE_NORETURN
-    PRINTF_ATTRIBUTE(2, 3);
-
 string GetUserName();
 
 // Return the path to the JVM launcher.
diff --git a/src/main/cpp/blaze_util_darwin.cc b/src/main/cpp/blaze_util_darwin.cc
index da4036e..30b1af5 100644
--- a/src/main/cpp/blaze_util_darwin.cc
+++ b/src/main/cpp/blaze_util_darwin.cc
@@ -22,11 +22,14 @@
 #include "blaze_exit_code.h"
 #include "blaze_util.h"
 #include "blaze_util_platform.h"
+#include "util/errors.h"
 #include "util/file.h"
 #include "util/strings.h"
 
 namespace blaze {
 
+using blaze_util::die;
+using blaze_util::pdie;
 using std::string;
 
 string GetOutputRoot() {
diff --git a/src/main/cpp/blaze_util_linux.cc b/src/main/cpp/blaze_util_linux.cc
index 2e7bce6..9945ebb 100644
--- a/src/main/cpp/blaze_util_linux.cc
+++ b/src/main/cpp/blaze_util_linux.cc
@@ -22,11 +22,14 @@
 #include "blaze_exit_code.h"
 #include "blaze_util_platform.h"
 #include "blaze_util.h"
+#include "util/errors.h"
 #include "util/file.h"
 #include "util/strings.h"
 
 namespace blaze {
 
+using blaze_util::die;
+using blaze_util::pdie;
 using std::string;
 
 string GetOutputRoot() {
diff --git a/src/main/cpp/blaze_util_mingw.cc b/src/main/cpp/blaze_util_mingw.cc
index dbe1731..972857c 100644
--- a/src/main/cpp/blaze_util_mingw.cc
+++ b/src/main/cpp/blaze_util_mingw.cc
@@ -24,11 +24,14 @@
 #include "blaze_exit_code.h"
 #include "blaze_util_platform.h"
 #include "blaze_util.h"
+#include "util/errors.h"
 #include "util/file.h"
 #include "util/strings.h"
 
 namespace blaze {
 
+using blaze_util::die;
+using blaze_util::pdie;
 using std::string;
 
 void WarnFilesystemType(const string& output_base) {
diff --git a/src/main/cpp/util/errors.cc b/src/main/cpp/util/errors.cc
new file mode 100644
index 0000000..ceaf93c
--- /dev/null
+++ b/src/main/cpp/util/errors.cc
@@ -0,0 +1,44 @@
+// Copyright 2015 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/errors.h"
+
+#include <errno.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+namespace blaze_util {
+
+void die(const int exit_status, const char *format, ...) {
+  va_list ap;
+  va_start(ap, format);
+  vfprintf(stderr, format, ap);
+  va_end(ap);
+  fputc('\n', stderr);
+  exit(exit_status);
+}
+
+void pdie(const int exit_status, const char *format, ...) {
+  fprintf(stderr, "Error: ");
+  va_list ap;
+  va_start(ap, format);
+  vfprintf(stderr, format, ap);
+  va_end(ap);
+  fprintf(stderr, ": %s\n", strerror(errno));
+  exit(exit_status);
+}
+
+}  // namespace blaze_util
diff --git a/src/main/cpp/util/errors.h b/src/main/cpp/util/errors.h
new file mode 100644
index 0000000..718169f
--- /dev/null
+++ b/src/main/cpp/util/errors.h
@@ -0,0 +1,32 @@
+// Copyright 2015 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 DEVTOOLS_BLAZE_MAIN_UTIL_ERRORS_H_
+#define DEVTOOLS_BLAZE_MAIN_UTIL_ERRORS_H_
+
+#include "util/port.h"
+
+namespace blaze_util {
+
+// Prints the specified error message and exits nonzero.
+void die(const int exit_status, const char *format, ...) ATTRIBUTE_NORETURN
+    PRINTF_ATTRIBUTE(2, 3);
+// Prints "Error: <formatted-message>: <strerror(errno)>\n",  and exits nonzero.
+void pdie(const int exit_status, const char *format, ...) ATTRIBUTE_NORETURN
+    PRINTF_ATTRIBUTE(2, 3);
+
+}  // namespace blaze_util
+
+#endif   // DEVTOOLS_BLAZE_MAIN_UTIL_ERRORS_H_
diff --git a/src/main/cpp/util/file.cc b/src/main/cpp/util/file.cc
index 581b71a..8618119 100644
--- a/src/main/cpp/util/file.cc
+++ b/src/main/cpp/util/file.cc
@@ -21,7 +21,7 @@
 #include <vector>
 
 #include "blaze_exit_code.h"
-#include "blaze_util.h"
+#include "util/errors.h"
 #include "util/strings.h"
 
 using std::pair;
@@ -76,8 +76,8 @@
 string Which(const string &executable) {
   string path(getenv("PATH"));
   if (path.empty()) {
-    blaze::die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
-               "Could not get PATH to find %s", executable.c_str());
+    die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
+        "Could not get PATH to find %s", executable.c_str());
   }
 
   std::vector<std::string> pieces = blaze_util::Split(path, ':');