aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/cpp/blaze_util.cc27
-rw-r--r--src/main/cpp/blaze_util.h10
-rw-r--r--src/main/cpp/option_processor.cc49
-rw-r--r--src/main/cpp/startup_options.cc9
-rw-r--r--src/main/cpp/startup_options.h4
-rw-r--r--src/main/cpp/workspace_layout.cc19
-rw-r--r--src/main/cpp/workspace_layout.h10
7 files changed, 76 insertions, 52 deletions
diff --git a/src/main/cpp/blaze_util.cc b/src/main/cpp/blaze_util.cc
index 7a69ad20cf..593f13f1a5 100644
--- a/src/main/cpp/blaze_util.cc
+++ b/src/main/cpp/blaze_util.cc
@@ -83,6 +83,33 @@ bool GetNullaryOption(const char *arg, const char *key) {
return true;
}
+const char* SearchUnaryOption(const vector<string>& args,
+ const char *key) {
+ if (args.empty()) {
+ return NULL;
+ }
+
+ vector<string>::size_type i = 0;
+ for (; i < args.size() - 1; ++i) {
+ const char* result = GetUnaryOption(args[i].c_str(),
+ args[i + 1].c_str(),
+ key);
+ if (result != NULL) {
+ return result;
+ }
+ }
+ return GetUnaryOption(args[i].c_str(), NULL, key);
+}
+
+bool SearchNullaryOption(const vector<string>& args, const char *key) {
+ for (vector<string>::size_type i = 0; i < args.size(); i++) {
+ if (GetNullaryOption(args[i].c_str(), key)) {
+ return true;
+ }
+ }
+ return false;
+}
+
bool VerboseLogging() { return !GetEnv("VERBOSE_BLAZE_CLIENT").empty(); }
// Read the Jvm version from a file descriptor. The read fd
diff --git a/src/main/cpp/blaze_util.h b/src/main/cpp/blaze_util.h
index 60a5a243f6..43d97c48d2 100644
--- a/src/main/cpp/blaze_util.h
+++ b/src/main/cpp/blaze_util.h
@@ -55,6 +55,16 @@ const char* GetUnaryOption(const char *arg,
// Returns false otherwise.
bool GetNullaryOption(const char *arg, const char *key);
+// Searches for 'key' in 'args' using GetUnaryOption.
+// Returns true iff key is a flag in args.
+const char* SearchUnaryOption(const std::vector<std::string>& args,
+ const char* key);
+
+// Searches for 'key' in 'args' using GetNullaryOption.
+// Returns the value of the 'key' flag iff it occurs in args.
+bool SearchNullaryOption(const std::vector<std::string>& args,
+ const char* key);
+
// Enable messages mostly of interest to developers.
bool VerboseLogging();
diff --git a/src/main/cpp/option_processor.cc b/src/main/cpp/option_processor.cc
index 680e2e331e..f01d79ae75 100644
--- a/src/main/cpp/option_processor.cc
+++ b/src/main/cpp/option_processor.cc
@@ -226,10 +226,9 @@ std::unique_ptr<CommandLine> OptionProcessor::SplitCommandLine(
// then fail.
blaze_util::StringPrintf(
error,
- "Unknown %s startup option: '%s'.\n"
+ "Unknown startup option: '%s'.\n"
" For more info, run '%s help startup_options'.",
- lowercase_product_name.c_str(), current_arg.c_str(),
- lowercase_product_name.c_str());
+ current_arg.c_str(), lowercase_product_name.c_str());
return nullptr;
}
}
@@ -299,42 +298,30 @@ blaze_exit_code::ExitCode OptionProcessor::ParseOptions(
assert(!initialized_);
initialized_ = true;
- const char* blazerc = NULL;
- bool use_master_blazerc = true;
-
- // Check if there is a blazerc related option given
args_ = args;
- for (int i= 1; i < args.size(); i++) {
- const char* arg_chr = args[i].c_str();
- const char* next_arg_chr = (i + 1) < args.size()
- ? args[i + 1].c_str()
- : NULL;
- if (blazerc == NULL) {
- blazerc = GetUnaryOption(arg_chr, next_arg_chr, "--blazerc");
- }
- if (blazerc == NULL) {
- blazerc = GetUnaryOption(arg_chr, next_arg_chr, "--bazelrc");
- }
- if (use_master_blazerc &&
- (GetNullaryOption(arg_chr, "--nomaster_blazerc") ||
- GetNullaryOption(arg_chr, "--nomaster_bazelrc"))) {
- use_master_blazerc = false;
- }
+ // Check if there is a blazerc related option given
+ std::unique_ptr<CommandLine> cmdLine = SplitCommandLine(args, error);
+ if (cmdLine == nullptr) {
+ return blaze_exit_code::BAD_ARGV;
}
- blaze_exit_code::ExitCode validate_startup_options_exit_code =
- parsed_startup_options_->ValidateStartupOptions(args, error);
- if (validate_startup_options_exit_code != blaze_exit_code::SUCCESS) {
- return validate_startup_options_exit_code;
+ const char* blazerc = SearchUnaryOption(cmdLine->startup_args, "--blazerc");
+ if (blazerc == NULL) {
+ blazerc = SearchUnaryOption(cmdLine->startup_args, "--bazelrc");
+ }
+
+ bool use_master_blazerc = true;
+ if (SearchNullaryOption(cmdLine->startup_args, "--nomaster_blazerc") ||
+ SearchNullaryOption(cmdLine->startup_args, "--nomaster_bazelrc")) {
+ use_master_blazerc = false;
}
// Parse depot and user blazerc files.
- // 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) {
- WorkspaceLayout::FindCandidateBlazercPaths(workspace, cwd, args,
- &candidate_blazerc_paths);
+ WorkspaceLayout::FindCandidateBlazercPaths(
+ workspace, cwd, cmdLine->path_to_binary, cmdLine->startup_args,
+ &candidate_blazerc_paths);
}
string user_blazerc_path;
diff --git a/src/main/cpp/startup_options.cc b/src/main/cpp/startup_options.cc
index 461be46ccd..8bd9c3d3e7 100644
--- a/src/main/cpp/startup_options.cc
+++ b/src/main/cpp/startup_options.cc
@@ -306,9 +306,9 @@ blaze_exit_code::ExitCode StartupOptions::ProcessArg(
if (!extra_argument_processed) {
blaze_util::StringPrintf(
error,
- "Unknown %s startup option: '%s'.\n"
+ "Unknown startup option: '%s'.\n"
" For more info, run '%s help startup_options'.",
- product_name.c_str(), arg, product_name.c_str());
+ arg, GetLowercaseProductName().c_str());
return blaze_exit_code::BAD_ARGV;
}
}
@@ -398,9 +398,4 @@ blaze_exit_code::ExitCode StartupOptions::AddJVMArguments(
return blaze_exit_code::SUCCESS;
}
-blaze_exit_code::ExitCode StartupOptions::ValidateStartupOptions(
- const std::vector<string>& args, string* error) {
- return blaze_exit_code::SUCCESS;
-}
-
} // namespace blaze
diff --git a/src/main/cpp/startup_options.h b/src/main/cpp/startup_options.h
index 833af1bd30..d9ebe27815 100644
--- a/src/main/cpp/startup_options.h
+++ b/src/main/cpp/startup_options.h
@@ -189,10 +189,6 @@ class StartupOptions {
// from a blazerc file, if a key is not present, it is the default.
std::map<std::string, std::string> option_sources;
- // Sanity check for the startup options
- virtual blaze_exit_code::ExitCode ValidateStartupOptions(
- const std::vector<std::string> &args, std::string *error);
-
// Returns the GetHostJavabase. This should be called after parsing
// the --host_javabase option.
std::string GetHostJavabase();
diff --git a/src/main/cpp/workspace_layout.cc b/src/main/cpp/workspace_layout.cc
index aa8bb09f2a..d3f8efab84 100644
--- a/src/main/cpp/workspace_layout.cc
+++ b/src/main/cpp/workspace_layout.cc
@@ -67,10 +67,14 @@ static string FindDepotBlazerc(const string& workspace) {
}
static string FindAlongsideBinaryBlazerc(const string& cwd,
- const string& arg0) {
- string path = arg0[0] == '/' ? arg0 : blaze_util::JoinPath(cwd, arg0);
- string base = blaze_util::Basename(arg0);
- string binary_blazerc_path = path + "." + base + "rc";
+ const string& path_to_binary) {
+ // TODO(b/32115171): This doesn't work on Windows. Fix this together with the
+ // associated bug.
+ const string path = path_to_binary[0] == '/'
+ ? path_to_binary
+ : blaze_util::JoinPath(cwd, path_to_binary);
+ const string base = blaze_util::Basename(path_to_binary);
+ const string binary_blazerc_path = path + "." + base + "rc";
if (blaze_util::CanAccess(binary_blazerc_path, true, false, false)) {
return binary_blazerc_path;
}
@@ -86,10 +90,13 @@ static string FindSystemWideBlazerc() {
}
void WorkspaceLayout::FindCandidateBlazercPaths(
- const string& workspace, const string& cwd, const vector<string>& args,
+ const string& workspace,
+ const string& cwd,
+ const string& path_to_binary,
+ const vector<string>& startup_args,
std::vector<string>* result) {
result->push_back(FindDepotBlazerc(workspace));
- result->push_back(FindAlongsideBinaryBlazerc(cwd, args[0]));
+ result->push_back(FindAlongsideBinaryBlazerc(cwd, path_to_binary));
result->push_back(FindSystemWideBlazerc());
}
diff --git a/src/main/cpp/workspace_layout.h b/src/main/cpp/workspace_layout.h
index f02371f541..26034ca6e5 100644
--- a/src/main/cpp/workspace_layout.h
+++ b/src/main/cpp/workspace_layout.h
@@ -53,10 +53,12 @@ class WorkspaceLayout {
static std::string RcBasename();
// Returns the candidate pathnames for the RC files.
- static void FindCandidateBlazercPaths(const std::string& workspace,
- const std::string& cwd,
- const std::vector<std::string>& args,
- std::vector<std::string>* result);
+ static void FindCandidateBlazercPaths(
+ const std::string& workspace,
+ const std::string& cwd,
+ const std::string& path_to_binary,
+ const std::vector<std::string>& startup_args,
+ std::vector<std::string>* result);
// Returns the candidate pathnames for the RC file in the workspace,
// the first readable one of which will be chosen.