Skip to contentSkip to conversation

mongodb: fix build with python 3.12

PATCH In review Awais Belal 3 participants 12 messages Mar 7, 2025 – Jan 14

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 mongodb: fix build with python 3.12

The moduleconfig.py build script uses the 'imp' module which is deprecated in favor of 'importlib' in python 3.12. This fixes the build issue by replacing the affected portion of the code and the package now builds fine on hosts with python 3.12.

---
 ...econfig.py-python-3.12-compatibility.patch | 57 +++++++++++++++++++
 .../recipes-dbs/mongodb/mongodb_git.bb        |  3 +-
 2 files changed, 58 insertions(+), 2 deletions(-)
 create mode 100644 meta-oe/dynamic-layers/meta-python/recipes-dbs/mongodb/mongodb/0001-moduleconfig.py-python-3.12-compatibility.patch
meta-oe/dynamic-layers/meta-python/recipes-dbs/mongodb/mongodb/0001-moduleconfig.py-python-3.12-compatibility.patch new file +57 -0
new file mode 100644
index 0000000000..51926b9d2e
@@ -0,0 +1,57 @@
+From 37580777bc5294d606584f3731d9f5f5425bb587 Mon Sep 17 00:00:00 2001
+From: Awais B <[email protected]>
+Date: Tue, 4 Mar 2025 11:27:10 +0000
+Subject: [PATCH] moduleconfig.py: python 3.12 compatibility
+
+The imp module was deprecated in python 3.4 and is dropped
+with python 3.12. We now need to use importlib for the
+purpose of manipulating/loading modules.
+
+Upstream-Status: Pending
+Signed-off-by: Awais B <[email protected]>
+---
+ buildscripts/moduleconfig.py | 21 ++++++++++++++-------
+ 1 file changed, 14 insertions(+), 7 deletions(-)
+
+diff --git a/buildscripts/moduleconfig.py b/buildscripts/moduleconfig.py
+index b4d0bba0490..69dd91ab30d 100644
+--- a/buildscripts/moduleconfig.py
++++ b/buildscripts/moduleconfig.py
+@@ -27,7 +27,8 @@ MongoDB SConscript files do.
+ __all__ = ('discover_modules', 'discover_module_directories', 'configure_modules',
+            'register_module_test')  # pylint: disable=undefined-all-variable
+ 
+-import imp
++import importlib
++import sys
+ import inspect
+ import os
+ 
+@@ -71,12 +72,18 @@ def discover_modules(module_root, allowed_modules):
+             print("adding module: %s" % (name))
+             fp = open(build_py, "r")
+             try:
+-                module = imp.load_module("module_" + name, fp, build_py,
+-                                         (".py", "r", imp.PY_SOURCE))
+-                if getattr(module, "name", None) is None:
+-                    module.name = name
+-                found_modules.append(module)
+-                found_module_names.append(name)
++                module_name = "module_" + name
++                module_spec = importlib.util.spec_from_file_location(module_name, build_py)
++
++                if module_spec is not None:
++                    module = importlib.util.module_from_spec(module_spec)
++                    sys.modules[module_name] = module
++                    module_spec.loader.exec_module(module)
++
++                    if not hasattr(module, "name"):
++                        module.name = name
++                    found_modules.append(module)
++                    found_module_names.append(name)
+             finally:
+                 fp.close()
+         except (FileNotFoundError, IOError):
+-- 
+2.34.1
+
meta-oe/dynamic-layers/meta-python/recipes-dbs/mongodb/mongodb_git.bb +1 -2
index ee5c77a85d..f7fd881713 100644
@@ -36,6 +36,7 @@ SRC_URI = "git://github.com/mongodb/mongo.git;branch=v4.4;protocol=https \
            file://0001-apply-msvc-workaround-for-clang-16.patch \
            file://0001-Fix-type-mismatch-on-32bit-arches.patch \
            file://0001-Fix-build-on-32bit.patch \
+           file://0001-moduleconfig.py-python-3.12-compatibility.patch \
            "
 SRC_URI:append:libc-musl ="\
            file://0001-Mark-one-of-strerror_r-implementation-glibc-specific.patch \
@@ -145,5 +146,3 @@ SYSTEMD_SERVICE:${PN} = "mongod.service"
 FILES:${PN} += "${nonarch_libdir}/tmpfiles.d"
 
 RDEPENDS:${PN} += "tzdata-core"
