Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple --bazelrc on command line #12740

Closed
wants to merge 42 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
a89e22a
nary
wisechengyi Dec 21, 2020
bda828c
more
wisechengyi Dec 21, 2020
e8b8931
no print
wisechengyi Dec 21, 2020
50d2b04
no dedup
wisechengyi Dec 21, 2020
13ae538
minor
wisechengyi Dec 21, 2020
421de4f
cmt
wisechengyi Dec 21, 2020
2f08fa8
initial tests
wisechengyi Dec 22, 2020
b52aa55
more
wisechengyi Dec 22, 2020
6b8b397
rm unused
wisechengyi Dec 22, 2020
d38eca0
rename
wisechengyi Dec 22, 2020
fd7540b
size_type
wisechengyi Dec 22, 2020
17e8b19
fmt
wisechengyi Dec 22, 2020
e1b2a07
one more size_t
wisechengyi Dec 22, 2020
3aa941e
auto
wisechengyi Dec 22, 2020
d72e7bc
potential index out of bound
wisechengyi Dec 22, 2020
2888227
nullptr
wisechengyi Dec 22, 2020
dda34c2
use vector<string>
wisechengyi Dec 22, 2020
b39c124
algo
wisechengyi Dec 22, 2020
71c781a
address comments
wisechengyi Jan 18, 2021
f690f2c
simplify
wisechengyi Jan 18, 2021
420d88a
integration tests for multirc
wisechengyi Jan 19, 2021
eb1894b
rm
wisechengyi Jan 19, 2021
dd78bd3
improve --bazelrc help message on multivalue
wisechengyi Jan 19, 2021
01d15ee
address comment
wisechengyi Jan 19, 2021
d73606d
rename
wisechengyi Jan 20, 2021
5fa3ff4
address comments
wisechengyi Jan 20, 2021
5099242
address comment
wisechengyi Jan 25, 2021
1d4ad3c
Use different options and PRODUCT_NAME
wisechengyi Jan 26, 2021
9307713
add doc string
wisechengyi Feb 1, 2021
35a899e
use info
wisechengyi Feb 4, 2021
438fd20
Merge branch 'master' into multi_rc
wisechengyi Feb 5, 2021
ed75ed9
fix tests
wisechengyi Feb 6, 2021
d7dc7e5
Ignore values after /dev/null (restart ci)
wisechengyi Mar 1, 2021
a2a7142
Merge branch 'master' into multi_rc
wisechengyi Mar 1, 2021
658a9bd
impl
wisechengyi Mar 5, 2021
23cdaf7
help msg
wisechengyi Mar 9, 2021
2a5ef01
add integ test
wisechengyi Mar 9, 2021
cf7f538
strcmp
wisechengyi Mar 9, 2021
f8f5b4b
help msg tweaks and fix format (retrigger ci x2)
wisechengyi Mar 10, 2021
af82fc1
grammar
wisechengyi Mar 11, 2021
c5350b6
use info
wisechengyi Mar 12, 2021
c8d093a
doc update
wisechengyi Mar 18, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/main/cpp/blaze_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,39 @@ bool GetNullaryOption(const char *arg, const char *key) {
return true;
}

std::vector<const char*> SearchNaryOption(const vector<string>& args,
wisechengyi marked this conversation as resolved.
Show resolved Hide resolved
const char *key) {
vector<const char *> values;
if (args.empty()) {
return values;
}

bool found_dupe = false; // true if 'key' was found twice
vector<string>::size_type i = 0;

for (; i < args.size(); ++i) {
if (args[i] == "--") {
wisechengyi marked this conversation as resolved.
Show resolved Hide resolved
// If the current argument is "--", all following args are target names.
// If 'key' was not found, 'value' is nullptr and we can return that.
wisechengyi marked this conversation as resolved.
Show resolved Hide resolved
// If 'key' was found exactly once, then 'value' has the value and again
// we can return that.
// If 'key' was found more than once then we could not have reached this
// line, because we would have broken out of the loop when 'key' was found
wisechengyi marked this conversation as resolved.
Show resolved Hide resolved
// the second time.
return values;
}
const char* result = GetUnaryOption(args[i].c_str(),
args[i + 1].c_str(),
wisechengyi marked this conversation as resolved.
Show resolved Hide resolved
key);
if (result != NULL) {
wisechengyi marked this conversation as resolved.
Show resolved Hide resolved
// 'key' was found and 'result' has its value.
values.push_back(result);
}
}

return values;
}

