Added /etc/bazel.bazelrc as a global Bazel's master rc.

This will allow system-wide configuration for system-wide
installation of Bazel.

--
Change-Id: I71b7232e648f2690766c3b9184f863dc888524c0
Reviewed-on: https://bazel-review.googlesource.com/#/c/1540/
MOS_MIGRATED_REVID=95994630
diff --git a/src/main/cpp/blaze_startup_options.cc b/src/main/cpp/blaze_startup_options.cc
index 1af062d..6428e22 100644
--- a/src/main/cpp/blaze_startup_options.cc
+++ b/src/main/cpp/blaze_startup_options.cc
@@ -161,4 +161,8 @@
   candidates->push_back("tools/bazel.rc");
 }
 
+string BlazeStartupOptions::SystemWideRcPath() {
+  return "/etc/bazel.bazelrc";
+}
+
 }  // namespace blaze
diff --git a/src/main/cpp/blaze_startup_options.h b/src/main/cpp/blaze_startup_options.h
index b62878e..dd1850f 100644
--- a/src/main/cpp/blaze_startup_options.h
+++ b/src/main/cpp/blaze_startup_options.h
@@ -189,6 +189,9 @@
   // Returns the basename for the rc file.
   static string RcBasename();
 
+  // Returns the path for the system-wide rc file.
+  static string SystemWideRcPath();
+
   // Returns the search paths for the RC file in the workspace.
   static void WorkspaceRcFileSearchPath(std::vector<string>* candidates);
 
diff --git a/src/main/cpp/option_processor.cc b/src/main/cpp/option_processor.cc
index 18a00e7..c15b57c 100644
--- a/src/main/cpp/option_processor.cc
+++ b/src/main/cpp/option_processor.cc
@@ -183,6 +183,17 @@
 }
 
 
+// Return the path of the bazelrc file that sits in /etc.
+// This allows for installing Bazel on system-wide directory.
+string OptionProcessor::FindSystemWideBlazerc() {
+  string path = BlazeStartupOptions::SystemWideRcPath();
+  if (!path.empty() && !access(path.c_str(), R_OK)) {
+    return path;
+  }
+  return "";
+}
+
+
 // Return the path the the user rc file.  If cmdLineRcFile != NULL,
 // use it, dying if it is not readable.  Otherwise, return the first
 // readable file called rc_basename from [workspace, $HOME]
@@ -279,6 +290,15 @@
         return parse_exit_code;
       }
     }
+    string system_wide_blazerc = FindSystemWideBlazerc();
+    if (!system_wide_blazerc.empty()) {
+      blazercs_.push_back(new RcFile(system_wide_blazerc, blazercs_.size()));
+      blaze_exit_code::ExitCode parse_exit_code =
+          blazercs_.back()->Parse(&blazercs_, &rcoptions_, error);
+      if (parse_exit_code != blaze_exit_code::SUCCESS) {
+        return parse_exit_code;
+      }
+    }
   }
 
   string user_blazerc_path;
diff --git a/src/main/cpp/option_processor.h b/src/main/cpp/option_processor.h
index f5eb27e..37a946f 100644
--- a/src/main/cpp/option_processor.h
+++ b/src/main/cpp/option_processor.h
@@ -64,6 +64,7 @@
   virtual string FindDepotBlazerc(const string& workspace);
   virtual string FindAlongsideBinaryBlazerc(const string& cwd,
                                             const string& arg0);
+  virtual string FindSystemWideBlazerc();
   virtual blaze_exit_code::ExitCode FindUserBlazerc(const char* cmdLineRcFile,
                                                     const string& rc_basename,
                                                     const string& workspace,