From 518be1494b65c6fe89a32152e7c71c08b0715e4a Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Thu, 14 Nov 2024 00:01:51 +0000 Subject: [PATCH] restore cmake logic --- test/core/http/httpcli_test_util.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/test/core/http/httpcli_test_util.cc b/test/core/http/httpcli_test_util.cc index 6a2f8952275d1..2d608c8889635 100644 --- a/test/core/http/httpcli_test_util.cc +++ b/test/core/http/httpcli_test_util.cc @@ -28,6 +28,7 @@ #include "absl/log/check.h" #include "absl/log/log.h" +#include "absl/strings/match.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" #include "absl/types/optional.h" @@ -41,12 +42,19 @@ namespace testing { HttpRequestTestServer StartHttpRequestTestServer(int argc, char** argv, bool use_ssl) { int server_port = grpc_pick_unused_port_or_die(); - // Find root path. + // Find root path. The logic is different for bazel vs. cmake. std::string root; absl::string_view me(argv[0]); size_t last_slash = me.rfind('/'); if (last_slash != me.npos) { - root = absl::StrCat(me.substr(0, last_slash), "/../../.."); + absl::string_view dirname = me.substr(0, last_slash); + if (absl::EndsWith(dirname, "/http")) { + // Bazel paths will end in "test/core/http". + root = absl::StrCat(dirname, "/../../.."); + } else { + // Cmake paths will be "cmake/build". + root = absl::StrCat(dirname, "/../.."); + } } else { root = "."; }