From dc14e97d63d47ccb56873b7d1bee6f5e50f1c185 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Fri, 8 Jul 2022 21:58:32 -0400 Subject: [PATCH] cmake: patch boost source to support python 3.10 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 Signed-off-by: Kefu Chai --- cmake/modules/BuildBoost.cmake | 5 +++ ...t-python-use-public-api-for-filename.patch | 38 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 cmake/modules/boost-python-use-public-api-for-filename.patch diff --git a/cmake/modules/BuildBoost.cmake b/cmake/modules/BuildBoost.cmake index 320c2dcd52497..f84428921013b 100644 --- a/cmake/modules/BuildBoost.cmake +++ b/cmake/modules/BuildBoost.cmake @@ -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 index 0000000000000..899a02384d8a8 --- /dev/null +++ b/cmake/modules/boost-python-use-public-api-for-filename.patch @@ -0,0 +1,38 @@ +From d9f06052e28873037db7f98629bce72182a42410 Mon Sep 17 00:00:00 2001 +From: Pat Riehecky +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(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("r")); + if (!pyfile) throw std::invalid_argument(std::string(f) + " : no such file"); + python::handle<> file(pyfile); -- 2.39.5