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

kou pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new 755fb9f31a ARROW-15422: [Packaging][RPM][deb] Add support for GDB 
plugin (#13477)
755fb9f31a is described below

commit 755fb9f31a43b26e74ac82622e4667279dc442d6
Author: Sutou Kouhei <[email protected]>
AuthorDate: Sun Jul 3 14:48:33 2022 +0900

    ARROW-15422: [Packaging][RPM][deb] Add support for GDB plugin (#13477)
    
    Authored-by: Sutou Kouhei <[email protected]>
    Signed-off-by: Sutou Kouhei <[email protected]>
---
 cpp/CMakeLists.txt                                 | 10 ++++---
 cpp/cmake_modules/BuildUtils.cmake                 | 11 ++++----
 cpp/cmake_modules/ThirdpartyToolchain.cmake        |  2 +-
 cpp/gdb_arrow.py                                   |  3 ++-
 cpp/src/arrow/CMakeLists.txt                       | 31 ++++++++++++++++++++--
 cpp/src/arrow/libarrow_gdb.py.in                   | 28 +++++++++++++++++++
 .../apache-arrow/debian/libarrow-dev.install       |  2 ++
 .../linux-packages/apache-arrow/yum/arrow.spec.in  |  4 +++
 8 files changed, 78 insertions(+), 13 deletions(-)

diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt
index fc8f74db53..6fc9f1a95b 100644
--- a/cpp/CMakeLists.txt
+++ b/cpp/CMakeLists.txt
@@ -119,12 +119,14 @@ if(IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}")
 else()
   set(ARROW_PKG_CONFIG_LIBDIR "\${prefix}/${CMAKE_INSTALL_LIBDIR}")
 endif()
+set(ARROW_GDB_DIR "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/gdb")
+set(ARROW_FULL_GDB_DIR "${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}/gdb")
+set(ARROW_GDB_AUTO_LOAD_DIR "${CMAKE_INSTALL_DATADIR}/gdb/auto-load")
+set(ARROW_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
+set(ARROW_DOC_DIR "share/doc/${PROJECT_NAME}")
 
 set(BUILD_SUPPORT_DIR "${CMAKE_SOURCE_DIR}/build-support")
 
-set(ARROW_CMAKE_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
-set(ARROW_DOC_DIR "share/doc/${PROJECT_NAME}")
-
 set(ARROW_LLVM_VERSIONS
     "14.0"
     "13.0"
@@ -1002,6 +1004,8 @@ install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/../LICENSE.txt
               ${CMAKE_CURRENT_SOURCE_DIR}/../NOTICE.txt
               ${CMAKE_CURRENT_SOURCE_DIR}/README.md DESTINATION 
"${ARROW_DOC_DIR}")
 
+install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/gdb_arrow.py DESTINATION 
"${ARROW_GDB_DIR}")
+
 #
 # Validate and print out Arrow configuration options
 #
diff --git a/cpp/cmake_modules/BuildUtils.cmake 
b/cpp/cmake_modules/BuildUtils.cmake
index c153f3ab88..c2347ad681 100644
--- a/cpp/cmake_modules/BuildUtils.cmake
+++ b/cpp/cmake_modules/BuildUtils.cmake
@@ -425,13 +425,13 @@ function(ADD_ARROW_LIB LIB_NAME)
     set(TARGETS_CMAKE "${ARG_CMAKE_PACKAGE_NAME}Targets.cmake")
     install(EXPORT ${LIB_NAME}_targets
             FILE "${TARGETS_CMAKE}"
-            DESTINATION "${ARROW_CMAKE_INSTALL_DIR}")
+            DESTINATION "${ARROW_CMAKE_DIR}")
 
     set(CONFIG_CMAKE "${ARG_CMAKE_PACKAGE_NAME}Config.cmake")
     set(BUILT_CONFIG_CMAKE "${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_CMAKE}")
     configure_package_config_file("${CONFIG_CMAKE}.in" "${BUILT_CONFIG_CMAKE}"
-                                  INSTALL_DESTINATION 
"${ARROW_CMAKE_INSTALL_DIR}")
-    install(FILES "${BUILT_CONFIG_CMAKE}" DESTINATION 
"${ARROW_CMAKE_INSTALL_DIR}")
+                                  INSTALL_DESTINATION "${ARROW_CMAKE_DIR}")
+    install(FILES "${BUILT_CONFIG_CMAKE}" DESTINATION "${ARROW_CMAKE_DIR}")
 
     set(CONFIG_VERSION_CMAKE "${ARG_CMAKE_PACKAGE_NAME}ConfigVersion.cmake")
     set(BUILT_CONFIG_VERSION_CMAKE 
"${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_VERSION_CMAKE}")
@@ -439,8 +439,7 @@ function(ADD_ARROW_LIB LIB_NAME)
       "${BUILT_CONFIG_VERSION_CMAKE}"
       VERSION ${${PROJECT_NAME}_VERSION}
       COMPATIBILITY AnyNewerVersion)
