aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Julio Merino <jmmv@google.com>2016-09-09 15:11:48 +0000
committerGravatar Dmitry Lomov <dslomov@google.com>2016-09-12 08:54:34 +0000
commitdfb2c73eda3d2dd8787ea9b2d0a03b49dfa2acc5 (patch)
treed656e66ff561371151b05032f64dce8851a99f95
parentf8e18b7b1cbb82a7dd9569041e08596a56b91109 (diff)
Inject the product name via the per-product main.cc files.
Instead of using a compile-time PRODUCT_NAME constant and complex Build rules to set the correct product name for Blaze and Bazel, use the new main.cc files to inject the appropriate value. -- MOS_MIGRATED_REVID=132675327
-rw-r--r--src/main/cpp/main.cc5
-rw-r--r--src/main/cpp/startup_options.cc13
-rw-r--r--src/main/cpp/startup_options.h6
3 files changed, 10 insertions, 14 deletions
diff --git a/src/main/cpp/main.cc b/src/main/cpp/main.cc
index c58b826661..26036e5fe8 100644
--- a/src/main/cpp/main.cc
+++ b/src/main/cpp/main.cc
@@ -19,7 +19,8 @@
#include "src/main/cpp/startup_options.h"
int main(int argc, const char *argv[]) {
+ std::unique_ptr<blaze::StartupOptions> startup_options(
+ new blaze::StartupOptions(blaze::BAZEL_PRODUCT_NAME));
return blaze::Main(argc, argv,
- new blaze::OptionProcessor(
- std::unique_ptr<blaze::StartupOptions>(new blaze::StartupOptions())));
+ new blaze::OptionProcessor(std::move(startup_options)));
}
diff --git a/src/main/cpp/startup_options.cc b/src/main/cpp/startup_options.cc
index 156cda916d..d88fa52a6b 100644
--- a/src/main/cpp/startup_options.cc
+++ b/src/main/cpp/startup_options.cc
@@ -28,15 +28,12 @@
#include "src/main/cpp/util/numbers.h"
#include "src/main/cpp/util/strings.h"
-#ifndef PRODUCT_NAME
-#define PRODUCT_NAME "Bazel"
-#endif
-
namespace blaze {
using std::vector;
-StartupOptions::StartupOptions() {
+StartupOptions::StartupOptions(const string& product_name) :
+ product_name(product_name) {
Init();
}
@@ -52,11 +49,7 @@ void StartupOptions::Init() {
output_root = GetOutputRoot();
}
- // TODO(jmmv): Now that we have per-product main.cc files, inject the
- // product_name at construction time instead of using preprocessor
- // definitions.
- product_name = PRODUCT_NAME;
- string product_name_lower = PRODUCT_NAME;
+ string product_name_lower = product_name;
blaze_util::ToLower(&product_name_lower);
output_user_root = blaze_util::JoinPath(
output_root, "_" + product_name_lower + "_" + GetUserName());
diff --git a/src/main/cpp/startup_options.h b/src/main/cpp/startup_options.h
index d1f33308cb..d47d043f1a 100644
--- a/src/main/cpp/startup_options.h
+++ b/src/main/cpp/startup_options.h
@@ -25,6 +25,8 @@ namespace blaze {
using std::string;
+constexpr char BAZEL_PRODUCT_NAME[] = "Bazel";
+
// This class holds the parsed startup options for Blaze.
// These options and their defaults must be kept in sync with those in
// src/main/java/com/google/devtools/build/lib/runtime/BlazeServerStartupOptions.java.
@@ -37,7 +39,7 @@ using std::string;
// names also don't conform to the style guide.
class StartupOptions {
public:
- StartupOptions();
+ explicit StartupOptions(const string& product_name);
virtual ~StartupOptions();
// Parses a single argument, either from the command line or from the .blazerc
@@ -115,7 +117,7 @@ class StartupOptions {
const std::vector<string> &user_options, string *error) const;
// The capitalized name of this binary.
- string product_name;
+ const string product_name;
// Blaze's output base. Everything is relative to this. See
// the BlazeDirectories Java class for details.