aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/cpp/bazel_startup_options.cc
diff options
context:
space:
mode:
authorGravatar ccalvarin <ccalvarin@google.com>2018-08-02 16:49:56 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-08-02 16:51:24 -0700
commitec83598cb6ee4136166bb562a24dc5dfa58921db (patch)
treeda003f48a11b4e3e8f56c5aea2673c49f84d3407 /src/main/cpp/bazel_startup_options.cc
parent1ae4fc24164a4131ac9f177f3e91170ae4e721bc (diff)
Change the list of rc files accepted.
The old list was, in order: - %workspace%/tools/bazel.rc (unless --nomaster_bazelrc) - %binary_dir%/bazel.bazelrc (unless --nomaster_bazelrc) - system rc, /etc/bazel.bazelrc or in %ProgramData% for Windows (unless --nomaster_bazelrc) - the first of the following gets called the "user" bazelrc - path passed by flag --bazelrc - %workspace%/.bazelrc - $HOME/.bazelrc The new list is hopefully a bit more consistent, as: - system rc (unless --nosystem_rc) - workspace, %workspace%/.bazelrc (unless --noworkspace_rc) - user, $HOME/.bazelrc (unless --nohome_rc) - command-line provided, passed as --bazelrc or nothing if the flag is absent. This list removes two less than useful locations, duplication in the Workspace directory, and the rc next to the bazel binary. This location made sense at Google but is generally nonsensical elsewhere so we are removing it. It also stops the user local rc file from being overriden by passing in a custom file in --bazelrc. In both old and new, --ignore_all_rc_files disables all of the above. For a transition period, any file that you would have loaded but was not read will cause a WARNING to be printed. If you want the old file to still be read without moving its location, you can always import it into one of the new standard locations, or create a symlink. Closes #4502, except for cleanup to remove the warning after a transition period of 1 Bazel version has passed. RELNOTES[INC]: New bazelrc file list. PiperOrigin-RevId: 207189212
Diffstat (limited to 'src/main/cpp/bazel_startup_options.cc')
-rw-r--r--src/main/cpp/bazel_startup_options.cc64
1 files changed, 61 insertions, 3 deletions
diff --git a/src/main/cpp/bazel_startup_options.cc b/src/main/cpp/bazel_startup_options.cc
index 950647e55d..2ec8c8c4f5 100644
--- a/src/main/cpp/bazel_startup_options.cc
+++ b/src/main/cpp/bazel_startup_options.cc
@@ -25,8 +25,14 @@ BazelStartupOptions::BazelStartupOptions(
const WorkspaceLayout *workspace_layout)
: StartupOptions("Bazel", workspace_layout),
user_bazelrc_(""),
+ use_system_rc(true),
+ use_workspace_rc(true),
+ use_home_rc(true),
use_master_bazelrc_(true) {
+ RegisterNullaryStartupFlag("home_rc");
RegisterNullaryStartupFlag("master_bazelrc");
+ RegisterNullaryStartupFlag("system_rc");
+ RegisterNullaryStartupFlag("workspace_rc");
RegisterUnaryStartupFlag("bazelrc");
}
@@ -42,6 +48,48 @@ blaze_exit_code::ExitCode BazelStartupOptions::ProcessArgExtra(
return blaze_exit_code::BAD_ARGV;
}
user_bazelrc_ = *value;
+ } else if (GetNullaryOption(arg, "--system_rc")) {
+ if (!rcfile.empty()) {
+ *error = "Can't specify --system_rc in .bazelrc file.";
+ return blaze_exit_code::BAD_ARGV;
+ }
+ use_system_rc = true;
+ option_sources["system_rc"] = rcfile;
+ } else if (GetNullaryOption(arg, "--nosystem_rc")) {
+ if (!rcfile.empty()) {
+ *error = "Can't specify --nosystem_rc in .bazelrc file.";
+ return blaze_exit_code::BAD_ARGV;
+ }
+ use_system_rc = false;
+ option_sources["system_rc"] = rcfile;
+ } else if (GetNullaryOption(arg, "--workspace_rc")) {
+ if (!rcfile.empty()) {
+ *error = "Can't specify --workspace_rc in .bazelrc file.";
+ return blaze_exit_code::BAD_ARGV;
+ }
+ use_workspace_rc = true;
+ option_sources["workspace_rc"] = rcfile;
+ } else if (GetNullaryOption(arg, "--noworkspace_rc")) {
+ if (!rcfile.empty()) {
+ *error = "Can't specify --noworkspace_rc in .bazelrc file.";
+ return blaze_exit_code::BAD_ARGV;
+ }
+ use_workspace_rc = false;
+ option_sources["workspace_rc"] = rcfile;
+ } else if (GetNullaryOption(arg, "--home_rc")) {
+ if (!rcfile.empty()) {
+ *error = "Can't specify --home_rc in .bazelrc file.";
+ return blaze_exit_code::BAD_ARGV;
+ }
+ use_home_rc = true;
+ option_sources["home_rc"] = rcfile;
+ } else if (GetNullaryOption(arg, "--nohome_rc")) {
+ if (!rcfile.empty()) {
+ *error = "Can't specify --nohome_rc in .bazelrc file.";
+ return blaze_exit_code::BAD_ARGV;
+ }
+ use_home_rc = false;
+ option_sources["home_rc"] = rcfile;
} else if (GetNullaryOption(arg, "--master_bazelrc")) {
if (!rcfile.empty()) {
*error = "Can't specify --master_bazelrc in .bazelrc file.";
@@ -71,9 +119,19 @@ void BazelStartupOptions::MaybeLogStartupOptionWarnings() const {
BAZEL_LOG(WARNING) << "Value of --bazelrc is ignored, since "
"--ignore_all_rc_files is on.";
}
- if ((use_master_bazelrc_) &&
- option_sources.find("blazerc") != option_sources.end()) {
- BAZEL_LOG(WARNING) << "Explicit value of --master_bazelrc is "
+ if ((use_home_rc) &&
+ option_sources.find("home_rc") != option_sources.end()) {
+ BAZEL_LOG(WARNING) << "Explicit value of --home_rc is "
+ "ignored, since --ignore_all_rc_files is on.";
+ }
+ if ((use_system_rc) &&
+ option_sources.find("system_rc") != option_sources.end()) {
+ BAZEL_LOG(WARNING) << "Explicit value of --system_rc is "
+ "ignored, since --ignore_all_rc_files is on.";
+ }
+ if ((use_workspace_rc) &&
+ option_sources.find("workspace_rc") != option_sources.end()) {
+ BAZEL_LOG(WARNING) << "Explicit value of --workspace_rc is "
"ignored, since --ignore_all_rc_files is on.";
}
}