diff options
author | 2016-09-15 13:48:10 +0000 | |
---|---|---|
committer | 2016-09-15 15:42:02 +0000 | |
commit | 41b5688b2ecb8d5ec6c6ed19f42599adb5df41c7 (patch) | |
tree | 71c1ba9cc8bfd0a7e86c906629b43b821d747b31 | |
parent | 35cad2bc21108301c915bc9cd44dc83219864a8b (diff) |
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
-rw-r--r-- | src/main/cpp/main.cc | 2 | ||||
-rw-r--r-- | src/main/cpp/startup_options.cc | 5 | ||||
-rw-r--r-- | src/main/cpp/startup_options.h | 10 | ||||
-rw-r--r-- | src/test/cpp/startup_options_test.cc | 11 |
4 files changed, 21 insertions, 7 deletions
diff --git a/src/main/cpp/main.cc b/src/main/cpp/main.cc index 26036e5fe8..02b771465b 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 b3a8afc957..5d3e9f4118 100644 --- a/src/main/cpp/startup_options.cc +++ b/src/main/cpp/startup_options.cc @@ -33,6 +33,11 @@ namespace blaze { 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 a4012bd425..cc77f2e376 100644 --- a/src/main/cpp/startup_options.h +++ b/src/main/cpp/startup_options.h @@ -25,8 +25,6 @@ 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. @@ -39,7 +37,7 @@ constexpr char BAZEL_PRODUCT_NAME[] = "Bazel"; // 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 @@ class StartupOptions { // 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 c15bc28065..5658c1ac28 100644 --- a/src/test/cpp/startup_options_test.cc +++ b/src/test/cpp/startup_options_test.cc @@ -42,11 +42,16 @@ class StartupOptionsTest : public ::testing::Test { 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 @@ TEST_F(StartupOptionsTest, OutputRootUseHomeDirectory) { 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 @@ TEST_F(StartupOptionsTest, OutputRootUseBuiltin) { 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); } |