-    install(FILES "${BUILT_CONFIG_VERSION_CMAKE}"
-            DESTINATION "${ARROW_CMAKE_INSTALL_DIR}")
+    install(FILES "${BUILT_CONFIG_VERSION_CMAKE}" DESTINATION 
"${ARROW_CMAKE_DIR}")
   endif()
 
   if(ARG_PKG_CONFIG_NAME)
@@ -907,7 +906,7 @@ endfunction()
 
 function(ARROW_INSTALL_CMAKE_FIND_MODULE MODULE)
   install(FILES "${ARROW_SOURCE_DIR}/cmake_modules/Find${MODULE}.cmake"
-          DESTINATION "${ARROW_CMAKE_INSTALL_DIR}")
+          DESTINATION "${ARROW_CMAKE_DIR}")
 endfunction()
 
 # Implementations of lisp "car" and "cdr" functions
diff --git a/cpp/cmake_modules/ThirdpartyToolchain.cmake 
b/cpp/cmake_modules/ThirdpartyToolchain.cmake
index c565db4655..245a458ef0 100644
--- a/cpp/cmake_modules/ThirdpartyToolchain.cmake
+++ b/cpp/cmake_modules/ThirdpartyToolchain.cmake
@@ -211,7 +211,7 @@ macro(provide_find_module PACKAGE_NAME)
   set(module_ "${CMAKE_SOURCE_DIR}/cmake_modules/Find${PACKAGE_NAME}.cmake")
   if(EXISTS "${module_}")
     message(STATUS "Providing CMake module for ${PACKAGE_NAME}")
-    install(FILES "${module_}" DESTINATION "${ARROW_CMAKE_INSTALL_DIR}")
+    install(FILES "${module_}" DESTINATION "${ARROW_CMAKE_DIR}")
   endif()
   unset(module_)
 endmacro()
diff --git a/cpp/gdb_arrow.py b/cpp/gdb_arrow.py
index 8a077a22e5..cd687ec8b2 100644
--- a/cpp/gdb_arrow.py
+++ b/cpp/gdb_arrow.py
@@ -2481,4 +2481,5 @@ def main():
     objfile.pretty_printers.append(arrow_pretty_print)
 
 
-main()
+if __name__ == '__main__':
+    main()
diff --git a/cpp/src/arrow/CMakeLists.txt b/cpp/src/arrow/CMakeLists.txt
index 4fc312a6e3..ac07ccf4b7 100644
--- a/cpp/src/arrow/CMakeLists.txt
+++ b/cpp/src/arrow/CMakeLists.txt
@@ -582,6 +582,33 @@ add_arrow_lib(arrow
               ${ARROW_STATIC_INSTALL_INTERFACE_LIBS}
               SHARED_INSTALL_INTERFACE_LIBS
               ${ARROW_SHARED_INSTALL_INTERFACE_LIBS})