-
-SKIP_RECIPE[mongodb] ?= "Needs porting to python 3.12"
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/2 mongodb: update to 4.4.29

Move on to 4.4.29 and drop a patch that is not applicable anymore.

---
 ...001-free_mon-Include-missing-cstdint.patch | 28 -------------------
 .../recipes-dbs/mongodb/mongodb_git.bb        |  7 ++---
 2 files changed, 3 insertions(+), 32 deletions(-)
 delete mode 100644 meta-oe/dynamic-layers/meta-python/recipes-dbs/mongodb/mongodb/0001-free_mon-Include-missing-cstdint.patch
meta-oe/dynamic-layers/meta-python/recipes-dbs/mongodb/mongodb/0001-free_mon-Include-missing-cstdint.patch deleted +0 -28
deleted file mode 100644
index 8cee14889f..0000000000
@@ -1,28 +0,0 @@
-From 5d8218b8a1b5bc71e2a0cf543a000e194daba599 Mon Sep 17 00:00:00 2001
-From: Khem Raj <[email protected]>
-Date: Sun, 29 Jan 2023 17:15:30 -0800
-Subject: [PATCH] free_mon: Include missing <cstdint>
-
-gcc 13 moved some includes around and as a result <cstdint> is no
-longer transitively included [1]. Explicitly include it
-for uintXX_t.
-
-[1] https://gcc.gnu.org/gcc-13/porting_to.html#header-dep-changes
-
-Signed-off-by: Khem Raj <[email protected]>
-
-Upstream-Status: Pending
----
- src/mongo/db/free_mon/free_mon_options.h | 1 +
- 1 file changed, 1 insertion(+)
-
---- a/src/mongo/db/free_mon/free_mon_options.h
-+++ b/src/mongo/db/free_mon/free_mon_options.h
-@@ -29,6 +29,7 @@
- 
- #pragma once
- 
-+#include <cstdint>
- #include <string>
- #include <vector>
- 
meta-oe/dynamic-layers/meta-python/recipes-dbs/mongodb/mongodb_git.bb +3 -4
index f7fd881713..5d904dd4f9 100644
@@ -11,9 +11,9 @@ DEPENDS = "openssl libpcap zlib boost curl python3 \
 
 inherit scons dos2unix siteinfo python3native systemd useradd
 
-PV = "4.4.24"
-#v4.4.24
-SRCREV = "0b86b9b7b42ad9970c5f818c527dd86c0634243a"
+PV = "4.4.29"
+#v4.4.29
+SRCREV = "89d6ffe6fc67b36fd47aff6425087003966588e3"
 SRC_URI = "git://github.com/mongodb/mongo.git;branch=v4.4;protocol=https \
            file://0001-Tell-scons-to-use-build-settings-from-environment-va.patch \
            file://0001-Use-long-long-instead-of-int64_t.patch \
@@ -32,7 +32,6 @@ SRC_URI = "git://github.com/mongodb/mongo.git;branch=v4.4;protocol=https \
            file://0001-add-explict-static_cast-size_t-to-maxMemoryUsageByte.patch \
            file://0001-server-Adjust-the-cache-alignment-assumptions.patch \
            file://0001-The-std-lib-unary-binary_function-base-classes-are-d.patch \
-           file://0001-free_mon-Include-missing-cstdint.patch \
            file://0001-apply-msvc-workaround-for-clang-16.patch \
            file://0001-Fix-type-mismatch-on-32bit-arches.patch \
            file://0001-Fix-build-on-32bit.patch \
