]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: patch boost source to support python 3.10 47027/head
authorKefu Chai <tchaikov@gmail.com>
Sat, 9 Jul 2022 01:58:32 +0000 (21:58 -0400)
committerKefu Chai <tchaikov@gmail.com>
Sat, 16 Jul 2022 03:57:17 +0000 (11:57 +0800)
Python 3.10 doesn't include the _Py_fopen() function.  Boost
1.75.0 includes a patch which switches to using fopen() for
python versions >= 3.1, but Pacific is using boost 1.73.0,
which still uses _Py_fopen().  This commit adds the boost
1.75.0 patch to `make-dist`, so it's applied to our copy of
the boost source which is then used when building RPM packages.

the included patch comes from
https://github.com/boostorg/python/commit/d9f06052e28873037db7f98629bce72182a42410

Fixes: https://tracker.ceph.com/issues/56466
please note, this change is not cherry-picked from the
"main" branch. as we use boost 1.75 already in that branch,
but to minimize the risk of switching boost from 1.73 to
1.75 in a LTS branch like pacific, we just add a fix to
address this particular issue in boost 1.73.

Signed-off-by: Tim Serong <tserong@suse.com>
Signed-off-by: Kefu Chai <tchaikov@gmail.com>
cmake/modules/BuildBoost.cmake
cmake/modules/boost-python-use-public-api-for-filename.patch [new file with mode: 0644]

index 320c2dcd524977b321cd593daa5d708e85792c0e..f84428921013bf16f1941b690b9c4291e648f351 100644 (file)
@@ -11,6 +11,9 @@
 #  Boost_USE_MULTITHREADED : boolean (default: OFF)
 #  BOOST_J: integer (defanult 1)
 
+# CMAKE_CURRENT_FUNCTION_LIST_DIR is introduced by cmake 3.17, but ubuntu comes with 3.16
+set(_build_boost_list_dir "${CMAKE_CURRENT_LIST_DIR}")
+
 function(check_boost_version source_dir expected_version)
   set(version_hpp "${source_dir}/boost/version.hpp")
   if(NOT EXISTS ${version_hpp})
@@ -167,10 +170,12 @@ function(do_build_boost version)
       URL_HASH SHA256=${boost_sha256}
       DOWNLOAD_NO_PROGRESS 1)
   endif()
+  find_program(PATCH_EXECUTABLE patch)
   # build all components in a single shot
   include(ExternalProject)
   ExternalProject_Add(Boost
     ${source_dir}
+    PATCH_COMMAND ${PATCH_EXECUTABLE} -p3 -i ${_build_boost_list_dir}/boost-python-use-public-api-for-filename.patch
     CONFIGURE_COMMAND CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER} ${configure_command}
     BUILD_COMMAND CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER} ${build_command}
     BUILD_IN_SOURCE 1
diff --git a/cmake/modules/boost-python-use-public-api-for-filename.patch b/cmake/modules/boost-python-use-public-api-for-filename.patch
new file mode 100644 (file)
index 0000000..899a023
--- /dev/null
@@ -0,0 +1,38 @@
+From d9f06052e28873037db7f98629bce72182a42410 Mon Sep 17 00:00:00 2001
+From: Pat Riehecky <riehecky@fnal.gov>
+Date: Mon, 29 Jun 2020 10:51:58 -0500
+Subject: [PATCH] Convert Python 3.1+ to use public C API for filenames
+---
+ src/exec.cpp | 16 ++++++++++++----
+ 1 file changed, 12 insertions(+), 4 deletions(-)
+diff --git a/src/exec.cpp b/src/exec.cpp
+index 171c6f4189..b2eabe59f6 100644
+--- a/src/boost/libs/python/src/exec.cpp
++++ b/src/boost/libs/python/src/exec.cpp
+@@ -104,14 +104,22 @@ object BOOST_PYTHON_DECL exec_file(char const *filename, object global, object l
+   if (local.is_none()) local = global;
+   // should be 'char const *' but older python versions don't use 'const' yet.
+   char *f = const_cast<char *>(filename);
+-  // Let python open the file to avoid potential binary incompatibilities.
+-#if PY_VERSION_HEX >= 0x03040000
+-  FILE *fs = _Py_fopen(f, "r");
++#if PY_VERSION_HEX >= 0x03010000
++  // Let python manage any UTF bits to avoid potential incompatibilities.
++  PyObject *fo = Py_BuildValue("s", f);
++  PyObject *fb = Py_None;
++  PyUnicode_FSConverter(fo, &fb);
++  f = PyBytes_AsString(fb);
++  FILE *fs = fopen(f, "r");
++  Py_DECREF(fo);
++  Py_DECREF(fb);
+ #elif PY_VERSION_HEX >= 0x03000000
++  // Let python open the file to avoid potential binary incompatibilities.
+   PyObject *fo = Py_BuildValue("s", f);
+-  FILE *fs = _Py_fopen(fo, "r");
++  FILE *fs = _Py_fopen(fo, "r"); // Private CPython API
+   Py_DECREF(fo);
+ #else
++  // Let python open the file to avoid potential binary incompatibilities.
+   PyObject *pyfile = PyFile_FromString(f, const_cast<char*>("r"));
+   if (!pyfile) throw std::invalid_argument(std::string(f) + " : no such file");
+   python::handle<> file(pyfile);