Determine the .bazelrc's name based on the product name.
When looking up the .bazelrc file in the workspace or the home directory,
construct its name using the built-in product name instead of hardcoding
the name in the WorkspaceLayout class.
This removes an additional hardcoded value and changes the code to do the
right thing based on the product name.
--
PiperOrigin-RevId: 145077783
MOS_MIGRATED_REVID=145077783
diff --git a/src/main/cpp/option_processor.cc b/src/main/cpp/option_processor.cc
index d9a7b2b..94d2d3f 100644
--- a/src/main/cpp/option_processor.cc
+++ b/src/main/cpp/option_processor.cc
@@ -259,15 +259,18 @@
// If no readable .blazerc file is found, return the empty string.
blaze_exit_code::ExitCode OptionProcessor::FindUserBlazerc(
const char* cmdLineRcFile,
- const string& rc_basename,
const string& workspace,
string* blaze_rc_file,
string* error) {
+ const string rc_basename =
+ "." + parsed_startup_options_->GetLowercaseProductName() + "rc";
+
if (cmdLineRcFile != NULL) {
string rcFile = MakeAbsolute(cmdLineRcFile);
if (!blaze_util::CanReadFile(rcFile)) {
blaze_util::StringPrintf(error,
- "Error: Unable to read .blazerc file '%s'.", rcFile.c_str());
+ "Error: Unable to read %s file '%s'.", rc_basename.c_str(),
+ rcFile.c_str());
return blaze_exit_code::BAD_ARGV;
}
*blaze_rc_file = rcFile;
@@ -331,8 +334,7 @@
string user_blazerc_path;
blaze_exit_code::ExitCode find_blazerc_exit_code = FindUserBlazerc(
- blazerc, workspace_layout_->RcBasename(), workspace, &user_blazerc_path,
- error);
+ blazerc, workspace, &user_blazerc_path, error);
if (find_blazerc_exit_code != blaze_exit_code::SUCCESS) {
return find_blazerc_exit_code;
}
diff --git a/src/main/cpp/option_processor.h b/src/main/cpp/option_processor.h
index fc6fb33..8ea7058 100644
--- a/src/main/cpp/option_processor.h
+++ b/src/main/cpp/option_processor.h
@@ -102,7 +102,7 @@
StartupOptions* GetParsedStartupOptions() const;
virtual blaze_exit_code::ExitCode FindUserBlazerc(
- const char* cmdLineRcFile, const std::string& rc_basename,
+ const char* cmdLineRcFile,
const std::string& workspace, std::string* user_blazerc_file,
std::string* error);
diff --git a/src/main/cpp/workspace_layout.cc b/src/main/cpp/workspace_layout.cc
index 7d8f4d7..99083d2 100644
--- a/src/main/cpp/workspace_layout.cc
+++ b/src/main/cpp/workspace_layout.cc
@@ -49,10 +49,6 @@
return "";
}
-string WorkspaceLayout::RcBasename() const {
- return ".bazelrc";
-}
-
static string FindDepotBlazerc(const blaze::WorkspaceLayout* workspace_layout,
const string& workspace) {
// Package semantics are ignored here, but that's acceptable because
diff --git a/src/main/cpp/workspace_layout.h b/src/main/cpp/workspace_layout.h
index 64c6a98..5f5a876 100644
--- a/src/main/cpp/workspace_layout.h
+++ b/src/main/cpp/workspace_layout.h
@@ -43,9 +43,6 @@
// Returns if workspace is a valid build workspace.
virtual bool InWorkspace(const std::string& workspace) const;
- // Returns the basename for the rc file.
- virtual std::string RcBasename() const;
-
// Returns the candidate pathnames for the RC files.
virtual void FindCandidateBlazercPaths(
const std::string& workspace,