Signature · 1 line
2.34.1
#2 lore raw

Re: [oe] [meta-oe][scarthgap][PATCH 2/2] mongodb: update to 4.4.29

I am seeing this build failure on master

| File "/srv/pokybuild/yocto-worker/meta-oe/build/build/tmp/work/core2-64-poky-linux/mongodb/4.4.29/git/src/mongo/base/generate_error_codes.py", line 31, in <module>
| from Cheetah.Template import Template
| File "/srv/pokybuild/yocto-worker/meta-oe/build/build/tmp/work/core2-64-poky-linux/mongodb/4.4.29/recipe-sysroot-native/usr/lib/python3.13/site-packages/Cheetah/Template.py", line 24, in <module>

| import cgi # Used by .webInput() if the template is a CGI script.
| ^^^^^^^^^^
| ModuleNotFoundError: No module named 'cgi'
| Generating build/59f4f0dd/mongo/db/repl/repl_settings_gen.cpp
| scons: *** [build/59f4f0dd/mongo/base/error_codes.h] Error 1
| scons: building terminated because of errors.
| build/59f4f0dd/mongo/base/error_codes.h failed: Error 1

For details see

https://autobuilder.yoctoproject.org/valkyrie/#/builders/81/builds/441/steps/15/logs/stdio

Quoted 81 lines · Awais Belal via lists.openembedded.org

Move on to 4.4.29 and drop a patch that is not applicable anymore.

---
 ...001-free_mon-Include-missing-cstdint.patch | 28 -------------------
 .../recipes-dbs/mongodb/mongodb_git.bb        |  7 ++---
 2 files changed, 3 insertions(+), 32 deletions(-)
 delete mode 100644 meta-oe/dynamic-layers/meta-python/recipes-dbs/mongodb/mongodb/0001-free_mon-Include-missing-cstdint.patch
meta-oe/dynamic-layers/meta-python/recipes-dbs/mongodb/mongodb/0001-free_mon-Include-missing-cstdint.patch deleted +0 -28
deleted file mode 100644
index 8cee14889f..0000000000
@@ -1,28 +0,0 @@
-From 5d8218b8a1b5bc71e2a0cf543a000e194daba599 Mon Sep 17 00:00:00 2001
-From: Khem Raj <[email protected]>
-Date: Sun, 29 Jan 2023 17:15:30 -0800
-Subject: [PATCH] free_mon: Include missing <cstdint>
-
-gcc 13 moved some includes around and as a result <cstdint> is no
-longer transitively included [1]. Explicitly include it
-for uintXX_t.
-
-[1] https://gcc.gnu.org/gcc-13/porting_to.html#header-dep-changes
-
-Signed-off-by: Khem Raj <[email protected]>
-
-Upstream-Status: Pending
----
- src/mongo/db/free_mon/free_mon_options.h | 1 +
- 1 file changed, 1 insertion(+)
-
---- a/src/mongo/db/free_mon/free_mon_options.h
-+++ b/src/mongo/db/free_mon/free_mon_options.h
-@@ -29,6 +29,7 @@
-
- #pragma once
-
-+#include <cstdint>
- #include <string>
- #include <vector>
-
meta-oe/dynamic-layers/meta-python/recipes-dbs/mongodb/mongodb_git.bb +3 -5
index f7fd881713..5d904dd4f9 100644
@@ -11,9 +11,9 @@ DEPENDS = "openssl libpcap zlib boost curl python3 \
 
 inherit scons dos2unix siteinfo python3native systemd useradd
 