+# The following block includes a code for MSYS2 but GDB on MSYS2 doesn't
+# auto load our plugin. GDB's auto load may not be supported on MSYS2...
+# So it's disabled for now.
+if(ARROW_BUILD_SHARED AND NOT WIN32)
+  configure_file(libarrow_gdb.py.in 
"${CMAKE_CURRENT_BINARY_DIR}/libarrow_gdb.py" @ONLY)
+  set(ARROW_GDB_AUTO_LOAD_LIBARROW_GDB_INSTALL FALSE)
+  if(WIN32)
+    find_program(cygpath "cygpath")
+    if(cygpath)
+      execute_process(COMMAND cygpath "${CMAKE_INSTALL_FULL_BINDIR}"
+                      OUTPUT_VARIABLE MSYS2_CMAKE_INSTALL_FULL_BINDIR
+                      OUTPUT_STRIP_TRAILING_WHITESPACE)
+      set(ARROW_GDB_AUTO_LOAD_LIBARROW_GDB_DIR
+          "${ARROW_GDB_AUTO_LOAD_DIR}${MSYS2_CMAKE_INSTALL_FULL_BINDIR}")
+      set(ARROW_GDB_AUTO_LOAD_LIBARROW_GDB_INSTALL TRUE)
+    endif()
+  else()
+    set(ARROW_GDB_AUTO_LOAD_LIBARROW_GDB_DIR
+        "${ARROW_GDB_AUTO_LOAD_DIR}/${CMAKE_INSTALL_FULL_LIBDIR}")
+    set(ARROW_GDB_AUTO_LOAD_LIBARROW_GDB_INSTALL TRUE)
+  endif()
+  if(ARROW_GDB_AUTO_LOAD_LIBARROW_GDB_INSTALL)
+    install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libarrow_gdb.py"
+            DESTINATION "${ARROW_GDB_AUTO_LOAD_LIBARROW_GDB_DIR}"
+            RENAME "$<TARGET_FILE_NAME:arrow_shared>-gdb.py")
+  endif()
+endif()
 
 add_dependencies(arrow ${ARROW_LIBRARIES})
 
@@ -657,11 +684,11 @@ arrow_install_all_headers("arrow")
 
 config_summary_cmake_setters("${CMAKE_CURRENT_BINARY_DIR}/ArrowOptions.cmake")
 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ArrowOptions.cmake
-        DESTINATION "${ARROW_CMAKE_INSTALL_DIR}")
+        DESTINATION "${ARROW_CMAKE_DIR}")
 
 # For backward compatibility for find_package(arrow)
 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/arrow-config.cmake
-        DESTINATION "${ARROW_CMAKE_INSTALL_DIR}")
+        DESTINATION "${ARROW_CMAKE_DIR}")
 
 #
 # Unit tests
diff --git a/cpp/src/arrow/libarrow_gdb.py.in b/cpp/src/arrow/libarrow_gdb.py.in
new file mode 100644
index 0000000000..1a2b0ca34e
--- /dev/null
+++ b/cpp/src/arrow/libarrow_gdb.py.in
@@ -0,0 +1,28 @@
+# -*- python -*-
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import sys
+import gdb
+
+dir_ = '@ARROW_FULL_GDB_DIR@'
+if not dir_ in sys.path:
+    sys.path.insert(0, dir_)
+
+from gdb_arrow import main
+main()
diff --git a/dev/tasks/linux-packages/apache-arrow/debian/libarrow-dev.install 
b/dev/tasks/linux-packages/apache-arrow/debian/libarrow-dev.install
index 26de6f7748..a1c15d7ed7 100644
--- a/dev/tasks/linux-packages/apache-arrow/debian/libarrow-dev.install
+++ b/dev/tasks/linux-packages/apache-arrow/debian/libarrow-dev.install
@@ -17,3 +17,5 @@ usr/lib/*/pkgconfig/arrow-filesystem.pc
 usr/lib/*/pkgconfig/arrow-json.pc
 usr/lib/*/pkgconfig/arrow-orc.pc
 usr/lib/*/pkgconfig/arrow.pc
+usr/share/arrow/gdb/
+usr/share/gdb/auto-load/
diff --git a/dev/tasks/linux-packages/apache-arrow/yum/arrow.spec.in 
b/dev/tasks/linux-packages/apache-arrow/yum/arrow.spec.in
index 01482984de..fac7737364 100644
--- a/dev/tasks/linux-packages/apache-arrow/yum/arrow.spec.in
+++ b/dev/tasks/linux-packages/apache-arrow/yum/arrow.spec.in
@@ -17,6 +17,8 @@
 # specific language governing permissions and limitations
 # under the License.
 
+%define __python /usr/bin/python3
+
 %define _amzn %{?amzn:%{amzn}}%{!?amzn:0}
 %define is_amazon_linux (%{_amzn} != 0)
 
@@ -300,6 +302,8 @@ Libraries and header files for Apache Arrow C++.
 %defattr(-,root,root,-)
 %doc README.md
 %license LICENSE.txt NOTICE.txt
+%{_datadir}/arrow/gdb/
+%{_datadir}/gdb/auto-load/
 %{_includedir}/arrow/
 %exclude %{_includedir}/arrow/dataset/
 %if %{use_flight}

Reply via email to