aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/cpp
diff options
context:
space:
mode:
authorGravatar ccalvarin <ccalvarin@google.com>2018-05-15 16:41:19 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-05-15 16:43:02 -0700
commit90e116c2358e2d1e71818f7d39ddb609581ee211 (patch)
tree998a51348dfe39c513d44a05bdc0935589fd9102 /src/main/cpp
parent0015d18f57e3f94905b58967b9dd6a1e8b364596 (diff)
Add --ignore_all_rc_files startup options.
This overrides --bazelrc and --[no]master_bazelrc regardless of order. Like --bazelrc and --[no]master_bazelrc, it cannot be mentioned in an rc file, this would be a contradiction. This flag is useful for testing, and for having a version-agnostic way to turn off all rc files, such as in the canonical command line reporting. Now that blazerc and bazelrc are separate, this is necessary. If explicit values for --bazelrc or --master_bazelrc are provided which are now ignored, Bazel will warn the user. #4502 Alternatives considered - We could avoid this flag but would need to have some well-documented, reusable list of the startup flags that effectively come to the same effect. This would be necessary in our integration tests and in the CommandLineEvent and other places where rc files need to be completely disabled for correctness. We decided that this startup option was more straightforward and usable for both users and Bazel devs: it shouldn't be used when more fine-grained control is needed, but provides warnings if users are likely to be confused by the outcome. RELNOTES: None. PiperOrigin-RevId: 196750704
Diffstat (limited to 'src/main/cpp')
-rw-r--r--src/main/cpp/bazel_startup_options.cc33
-rw-r--r--src/main/cpp/bazel_startup_options.h6
-rw-r--r--src/main/cpp/blaze.cc4
-rw-r--r--src/main/cpp/option_processor.cc16
-rw-r--r--src/main/cpp/startup_options.cc38
-rw-r--r--src/main/cpp/startup_options.h7
6 files changed, 83 insertions, 21 deletions
diff --git a/src/main/cpp/bazel_startup_options.cc b/src/main/cpp/bazel_startup_options.cc
index f3138f781b..950647e55d 100644
--- a/src/main/cpp/bazel_startup_options.cc
+++ b/src/main/cpp/bazel_startup_options.cc
@@ -16,13 +16,16 @@
#include <cassert>
#include "src/main/cpp/blaze_util.h"
+#include "src/main/cpp/util/logging.h"
#include "src/main/cpp/workspace_layout.h"
namespace blaze {
BazelStartupOptions::BazelStartupOptions(
const WorkspaceLayout *workspace_layout)
- : StartupOptions("Bazel", workspace_layout) {
+ : StartupOptions("Bazel", workspace_layout),
+ user_bazelrc_(""),
+ use_master_bazelrc_(true) {
RegisterNullaryStartupFlag("master_bazelrc");
RegisterUnaryStartupFlag("bazelrc");
}
@@ -38,12 +41,20 @@ blaze_exit_code::ExitCode BazelStartupOptions::ProcessArgExtra(
*error = "Can't specify --bazelrc in the .bazelrc file.";
return blaze_exit_code::BAD_ARGV;
}
- } else if (GetNullaryOption(arg, "--nomaster_bazelrc") ||
- GetNullaryOption(arg, "--master_bazelrc")) {
+ user_bazelrc_ = *value;
+ } else if (GetNullaryOption(arg, "--master_bazelrc")) {
if (!rcfile.empty()) {
- *error = "Can't specify --[no]master_bazelrc in .bazelrc file.";
+ *error = "Can't specify --master_bazelrc in .bazelrc file.";
return blaze_exit_code::BAD_ARGV;
}
+ use_master_bazelrc_ = true;
+ option_sources["blazerc"] = rcfile;
+ } else if (GetNullaryOption(arg, "--nomaster_bazelrc")) {
+ if (!rcfile.empty()) {
+ *error = "Can't specify --nomaster_bazelrc in .bazelrc file.";
+ return blaze_exit_code::BAD_ARGV;
+ }
+ use_master_bazelrc_ = false;
option_sources["blazerc"] = rcfile;
} else {
*is_processed = false;
@@ -54,4 +65,18 @@ blaze_exit_code::ExitCode BazelStartupOptions::ProcessArgExtra(
return blaze_exit_code::SUCCESS;
}
+void BazelStartupOptions::MaybeLogStartupOptionWarnings() const {
+ if (ignore_all_rc_files) {
+ if (!user_bazelrc_.empty()) {
+ 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 "
+ "ignored, since --ignore_all_rc_files is on.";
+ }
+ }
+}
+
} // namespace blaze
diff --git a/src/main/cpp/bazel_startup_options.h b/src/main/cpp/bazel_startup_options.h
index 53ce6cb021..b27aaef613 100644
--- a/src/main/cpp/bazel_startup_options.h
+++ b/src/main/cpp/bazel_startup_options.h
@@ -29,6 +29,12 @@ class BazelStartupOptions : public StartupOptions {
blaze_exit_code::ExitCode ProcessArgExtra(
const char *arg, const char *next_arg, const std::string &rcfile,
const char **value, bool *is_processed, std::string *error) override;
+
+ void MaybeLogStartupOptionWarnings() const override;
+
+ private:
+ std::string user_bazelrc_;
+ bool use_master_bazelrc_;
};
} // namespace blaze
diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc
index 331c4c212b..655406ae94 100644
--- a/src/main/cpp/blaze.cc
+++ b/src/main/cpp/blaze.cc
@@ -1473,6 +1473,10 @@ int Main(int argc, const char *argv[], WorkspaceLayout *workspace_layout,
// If client_debug was false, this is ignored, so it's accurate.
BAZEL_LOG(INFO) << "Debug logging requested, sending all client log "
"statements to stderr";
+ // TODO(b/79206210): Can't log this before SetDebugLog is called, since the
+ // warning might get swallowed. Once the bug is fixed, move this call to
+ // OptionProcessor::ParseOptions where the order of operations is more clear.
+ globals->options->MaybeLogStartupOptionWarnings();
blaze::CreateSecureOutputRoot(globals->options->output_user_root);
diff --git a/src/main/cpp/option_processor.cc b/src/main/cpp/option_processor.cc
index 6fa48fee2a..7df0af7203 100644
--- a/src/main/cpp/option_processor.cc
+++ b/src/main/cpp/option_processor.cc
@@ -292,15 +292,19 @@ blaze_exit_code::ExitCode OptionProcessor::ParseOptions(
return blaze_exit_code::BAD_ARGV;
}
- // Read the rc files. This depends on the startup options in argv since these
- // may contain rc-modifying options. For all other options, the precedence of
+ // Read the rc files, unless --ignore_all_rc_files was provided on the command
+ // line. This depends on the startup options in argv since these may contain
+ // other rc-modifying options. For all other options, the precedence of
// options will be rc first, then command line options, though, despite this
// exception.
std::vector<std::unique_ptr<RcFile>> rc_files;
- const blaze_exit_code::ExitCode rc_parsing_exit_code = GetRcFiles(
- workspace_layout_, workspace, cwd, cmd_line_.get(), &rc_files, error);
- if (rc_parsing_exit_code != blaze_exit_code::SUCCESS) {
- return rc_parsing_exit_code;
+ if (!SearchNullaryOption(cmd_line_->startup_args, "ignore_all_rc_files",
+ false)) {
+ const blaze_exit_code::ExitCode rc_parsing_exit_code = GetRcFiles(
+ workspace_layout_, workspace, cwd, cmd_line_.get(), &rc_files, error);
+ if (rc_parsing_exit_code != blaze_exit_code::SUCCESS) {
+ return rc_parsing_exit_code;
+ }
}
// Parse the startup options in the correct priority order.
diff --git a/src/main/cpp/startup_options.cc b/src/main/cpp/startup_options.cc
index f2cc25dea0..5ccec1d635 100644
--- a/src/main/cpp/startup_options.cc
+++ b/src/main/cpp/startup_options.cc
@@ -71,6 +71,7 @@ void StartupOptions::RegisterUnaryStartupFlag(const std::string &flag_name) {
StartupOptions::StartupOptions(const string &product_name,
const WorkspaceLayout *workspace_layout)
: product_name(product_name),
+ ignore_all_rc_files(false),
deep_execroot(true),
block_for_lock(true),
host_jvm_debug(false),
@@ -125,12 +126,13 @@ StartupOptions::StartupOptions(const string &product_name,
RegisterNullaryStartupFlag("block_for_lock");
RegisterNullaryStartupFlag("client_debug");
RegisterNullaryStartupFlag("deep_execroot");
+ RegisterNullaryStartupFlag("expand_configs_in_place");
RegisterNullaryStartupFlag("experimental_oom_more_eagerly");
RegisterNullaryStartupFlag("fatal_event_bus_exceptions");
RegisterNullaryStartupFlag("host_jvm_debug");
+ RegisterNullaryStartupFlag("ignore_all_rc_files");
RegisterNullaryStartupFlag("watchfs");
RegisterNullaryStartupFlag("write_command_log");
- RegisterNullaryStartupFlag("expand_configs_in_place");
RegisterUnaryStartupFlag("command_port");
RegisterUnaryStartupFlag("connect_timeout_secs");
RegisterUnaryStartupFlag("experimental_oom_more_eagerly_threshold");
@@ -225,6 +227,20 @@ blaze_exit_code::ExitCode StartupOptions::ProcessArg(
NULL) {
host_jvm_args.push_back(value);
option_sources["host_jvm_args"] = rcfile; // NB: This is incorrect
+ } else if (GetNullaryOption(arg, "--ignore_all_rc_files")) {
+ if (!rcfile.empty()) {
+ *error = "Can't specify --ignore_all_rc_files in an rc file.";
+ return blaze_exit_code::BAD_ARGV;
+ }
+ ignore_all_rc_files = true;
+ option_sources["ignore_all_rc_files"] = rcfile;
+ } else if (GetNullaryOption(arg, "--noignore_all_rc_files")) {
+ if (!rcfile.empty()) {
+ *error = "Can't specify --noignore_all_rc_files in an rc file.";
+ return blaze_exit_code::BAD_ARGV;
+ }
+ ignore_all_rc_files = false;
+ option_sources["ignore_all_rc_files"] = rcfile;
} else if (GetNullaryOption(arg, "--batch")) {
batch = true;
option_sources["batch"] = rcfile;
@@ -243,8 +259,8 @@ blaze_exit_code::ExitCode StartupOptions::ProcessArg(
} else if (GetNullaryOption(arg, "--nofatal_event_bus_exceptions")) {
fatal_event_bus_exceptions = false;
option_sources["fatal_event_bus_exceptions"] = rcfile;
- } else if ((value = GetUnaryOption(arg, next_arg,
- "--io_nice_level")) != NULL) {
+ } else if ((value = GetUnaryOption(arg, next_arg, "--io_nice_level")) !=
+ NULL) {
if (!blaze_util::safe_strto32(value, &io_nice_level) ||
io_nice_level > 7) {
blaze_util::StringPrintf(error,
@@ -253,8 +269,8 @@ blaze_exit_code::ExitCode StartupOptions::ProcessArg(
return blaze_exit_code::BAD_ARGV;
}
option_sources["io_nice_level"] = rcfile;
- } else if ((value = GetUnaryOption(arg, next_arg,
- "--max_idle_secs")) != NULL) {
+ } else if ((value = GetUnaryOption(arg, next_arg, "--max_idle_secs")) !=
+ NULL) {
if (!blaze_util::safe_strto32(value, &max_idle_secs) ||
max_idle_secs < 0) {
blaze_util::StringPrintf(error,
@@ -305,8 +321,8 @@ blaze_exit_code::ExitCode StartupOptions::ProcessArg(
} else if (GetNullaryOption(arg, "--noexpand_configs_in_place")) {
expand_configs_in_place = false;
option_sources["expand_configs_in_place"] = rcfile;
- } else if ((value = GetUnaryOption(
- arg, next_arg, "--connect_timeout_secs")) != NULL) {
+ } else if ((value = GetUnaryOption(arg, next_arg,
+ "--connect_timeout_secs")) != NULL) {
if (!blaze_util::safe_strto32(value, &connect_timeout_secs) ||
connect_timeout_secs < 1 || connect_timeout_secs > 120) {
blaze_util::StringPrintf(error,
@@ -316,8 +332,8 @@ blaze_exit_code::ExitCode StartupOptions::ProcessArg(
return blaze_exit_code::BAD_ARGV;
}
option_sources["connect_timeout_secs"] = rcfile;
- } else if ((value = GetUnaryOption(
- arg, next_arg, "--command_port")) != NULL) {
+ } else if ((value = GetUnaryOption(arg, next_arg, "--command_port")) !=
+ NULL) {
if (!blaze_util::safe_strto32(value, &command_port) ||
command_port < 0 || command_port > 65535) {
blaze_util::StringPrintf(error,
@@ -327,8 +343,8 @@ blaze_exit_code::ExitCode StartupOptions::ProcessArg(
return blaze_exit_code::BAD_ARGV;
}
option_sources["command_port"] = rcfile;
- } else if ((value = GetUnaryOption(arg, next_arg, "--invocation_policy"))
- != NULL) {
+ } else if ((value = GetUnaryOption(arg, next_arg, "--invocation_policy")) !=
+ NULL) {
if (invocation_policy == NULL) {
invocation_policy = value;
option_sources["invocation_policy"] = rcfile;
diff --git a/src/main/cpp/startup_options.h b/src/main/cpp/startup_options.h
index 242a383fa3..f6ffd25b6e 100644
--- a/src/main/cpp/startup_options.h
+++ b/src/main/cpp/startup_options.h
@@ -133,6 +133,10 @@ class StartupOptions {
const char *arg, const char *next_arg, const std::string &rcfile,
const char **value, bool *is_processed, std::string *error) = 0;
+ // Once startup options have been parsed, warn the user if certain options
+ // might combine in surprising ways.
+ virtual void MaybeLogStartupOptionWarnings() const = 0;
+
// Returns the absolute path to the user's local JDK install, to be used as
// the default target javabase and as a fall-back host_javabase. This is not
// the embedded JDK.
@@ -213,6 +217,9 @@ class StartupOptions {
// output_base.
std::string output_user_root;
+ // Override more finegrained rc file flags and ignore them all.
+ bool ignore_all_rc_files;
+
// Whether to put the execroot at $OUTPUT_BASE/$WORKSPACE_NAME (if false) or
// $OUTPUT_BASE/execroot/$WORKSPACE_NAME (if true).
bool deep_execroot;