aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/cpp
diff options
context:
space:
mode:
authorGravatar jmmv <jmmv@google.com>2018-04-19 12:32:59 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-04-19 12:34:13 -0700
commit64553797c63845d00c8ed162e4ddfae03295e8b9 (patch)
tree63f9bbd2a79e1fbce45858d58cd24d22f37781e6 /src/main/cpp
parent788b63a8c90e57dba511de82afd47ea73680c906 (diff)
Reduce the state kept in OptionProcessor.
Make the list of rc files a local variable as it need not be a class attribute, and drop the unused rcoptions_ field. This is a trivial refactoring and the remaining code is still too confusing. It'd be worth splitting OptionProcessor in two pieces: OptionProcessor to exclusively keep the virtual ParseOptions method and no state, and a new ParsedOptions type to act as the immutable return value of ParseOptions. This would decouple all state mutations. RELNOTES: None. PiperOrigin-RevId: 193557347
Diffstat (limited to 'src/main/cpp')
-rw-r--r--src/main/cpp/option_processor.cc19
-rw-r--r--src/main/cpp/option_processor.h13
2 files changed, 13 insertions, 19 deletions
diff --git a/src/main/cpp/option_processor.cc b/src/main/cpp/option_processor.cc
index fdfd18070b..864d968a3b 100644
--- a/src/main/cpp/option_processor.cc
+++ b/src/main/cpp/option_processor.cc
@@ -297,25 +297,26 @@ blaze_exit_code::ExitCode OptionProcessor::ParseOptions(
return blaze_exit_code::BAD_ARGV;
}
- // Populate rc_files_. This depends on the startup options in argv since these
+ // 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
// 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);
+ 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.
const blaze_exit_code::ExitCode parse_startup_options_exit_code =
- ParseStartupOptions(error);
+ ParseStartupOptions(rc_files, error);
if (parse_startup_options_exit_code != blaze_exit_code::SUCCESS) {
return parse_startup_options_exit_code;
}
blazerc_and_env_command_args_ =
- GetBlazercAndEnvCommandArgs(cwd, rc_files_, GetProcessedEnv());
+ GetBlazercAndEnvCommandArgs(cwd, rc_files, GetProcessedEnv());
return blaze_exit_code::SUCCESS;
}
@@ -357,15 +358,15 @@ void OptionProcessor::PrintStartupOptionsProvenanceMessage() const {
}
blaze_exit_code::ExitCode OptionProcessor::ParseStartupOptions(
+ const std::vector<std::unique_ptr<RcFile>> &rc_files,
std::string *error) {
// Rc files can import other files at any point, and these imported rcs are
- // expanded in place. The effective ordering of rc flags is stored in
- // rcoptions_ and should be processed in that order. Here, we isolate just the
- // startup options, but keep the file they came from attached for the
- // option_sources tracking and for sending to the server.
+ // expanded in place. Here, we isolate just the startup options but keep the
+ // file they came from attached for the option_sources tracking and for
+ // sending to the server.
std::vector<RcStartupFlag> rcstartup_flags;
- for (const auto& blazerc : rc_files_) {
+ for (const auto& blazerc : rc_files) {
const auto iter = blazerc->options().find("startup");
if (iter == blazerc->options().end()) continue;
diff --git a/src/main/cpp/option_processor.h b/src/main/cpp/option_processor.h
index 736c004903..2ae1798f85 100644
--- a/src/main/cpp/option_processor.h
+++ b/src/main/cpp/option_processor.h
@@ -16,7 +16,6 @@
#define BAZEL_SRC_MAIN_CPP_OPTION_PROCESSOR_H_
#include <list>
-#include <map>
#include <memory>
#include <string>
#include <vector>
@@ -135,15 +134,9 @@ class OptionProcessor {
std::string* user_blazerc_file, std::string* error) const;
private:
- blaze_exit_code::ExitCode ParseStartupOptions(std::string* error);
-
- // The list of parsed rc files, this field is initialized by ParseOptions.
- std::vector<std::unique_ptr<RcFile>> rc_files_;
-
- // A map representing the flags parsed from the bazelrc files.
- // A key is a command (e.g. 'build', 'startup') and its value is an ordered
- // list of RcOptions.
- std::map<std::string, std::vector<RcOption>> rcoptions_;
+ blaze_exit_code::ExitCode ParseStartupOptions(
+ const std::vector<std::unique_ptr<RcFile>>& rc_files,
+ std::string* error);
// An ordered list of command args that contain information about the
// execution environment and the flags passed via the bazelrc files.