From 5586dda17823fae0695d3eded69b46ebe7bc3455 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Sat, 23 Oct 2021 13:40:48 +0200 Subject: [PATCH 1/2] bpo-45548: Put Modules/Setup extensions into builddir Modules/Setup used to put shared extensions into ``./Modules/`` directory. Now it puts the shared extensions in the same directory library directory ``./build/lib.$plat-$ver`` as distutils. The change makes the shared modules importable and fixes build issues. Signed-off-by: Christian Heimes --- Makefile.pre.in | 1 + Modules/makesetup | 18 +++++++++++++++--- setup.py | 5 +++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in index 7d403663cec0b8d..6cd8af128015e6b 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -21,6 +21,7 @@ # === Variables set by makesetup === MODBUILT_NAMES= _MODBUILT_NAMES_ +MODBUILT_SHARED_NAMES= _MODBUILT_SHARED_NAMES_ MODDISABLED_NAMES= _MODDISABLED_NAMES_ MODOBJS= _MODOBJS_ MODLIBS= _MODLIBS_ diff --git a/Modules/makesetup b/Modules/makesetup index 849f15fddaab0aa..085ed47ff5c61e3 100755 --- a/Modules/makesetup +++ b/Modules/makesetup @@ -111,9 +111,11 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' | trap 'rm -f $rulesf' 0 1 2 3 echo " # Rules appended by makesetup +\$(SHAREDMODS): pybuilddir.txt " >$rulesf DEFS= BUILT= + BUILT_SHARED= DISABLED= MODS= SHAREDMODS= @@ -244,9 +246,15 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' | esac for mod in $mods do - file="$srcdir/$mod\$(EXT_SUFFIX)" case $doconfig in - no) SHAREDMODS="$SHAREDMODS $file";; + no) + file="\$(PYBUILDDIR)/$mod\$(EXT_SUFFIX)" + SHAREDMODS="$SHAREDMODS $file" + BUILT_SHARED="$BUILT_SHARED $mod" + ;; + *) + file="\$(srcdir)/$mod\$(EXT_SUFFIX)" + ;; esac rule="$file: $objs" rule="$rule; \$(BLDSHARED) $objs $libs $ExtraLibs -o \$@" @@ -256,7 +264,10 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' | case $SHAREDMODS in '') ;; - *) DEFS="SHAREDMODS=$SHAREDMODS$NL$DEFS";; + *) + DEFS="PYBUILDDIR=\$(file < pybuilddir.txt)$NL$DEFS" + DEFS="SHAREDMODS=$SHAREDMODS$NL$DEFS" + ;; esac case $noobjects in @@ -296,6 +307,7 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' | str="# Generated automatically from $makepre by makesetup." echo "$str" >>$sedf echo "s%_MODBUILT_NAMES_%$BUILT%" >>$sedf + echo "s%_MODBUILT_SHARED_NAMES_%$BUILT_SHARED%" >>$sedf echo "s%_MODDISABLED_NAMES_%$DISABLED%" >>$sedf echo "s%_MODOBJS_%$OBJS%" >>$sedf echo "s%_MODLIBS_%$LIBS%" >>$sedf diff --git a/setup.py b/setup.py index f32dd4c6e5e1455..84155ff88b44fef 100644 --- a/setup.py +++ b/setup.py @@ -431,6 +431,7 @@ def remove_configured_extensions(self): # built modules and the disabled modules as configured by the Setup # files. sysconf_built = sysconfig.get_config_var('MODBUILT_NAMES').split() + sysconf_built_shared = sysconfig.get_config_var('MODBUILT_SHARED_NAMES').split() sysconf_dis = sysconfig.get_config_var('MODDISABLED_NAMES').split() mods_built = [] @@ -449,6 +450,10 @@ def remove_configured_extensions(self): mods_configured] # Remove the shared libraries built by a previous build. for ext in mods_configured: + # don't remove shared extensions that have been + # declared in Modules/Setup and built by Makefile + if ext.name in sysconf_built_shared: + continue fullpath = self.get_ext_fullpath(ext.name) if os.path.exists(fullpath): os.unlink(fullpath) From 632bb41059e841f19115d3b143c7684810e7e096 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Mon, 25 Oct 2021 13:48:36 +0200 Subject: [PATCH 2/2] blurb --- .../NEWS.d/next/Build/2021-10-25-13-48-27.bpo-45548.kSFSrQ.rst | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Misc/NEWS.d/next/Build/2021-10-25-13-48-27.bpo-45548.kSFSrQ.rst diff --git a/Misc/NEWS.d/next/Build/2021-10-25-13-48-27.bpo-45548.kSFSrQ.rst b/Misc/NEWS.d/next/Build/2021-10-25-13-48-27.bpo-45548.kSFSrQ.rst new file mode 100644 index 000000000000000..18d7c405fe70ee5 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2021-10-25-13-48-27.bpo-45548.kSFSrQ.rst @@ -0,0 +1,3 @@ +``Modules/Setup`` now puts shared extensions in the same directory as +distutils. Before the change, ``makesetup`` created shared libraries in +``Modules/`` directory, which is not on the import path.