-PV = "4.4.24"
-#v4.4.24
-SRCREV = "0b86b9b7b42ad9970c5f818c527dd86c0634243a"
+PV = "4.4.29"
+#v4.4.29
+SRCREV = "89d6ffe6fc67b36fd47aff6425087003966588e3"
 SRC_URI = "git://github.com/mongodb/mongo.git;branch=v4.4;protocol=https \
            file://0001-Tell-scons-to-use-build-settings-from-environment-va.patch \
            file://0001-Use-long-long-instead-of-int64_t.patch \
@@ -32,7 +32,6 @@ SRC_URI = "git://github.com/mongodb/mongo.git;branch=v4.4;protocol=https \
            file://0001-add-explict-static_cast-size_t-to-maxMemoryUsageByte.patch \
            file://0001-server-Adjust-the-cache-alignment-assumptions.patch \
            file://0001-The-std-lib-unary-binary_function-base-classes-are-d.patch \
-           file://0001-free_mon-Include-missing-cstdint.patch \
            file://0001-apply-msvc-workaround-for-clang-16.patch \
            file://0001-Fix-type-mismatch-on-32bit-arches.patch \
            file://0001-Fix-build-on-32bit.patch \
--

2.34.1

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#115781): https://lists.openembedded.org/g/openembedded-devel/message/115781
Mute This Topic: https://lists.openembedded.org/mt/111564957/1997914
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#3 lore raw

Re: [oe] [meta-oe][scarthgap][PATCH 2/2] mongodb: update to 4.4.29

Quoted 11 lines

I am seeing this build failure on master

| File "/srv/pokybuild/yocto-worker/meta-oe/build/build/tmp/work/core2-64-poky-linux/mongodb/4.4.29/git/src/mongo/base/generate_error_codes.py", line 31, in <module>
| from Cheetah.Template import Template
| File "/srv/pokybuild/yocto-worker/meta-oe/build/build/tmp/work/core2-64-poky-linux/mongodb/4.4.29/recipe-sysroot-native/usr/lib/python3.13/site-packages/Cheetah/Template.py", line 24, in <module>

Quoted 9 lines
| import cgi # Used by .webInput() if the template is a CGI script.
| ^^^^^^^^^^
| ModuleNotFoundError: No module named 'cgi'
| Generating build/59f4f0dd/mongo/db/repl/repl_settings_gen.cpp
| scons: *** [build/59f4f0dd/mongo/base/error_codes.h] Error 1
| scons: building terminated because of errors.
| build/59f4f0dd/mongo/base/error_codes.h failed: Error 1

The changeset was intended for scarthgap and I haven't made sure if master
builds. Is that a requirement? The cgi module was dropped in python 3.13 which is what master is following at this point. I might send a separate series for master once I move on to that.

#4 lore raw

Re: [oe] [meta-oe][scarthgap][PATCH 2/2] mongodb: update to 4.4.29

Quoted 19 lines · Awais Belal
Quoted 10 lines

I am seeing this build failure on master

| File "/srv/pokybuild/yocto-worker/meta-oe/build/build/tmp/work/core2-64-poky-linux/mongodb/4.4.29/git/src/mongo/base/generate_error_codes.py", line 31, in <module>
| from Cheetah.Template import Template
| File "/srv/pokybuild/yocto-worker/meta-oe/build/build/tmp/work/core2-64-poky-linux/mongodb/4.4.29/recipe-sysroot-native/usr/lib/python3.13/site-packages/Cheetah/Template.py", line 24, in <module>

Quoted 9 lines
| import cgi # Used by .webInput() if the template is a CGI script.
| ^^^^^^^^^^
| ModuleNotFoundError: No module named 'cgi'
| Generating build/59f4f0dd/mongo/db/repl/repl_settings_gen.cpp
| scons: *** [build/59f4f0dd/mongo/base/error_codes.h] Error 1
| scons: building terminated because of errors.
| build/59f4f0dd/mongo/base/error_codes.h failed: Error 1
Quoted 5 lines

The changeset was intended for scarthgap and I haven't made sure if
master builds. Is that a requirement? The cgi module was dropped in python 3.13 which is what master is following at this point. I might send a separate series for master once I move on to that.

Patches are routed by master to release branches if they are needed in master. They are done for master and then backported

Quoted 1 line
#5 lore raw

