Bake in the product name into the StartupOptions classes.
Now that we have gotten a StartupOptions class for each of the products
we support, we can bake in the product name in each instance instead of
passing it to the constructor. Helps with encapsulation and simplifies
various instantiations of these classes.
--
MOS_MIGRATED_REVID=133255854
diff --git a/src/main/cpp/main.cc b/src/main/cpp/main.cc
index 26036e5..02b7714 100644
--- a/src/main/cpp/main.cc
+++ b/src/main/cpp/main.cc
@@ -20,7 +20,7 @@
int main(int argc, const char *argv[]) {
std::unique_ptr<blaze::StartupOptions> startup_options(
- new blaze::StartupOptions(blaze::BAZEL_PRODUCT_NAME));
+ new blaze::StartupOptions());
return blaze::Main(argc, argv,
new blaze::OptionProcessor(std::move(startup_options)));
}
diff --git a/src/main/cpp/startup_options.cc b/src/main/cpp/startup_options.cc
index b3a8afc9..5d3e9f4 100644
--- a/src/main/cpp/startup_options.cc
+++ b/src/main/cpp/startup_options.cc
@@ -33,6 +33,11 @@
using std::vector;
+StartupOptions::StartupOptions() :
+ StartupOptions("Bazel") {
+ Init();
+}
+
StartupOptions::StartupOptions(const string& product_name) :
product_name(product_name) {
Init();
diff --git a/src/main/cpp/startup_options.h b/src/main/cpp/startup_options.h
index a4012bd..cc77f2e 100644
--- a/src/main/cpp/startup_options.h
+++ b/src/main/cpp/startup_options.h
@@ -25,8 +25,6 @@
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.
@@ -39,7 +37,7 @@
// names also don't conform to the style guide.
class StartupOptions {
public:
- explicit StartupOptions(const string& product_name);
+ StartupOptions();
virtual ~StartupOptions();
// Parses a single argument, either from the command line or from the .blazerc
@@ -199,6 +197,12 @@
// Invocation policy proto. May be NULL.
const char* invocation_policy;
+ protected:
+ // Constructor for subclasses only so that site-specific extensions of this
+ // class can override the product name. The product_name must be the
+ // capitalized version of the name, as in "Bazel".
+ explicit StartupOptions(const string& product_name);
+
private:
string host_javabase;
diff --git a/src/test/cpp/startup_options_test.cc b/src/test/cpp/startup_options_test.cc
index c15bc28..5658c1a 100644
--- a/src/test/cpp/startup_options_test.cc
+++ b/src/test/cpp/startup_options_test.cc
@@ -42,11 +42,16 @@
std::string old_test_tmpdir_;
};
+TEST_F(StartupOptionsTest, ProductName) {
+ blaze::StartupOptions startup_options;
+ ASSERT_EQ("Bazel", startup_options.product_name);
+}
+
TEST_F(StartupOptionsTest, OutputRootPreferTestTmpdirIfSet) {
setenv("HOME", "/nonexistent/home", 1);
setenv("TEST_TMPDIR", "/nonexistent/tmpdir", 1);
- blaze::StartupOptions startup_options(blaze::BAZEL_PRODUCT_NAME);
+ blaze::StartupOptions startup_options;
ASSERT_EQ("/nonexistent/tmpdir", startup_options.output_root);
}
@@ -54,7 +59,7 @@
setenv("HOME", "/nonexistent/home", 1);
unsetenv("TEST_TMPDIR");
- blaze::StartupOptions startup_options(blaze::BAZEL_PRODUCT_NAME);
+ blaze::StartupOptions startup_options;
ASSERT_EQ("/nonexistent/home/.cache/bazel", startup_options.output_root);
}
@@ -65,7 +70,7 @@
setenv("HOME", "", 1);
unsetenv("TEST_TMPDIR");
- blaze::StartupOptions startup_options(blaze::BAZEL_PRODUCT_NAME);
+ blaze::StartupOptions startup_options;
ASSERT_EQ("/tmp", startup_options.output_root);
}