This is an automated email from the ASF dual-hosted git repository.

dongjoon pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/orc.git


The following commit(s) were added to refs/heads/main by this push:
     new a3940f293 ORC-1936: Get build and example dir from build system rather 
than gtest
a3940f293 is described below

commit a3940f293a97caed40b395fe9b1c9e30035517bf
Author: Will Ayd <william....@icloud.com>
AuthorDate: Mon Jun 23 13:59:07 2025 -0700

    ORC-1936: Get build and example dir from build system rather than gtest
    
    ### What changes were proposed in this pull request?
    
    Rather than pulling the build and example directory from gtest arguments, 
this pulls it from the build system.
    
    ### Why are the changes needed?
    
    When orc is used as a subproject, the current method of grabbing the 
arguments from the build system fails
    
    ### How was this patch tested?
    
    Tests were run locally
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    No
    
    Closes #2291 from WillAyd/improve-gtest-cli.
    
    Authored-by: Will Ayd <william....@icloud.com>
    Signed-off-by: Dongjoon Hyun <dongj...@apache.org>
---
 tools/test/CMakeLists.txt |  5 +++++
 tools/test/ToolTest.cc    | 28 +++++++---------------------
 tools/test/meson.build    |  4 ++++
 3 files changed, 16 insertions(+), 21 deletions(-)

diff --git a/tools/test/CMakeLists.txt b/tools/test/CMakeLists.txt
index ed67b4007..39a6782bd 100644
--- a/tools/test/CMakeLists.txt
+++ b/tools/test/CMakeLists.txt
@@ -45,6 +45,11 @@ target_include_directories(tool-test PRIVATE
   ${PROJECT_SOURCE_DIR}/tools-c++/src
 )
 
+target_compile_definitions(tool-test PRIVATE
+  "-DORC_EXAMPLE_DIR=${PROJECT_SOURCE_DIR}/examples"
+  "-DORC_BUILD_DIR=${PROJECT_BINARY_DIR}"
+)
+
 add_dependencies(tool-test tool-set)
 
 if (TEST_VALGRIND_MEMCHECK)
diff --git a/tools/test/ToolTest.cc b/tools/test/ToolTest.cc
index 8e3c546ea..38de3db0a 100644
--- a/tools/test/ToolTest.cc
+++ b/tools/test/ToolTest.cc
@@ -29,28 +29,9 @@
 #include <string>
 #include <vector>
 
-namespace {
-  const char* exampleDirectory = 0;
-  const char* buildDirectory = 0;
-}  // namespace
-
 GTEST_API_ int main(int argc, char** argv) {
   GOOGLE_PROTOBUF_VERIFY_VERSION;
   std::cout << "ORC version: " << ORC_VERSION << "\n";
-  if (argc >= 2) {
-    exampleDirectory = argv[1];
-  } else {
-    exampleDirectory = "../examples";
-  }
-  if (argc >= 3) {
-    buildDirectory = argv[2];
-  } else {
-    buildDirectory = ".";
-  }
-  std::cout << "example dir = " << exampleDirectory << "\n";
-  if (buildDirectory) {
-    std::cout << "build dir = " << buildDirectory << "\n";
-  }
   testing::InitGoogleTest(&argc, argv);
   int result = RUN_ALL_TESTS();
   google::protobuf::ShutdownProtobufLibrary();
@@ -77,12 +58,16 @@ int runProgram(const std::vector<std::string>& args, 
std::string& out, std::stri
   return WEXITSTATUS(status);
 }
 
+#define ORC_TOOL_TEST_STRINGIFY(path) ORC_TOOL_TEST_STR(path)
+#define ORC_TOOL_TEST_STR(path) #path
+
 /**
  * Get the name of the given example file.
  * @param name the simple name of the example file
  */
 std::string findExample(const std::string& name) {
-  std::string result = exampleDirectory;
+#define ORC_EXAMPLE_DIR_STR ORC_TOOL_TEST_STRINGIFY(ORC_EXAMPLE_DIR)
+  std::string result = ORC_EXAMPLE_DIR_STR;
   result += "/";
   result += name;
   return result;
@@ -93,7 +78,8 @@ std::string findExample(const std::string& name) {
  * @param name the simple name of the executable
  */
 std::string findProgram(const std::string& name) {
-  std::string result = buildDirectory;
+#define ORC_BUILD_DIR_STR ORC_TOOL_TEST_STRINGIFY(ORC_BUILD_DIR)
+  std::string result = ORC_BUILD_DIR_STR;
   result += "/";
   result += name;
   return result;
diff --git a/tools/test/meson.build b/tools/test/meson.build
index 80418daaf..542356558 100644
--- a/tools/test/meson.build
+++ b/tools/test/meson.build
@@ -36,5 +36,9 @@ exc = executable(
         gtest_dep,
         gmock_dep,
     ],
+    cpp_args: [
+        '-DORC_EXAMPLE_DIR=@0@'.format(meson.project_source_root() / 
'examples'),
+        '-DORC_BUILD_DIR=@0@'.format(meson.project_build_root()),
+    ],
 )
 test('tool-test', exc)

Reply via email to