Re: [oe] [meta-oe][scarthgap][PATCH 2/2] mongodb: update to 4.4.29

Quoted 13 lines
Quoted 8 lines
Quoted 3 lines

The changeset was intended for scarthgap and I haven't made sure if
master builds. Is that a requirement? The cgi module was dropped in python 3.13 which is what master is following at this point. I might send a separate series for master once I move on to that.

Patches are routed by master to release branches if they are needed in master. They are done for master and then backported

Quoted 1 line

Hi Khem,
I've just sent
https://patchwork.yoctoproject.org/project/oe/list/?series=32428 which coupled with the changes here fixes mongodb build for master as well. Kindly note that the other series (
https://patchwork.yoctoproject.org/project/oe/list/?series=32428) is not needed for scarthgap.

Signature · 2 lines
Regards,
Awais Belal
#6 lore raw

Re: [oe] [meta-oe][scarthgap][PATCH 2/2] mongodb: update to 4.4.29

there still are errors see

https://autobuilder.yoctoproject.org/valkyrie/#/builders/81/builds/452/steps/15/logs/stdio

Quoted 15 lines · Awais Belal
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

The changeset was intended for scarthgap and I haven't made sure if master builds. Is that a requirement? The cgi module was dropped in python 3.13 which is what master is following at this point. I might send a separate series for master once I move on to that.

Patches are routed by master to release branches if they are needed in master. They are done for master and then backported

Hi Khem,
I've just sent https://patchwork.yoctoproject.org/project/oe/list/?series=32428 which coupled with the changes here fixes mongodb build for master as well. Kindly note that the other series (https://patchwork.yoctoproject.org/project/oe/list/?series=32428) is not needed for scarthgap.

--
Regards,
Awais Belal

#7 lore raw

Re: [oe] [meta-oe][scarthgap][PATCH 2/2] mongodb: update to 4.4.29

Awais: any update on this? the 1/2 is already applied in scarthgap, but in walnascar and master it's still skipped with:
SKIP_RECIPE[mongodb] ?= "Needs porting to python 3.12"

and there is also:

ERROR: mongodb-4.4.24-r0 do_package_qa: QA Issue: File /usr/bin/mongod in package mongodb contains reference to TMPDIR
File /usr/bin/mongos in package mongodb contains reference to TMPDIR [buildpaths]
ERROR: mongodb-4.4.24-r0 do_package_qa: Fatal QA errors were found, failing task.

even in scarthgap (where it usually isn't fatal error, but will need to be fixed for walnascar - I haven't checked the new version from this review yet).

Regards,

Quoted 30 lines · Khem Raj via lists.openembedded.org

there still are errors see

https://autobuilder.yoctoproject.org/valkyrie/#/builders/81/builds/452/steps/15/logs/stdio

Quoted 9 lines · Awais Belal
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

The changeset was intended for scarthgap and I haven't made sure if master builds. Is that a requirement? The cgi module was dropped in python 3.13 which is what master is following at this point. I might send a separate series for master once I move on to that.

Patches are routed by master to release branches if they are needed in master. They are done for master and then backported

Quoted 6 lines

Hi Khem,
I've just sent https://patchwork.yoctoproject.org/project/oe/list/?series=32428 which coupled with the changes here fixes mongodb build for master as well. Kindly note that the other series (https://patchwork.yoctoproject.org/project/oe/list/?series=32428) is not needed for scarthgap.

--
Regards,
Awais Belal

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#115976): https://lists.openembedded.org/g/openembedded-devel/message/115976
Mute This Topic: https://lists.openembedded.org/mt/111564957/3617156
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#8 lore raw

Re: [oe] [meta-oe][scarthgap][PATCH 2/2] mongodb: update to 4.4.29

Quoted 15 lines

Awais: any update on this? the 1/2 is already applied in scarthgap, but in walnascar and master it's still skipped with:
SKIP_RECIPE[mongodb] ?= "Needs porting to python 3.12"

