diff options
-rw-r--r-- | src/main/cpp/blaze.cc | 16 | ||||
-rw-r--r-- | src/main/cpp/workspace_layout.cc | 7 | ||||
-rw-r--r-- | src/main/cpp/workspace_layout.h | 5 | ||||
-rwxr-xr-x | src/test/shell/bazel/client_test.sh | 11 |
4 files changed, 32 insertions, 7 deletions
diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc index 243df26b72..195134c524 100644 --- a/src/main/cpp/blaze.cc +++ b/src/main/cpp/blaze.cc @@ -394,13 +394,14 @@ string GetEmbeddedBinariesRoot(const string &install_base) { } // Returns the JVM command argument array. -static vector<string> GetArgumentArray() { +static vector<string> GetArgumentArray( + const WorkspaceLayout *workspace_layout) { vector<string> result; // e.g. A Blaze server process running in ~/src/build_root (where there's a // ~/src/build_root/WORKSPACE file) will appear in ps(1) as "blaze(src)". string workspace = - blaze_util::Basename(blaze_util::Dirname(globals->workspace)); + workspace_layout->GetPrettyWorkspaceName(globals->workspace); string product = globals->options->product_name; blaze_util::ToLower(&product); result.push_back(product + "(" + workspace + ")"); @@ -673,7 +674,7 @@ static void VerifyJavaVersionAndSetJvm() { // Starts the Blaze server. static int StartServer(const WorkspaceLayout *workspace_layout, BlazeServerStartup **server_startup) { - vector<string> jvm_args_vector = GetArgumentArray(); + vector<string> jvm_args_vector = GetArgumentArray(workspace_layout); string argument_string = GetArgumentString(jvm_args_vector); string server_dir = blaze_util::JoinPath(globals->options->output_base, "server"); @@ -734,7 +735,7 @@ static void StartStandalone(const WorkspaceLayout *workspace_layout, globals->options->product_name.c_str(), globals->options->product_name.c_str(), product.c_str()); } - vector<string> jvm_args_vector = GetArgumentArray(); + vector<string> jvm_args_vector = GetArgumentArray(workspace_layout); if (!command.empty()) { jvm_args_vector.push_back(command); AddLoggingArgs(&jvm_args_vector); @@ -1134,7 +1135,8 @@ static bool ServerNeedsToBeKilled(const vector<string> &args1, } // Kills the running Blaze server, if any, if the startup options do not match. -static void KillRunningServerIfDifferentStartupOptions(BlazeServer *server) { +static void KillRunningServerIfDifferentStartupOptions( + const WorkspaceLayout *workspace_layout, BlazeServer *server) { if (!server->Connected()) { return; } @@ -1153,7 +1155,7 @@ static void KillRunningServerIfDifferentStartupOptions(BlazeServer *server) { // These strings contain null-separated command line arguments. If they are // the same, the server can stay alive, otherwise, it needs shuffle off this // mortal coil. - if (ServerNeedsToBeKilled(arguments, GetArgumentArray())) { + if (ServerNeedsToBeKilled(arguments, GetArgumentArray(workspace_layout))) { globals->restart_reason = NEW_OPTIONS; PrintWarning( "Running %s server needs to be killed, because the " @@ -1493,7 +1495,7 @@ int Main(int argc, const char *argv[], WorkspaceLayout *workspace_layout, blaze_server->Connect(); EnsureCorrectRunningVersion(blaze_server); - KillRunningServerIfDifferentStartupOptions(blaze_server); + KillRunningServerIfDifferentStartupOptions(workspace_layout, blaze_server); if (globals->options->batch) { SetScheduling(globals->options->batch_cpu_scheduling, diff --git a/src/main/cpp/workspace_layout.cc b/src/main/cpp/workspace_layout.cc index 99083d2b7f..cc02c78113 100644 --- a/src/main/cpp/workspace_layout.cc +++ b/src/main/cpp/workspace_layout.cc @@ -49,6 +49,13 @@ string WorkspaceLayout::GetWorkspace(const string &cwd) const { return ""; } +string WorkspaceLayout::GetPrettyWorkspaceName( + const std::string& workspace) const { + // e.g. A Bazel server process running in ~/src/myproject (where there's a + // ~/src/myproject/WORKSPACE file) will appear in ps(1) as "bazel(myproject)". + return blaze_util::Basename(workspace); +} + static string FindDepotBlazerc(const blaze::WorkspaceLayout* workspace_layout, const string& workspace) { // Package semantics are ignored here, but that's acceptable because diff --git a/src/main/cpp/workspace_layout.h b/src/main/cpp/workspace_layout.h index 5f5a87691d..a8dd6d1ace 100644 --- a/src/main/cpp/workspace_layout.h +++ b/src/main/cpp/workspace_layout.h @@ -40,6 +40,11 @@ class WorkspaceLayout { // relative or absolute. virtual std::string GetWorkspace(const std::string& cwd) const; + // Given a result returned from GetWorkspace, returns a pretty workspace name + // than can e.g. be used in the process title of the Bazel server. + virtual std::string GetPrettyWorkspaceName( + const std::string& workspace) const; + // Returns if workspace is a valid build workspace. virtual bool InWorkspace(const std::string& workspace) const; diff --git a/src/test/shell/bazel/client_test.sh b/src/test/shell/bazel/client_test.sh index c04acbbdd9..dd67dc487c 100755 --- a/src/test/shell/bazel/client_test.sh +++ b/src/test/shell/bazel/client_test.sh @@ -33,3 +33,14 @@ EOF expect_log "^output_path:.*/execroot/blerp/bazel-out\$" expect_log "^execution_root:.*/execroot/blerp\$" } + +# This test is for Bazel only and not for Google's internal version (Blaze), +# because Bazel uses a different way to compute the workspace name. +function test_server_process_name_has_workspace_name() { + mkdir foobarspace + cd foobarspace + touch WORKSPACE BUILD + ps -o cmd= "$(bazel info server_pid)" &>"$TEST_log" + expect_log "^bazel(foobarspace)" + bazel shutdown +} |