diff options
author | Nathan Harmata <nharmata@google.com> | 2015-12-21 16:10:05 +0000 |
---|---|---|
committer | Kristina Chodorow <kchodorow@google.com> | 2015-12-21 21:35:47 +0000 |
commit | 7d300b2d34c760d76303111c523f18e4acf5fdb6 (patch) | |
tree | 0928dfb26a0e02f83a543f8bfd00413484afcf1c | |
parent | e848d9091db2e6d65e205b9615a2b06c268d8ea7 (diff) |
Don't parse the same .bazelrc file more than once. The old behavior is problematic if a .bazelrc file specifies an option that is allowed to be repeated, duplicates of that option are problematic (one example is http://bazel.io/docs/bazel-user-manual.html#flag--per_file_copt).
--
MOS_MIGRATED_REVID=110689696
-rw-r--r-- | src/main/cpp/option_processor.cc | 58 |
1 files changed, 23 insertions, 35 deletions
diff --git a/src/main/cpp/option_processor.cc b/src/main/cpp/option_processor.cc index 209c9a08fb..a71b56599d 100644 --- a/src/main/cpp/option_processor.cc +++ b/src/main/cpp/option_processor.cc @@ -20,6 +20,7 @@ #include <unistd.h> #include <algorithm> #include <cassert> +#include <set> #include <utility> #include "src/main/cpp/blaze_util.h" @@ -29,6 +30,7 @@ using std::list; using std::map; +using std::set; using std::vector; // On OSX, there apparently is no header that defines this. @@ -278,37 +280,13 @@ blaze_exit_code::ExitCode OptionProcessor::ParseOptions( } // Parse depot and user blazerc files. - // This is not a little ineffective (copying a multimap around), but it is a + // This is a little inefficient (copying a multimap around), but it is a // small one and this way I don't have to care about memory management. + vector<string> candidate_blazerc_paths; if (use_master_blazerc) { - string depot_blazerc_path = FindDepotBlazerc(workspace); - if (!depot_blazerc_path.empty()) { - blazercs_.push_back(new RcFile(depot_blazerc_path, blazercs_.size())); - blaze_exit_code::ExitCode parse_exit_code = - blazercs_.back()->Parse(workspace, &blazercs_, &rcoptions_, error); - if (parse_exit_code != blaze_exit_code::SUCCESS) { - return parse_exit_code; - } - } - string alongside_binary_blazerc = FindAlongsideBinaryBlazerc(cwd, args[0]); - if (!alongside_binary_blazerc.empty()) { - blazercs_.push_back(new RcFile(alongside_binary_blazerc, - blazercs_.size())); - blaze_exit_code::ExitCode parse_exit_code = - blazercs_.back()->Parse(workspace, &blazercs_, &rcoptions_, error); - if (parse_exit_code != blaze_exit_code::SUCCESS) { - return parse_exit_code; - } - } - string system_wide_blazerc = FindSystemWideBlazerc(); - if (!system_wide_blazerc.empty()) { - blazercs_.push_back(new RcFile(system_wide_blazerc, blazercs_.size())); - blaze_exit_code::ExitCode parse_exit_code = - blazercs_.back()->Parse(workspace, &blazercs_, &rcoptions_, error); - if (parse_exit_code != blaze_exit_code::SUCCESS) { - return parse_exit_code; - } - } + candidate_blazerc_paths.push_back(FindDepotBlazerc(workspace)); + candidate_blazerc_paths.push_back(FindAlongsideBinaryBlazerc(cwd, args[0])); + candidate_blazerc_paths.push_back(FindSystemWideBlazerc()); } string user_blazerc_path; @@ -318,12 +296,22 @@ blaze_exit_code::ExitCode OptionProcessor::ParseOptions( if (find_blazerc_exit_code != blaze_exit_code::SUCCESS) { return find_blazerc_exit_code; } - if (!user_blazerc_path.empty()) { - blazercs_.push_back(new RcFile(user_blazerc_path, blazercs_.size())); - blaze_exit_code::ExitCode parse_exit_code = - blazercs_.back()->Parse(workspace, &blazercs_, &rcoptions_, error); - if (parse_exit_code != blaze_exit_code::SUCCESS) { - return parse_exit_code; + candidate_blazerc_paths.push_back(user_blazerc_path); + + // Throw away missing files, dedupe candidate blazerc paths, and parse the + // blazercs, all while preserving order. Duplicates can arise if e.g. the + // binary's path *is* the depot path. + set<string> blazerc_paths; + for (const auto& candidate_blazerc_path : candidate_blazerc_paths) { + if (!candidate_blazerc_path.empty() + && (blazerc_paths.insert(candidate_blazerc_path).second)) { + blazercs_.push_back( + new RcFile(candidate_blazerc_path, blazercs_.size())); + blaze_exit_code::ExitCode parse_exit_code = + blazercs_.back()->Parse(workspace, &blazercs_, &rcoptions_, error); + if (parse_exit_code != blaze_exit_code::SUCCESS) { + return parse_exit_code; + } } } |