and there is also:

ERROR: mongodb-4.4.24-r0 do_package_qa: QA Issue: File /usr/bin/mongod in package mongodb contains reference to TMPDIR
File /usr/bin/mongos in package mongodb contains reference to TMPDIR [buildpaths]
ERROR: mongodb-4.4.24-r0 do_package_qa: Fatal QA errors were found, failing task.

Quoted 5 lines

even in scarthgap (where it usually isn't fatal error, but will need to be fixed for walnascar - I haven't checked the new version from this review yet).

Hi Martin,
I believe the only issues left here are the TMPDIR references but I haven't been able to pick those up just yet. I also tried pinging Khem for some pointers on TMPDIR issues as I myself haven't had an encounter with those earlier. Any suggestions on how I should go about debugging/fixing them?

Signature · 2 lines
Regards,
Awais Belal
#9 lore raw

Re: [oe] [meta-oe][scarthgap][PATCH 2/2] mongodb: update to 4.4.29

Quoted 14 lines · Awais Belal

Awais: any update on this? the 1/2 is already applied in scarthgap, but in walnascar and master it's still skipped with:
SKIP_RECIPE[mongodb] ?= "Needs porting to python 3.12"

and there is also:

ERROR: mongodb-4.4.24-r0 do_package_qa: QA Issue: File /usr/bin/mongod in package mongodb contains reference to TMPDIR
File /usr/bin/mongos in package mongodb contains reference to TMPDIR [buildpaths]
ERROR: mongodb-4.4.24-r0 do_package_qa: Fatal QA errors were found, failing task.

Quoted 8 lines

even in scarthgap (where it usually isn't fatal error, but will need to be fixed for walnascar - I haven't checked the new version from this review yet).

Hi Martin,
I believe the only issues left here are the TMPDIR references but I haven't been able to pick those up just yet. I also tried pinging Khem for some pointers on TMPDIR issues as I myself haven't had an encounter with those earlier. Any suggestions on how I should go about debugging/ fixing them?

I did not ignore you, :) I just did not have time to help out. There are
some patterns of TMPDIR embedding into target packages, but it needs to be root caused. If you look through repo, you might find some help on what different use cases have been found and how they were handled.

Quoted 3 lines
Signature · 2 lines
Regards,
Awais Belal
#10 lore raw

Re: [oe] [meta-oe][scarthgap][PATCH 2/2] mongodb: update to 4.4.29

Hi Khem,

I did not ignore you, :) I just did not have time to help out. There are

Quoted 4 lines

some patterns of TMPDIR embedding into target packages, but it needs to be root caused. If you look through repo, you might find some help on what different use cases have been found and how they were handled.

Sorry for being so so late with this but I now have a patch for mongodb src which coupled with the earlier changes I submitted will allow us to build mongodb 4.4.29 on OE cleanly. The additional patch is to fix the last outstanding TMPDIR issue that we saw around last time. What would be the best way for submission here? i.e. should I just send over the patch or redo the whole series for master?

Signature · 2 lines
Regards,
Awais Belal
#11 lore raw

Re: [oe] [meta-oe][scarthgap][PATCH 2/2] mongodb: update to 4.4.29

Quoted 8 lines · Awais Belal

Hi Khem,

I did not ignore you, :) I just did not have time to help out. There are

Quoted 4 lines

some patterns of TMPDIR embedding into target packages, but it needs to be root caused. If you look through repo, you might find some help on what different use cases have been found and how they were handled.

Quoted 7 lines

Sorry for being so so late with this but I now have a patch for mongodb src which coupled with the earlier changes I submitted will allow us to build mongodb 4.4.29 on OE cleanly. The additional patch is to fix the last outstanding TMPDIR issue that we saw around last time. What would be the best way for submission here? i.e. should I just send over the patch or redo the whole series for master?

I think do the changes on top of latest meta-oe master and submit again

Quoted 5 lines

--
Regards,
Awais Belal