aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/cpp/option_processor.h
diff options
context:
space:
mode:
authorGravatar ccalvarin <ccalvarin@google.com>2018-04-19 08:47:28 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-04-19 08:49:16 -0700
commitd8dfd7882585fafc2be60d42ae996a4a536ac469 (patch)
treefc536b0521b0443ce2f6fd067ef0030a7d79199f /src/main/cpp/option_processor.h
parent3b644d6ba753350165841feadf12a1f401329ee1 (diff)
Refactor where rc files are controlled.
In preparation for https://github.com/bazelbuild/bazel/issues/4502, make OptionProcessor::GetRcFiles contain the logic for both the user bazelrcs and the master bazelrcs. RELNOTES: None PiperOrigin-RevId: 193521683
Diffstat (limited to 'src/main/cpp/option_processor.h')
-rw-r--r--src/main/cpp/option_processor.h45
1 files changed, 33 insertions, 12 deletions
diff --git a/src/main/cpp/option_processor.h b/src/main/cpp/option_processor.h
index d2053017ef..736c004903 100644
--- a/src/main/cpp/option_processor.h
+++ b/src/main/cpp/option_processor.h
@@ -82,8 +82,8 @@ class OptionProcessor {
const std::vector<std::string>& args,
std::string* error) const;
- // Parse a command line and the appropriate blazerc files. This should be
- // invoked only once per OptionProcessor object.
+ // Parse a command line and the appropriate blazerc files and stores the
+ // results. This should be invoked only once per OptionProcessor object.
blaze_exit_code::ExitCode ParseOptions(const std::vector<std::string>& args,
const std::string& workspace,
const std::string& cwd,
@@ -104,18 +104,11 @@ class OptionProcessor {
virtual StartupOptions* GetParsedStartupOptions() const;
- virtual blaze_exit_code::ExitCode FindUserBlazerc(
- const char* cmdLineRcFile,
- const std::string& workspace, std::string* user_blazerc_file,
- std::string* error);
-
// Prints a message about the origin of startup options. This should be called
- // if the server is not started or called, in case the options are related
- // to the failure. Otherwise, the server will handle any required logging.
+ // if the server is not started or called, in case the options are related to
+ // the failure. Otherwise, the server will handle any required logging.
void PrintStartupOptionsProvenanceMessage() const;
- blaze_exit_code::ExitCode ParseStartupOptions(std::string* error);
-
// Constructs all synthetic command args that should be passed to the
// server to configure blazerc options and client environment.
static std::vector<std::string> GetBlazercAndEnvCommandArgs(
@@ -123,8 +116,29 @@ class OptionProcessor {
const std::vector<std::unique_ptr<RcFile>>& blazercs,
const std::vector<std::string>& env);
+ // Finds and parses the appropriate RcFiles.
+ // TODO(#4502) Change where the bazelrcs are read from.
+ virtual blaze_exit_code::ExitCode GetRcFiles(
+ const WorkspaceLayout* workspace_layout, const std::string& workspace,
+ const std::string& cwd, const CommandLine* cmd_line,
+ std::vector<std::unique_ptr<RcFile>>* result_rc_files,
+ std::string* error) const;
+
+ protected:
+ // Return the path to the user's rc file. If cmd_line_rc_file != NULL,
+ // use it, dying if it is not readable. Otherwise, return the first
+ // readable file called rc_basename from [workspace, $HOME]
+ //
+ // If no readable .blazerc file is found, return the empty string.
+ virtual blaze_exit_code::ExitCode FindUserBlazerc(
+ const char* cmd_line_rc_file, const std::string& workspace,
+ 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>> blazercs_;
+ 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
@@ -145,6 +159,13 @@ class OptionProcessor {
std::unique_ptr<StartupOptions> parsed_startup_options_;
};
+// Parses and returns the contents of the rc file.
+blaze_exit_code::ExitCode ParseRcFile(const WorkspaceLayout* workspace_layout,
+ const std::string& workspace,
+ const std::string& rc_file_path,
+ std::unique_ptr<RcFile>* result_rc_file,
+ std::string* error);
+
} // namespace blaze
#endif // BAZEL_SRC_MAIN_CPP_OPTION_PROCESSOR_H_