const char* SearchUnaryOption(const vector<string>& args,
const char *key, bool warn_if_dupe) {
if (args.empty()) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/cpp/blaze_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ bool GetNullaryOption(const char *arg, const char *key);
const char* SearchUnaryOption(const std::vector<std::string>& args,
const char* key, bool warn_if_dupe);

std::vector<const char*> SearchNaryOption(const std::vector<std::string>& args,
const char* key);

// Searches for '--flag_name' and '--noflag_name' in 'args' using
// GetNullaryOption. Arguments found after '--' are omitted from the search.
// Returns true if '--flag_name' is a flag in args and '--noflag_name' does not
Expand Down
42 changes: 23 additions & 19 deletions src/main/cpp/option_processor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <set>
#include <sstream>
#include <utility>
#include <iostream>

#include "src/main/cpp/blaze_util.h"
#include "src/main/cpp/blaze_util_platform.h"
Expand All @@ -41,6 +42,8 @@ extern char **environ;

namespace blaze {

using std::cout;
using std::endl;
wisechengyi marked this conversation as resolved.
Show resolved Hide resolved
using std::map;
using std::set;
using std::string;
Expand Down Expand Up @@ -201,11 +204,14 @@ std::set<std::string> GetOldRcPaths(
internal::FindRcAlongsideBinary(cwd, path_to_binary);
candidate_bazelrc_paths = {workspace_rc, binary_rc, system_bazelrc_path};
}
string user_bazelrc_path = internal::FindLegacyUserBazelrc(
SearchUnaryOption(startup_args, "--bazelrc", /* warn_if_dupe */ true),
workspace);
if (!user_bazelrc_path.empty()) {
candidate_bazelrc_paths.push_back(user_bazelrc_path);
vector<const char *> cmd_line_rc_files = SearchNaryOption(startup_args, "--bazelrc");
for (int i=0; i<cmd_line_rc_files.size(); i++) {
wisechengyi marked this conversation as resolved.
Show resolved Hide resolved
string user_bazelrc_path = internal::FindLegacyUserBazelrc(
cmd_line_rc_files[i],
workspace);
if (!user_bazelrc_path.empty()) {
candidate_bazelrc_paths.push_back(user_bazelrc_path);
wisechengyi marked this conversation as resolved.
Show resolved Hide resolved
}
}
// DedupeBlazercPaths returns paths whose canonical path could be computed,
// therefore these paths must exist.
Expand Down Expand Up @@ -370,20 +376,18 @@ blaze_exit_code::ExitCode OptionProcessor::GetRcFiles(

// Get the command-line provided rc, passed as --bazelrc or nothing if the
// flag is absent.
const char* cmd_line_rc_file =
SearchUnaryOption(cmd_line->startup_args, "--bazelrc",
/* warn_if_dupe */ true);
if (cmd_line_rc_file != nullptr) {
string absolute_cmd_line_rc = blaze::AbsolutePathFromFlag(cmd_line_rc_file);
// Unlike the previous 3 paths, where we ignore it if the file does not
// exist or is unreadable, since this path is explicitly passed, this is an
// error. Check this condition here.
if (!blaze_util::CanReadFile(absolute_cmd_line_rc)) {
BAZEL_LOG(ERROR) << "Error: Unable to read .bazelrc file '"
<< absolute_cmd_line_rc << "'.";
return blaze_exit_code::BAD_ARGV;
}
rc_files.push_back(absolute_cmd_line_rc);
vector<const char *> cmd_line_rc_files = SearchNaryOption(cmd_line->startup_args, "--bazelrc");
for (int i=0; i< cmd_line_rc_files.size(); i++) {
wisechengyi marked this conversation as resolved.
Show resolved Hide resolved
string absolute_cmd_line_rc = blaze::AbsolutePathFromFlag(cmd_line_rc_files[i]);
// Unlike the previous 3 paths, where we ignore it if the file does not
// exist or is unreadable, since this path is explicitly passed, this is an
// error. Check this condition here.
if (!blaze_util::CanReadFile(absolute_cmd_line_rc)) {
BAZEL_LOG(ERROR) << "Error: Unable to read .bazelrc file '"
<< absolute_cmd_line_rc << "'.";
return blaze_exit_code::BAD_ARGV;
}
rc_files.push_back(absolute_cmd_line_rc);
}

// Log which files we're looking for before removing duplicates and
Expand Down