remove everything except what's needed for stdlib

This commit is contained in:
tcmal 2024-05-14 01:11:31 +01:00
parent e6a9076f9c
commit 4ea8b1c428
60 changed files with 4224 additions and 0 deletions

View file

@ -0,0 +1,34 @@
--- origsrc/Lib/ctypes/util.py 2007-09-14 15:05:26.000000000 -0500
+++ src/Lib/ctypes/util.py 2008-11-25 17:54:47.319296200 -0600
@@ -41,6 +41,20 @@
continue
return None
+elif sys.platform == "cygwin":
+ def find_library(name):
+ for libdir in ['/usr/lib', '/usr/local/lib']:
+ for libext in ['lib%s.dll.a' % name, 'lib%s.a' % name]:
+ implib = os.path.join(libdir, libext)
+ if not os.path.exists(implib):
+ continue
+ cmd = "dlltool -I " + implib + " 2>/dev/null"
+ res = os.popen(cmd).read().replace("\n","")
+ if not res:
+ continue
+ return res
+ return None
+
elif os.name == "posix":
# Andreas Degert's find functions, using gcc, /sbin/ldconfig, objdump
import re, tempfile, errno
@@ -157,6 +173,10 @@
print cdll.LoadLibrary("libcrypto.dylib")
print cdll.LoadLibrary("libSystem.dylib")
print cdll.LoadLibrary("System.framework/System")
+ elif sys.platform == "cygwin":
+ print cdll.LoadLibrary("cygbz2-1.dll")
+ print find_library("crypt")
+ print cdll.LoadLibrary("cygcrypt-0.dll")
else:
print cdll.LoadLibrary("libm.so")
print cdll.LoadLibrary("libcrypt.so")

View file

@ -0,0 +1,27 @@
--- origsrc/setup.py 2008-02-04 17:41:02.000000000 -0600
+++ src/setup.py 2008-07-02 02:11:28.671875000 -0500
@@ -1277,12 +1279,6 @@
include_dirs.append('/usr/X11/include')
added_lib_dirs.append('/usr/X11/lib')
- # If Cygwin, then verify that X is installed before proceeding
- if host_platform == 'cygwin':
- x11_inc = find_file('X11/Xlib.h', [], include_dirs)
- if x11_inc is None:
- return
-
# Check for BLT extension
if self.compiler.find_library_file(lib_dirs + added_lib_dirs,
'BLT8.0'):
@@ -1300,9 +1296,8 @@
if host_platform in ['aix3', 'aix4']:
libs.append('ld')
- # Finally, link with the X11 libraries (not appropriate on cygwin)
- if host_platform != "cygwin":
- libs.append('X11')
+ # Finally, link with the X11 libraries
+ libs.append('X11')
ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
define_macros=[('WITH_APPINIT', 1)] + defs,

View file

@ -0,0 +1,13 @@
--- origsrc/Modules/_ssl.c 2009-01-26 10:55:41.000000000 -0600
+++ src/Modules/_ssl.c 2009-08-20 00:04:59.346816700 -0500
@@ -15,6 +15,10 @@
#include "Python.h"
+#ifdef __CYGWIN__
+#undef WITH_THREAD
+#endif
+
#ifdef WITH_THREAD
#include "pythread.h"
#define PySSL_BEGIN_ALLOW_THREADS { \

View file

@ -0,0 +1,41 @@
--- Python-2.6.5.orig/Modules/selectmodule.c 2012-02-02 22:35:21.835125000 -0500
+++ Python-2.6.5/Modules/selectmodule.c 2012-02-02 22:41:41.210125000 -0500
@@ -6,6 +6,21 @@
>= 0.
*/
+/* Windows #defines FD_SETSIZE to 64 if FD_SETSIZE isn't already defined.
+ 64 is too small (too many people have bumped into that limit).
+ Here we boost it.
+
+ Cygwin also defines FD_SETSIZE to 64, so also increase the limit on
+ Cygwin. We must do this before sys/types.h is included, which otherwise
+ sets FD_SETSIZE to the default.
+
+ Users who want even more than the boosted limit should #define
+ FD_SETSIZE higher before this; e.g., via compiler /D switch.
+*/
+#if (defined(MS_WINDOWS) || defined(__CYGWIN__)) && !defined(FD_SETSIZE)
+#define FD_SETSIZE 512
+#endif
+
#include "Python.h"
#include <structmember.h>
@@ -16,16 +31,6 @@
#undef HAVE_BROKEN_POLL
#endif
-/* Windows #defines FD_SETSIZE to 64 if FD_SETSIZE isn't already defined.
- 64 is too small (too many people have bumped into that limit).
- Here we boost it.
- Users who want even more than the boosted limit should #define
- FD_SETSIZE higher before this; e.g., via compiler /D switch.
-*/
-#if defined(MS_WINDOWS) && !defined(FD_SETSIZE)
-#define FD_SETSIZE 512
-#endif
-
#if defined(HAVE_POLL_H)
#include <poll.h>
#elif defined(HAVE_SYS_POLL_H)

View file

@ -0,0 +1,11 @@
--- origsrc/Include/pyerrors.h 2008-06-08 23:58:54.000000000 -0500
+++ src/Include/pyerrors.h 2010-05-12 04:19:31.535297200 -0500
@@ -232,7 +232,7 @@ PyAPI_FUNC(int) PyErr_CheckSignals(void)
PyAPI_FUNC(void) PyErr_SetInterrupt(void);
/* In signalmodule.c */
-int PySignal_SetWakeupFd(int fd);
+PyAPI_FUNC(int) PySignal_SetWakeupFd(int fd);
/* Support for adding program text to SyntaxErrors */
PyAPI_FUNC(void) PyErr_SyntaxLocation(const char *, int);

View file

@ -0,0 +1,16 @@
--- origsrc/Include/py_curses.h 2009-09-06 16:23:05.000000000 -0500
+++ src/Include/py_curses.h 2010-04-14 15:21:23.008971400 -0500
@@ -17,6 +17,13 @@
#define NCURSES_OPAQUE 0
#endif /* __APPLE__ */
+#ifdef __CYGWIN__
+/* the following define is necessary for Cygwin; without it, the
+ Cygwin-supplied ncurses.h sets NCURSES_OPAQUE to 1, and then Python
+ can't get at the WINDOW flags field. */
+#define NCURSES_INTERNALS
+#endif /* __CYGWIN__ */
+
#ifdef __FreeBSD__
/*
** On FreeBSD, [n]curses.h and stdlib.h/wchar.h use different guards

View file

@ -0,0 +1,27 @@
--- origsrc/setup.py.orig 2012-11-27 10:20:47.442395900 -0500
+++ src/setup.py 2012-11-27 10:53:15.583020900 -0500
@@ -1141,7 +1141,7 @@
dbm_order = ['gdbm']
# The standard Unix dbm module:
- if host_platform not in ['cygwin']:
+ if host_platform not in ['win32']:
config_args = [arg.strip("'")
for arg in sysconfig.get_config_var("CONFIG_ARGS").split()]
dbm_args = [arg for arg in config_args
@@ -1192,6 +1192,15 @@
],
libraries = gdbm_libs)
break
+ if find_file("ndbm.h", inc_dirs, []) is not None:
+ print("building dbm using gdbm")
+ dbmext = Extension(
+ 'dbm', ['dbmmodule.c'],
+ define_macros=[
+ ('HAVE_NDBM_H', None),
+ ],
+ libraries = gdbm_libs)
+ break
elif cand == "bdb":
if db_incs is not None:
print "building dbm using bdb"

View file

@ -0,0 +1,10 @@
--- origsrc/Lib/distutils/unixccompiler.py.orig 2012-11-27 07:44:15.409993500 -0500
+++ src/Lib/distutils/unixccompiler.py 2012-11-27 08:09:57.801770900 -0500
@@ -141,6 +141,7 @@
static_lib_format = shared_lib_format = dylib_lib_format = "lib%s%s"
if sys.platform == "cygwin":
exe_extension = ".exe"
+ dylib_lib_extension = ".dll.a"
def preprocess(self, source,
output_file=None, macros=None, include_dirs=None,

View file

@ -0,0 +1,31 @@
--- origsrc/Modules/getpath.c.orig 2012-11-27 12:07:56.098645900 -0500
+++ src/Modules/getpath.c 2012-11-27 12:10:11.254895900 -0500
@@ -436,6 +436,28 @@
if (isxfile(progpath))
break;
+#ifdef __CYGWIN__
+ /*
+ * Cygwin automatically removes the ".exe" extension from argv[0]
+ * to make programs feel like they are in a more Unix-like
+ * environment. Unfortunately, this can make it problemmatic for
+ * Cygwin to distinguish between a directory and an executable with
+ * the same name excluding the ".exe" extension. For example, the
+ * Cygwin Python build directory has a "Python" directory and a
+ * "python.exe" executable. This causes isxfile() to erroneously
+ * return false. If isdir() returns true and there is enough space
+ * to append the ".exe" extension, then we try again with the
+ * extension appended.
+ */
+#define EXE ".exe"
+ if (isdir(progpath) && strlen(progpath) + strlen(EXE) <= MAXPATHLEN)
+ {
+ strcat(progpath, EXE);
+ if (isxfile(progpath))
+ break;
+ }
+#endif /* __CYGWIN__ */
+
if (!delim) {
progpath[0] = '\0';
break;

View file

@ -0,0 +1,11 @@
--- origsrc/setup.py.orig 2012-11-27 09:28:34.051770900 -0500
+++ src/setup.py 2012-11-27 09:28:47.239270900 -0500
@@ -470,7 +470,7 @@
# Check for MacOS X, which doesn't need libm.a at all
math_libs = ['m']
- if host_platform in ['darwin', 'beos']:
+ if host_platform in ['darwin', 'beos', 'cygwin']:
math_libs = []
# XXX Omitted modules: gl, pure, dl, SGI-specific modules

View file

@ -0,0 +1,116 @@
diff --git a/Lib/py_compile.py b/Lib/py_compile.py
index 978da73d74..3559eb95ca 100644
--- a/Lib/py_compile.py
+++ b/Lib/py_compile.py
@@ -120,16 +120,27 @@ def compile(file, cfile=None, dfile=None, doraise=False):
return
if cfile is None:
cfile = file + (__debug__ and 'c' or 'o')
- with open(cfile, 'wb') as fc:
- fc.write('\0\0\0\0')
- if "DETERMINISTIC_BUILD" in os.environ:
+ # Atomically write the pyc/pyo file. Issue #13146.
+ # id() is used to generate a pseudo-random filename.
+ path_tmp = '{}.{}'.format(cfile, id(cfile))
+ try:
+ with open(path_tmp, 'wb') as fc:
fc.write('\0\0\0\0')
- else:
- wr_long(fc, timestamp)
- marshal.dump(codeobject, fc)
- fc.flush()
- fc.seek(0, 0)
- fc.write(MAGIC)
+ if "DETERMINISTIC_BUILD" in os.environ:
+ fc.write('\0\0\0\0')
+ else:
+ wr_long(fc, timestamp)
+ marshal.dump(codeobject, fc)
+ fc.flush()
+ fc.seek(0, 0)
+ fc.write(MAGIC)
+ os.rename(path_tmp, cfile)
+ except OSError:
+ try:
+ os.unlink(path_tmp)
+ except OSError:
+ pass
+ raise
def main(args=None):
"""Compile several source files.
diff --git a/Python/import.c b/Python/import.c
index 1e31d79279..f78a1efcf0 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -951,6 +951,8 @@ static void
write_compiled_module(PyCodeObject *co, char *cpathname, struct stat *srcstat, time_t mtime)
{
FILE *fp;
+ size_t cpathname_len;
+ char *cpathname_tmp;
#ifdef MS_WINDOWS /* since Windows uses different permissions */
mode_t mode = srcstat->st_mode & ~S_IEXEC;
/* Issue #6074: We ensure user write access, so we can delete it later
@@ -963,11 +965,28 @@ write_compiled_module(PyCodeObject *co, char *cpathname, struct stat *srcstat, t
mode_t mode = srcstat->st_mode & ~S_IXUSR & ~S_IXGRP & ~S_IXOTH;
#endif
+#ifdef MS_WINDOWS
fp = open_exclusive(cpathname, mode);
+#else
+ /* Under POSIX, we first write to a tmp file and then take advantage
+ of atomic renaming. */
+ cpathname_len = strlen(cpathname);
+ cpathname_tmp = PyMem_MALLOC(cpathname_len + 5);
+ if (cpathname_tmp == NULL) {
+ PyErr_Clear();
+ return;
+ }
+ memcpy(cpathname_tmp, cpathname, cpathname_len);
+ memcpy(cpathname_tmp + cpathname_len, ".tmp", 5);
+ fp = open_exclusive(cpathname_tmp, mode);
+#endif
if (fp == NULL) {
if (Py_VerboseFlag)
PySys_WriteStderr(
"# can't create %s\n", cpathname);
+#ifndef MS_WINDOWS
+ PyMem_FREE(cpathname_tmp);
+#endif
return;
}
PyMarshal_WriteLongToFile(pyc_magic, fp, Py_MARSHAL_VERSION);
@@ -979,7 +998,12 @@ write_compiled_module(PyCodeObject *co, char *cpathname, struct stat *srcstat, t
PySys_WriteStderr("# can't write %s\n", cpathname);
/* Don't keep partial file */
fclose(fp);
+#ifdef MS_WINDOWS
(void) unlink(cpathname);
+#else
+ (void) unlink(cpathname_tmp);
+ PyMem_FREE(cpathname_tmp);
+#endif
return;
}
/* Now write the true mtime (as a 32-bit field) */
@@ -989,6 +1013,19 @@ write_compiled_module(PyCodeObject *co, char *cpathname, struct stat *srcstat, t
PyMarshal_WriteLongToFile((long)mtime, fp, Py_MARSHAL_VERSION);
fflush(fp);
}
+ /* Under POSIX, do an atomic rename */
+#ifndef MS_WINDOWS
+ if (rename(cpathname_tmp, cpathname)) {
+ if (Py_VerboseFlag)
+ PySys_WriteStderr("# can't write %s\n", cpathname);
+ /* Don't keep tmp file */
+ fclose(fp);
+ (void) unlink(cpathname_tmp);
+ PyMem_FREE(cpathname_tmp);
+ return;
+ }
+ PyMem_FREE(cpathname_tmp);
+#endif
fclose(fp);
if (Py_VerboseFlag)
PySys_WriteStderr("# wrote %s\n", cpathname);

View file

@ -0,0 +1,32 @@
--- ./setup.py.orig 2018-04-29 15:47:33.000000000 -0700
+++ ./setup.py 2018-11-11 09:41:58.097682221 -0800
@@ -458,8 +458,6 @@
if not cross_compiling:
add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
- if cross_compiling:
- self.add_gcc_paths()
self.add_multiarch_paths()
# Add paths specified in the environment variables LDFLAGS and
@@ -517,7 +515,10 @@
# be assumed that no additional -I,-L directives are needed.
inc_dirs = self.compiler.include_dirs[:]
lib_dirs = self.compiler.library_dirs[:]
- if not cross_compiling:
+ if cross_compiling:
+ inc_dirs = []
+ lib_dirs = []
+ else:
for d in (
'/usr/include',
):
@@ -582,6 +584,8 @@ class PyBuildExt(build_ext):
# Some modules that are normally always on:
#exts.append( Extension('_weakref', ['_weakref.c']) )
+ self.compiler.library_dirs = lib_dirs + [ '.' ]
+
# array objects
exts.append( Extension('array', ['arraymodule.c']) )

View file

@ -0,0 +1,340 @@
{ lib, stdenv, fetchFromGitHub, fetchpatch, bzip2, expat, libffi, gdbm, db
, ncurses, openssl, readline, sqlite, tcl ? null, tk ? null, tix ? null
, libX11 ? null, x11Support ? false, zlib, self, configd, coreutils
, autoreconfHook, python-setup-hook
# Some proprietary libs assume UCS2 unicode, especially on darwin :(
, ucsEncoding ? 4
# For the Python package set
, packageOverrides ? (self: super: { }), pkgsBuildBuild, pkgsBuildHost
, pkgsBuildTarget, pkgsHostHost, pkgsTargetTarget, sourceVersion, hash
, passthruFun, static ? stdenv.hostPlatform.isStatic
, stripBytecode ? reproducibleBuild, rebuildBytecode ? true
, reproducibleBuild ? false, enableOptimizations ? false, strip2to3 ? false
, stripConfig ? false, stripIdlelib ? false, stripTests ? false
, pythonAttr ? "python${sourceVersion.major}${sourceVersion.minor}" }:
assert x11Support -> tcl != null && tk != null && libX11 != null;
assert lib.assertMsg (enableOptimizations -> (!stdenv.cc.isClang))
"Optimizations with clang are not supported. configure: error: llvm-profdata is required for a --enable-optimizations build but could not be found.";
assert lib.assertMsg (reproducibleBuild -> stripBytecode)
"Deterministic builds require stripping bytecode.";
assert lib.assertMsg (reproducibleBuild -> (!enableOptimizations))
"Deterministic builds are not achieved when optimizations are enabled.";
assert lib.assertMsg (reproducibleBuild -> (!rebuildBytecode))
"Deterministic builds are not achieved when (default unoptimized) bytecode is created.";
let
buildPackages = pkgsBuildHost;
inherit (passthru) pythonOnBuildForHost;
pythonOnBuildForHostInterpreter =
if stdenv.hostPlatform == stdenv.buildPlatform then
"$out/bin/python"
else
pythonOnBuildForHost.interpreter;
passthru = passthruFun rec {
inherit self sourceVersion packageOverrides;
implementation = "cpython";
libPrefix = "python${pythonVersion}";
executable = libPrefix;
pythonVersion = with sourceVersion; "${major}.${minor}";
sitePackages = "lib/${libPrefix}/site-packages";
inherit hasDistutilsCxxPatch pythonAttr;
pythonOnBuildForBuild = pkgsBuildBuild.${pythonAttr};
pythonOnBuildForHost = pkgsBuildHost.${pythonAttr};
pythonOnBuildForTarget = pkgsBuildTarget.${pythonAttr};
pythonOnHostForHost = pkgsHostHost.${pythonAttr};
pythonOnTargetForTarget = pkgsTargetTarget.${pythonAttr} or { };
} // {
inherit ucsEncoding;
};
version = with sourceVersion; "${major}.${minor}.${patch}${suffix}";
# ActiveState is a fork of cpython that includes fixes for security
# issues after its EOL
src = fetchFromGitHub {
owner = "ActiveState";
repo = "cpython";
rev = "v${version}";
inherit hash;
};
hasDistutilsCxxPatch = !(stdenv.cc.isGNU or false);
patches = [ # Look in C_INCLUDE_PATH and LIBRARY_PATH for stuff.
./search-path.patch
# Python recompiles a Python if the mtime stored *in* the
# pyc/pyo file differs from the mtime of the source file. This
# doesn't work in Nix because Nix changes the mtime of files in
# the Nix store to 1. So treat that as a special case.
./nix-store-mtime.patch
# patch python to put zero timestamp into pyc
# if DETERMINISTIC_BUILD env var is set
./deterministic-build.patch
# Fix python bug #27177 (https://bugs.python.org/issue27177)
# The issue is that `match.group` only recognizes python integers
# instead of everything that has `__index__`.
# This bug was fixed upstream, but not backported to 2.7
(fetchpatch {
name = "re_match_index.patch";
url = "https://bugs.python.org/file43084/re_match_index.patch";
sha256 = "0l9rw6r5r90iybdkp3hhl2pf0h0s1izc68h5d3ywrm92pq32wz57";
})
# Fix race-condition during pyc creation. Has a slight backwards
# incompatible effect: pyc symlinks will now be overridden
# (https://bugs.python.org/issue17222). Included in python >= 3.4,
# backported in debian since 2013.
# https://bugs.python.org/issue13146
./atomic_pyc.patch
# Backport from CPython 3.8 of a good list of tests to run for PGO.
./profile-task.patch
# The workaround is for unittests on Win64, which we don't support.
# It does break aarch64-darwin, which we do support. See:
# * https://bugs.python.org/issue35523
# * https://github.com/python/cpython/commit/e6b247c8e524
../3.7/no-win64-workaround.patch
# fix openssl detection by reverting irrelevant change for us, to enable hashlib which is required by pip
(fetchpatch {
url =
"https://github.com/ActiveState/cpython/pull/35/commits/20ea5b46aaf1e7bdf9d6905ba8bece2cc73b05b0.patch";
revert = true;
hash = "sha256-Lp5fGlcfJJ6p6vKmcLckJiAA2AZz4prjFE0aMEJxotw=";
})
] ++ lib.optionals (x11Support && stdenv.isDarwin) [
./use-correct-tcl-tk-on-darwin.patch
] ++ lib.optionals stdenv.isDarwin [
# Fix darwin build https://bugs.python.org/issue34027
../3.7/darwin-libutil.patch
] ++ lib.optionals stdenv.isLinux [
# Disable the use of ldconfig in ctypes.util.find_library (since
# ldconfig doesn't work on NixOS), and don't use
# ctypes.util.find_library during the loading of the uuid module
# (since it will do a futile invocation of gcc (!) to find
# libuuid, slowing down program startup a lot).
./no-ldconfig.patch
# Fix ctypes.util.find_library with gcc10.
./find_library-gcc10.patch
] ++ lib.optionals stdenv.hostPlatform.isCygwin [
./2.5.2-ctypes-util-find_library.patch
./2.5.2-tkinter-x11.patch
./2.6.2-ssl-threads.patch
./2.6.5-export-PySignal_SetWakeupFd.patch
./2.6.5-FD_SETSIZE.patch
./2.6.5-ncurses-abi6.patch
./2.7.3-dbm.patch
./2.7.3-dylib.patch
./2.7.3-getpath-exe-extension.patch
./2.7.3-no-libm.patch
] ++ lib.optionals hasDistutilsCxxPatch [
# Patch from http://bugs.python.org/issue1222585 adapted to work with
# `patch -p1' and with a last hunk removed
# Upstream distutils is calling C compiler to compile C++ code, which
# only works for GCC and Apple Clang. This makes distutils to call C++
# compiler when needed.
./python-2.7-distutils-C++.patch
] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform)
[ ./cross-compile.patch ];
preConfigure = ''
# Purity.
for i in /usr /sw /opt /pkg; do
substituteInPlace ./setup.py --replace $i /no-such-path
done
'' + lib.optionalString (stdenv ? cc && stdenv.cc.libc != null) ''
for i in Lib/plat-*/regen; do
substituteInPlace $i --replace /usr/include/ ${stdenv.cc.libc}/include/
done
'' + lib.optionalString stdenv.isDarwin ''
substituteInPlace configure --replace '`/usr/bin/arch`' '"i386"'
substituteInPlace Lib/multiprocessing/__init__.py \
--replace 'os.popen(comm)' 'os.popen("${coreutils}/bin/nproc")'
'';
configureFlags =
lib.optionals enableOptimizations [ "--enable-optimizations" ]
++ lib.optionals (!static) [ "--enable-shared" ] ++ [
"--with-threads"
"--with-system-ffi"
"--with-system-expat"
"--enable-unicode=ucs${toString ucsEncoding}"
] ++ lib.optionals stdenv.hostPlatform.isCygwin
[ "ac_cv_func_bind_textdomain_codeset=yes" ]
++ lib.optionals stdenv.isDarwin [ "--disable-toolbox-glue" ]
++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
"PYTHON_FOR_BUILD=${lib.getBin buildPackages.python}/bin/python"
"ac_cv_buggy_getaddrinfo=no"
# Assume little-endian IEEE 754 floating point when cross compiling
"ac_cv_little_endian_double=yes"
"ac_cv_big_endian_double=no"
"ac_cv_mixed_endian_double=no"
"ac_cv_x87_double_rounding=yes"
"ac_cv_tanh_preserves_zero_sign=yes"
# Generally assume that things are present and work
"ac_cv_posix_semaphores_enabled=yes"
"ac_cv_broken_sem_getvalue=no"
"ac_cv_wchar_t_signed=yes"
"ac_cv_rshift_extends_sign=yes"
"ac_cv_broken_nice=no"
"ac_cv_broken_poll=no"
"ac_cv_working_tzset=yes"
"ac_cv_have_long_long_format=yes"
"ac_cv_have_size_t_format=yes"
"ac_cv_computed_gotos=yes"
"ac_cv_file__dev_ptmx=yes"
"ac_cv_file__dev_ptc=yes"
]
# Never even try to use lchmod on linux,
# don't rely on detecting glibc-isms.
++ lib.optional stdenv.hostPlatform.isLinux "ac_cv_func_lchmod=no"
++ lib.optional static "LDFLAGS=-static";
strictDeps = true;
buildInputs =
lib.optional (stdenv ? cc && stdenv.cc.libc != null) stdenv.cc.libc
++ [ bzip2 openssl zlib libffi expat db gdbm ncurses sqlite readline ]
++ lib.optionals x11Support [ tcl tk libX11 ]
++ lib.optional (stdenv.isDarwin && configd != null) configd;
nativeBuildInputs = [ autoreconfHook ]
++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
buildPackages.stdenv.cc
buildPackages.python
];
mkPaths = paths: {
C_INCLUDE_PATH = lib.makeSearchPathOutput "dev" "include" paths;
LIBRARY_PATH = lib.makeLibraryPath paths;
};
# Python 2.7 needs this
crossCompileEnv =
lib.optionalAttrs (stdenv.hostPlatform != stdenv.buildPlatform) {
_PYTHON_HOST_PLATFORM = stdenv.hostPlatform.config;
};
# Build the basic Python interpreter without modules that have
# external dependencies.
in with passthru;
stdenv.mkDerivation ({
pname = "python";
inherit version;
inherit src patches buildInputs nativeBuildInputs preConfigure configureFlags;
LDFLAGS = lib.optionalString (!stdenv.isDarwin) "-lgcc_s";
inherit (mkPaths buildInputs) C_INCLUDE_PATH LIBRARY_PATH;
env.NIX_CFLAGS_COMPILE =
lib.optionalString (stdenv.targetPlatform.system == "x86_64-darwin")
"-msse2" + lib.optionalString stdenv.hostPlatform.isMusl
" -DTHREAD_STACK_SIZE=0x100000";
DETERMINISTIC_BUILD = 1;
setupHook = python-setup-hook sitePackages;
postPatch = lib.optionalString (x11Support && (tix != null)) ''
substituteInPlace "Lib/lib-tk/Tix.py" --replace "os.environ.get('TIX_LIBRARY')" "os.environ.get('TIX_LIBRARY') or '${tix}/lib'"
'';
postInstall = ''
# needed for some packages, especially packages that backport
# functionality to 2.x from 3.x
for item in $out/lib/${libPrefix}/test/*; do
if [[ "$item" != */test_support.py*
&& "$item" != */test/support
&& "$item" != */test/regrtest.py* ]]; then
rm -rf "$item"
else
echo $item
fi
done
touch $out/lib/${libPrefix}/test/__init__.py
ln -s $out/lib/${libPrefix}/pdb.py $out/bin/pdb
ln -s $out/lib/${libPrefix}/pdb.py $out/bin/pdb${sourceVersion.major}.${sourceVersion.minor}
ln -s $out/share/man/man1/{python2.7.1.gz,python.1.gz}
rm "$out"/lib/python*/plat-*/regen # refers to glibc.dev
# Determinism: Windows installers were not deterministic.
# We're also not interested in building Windows installers.
find "$out" -name 'wininst*.exe' | xargs -r rm -f
'' + lib.optionalString stripBytecode ''
# Determinism: deterministic bytecode
# First we delete all old bytecode.
find $out -name "*.pyc" -delete
'' + lib.optionalString rebuildBytecode ''
# We build 3 levels of optimized bytecode. Note the default level, without optimizations,
# is not reproducible yet. https://bugs.python.org/issue29708
# Not creating bytecode will result in a large performance loss however, so we do build it.
find $out -name "*.py" | ${pythonOnBuildForHostInterpreter} -m compileall -q -f -x "lib2to3" -i -
find $out -name "*.py" | ${pythonOnBuildForHostInterpreter} -O -m compileall -q -f -x "lib2to3" -i -
find $out -name "*.py" | ${pythonOnBuildForHostInterpreter} -OO -m compileall -q -f -x "lib2to3" -i -
'' + lib.optionalString stdenv.hostPlatform.isCygwin ''
cp libpython2.7.dll.a $out/lib
'';
inherit passthru;
postFixup = ''
# Include a sitecustomize.py file. Note it causes an error when it's in postInstall with 2.7.
cp ${../../sitecustomize.py} $out/${sitePackages}/sitecustomize.py
'' + lib.optionalString strip2to3 ''
rm -R $out/bin/2to3 $out/lib/python*/lib2to3
'' + lib.optionalString stripConfig ''
rm -R $out/bin/python*-config $out/lib/python*/config*
'' + lib.optionalString stripIdlelib ''
# Strip IDLE
rm -R $out/bin/idle* $out/lib/python*/idlelib
'' + lib.optionalString stripTests ''
# Strip tests
rm -R $out/lib/python*/test $out/lib/python*/**/test{,s}
'';
enableParallelBuilding = true;
doCheck = false; # expensive, and fails
meta = {
homepage = "http://python.org";
description = "A high-level dynamically-typed programming language";
longDescription = ''
Python is a remarkably powerful dynamic programming language that
is used in a wide variety of application domains. Some of its key
distinguishing features include: clear, readable syntax; strong
introspection capabilities; intuitive object orientation; natural
expression of procedural code; full modularity, supporting
hierarchical packages; exception-based error handling; and very
high level dynamic data types.
'';
license = lib.licenses.psfl;
platforms = lib.platforms.all;
maintainers = with lib.maintainers; [ fridh ];
knownVulnerabilities = [
"Python 2.7 has reached its end of life after 2020-01-01. See https://www.python.org/doc/sunset-python-2/."
# Quote: That means that we will not improve it anymore after that day,
# even if someone finds a security problem in it. You should upgrade to
# Python 3 as soon as you can. [..] So, in 2008, we announced that we
# would sunset Python 2 in 2015, and asked people to upgrade before
# then. Some did, but many did not. So, in 2014, we extended that
# sunset till 2020.
];
};
} // crossCompileEnv)

View file

@ -0,0 +1,36 @@
diff -ur orig/Lib/py_compile.py new/Lib/py_compile.py
--- orig/Lib/py_compile.py
+++ new/Lib/py_compile.py
@@ -122,7 +122,10 @@
cfile = file + (__debug__ and 'c' or 'o')
with open(cfile, 'wb') as fc:
fc.write('\0\0\0\0')
- wr_long(fc, timestamp)
+ if "DETERMINISTIC_BUILD" in os.environ:
+ fc.write('\0\0\0\0')
+ else:
+ wr_long(fc, timestamp)
marshal.dump(codeobject, fc)
fc.flush()
fc.seek(0, 0)
diff -ur orig/Python/import.c new/Python/import.c
--- orig/Python/import.c
+++ new/Python/import.c
@@ -939,10 +939,12 @@
return;
}
/* Now write the true mtime (as a 32-bit field) */
- fseek(fp, 4L, 0);
- assert(mtime <= 0xFFFFFFFF);
- PyMarshal_WriteLongToFile((long)mtime, fp, Py_MARSHAL_VERSION);
- fflush(fp);
+ if (Py_GETENV("DETERMINISTIC_BUILD") == NULL) {
+ fseek(fp, 4L, 0);
+ assert(mtime <= 0xFFFFFFFF);
+ PyMarshal_WriteLongToFile((long)mtime, fp, Py_MARSHAL_VERSION);
+ fflush(fp);
+ }
fclose(fp);
if (Py_VerboseFlag)
PySys_WriteStderr("# wrote %s\n", cpathname);

View file

@ -0,0 +1,79 @@
Backport https://github.com/python/cpython/commit/82df3b3071bb003247c33eac4670775e9883c994
and https://github.com/python/cpython/commit/27ac19cca2c639caaf6fedf3632fe6beb265f24f
Fixes the check phase of python2Packages.cffi.
--- a/Lib/ctypes/util.py
+++ b/Lib/ctypes/util.py
@@ -87,6 +87,12 @@ elif os.name == "posix":
# Andreas Degert's find functions, using gcc, /sbin/ldconfig, objdump
import re, tempfile, errno
+ def _is_elf(filename):
+ "Return True if the given file is an ELF file"
+ elf_header = b'\x7fELF'
+ with open(filename, 'rb') as thefile:
+ return thefile.read(4) == elf_header
+
def _findLib_gcc(name):
# Run GCC's linker with the -t (aka --trace) option and examine the
# library name it prints out. The GCC command will fail because we
@@ -110,10 +116,17 @@ elif os.name == "posix":
# the normal behaviour of GCC if linking fails
if e.errno != errno.ENOENT:
raise
- res = re.search(expr, trace)
+ res = re.findall(expr, trace)
if not res:
return None
- return res.group(0)
+
+ for file in res:
+ # Check if the given file is an elf file: gcc can report
+ # some files that are linker scripts and not actual
+ # shared objects. See bpo-41976 for more details
+ if not _is_elf(file):
+ continue
+ return file
if sys.platform == "sunos5":
@@ -237,8 +250,37 @@ elif os.name == "posix":
def _findSoname_ldconfig(name):
return None
+ def _findLib_ld(name):
+ # See issue #9998 for why this is needed
+ expr = r'[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name)
+ cmd = ['ld', '-t']
+ libpath = os.environ.get('LD_LIBRARY_PATH')
+ if libpath:
+ for d in libpath.split(':'):
+ cmd.extend(['-L', d])
+ cmd.extend(['-o', os.devnull, '-l%s' % name])
+ result = None
+ try:
+ p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ universal_newlines=True)
+ out, _ = p.communicate()
+ res = re.findall(expr, out)
+ for file in res:
+ # Check if the given file is an elf file: gcc can report
+ # some files that are linker scripts and not actual
+ # shared objects. See bpo-41976 for more details
+ if not _is_elf(file):
+ continue
+ return file
+ except Exception:
+ pass # result will be None
+ return result
+
def find_library(name):
- return _findSoname_ldconfig(name) or _get_soname(_findLib_gcc(name))
+ # See issue #9998
+ return _findSoname_ldconfig(name) or \
+ _get_soname(_findLib_gcc(name)) or _get_soname(_findLib_ld(name))
################################################################
# test code

View file

@ -0,0 +1,12 @@
diff -ru -x '*~' Python-2.7.1-orig/Python/import.c Python-2.7.1/Python/import.c
--- Python-2.7.1-orig/Python/import.c 2010-05-20 20:37:55.000000000 +0200
+++ Python-2.7.1/Python/import.c 2011-01-04 15:55:11.000000000 +0100
@@ -751,7 +751,7 @@
return NULL;
}
pyc_mtime = PyMarshal_ReadLongFromFile(fp);
- if (pyc_mtime != mtime) {
+ if (pyc_mtime != mtime && mtime != 1) {
if (Py_VerboseFlag)
PySys_WriteStderr("# %s has bad mtime\n", cpathname);
fclose(fp);

View file

@ -0,0 +1,117 @@
From 6b0f329a9f37110020ca02b35c8125391ef282b7 Mon Sep 17 00:00:00 2001
From: Frederik Rietdijk <fridh@fridh.nl>
Date: Sat, 24 Dec 2016 15:56:10 +0100
Subject: [PATCH] no ldconfig
---
Lib/ctypes/util.py | 35 +----------------------------------
Lib/uuid.py | 47 -----------------------------------------------
2 files changed, 1 insertion(+), 81 deletions(-)
diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py
index ab10ec5..f253e34 100644
--- a/Lib/ctypes/util.py
+++ b/Lib/ctypes/util.py
@@ -235,40 +235,7 @@ elif os.name == "posix":
else:
def _findSoname_ldconfig(name):
- import struct
- if struct.calcsize('l') == 4:
- machine = os.uname()[4] + '-32'
- else:
- machine = os.uname()[4] + '-64'
- mach_map = {
- 'x86_64-64': 'libc6,x86-64',
- 'ppc64-64': 'libc6,64bit',
- 'sparc64-64': 'libc6,64bit',
- 's390x-64': 'libc6,64bit',
- 'ia64-64': 'libc6,IA-64',
- }
- abi_type = mach_map.get(machine, 'libc6')
-
- # XXX assuming GLIBC's ldconfig (with option -p)
- expr = r'\s+(lib%s\.[^\s]+)\s+\(%s' % (re.escape(name), abi_type)
-
- env = dict(os.environ)
- env['LC_ALL'] = 'C'
- env['LANG'] = 'C'
- null = open(os.devnull, 'wb')
- try:
- with null:
- p = subprocess.Popen(['/sbin/ldconfig', '-p'],
- stderr=null,
- stdout=subprocess.PIPE,
- env=env)
- except OSError: # E.g. command not found
- return None
- [data, _] = p.communicate()
- res = re.search(expr, data)
- if not res:
- return None
- return res.group(1)
+ return None
def find_library(name):
return _findSoname_ldconfig(name) or _get_soname(_findLib_gcc(name))
diff --git a/Lib/uuid.py b/Lib/uuid.py
index 7432032..05eeee5 100644
--- a/Lib/uuid.py
+++ b/Lib/uuid.py
@@ -441,53 +441,6 @@ def _netbios_getnode():
# If ctypes is available, use it to find system routines for UUID generation.
_uuid_generate_time = _UuidCreate = None
-try:
- import ctypes, ctypes.util
- import sys
-
- # The uuid_generate_* routines are provided by libuuid on at least
- # Linux and FreeBSD, and provided by libc on Mac OS X.
- _libnames = ['uuid']
- if not sys.platform.startswith('win'):
- _libnames.append('c')
- for libname in _libnames:
- try:
- lib = ctypes.CDLL(ctypes.util.find_library(libname))
- except:
- continue
- if hasattr(lib, 'uuid_generate_time'):
- _uuid_generate_time = lib.uuid_generate_time
- break
- del _libnames
-
- # The uuid_generate_* functions are broken on MacOS X 10.5, as noted
- # in issue #8621 the function generates the same sequence of values
- # in the parent process and all children created using fork (unless
- # those children use exec as well).
- #
- # Assume that the uuid_generate functions are broken from 10.5 onward,
- # the test can be adjusted when a later version is fixed.
- if sys.platform == 'darwin':
- import os
- if int(os.uname()[2].split('.')[0]) >= 9:
- _uuid_generate_time = None
-
- # On Windows prior to 2000, UuidCreate gives a UUID containing the
- # hardware address. On Windows 2000 and later, UuidCreate makes a
- # random UUID and UuidCreateSequential gives a UUID containing the
- # hardware address. These routines are provided by the RPC runtime.
- # NOTE: at least on Tim's WinXP Pro SP2 desktop box, while the last
- # 6 bytes returned by UuidCreateSequential are fixed, they don't appear
- # to bear any relationship to the MAC address of any network device
- # on the box.
- try:
- lib = ctypes.windll.rpcrt4
- except:
- lib = None
- _UuidCreate = getattr(lib, 'UuidCreateSequential',
- getattr(lib, 'UuidCreate', None))
-except:
- pass
def _unixdll_getnode():
"""Get the hardware address on Unix using ctypes."""
--
2.11.0

View file

@ -0,0 +1,21 @@
Backport from CPython 3.8 of a good list of tests to run for PGO.
Upstream commit:
https://github.com/python/cpython/commit/4e16a4a31
Upstream discussion:
https://bugs.python.org/issue36044
diff --git a/Makefile.pre.in b/Makefile.pre.in
index 00fdd21ce..713dc1e53 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -259,7 +259,7 @@ TCLTK_LIBS=
# The task to run while instrumented when building the profile-opt target.
# We exclude unittests with -x that take a rediculious amount of time to
# run in the instrumented training build or do not provide much value.
-PROFILE_TASK=-m test.regrtest --pgo -x test_asyncore test_gdb test_multiprocessing test_subprocess
+PROFILE_TASK=-m test.regrtest --pgo test_array test_base64 test_binascii test_binop test_bisect test_bytes test_bz2 test_cmath test_codecs test_collections test_complex test_dataclasses test_datetime test_decimal test_difflib test_embed test_float test_fstring test_functools test_generators test_hashlib test_heapq test_int test_itertools test_json test_long test_lzma test_math test_memoryview test_operator test_ordered_dict test_pickle test_pprint test_re test_set test_sqlite test_statistics test_struct test_tabnanny test_time test_unicode test_xml_etree test_xml_etree_c
# report files for gcov / lcov coverage report
COVERAGE_INFO= $(abs_builddir)/coverage.info

View file

@ -0,0 +1,259 @@
--- a/Lib/distutils/cygwinccompiler.py
+++ b/Lib/distutils/cygwinccompiler.py
@@ -117,8 +117,10 @@
# dllwrap 2.10.90 is buggy
if self.ld_version >= "2.10.90":
self.linker_dll = "gcc"
+ self.linker_dll_cxx = "g++"
else:
self.linker_dll = "dllwrap"
+ self.linker_dll_cxx = "dllwrap"
# ld_version >= "2.13" support -shared so use it instead of
# -mdll -static
@@ -132,9 +134,13 @@
self.set_executables(compiler='gcc -mcygwin -O -Wall',
compiler_so='gcc -mcygwin -mdll -O -Wall',
compiler_cxx='g++ -mcygwin -O -Wall',
+ compiler_so_cxx='g++ -mcygwin -mdll -O -Wall',
linker_exe='gcc -mcygwin',
linker_so=('%s -mcygwin %s' %
- (self.linker_dll, shared_option)))
+ (self.linker_dll, shared_option)),
+ linker_exe_cxx='g++ -mcygwin',
+ linker_so_cxx=('%s -mcygwin %s' %
+ (self.linker_dll_cxx, shared_option)))
# cygwin and mingw32 need different sets of libraries
if self.gcc_version == "2.91.57":
@@ -160,8 +166,12 @@
raise CompileError, msg
else: # for other files use the C-compiler
try:
- self.spawn(self.compiler_so + cc_args + [src, '-o', obj] +
- extra_postargs)
+ if self.detect_language(src) == 'c++':
+ self.spawn(self.compiler_so_cxx + cc_args + [src, '-o', obj] +
+ extra_postargs)
+ else:
+ self.spawn(self.compiler_so + cc_args + [src, '-o', obj] +
+ extra_postargs)
except DistutilsExecError, msg:
raise CompileError, msg
@@ -327,9 +337,14 @@
self.set_executables(compiler='gcc%s -O -Wall' % no_cygwin,
compiler_so='gcc%s -mdll -O -Wall' % no_cygwin,
compiler_cxx='g++%s -O -Wall' % no_cygwin,
+ compiler_so_cxx='g++%s -mdll -O -Wall' % no_cygwin,
linker_exe='gcc%s' % no_cygwin,
linker_so='%s%s %s %s'
% (self.linker_dll, no_cygwin,
+ shared_option, entry_point),
+ linker_exe_cxx='g++%s' % no_cygwin,
+ linker_so_cxx='%s%s %s %s'
+ % (self.linker_dll_cxx, no_cygwin,
shared_option, entry_point))
# Maybe we should also append -mthreads, but then the finished
# dlls need another dll (mingwm10.dll see Mingw32 docs)
--- a/Lib/distutils/emxccompiler.py
+++ b/Lib/distutils/emxccompiler.py
@@ -65,8 +65,12 @@
# XXX optimization, warnings etc. should be customizable.
self.set_executables(compiler='gcc -Zomf -Zmt -O3 -fomit-frame-pointer -mprobe -Wall',
compiler_so='gcc -Zomf -Zmt -O3 -fomit-frame-pointer -mprobe -Wall',
+ compiler_cxx='g++ -Zomf -Zmt -O3 -fomit-frame-pointer -mprobe -Wall',
+ compiler_so_cxx='g++ -Zomf -Zmt -O3 -fomit-frame-pointer -mprobe -Wall',
linker_exe='gcc -Zomf -Zmt -Zcrtdll',
- linker_so='gcc -Zomf -Zmt -Zcrtdll -Zdll')
+ linker_so='gcc -Zomf -Zmt -Zcrtdll -Zdll',
+ linker_exe_cxx='g++ -Zomf -Zmt -Zcrtdll',
+ linker_so_cxx='g++ -Zomf -Zmt -Zcrtdll -Zdll')
# want the gcc library statically linked (so that we don't have
# to distribute a version dependent on the compiler we have)
@@ -83,8 +87,12 @@
raise CompileError, msg
else: # for other files use the C-compiler
try:
- self.spawn(self.compiler_so + cc_args + [src, '-o', obj] +
- extra_postargs)
+ if self.detect_language(src) == 'c++':
+ self.spawn(self.compiler_so_cxx + cc_args + [src, '-o', obj] +
+ extra_postargs)
+ else:
+ self.spawn(self.compiler_so + cc_args + [src, '-o', obj] +
+ extra_postargs)
except DistutilsExecError, msg:
raise CompileError, msg
--- a/Lib/distutils/sysconfig.py
+++ b/Lib/distutils/sysconfig.py
@@ -170,10 +170,12 @@
_osx_support.customize_compiler(_config_vars)
_config_vars['CUSTOMIZED_OSX_COMPILER'] = 'True'
- (cc, cxx, cflags, ccshared, ldshared, so_ext, ar, ar_flags) = \
- get_config_vars('CC', 'CXX', 'CFLAGS',
- 'CCSHARED', 'LDSHARED', 'SO', 'AR',
- 'ARFLAGS')
+ (cc, cxx, ccshared, ldshared, ldcxxshared, so_ext, ar, ar_flags) = \
+ get_config_vars('CC', 'CXX', 'CCSHARED', 'LDSHARED', 'LDCXXSHARED',
+ 'SO', 'AR', 'ARFLAGS')
+
+ cflags = ''
+ cxxflags = ''
if 'CC' in os.environ:
newcc = os.environ['CC']
@@ -188,19 +190,27 @@
cxx = os.environ['CXX']
if 'LDSHARED' in os.environ:
ldshared = os.environ['LDSHARED']
+ if 'LDCXXSHARED' in os.environ:
+ ldcxxshared = os.environ['LDCXXSHARED']
if 'CPP' in os.environ:
cpp = os.environ['CPP']
else:
cpp = cc + " -E" # not always
if 'LDFLAGS' in os.environ:
ldshared = ldshared + ' ' + os.environ['LDFLAGS']
+ ldcxxshared = ldcxxshared + ' ' + os.environ['LDFLAGS']
if 'CFLAGS' in os.environ:
cflags = cflags + ' ' + os.environ['CFLAGS']
ldshared = ldshared + ' ' + os.environ['CFLAGS']
+ if 'CXXFLAGS' in os.environ:
+ cxxflags = os.environ['CXXFLAGS']
+ ldcxxshared = ldcxxshared + ' ' + os.environ['CXXFLAGS']
if 'CPPFLAGS' in os.environ:
cpp = cpp + ' ' + os.environ['CPPFLAGS']
cflags = cflags + ' ' + os.environ['CPPFLAGS']
+ cxxflags = cxxflags + ' ' + os.environ['CPPFLAGS']
ldshared = ldshared + ' ' + os.environ['CPPFLAGS']
+ ldcxxshared = ldcxxshared + ' ' + os.environ['CPPFLAGS']
if 'AR' in os.environ:
ar = os.environ['AR']
if 'ARFLAGS' in os.environ:
@@ -209,13 +219,17 @@
archiver = ar + ' ' + ar_flags
cc_cmd = cc + ' ' + cflags
+ cxx_cmd = cxx + ' ' + cxxflags
compiler.set_executables(
preprocessor=cpp,
compiler=cc_cmd,
compiler_so=cc_cmd + ' ' + ccshared,
- compiler_cxx=cxx,
+ compiler_cxx=cxx_cmd,
+ compiler_so_cxx=cxx_cmd + ' ' + ccshared,
linker_so=ldshared,
linker_exe=cc,
+ linker_so_cxx=ldcxxshared,
+ linker_exe_cxx=cxx,
archiver=archiver)
compiler.shared_lib_extension = so_ext
--- a/Lib/distutils/unixccompiler.py
+++ b/Lib/distutils/unixccompiler.py
@@ -55,14 +55,17 @@
# are pretty generic; they will probably have to be set by an outsider
# (eg. using information discovered by the sysconfig about building
# Python extensions).
- executables = {'preprocessor' : None,
- 'compiler' : ["cc"],
- 'compiler_so' : ["cc"],
- 'compiler_cxx' : ["cc"],
- 'linker_so' : ["cc", "-shared"],
- 'linker_exe' : ["cc"],
- 'archiver' : ["ar", "-cr"],
- 'ranlib' : None,
+ executables = {'preprocessor' : None,
+ 'compiler' : ["cc"],
+ 'compiler_so' : ["cc"],
+ 'compiler_cxx' : ["c++"],
+ 'compiler_so_cxx' : ["c++"],
+ 'linker_so' : ["cc", "-shared"],
+ 'linker_exe' : ["cc"],
+ 'linker_so_cxx' : ["c++", "-shared"],
+ 'linker_exe_cxx' : ["c++"],
+ 'archiver' : ["ar", "-cr"],
+ 'ranlib' : None,
}
if sys.platform[:6] == "darwin":
@@ -112,12 +115,19 @@
def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
compiler_so = self.compiler_so
+ compiler_so_cxx = self.compiler_so_cxx
if sys.platform == 'darwin':
compiler_so = _osx_support.compiler_fixup(compiler_so,
cc_args + extra_postargs)
+ compiler_so_cxx = _osx_support.compiler_fixup(compiler_so_cxx,
+ cc_args + extra_postargs)
try:
- self.spawn(compiler_so + cc_args + [src, '-o', obj] +
- extra_postargs)
+ if self.detect_language(src) == 'c++':
+ self.spawn(compiler_so_cxx + cc_args + [src, '-o', obj] +
+ extra_postargs)
+ else:
+ self.spawn(compiler_so + cc_args + [src, '-o', obj] +
+ extra_postargs)
except DistutilsExecError, msg:
raise CompileError, msg
@@ -174,23 +184,16 @@
ld_args.extend(extra_postargs)
self.mkpath(os.path.dirname(output_filename))
try:
- if target_desc == CCompiler.EXECUTABLE:
- linker = self.linker_exe[:]
+ if target_lang == "c++":
+ if target_desc == CCompiler.EXECUTABLE:
+ linker = self.linker_exe_cxx[:]
+ else:
+ linker = self.linker_so_cxx[:]
else:
- linker = self.linker_so[:]
- if target_lang == "c++" and self.compiler_cxx:
- # skip over environment variable settings if /usr/bin/env
- # is used to set up the linker's environment.
- # This is needed on OSX. Note: this assumes that the
- # normal and C++ compiler have the same environment
- # settings.
- i = 0
- if os.path.basename(linker[0]) == "env":
- i = 1
- while '=' in linker[i]:
- i = i + 1
-
- linker[i] = self.compiler_cxx[i]
+ if target_desc == CCompiler.EXECUTABLE:
+ linker = self.linker_exe[:]
+ else:
+ linker = self.linker_so[:]
if sys.platform == 'darwin':
linker = _osx_support.compiler_fixup(linker, ld_args)
--- a/Lib/_osx_support.py
+++ b/Lib/_osx_support.py
@@ -14,13 +14,13 @@
# configuration variables that may contain universal build flags,
# like "-arch" or "-isdkroot", that may need customization for
# the user environment
-_UNIVERSAL_CONFIG_VARS = ('CFLAGS', 'LDFLAGS', 'CPPFLAGS', 'BASECFLAGS',
- 'BLDSHARED', 'LDSHARED', 'CC', 'CXX',
- 'PY_CFLAGS', 'PY_LDFLAGS', 'PY_CPPFLAGS',
- 'PY_CORE_CFLAGS')
+_UNIVERSAL_CONFIG_VARS = ('CFLAGS', 'CXXFLAGS', 'LDFLAGS', 'CPPFLAGS',
+ 'BASECFLAGS', 'BLDSHARED', 'LDSHARED', 'LDCXXSHARED',
+ 'CC', 'CXX', 'PY_CFLAGS', 'PY_LDFLAGS',
+ 'PY_CPPFLAGS', 'PY_CORE_CFLAGS')
# configuration variables that may contain compiler calls
-_COMPILER_CONFIG_VARS = ('BLDSHARED', 'LDSHARED', 'CC', 'CXX')
+_COMPILER_CONFIG_VARS = ('BLDSHARED', 'LDSHARED', 'LDCXXSHARED', 'CC', 'CXX')
# prefix added to original configuration variable names
_INITPRE = '_OSX_SUPPORT_INITIAL_'

View file

@ -0,0 +1,27 @@
diff -rc Python-2.4.4-orig/setup.py Python-2.4.4/setup.py
*** Python-2.4.4-orig/setup.py 2006-10-08 19:41:25.000000000 +0200
--- Python-2.4.4/setup.py 2007-05-27 16:04:54.000000000 +0200
***************
*** 279,288 ****
# Check for AtheOS which has libraries in non-standard locations
if platform == 'atheos':
lib_dirs += ['/system/libs', '/atheos/autolnk/lib']
- lib_dirs += os.getenv('LIBRARY_PATH', '').split(os.pathsep)
inc_dirs += ['/system/include', '/atheos/autolnk/include']
- inc_dirs += os.getenv('C_INCLUDE_PATH', '').split(os.pathsep)
# OSF/1 and Unixware have some stuff in /usr/ccs/lib (like -ldb)
if platform in ['osf1', 'unixware7', 'openunix8']:
lib_dirs += ['/usr/ccs/lib']
--- 279,289 ----
# Check for AtheOS which has libraries in non-standard locations
if platform == 'atheos':
lib_dirs += ['/system/libs', '/atheos/autolnk/lib']
inc_dirs += ['/system/include', '/atheos/autolnk/include']
+ lib_dirs += os.getenv('LIBRARY_PATH', '').split(os.pathsep)
+ inc_dirs += os.getenv('C_INCLUDE_PATH', '').split(os.pathsep)
+
# OSF/1 and Unixware have some stuff in /usr/ccs/lib (like -ldb)
if platform in ['osf1', 'unixware7', 'openunix8']:
lib_dirs += ['/usr/ccs/lib']

View file

@ -0,0 +1,48 @@
diff --git a/setup.py b/setup.py
index 2779658..902d0eb 100644
--- a/setup.py
+++ b/setup.py
@@ -1699,9 +1699,6 @@ class PyBuildExt(build_ext):
# Rather than complicate the code below, detecting and building
# AquaTk is a separate method. Only one Tkinter will be built on
# Darwin - either AquaTk, if it is found, or X11 based Tk.
- if (host_platform == 'darwin' and
- self.detect_tkinter_darwin(inc_dirs, lib_dirs)):
- return
# Assume we haven't found any of the libraries or include files
# The versions with dots are used on Unix, and the versions without
@@ -1747,22 +1744,6 @@ class PyBuildExt(build_ext):
if dir not in include_dirs:
include_dirs.append(dir)
- # Check for various platform-specific directories
- if host_platform == 'sunos5':
- include_dirs.append('/usr/openwin/include')
- added_lib_dirs.append('/usr/openwin/lib')
- elif os.path.exists('/usr/X11R6/include'):
- include_dirs.append('/usr/X11R6/include')
- added_lib_dirs.append('/usr/X11R6/lib64')
- added_lib_dirs.append('/usr/X11R6/lib')
- elif os.path.exists('/usr/X11R5/include'):
- include_dirs.append('/usr/X11R5/include')
- added_lib_dirs.append('/usr/X11R5/lib')
- else:
- # Assume default location for X11
- include_dirs.append('/usr/X11/include')
- added_lib_dirs.append('/usr/X11/lib')
-
# If Cygwin, then verify that X is installed before proceeding
if host_platform == 'cygwin':
x11_inc = find_file('X11/Xlib.h', [], include_dirs)
@@ -1786,10 +1767,6 @@ class PyBuildExt(build_ext):
if host_platform in ['aix3', 'aix4']:
libs.append('ld')
- # Finally, link with the X11 libraries (not appropriate on cygwin)
- if host_platform != "cygwin":
- libs.append('X11')
-
ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
define_macros=[('WITH_APPINIT', 1)] + defs,
include_dirs = include_dirs,

View file

@ -0,0 +1,107 @@
From 084c6dd6352077e64f10cf7aa168f95d800f3819 Mon Sep 17 00:00:00 2001
From: Jonathan Ringer <jonringer117@gmail.com>
Date: Mon, 9 Nov 2020 10:24:35 -0800
Subject: [PATCH] CPython: Don't use ldconfig
---
Lib/ctypes/util.py | 77 ++--------------------------------------------
1 file changed, 2 insertions(+), 75 deletions(-)
diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py
index 0c2510e..7fb98af 100644
--- a/Lib/ctypes/util.py
+++ b/Lib/ctypes/util.py
@@ -100,53 +100,7 @@ elif os.name == "posix":
return thefile.read(4) == elf_header
def _findLib_gcc(name):
- # Run GCC's linker with the -t (aka --trace) option and examine the
- # library name it prints out. The GCC command will fail because we
- # haven't supplied a proper program with main(), but that does not
- # matter.
- expr = os.fsencode(r'[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name))
-
- c_compiler = shutil.which('gcc')
- if not c_compiler:
- c_compiler = shutil.which('cc')
- if not c_compiler:
- # No C compiler available, give up
- return None
-
- temp = tempfile.NamedTemporaryFile()
- try:
- args = [c_compiler, '-Wl,-t', '-o', temp.name, '-l' + name]
-
- env = dict(os.environ)
- env['LC_ALL'] = 'C'
- env['LANG'] = 'C'
- try:
- proc = subprocess.Popen(args,
- stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT,
- env=env)
- except OSError: # E.g. bad executable
- return None
- with proc:
- trace = proc.stdout.read()
- finally:
- try:
- temp.close()
- except FileNotFoundError:
- # Raised if the file was already removed, which is the normal
- # behaviour of GCC if linking fails
- pass
- res = re.findall(expr, trace)
- if not res:
- return None
-
- for file in res:
- # Check if the given file is an elf file: gcc can report
- # some files that are linker scripts and not actual
- # shared objects. See bpo-41976 for more details
- if not _is_elf(file):
- continue
- return os.fsdecode(file)
+ return None
if sys.platform == "sunos5":
@@ -268,34 +222,7 @@ elif os.name == "posix":
else:
def _findSoname_ldconfig(name):
- import struct
- if struct.calcsize('l') == 4:
- machine = os.uname().machine + '-32'
- else:
- machine = os.uname().machine + '-64'
- mach_map = {
- 'x86_64-64': 'libc6,x86-64',
- 'ppc64-64': 'libc6,64bit',
- 'sparc64-64': 'libc6,64bit',
- 's390x-64': 'libc6,64bit',
- 'ia64-64': 'libc6,IA-64',
- }
- abi_type = mach_map.get(machine, 'libc6')
-
- # XXX assuming GLIBC's ldconfig (with option -p)
- regex = r'\s+(lib%s\.[^\s]+)\s+\(%s'
- regex = os.fsencode(regex % (re.escape(name), abi_type))
- try:
- with subprocess.Popen(['/sbin/ldconfig', '-p'],
- stdin=subprocess.DEVNULL,
- stderr=subprocess.DEVNULL,
- stdout=subprocess.PIPE,
- env={'LC_ALL': 'C', 'LANG': 'C'}) as p:
- res = re.search(regex, p.stdout.read())
- if res:
- return os.fsdecode(res.group(1))
- except OSError:
- pass
+ return None
def _findLib_ld(name):
# See issue #9998 for why this is needed
--
2.28.0

View file

@ -0,0 +1,13 @@
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 40229bce0f..3cc604930e 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -7258,7 +7258,7 @@ os_sched_getaffinity_impl(PyObject *module, pid_t pid)
#ifdef HAVE_UTMP_H
#include <utmp.h>
#endif /* HAVE_UTMP_H */
-#elif defined(HAVE_LIBUTIL_H)
+#elif defined(HAVE_LIBUTIL_H) && !defined(__APPLE__)
#include <libutil.h>
#elif defined(HAVE_UTIL_H)
#include <util.h>

View file

@ -0,0 +1,107 @@
From 5330b6af9f832af59aa5c61d9ef6971053a8e709 Mon Sep 17 00:00:00 2001
From: Jonathan Ringer <jonringer117@gmail.com>
Date: Mon, 9 Nov 2020 10:24:35 -0800
Subject: [PATCH] CPython: Don't use ldconfig
---
Lib/ctypes/util.py | 77 ++--------------------------------------------
1 file changed, 2 insertions(+), 75 deletions(-)
diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py
index 0c2510e161..7fb98af308 100644
--- a/Lib/ctypes/util.py
+++ b/Lib/ctypes/util.py
@@ -100,53 +100,7 @@ def _is_elf(filename):
return thefile.read(4) == elf_header
def _findLib_gcc(name):
- # Run GCC's linker with the -t (aka --trace) option and examine the
- # library name it prints out. The GCC command will fail because we
- # haven't supplied a proper program with main(), but that does not
- # matter.
- expr = os.fsencode(r'[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name))
-
- c_compiler = shutil.which('gcc')
- if not c_compiler:
- c_compiler = shutil.which('cc')
- if not c_compiler:
- # No C compiler available, give up
- return None
-
- temp = tempfile.NamedTemporaryFile()
- try:
- args = [c_compiler, '-Wl,-t', '-o', temp.name, '-l' + name]
-
- env = dict(os.environ)
- env['LC_ALL'] = 'C'
- env['LANG'] = 'C'
- try:
- proc = subprocess.Popen(args,
- stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT,
- env=env)
- except OSError: # E.g. bad executable
- return None
- with proc:
- trace = proc.stdout.read()
- finally:
- try:
- temp.close()
- except FileNotFoundError:
- # Raised if the file was already removed, which is the normal
- # behaviour of GCC if linking fails
- pass
- res = re.findall(expr, trace)
- if not res:
- return None
-
- for file in res:
- # Check if the given file is an elf file: gcc can report
- # some files that are linker scripts and not actual
- # shared objects. See bpo-41976 for more details
- if not _is_elf(file):
- continue
- return os.fsdecode(file)
+ return None
if sys.platform == "sunos5":
@@ -268,34 +222,7 @@ def find_library(name, is64 = False):
else:
def _findSoname_ldconfig(name):
- import struct
- if struct.calcsize('l') == 4:
- machine = os.uname().machine + '-32'
- else:
- machine = os.uname().machine + '-64'
- mach_map = {
- 'x86_64-64': 'libc6,x86-64',
- 'ppc64-64': 'libc6,64bit',
- 'sparc64-64': 'libc6,64bit',
- 's390x-64': 'libc6,64bit',
- 'ia64-64': 'libc6,IA-64',
- }
- abi_type = mach_map.get(machine, 'libc6')
-
- # XXX assuming GLIBC's ldconfig (with option -p)
- regex = r'\s+(lib%s\.[^\s]+)\s+\(%s'
- regex = os.fsencode(regex % (re.escape(name), abi_type))
- try:
- with subprocess.Popen(['/sbin/ldconfig', '-p'],
- stdin=subprocess.DEVNULL,
- stderr=subprocess.DEVNULL,
- stdout=subprocess.PIPE,
- env={'LC_ALL': 'C', 'LANG': 'C'}) as p:
- res = re.search(regex, p.stdout.read())
- if res:
- return os.fsdecode(res.group(1))
- except OSError:
- pass
+ return None
def _findLib_ld(name):
# See issue #9998 for why this is needed
--
2.33.1

View file

@ -0,0 +1,257 @@
diff --git a/Lib/_osx_support.py b/Lib/_osx_support.py
index aa66c8b9f4..71e6556bac 100644
--- a/Lib/_osx_support.py
+++ b/Lib/_osx_support.py
@@ -14,13 +14,13 @@
# configuration variables that may contain universal build flags,
# like "-arch" or "-isdkroot", that may need customization for
# the user environment
-_UNIVERSAL_CONFIG_VARS = ('CFLAGS', 'LDFLAGS', 'CPPFLAGS', 'BASECFLAGS',
- 'BLDSHARED', 'LDSHARED', 'CC', 'CXX',
- 'PY_CFLAGS', 'PY_LDFLAGS', 'PY_CPPFLAGS',
- 'PY_CORE_CFLAGS', 'PY_CORE_LDFLAGS')
+_UNIVERSAL_CONFIG_VARS = ('CFLAGS', 'CXXFLAGS', 'LDFLAGS', 'CPPFLAGS',
+ 'BASECFLAGS', 'BLDSHARED', 'LDSHARED', 'LDCXXSHARED',
+ 'CC', 'CXX', 'PY_CFLAGS', 'PY_LDFLAGS',
+ 'PY_CPPFLAGS', 'PY_CORE_LDFLAGS', 'PY_CORE_CFLAGS')
# configuration variables that may contain compiler calls
-_COMPILER_CONFIG_VARS = ('BLDSHARED', 'LDSHARED', 'CC', 'CXX')
+_COMPILER_CONFIG_VARS = ('BLDSHARED', 'LDSHARED', 'LDCXXSHARED', 'CC', 'CXX')
# prefix added to original configuration variable names
_INITPRE = '_OSX_SUPPORT_INITIAL_'
diff --git a/Lib/distutils/cygwinccompiler.py b/Lib/distutils/cygwinccompiler.py
index 66c12dd358..dddb9fd2d4 100644
--- a/Lib/distutils/cygwinccompiler.py
+++ b/Lib/distutils/cygwinccompiler.py
@@ -123,8 +123,10 @@ def __init__(self, verbose=0, dry_run=0, force=0):
# dllwrap 2.10.90 is buggy
if self.ld_version >= "2.10.90":
self.linker_dll = "gcc"
+ self.linker_dll_cxx = "g++"
else:
self.linker_dll = "dllwrap"
+ self.linker_dll_cxx = "dllwrap"
# ld_version >= "2.13" support -shared so use it instead of
# -mdll -static
@@ -138,9 +140,13 @@ def __init__(self, verbose=0, dry_run=0, force=0):
self.set_executables(compiler='gcc -mcygwin -O -Wall',
compiler_so='gcc -mcygwin -mdll -O -Wall',
compiler_cxx='g++ -mcygwin -O -Wall',
+ compiler_so_cxx='g++ -mcygwin -mdll -O -Wall',
linker_exe='gcc -mcygwin',
linker_so=('%s -mcygwin %s' %
- (self.linker_dll, shared_option)))
+ (self.linker_dll, shared_option)),
+ linker_exe_cxx='g++ -mcygwin',
+ linker_so_cxx=('%s -mcygwin %s' %
+ (self.linker_dll_cxx, shared_option)))
# cygwin and mingw32 need different sets of libraries
if self.gcc_version == "2.91.57":
@@ -164,8 +170,12 @@ def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
raise CompileError(msg)
else: # for other files use the C-compiler
try:
- self.spawn(self.compiler_so + cc_args + [src, '-o', obj] +
- extra_postargs)
+ if self.detect_language(src) == 'c++':
+ self.spawn(self.compiler_so_cxx + cc_args + [src, '-o', obj] +
+ extra_postargs)
+ else:
+ self.spawn(self.compiler_so + cc_args + [src, '-o', obj] +
+ extra_postargs)
except DistutilsExecError as msg:
raise CompileError(msg)
@@ -300,9 +310,14 @@ def __init__(self, verbose=0, dry_run=0, force=0):
self.set_executables(compiler='gcc -O -Wall',
compiler_so='gcc -mdll -O -Wall',
compiler_cxx='g++ -O -Wall',
+ compiler_so_cxx='g++ -mdll -O -Wall',
linker_exe='gcc',
linker_so='%s %s %s'
% (self.linker_dll, shared_option,
+ entry_point),
+ linker_exe_cxx='g++',
+ linker_so_cxx='%s %s %s'
+ % (self.linker_dll_cxx, shared_option,
entry_point))
# Maybe we should also append -mthreads, but then the finished
# dlls need another dll (mingwm10.dll see Mingw32 docs)
diff --git a/Lib/distutils/sysconfig.py b/Lib/distutils/sysconfig.py
index 3414a761e7..f1af560cc1 100644
--- a/Lib/distutils/sysconfig.py
+++ b/Lib/distutils/sysconfig.py
@@ -216,9 +216,11 @@ def customize_compiler(compiler):
_osx_support.customize_compiler(_config_vars)
_config_vars['CUSTOMIZED_OSX_COMPILER'] = 'True'
- (cc, cxx, cflags, ccshared, ldshared, shlib_suffix, ar, ar_flags) = \
- get_config_vars('CC', 'CXX', 'CFLAGS',
- 'CCSHARED', 'LDSHARED', 'SHLIB_SUFFIX', 'AR', 'ARFLAGS')
+ (cc, cxx, cflags, ccshared, ldshared, ldcxxshared, shlib_suffix, ar, ar_flags) = \
+ get_config_vars('CC', 'CXX', 'CFLAGS', 'CCSHARED', 'LDSHARED', 'LDCXXSHARED',
+ 'SHLIB_SUFFIX', 'AR', 'ARFLAGS')
+
+ cxxflags = cflags
if 'CC' in os.environ:
newcc = os.environ['CC']
@@ -233,19 +235,27 @@ def customize_compiler(compiler):
cxx = os.environ['CXX']
if 'LDSHARED' in os.environ:
ldshared = os.environ['LDSHARED']
+ if 'LDCXXSHARED' in os.environ:
+ ldcxxshared = os.environ['LDCXXSHARED']
if 'CPP' in os.environ:
cpp = os.environ['CPP']
else:
cpp = cc + " -E" # not always
if 'LDFLAGS' in os.environ:
ldshared = ldshared + ' ' + os.environ['LDFLAGS']
+ ldcxxshared = ldcxxshared + ' ' + os.environ['LDFLAGS']
if 'CFLAGS' in os.environ:
- cflags = cflags + ' ' + os.environ['CFLAGS']
+ cflags = os.environ['CFLAGS']
ldshared = ldshared + ' ' + os.environ['CFLAGS']
+ if 'CXXFLAGS' in os.environ:
+ cxxflags = os.environ['CXXFLAGS']
+ ldcxxshared = ldcxxshared + ' ' + os.environ['CXXFLAGS']
if 'CPPFLAGS' in os.environ:
cpp = cpp + ' ' + os.environ['CPPFLAGS']
cflags = cflags + ' ' + os.environ['CPPFLAGS']
+ cxxflags = cxxflags + ' ' + os.environ['CPPFLAGS']
ldshared = ldshared + ' ' + os.environ['CPPFLAGS']
+ ldcxxshared = ldcxxshared + ' ' + os.environ['CPPFLAGS']
if 'AR' in os.environ:
ar = os.environ['AR']
if 'ARFLAGS' in os.environ:
@@ -254,13 +264,17 @@ def customize_compiler(compiler):
archiver = ar + ' ' + ar_flags
cc_cmd = cc + ' ' + cflags
+ cxx_cmd = cxx + ' ' + cxxflags
compiler.set_executables(
preprocessor=cpp,
compiler=cc_cmd,
compiler_so=cc_cmd + ' ' + ccshared,
- compiler_cxx=cxx,
+ compiler_cxx=cxx_cmd,
+ compiler_so_cxx=cxx_cmd + ' ' + ccshared,
linker_so=ldshared,
linker_exe=cc,
+ linker_so_cxx=ldcxxshared,
+ linker_exe_cxx=cxx,
archiver=archiver)
compiler.shared_lib_extension = shlib_suffix
diff --git a/Lib/distutils/unixccompiler.py b/Lib/distutils/unixccompiler.py
index d00c48981e..4a3d271fee 100644
--- a/Lib/distutils/unixccompiler.py
+++ b/Lib/distutils/unixccompiler.py
@@ -52,14 +52,17 @@ class UnixCCompiler(CCompiler):
# are pretty generic; they will probably have to be set by an outsider
# (eg. using information discovered by the sysconfig about building
# Python extensions).
- executables = {'preprocessor' : None,
- 'compiler' : ["cc"],
- 'compiler_so' : ["cc"],
- 'compiler_cxx' : ["cc"],
- 'linker_so' : ["cc", "-shared"],
- 'linker_exe' : ["cc"],
- 'archiver' : ["ar", "-cr"],
- 'ranlib' : None,
+ executables = {'preprocessor' : None,
+ 'compiler' : ["cc"],
+ 'compiler_so' : ["cc"],
+ 'compiler_cxx' : ["c++"],
+ 'compiler_so_cxx' : ["c++"],
+ 'linker_so' : ["cc", "-shared"],
+ 'linker_exe' : ["cc"],
+ 'linker_so_cxx' : ["c++", "-shared"],
+ 'linker_exe_cxx' : ["c++"],
+ 'archiver' : ["ar", "-cr"],
+ 'ranlib' : None,
}
if sys.platform[:6] == "darwin":
@@ -110,12 +113,19 @@ def preprocess(self, source, output_file=None, macros=None,
def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
compiler_so = self.compiler_so
+ compiler_so_cxx = self.compiler_so_cxx
if sys.platform == 'darwin':
compiler_so = _osx_support.compiler_fixup(compiler_so,
cc_args + extra_postargs)
+ compiler_so_cxx = _osx_support.compiler_fixup(compiler_so_cxx,
+ cc_args + extra_postargs)
try:
- self.spawn(compiler_so + cc_args + [src, '-o', obj] +
- extra_postargs)
+ if self.detect_language(src) == 'c++':
+ self.spawn(compiler_so_cxx + cc_args + [src, '-o', obj] +
+ extra_postargs)
+ else:
+ self.spawn(compiler_so + cc_args + [src, '-o', obj] +
+ extra_postargs)
except DistutilsExecError as msg:
raise CompileError(msg)
@@ -173,30 +183,16 @@ def link(self, target_desc, objects,
ld_args.extend(extra_postargs)
self.mkpath(os.path.dirname(output_filename))
try:
- if target_desc == CCompiler.EXECUTABLE:
- linker = self.linker_exe[:]
+ if target_lang == "c++":
+ if target_desc == CCompiler.EXECUTABLE:
+ linker = self.linker_exe_cxx[:]
+ else:
+ linker = self.linker_so_cxx[:]
else:
- linker = self.linker_so[:]
- if target_lang == "c++" and self.compiler_cxx:
- # skip over environment variable settings if /usr/bin/env
- # is used to set up the linker's environment.
- # This is needed on OSX. Note: this assumes that the
- # normal and C++ compiler have the same environment
- # settings.
- i = 0
- if os.path.basename(linker[0]) == "env":
- i = 1
- while '=' in linker[i]:
- i += 1
-
- if os.path.basename(linker[i]) == 'ld_so_aix':
- # AIX platforms prefix the compiler with the ld_so_aix
- # script, so we need to adjust our linker index
- offset = 1
+ if target_desc == CCompiler.EXECUTABLE:
+ linker = self.linker_exe[:]
else:
- offset = 0
-
- linker[i+offset] = self.compiler_cxx[i]
+ linker = self.linker_so[:]
if sys.platform == 'darwin':
linker = _osx_support.compiler_fixup(linker, ld_args)
diff --git a/Makefile.pre.in b/Makefile.pre.in
index f803391346..090f14c46c 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -732,9 +732,9 @@ sharedmods: $(BUILDPYTHON) pybuilddir.txt @LIBMPDEC_INTERNAL@ @LIBEXPAT_INTERNAL
*\ -s*|s*) quiet="-q";; \
*) quiet="";; \
esac; \
- echo "$(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \
+ echo "$(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' CFLAGS='$(PY_CFLAGS)' \
$(PYTHON_FOR_BUILD) $(srcdir)/setup.py $$quiet build"; \
- $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \
+ $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' CFLAGS='$(PY_CFLAGS)' \
$(PYTHON_FOR_BUILD) $(srcdir)/setup.py $$quiet build

View file

@ -0,0 +1,107 @@
From 5330b6af9f832af59aa5c61d9ef6971053a8e709 Mon Sep 17 00:00:00 2001
From: Jonathan Ringer <jonringer117@gmail.com>
Date: Mon, 9 Nov 2020 10:24:35 -0800
Subject: [PATCH] CPython: Don't use ldconfig
---
Lib/ctypes/util.py | 77 ++--------------------------------------------
1 file changed, 2 insertions(+), 75 deletions(-)
diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py
index 0c2510e161..7fb98af308 100644
--- a/Lib/ctypes/util.py
+++ b/Lib/ctypes/util.py
@@ -100,53 +100,7 @@ def _is_elf(filename):
return thefile.read(4) == elf_header
def _findLib_gcc(name):
- # Run GCC's linker with the -t (aka --trace) option and examine the
- # library name it prints out. The GCC command will fail because we
- # haven't supplied a proper program with main(), but that does not
- # matter.
- expr = os.fsencode(r'[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name))
-
- c_compiler = shutil.which('gcc')
- if not c_compiler:
- c_compiler = shutil.which('cc')
- if not c_compiler:
- # No C compiler available, give up
- return None
-
- temp = tempfile.NamedTemporaryFile()
- try:
- args = [c_compiler, '-Wl,-t', '-o', temp.name, '-l' + name]
-
- env = dict(os.environ)
- env['LC_ALL'] = 'C'
- env['LANG'] = 'C'
- try:
- proc = subprocess.Popen(args,
- stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT,
- env=env)
- except OSError: # E.g. bad executable
- return None
- with proc:
- trace = proc.stdout.read()
- finally:
- try:
- temp.close()
- except FileNotFoundError:
- # Raised if the file was already removed, which is the normal
- # behaviour of GCC if linking fails
- pass
- res = re.findall(expr, trace)
- if not res:
- return None
-
- for file in res:
- # Check if the given file is an elf file: gcc can report
- # some files that are linker scripts and not actual
- # shared objects. See bpo-41976 for more details
- if not _is_elf(file):
- continue
- return os.fsdecode(file)
+ return None
if sys.platform == "sunos5":
@@ -268,34 +222,7 @@ def find_library(name, is64 = False):
else:
def _findSoname_ldconfig(name):
- import struct
- if struct.calcsize('l') == 4:
- machine = os.uname().machine + '-32'
- else:
- machine = os.uname().machine + '-64'
- mach_map = {
- 'x86_64-64': 'libc6,x86-64',
- 'ppc64-64': 'libc6,64bit',
- 'sparc64-64': 'libc6,64bit',
- 's390x-64': 'libc6,64bit',
- 'ia64-64': 'libc6,IA-64',
- }
- abi_type = mach_map.get(machine, 'libc6')
-
- # XXX assuming GLIBC's ldconfig (with option -p)
- regex = r'\s+(lib%s\.[^\s]+)\s+\(%s'
- regex = os.fsencode(regex % (re.escape(name), abi_type))
- try:
- with subprocess.Popen(['/sbin/ldconfig', '-p'],
- stdin=subprocess.DEVNULL,
- stderr=subprocess.DEVNULL,
- stdout=subprocess.PIPE,
- env={'LC_ALL': 'C', 'LANG': 'C'}) as p:
- res = re.search(regex, p.stdout.read())
- if res:
- return os.fsdecode(res.group(1))
- except OSError:
- pass
+ return None
def _findLib_ld(name):
# See issue #9998 for why this is needed
--
2.33.1

View file

@ -0,0 +1,107 @@
From 5330b6af9f832af59aa5c61d9ef6971053a8e709 Mon Sep 17 00:00:00 2001
From: Jonathan Ringer <jonringer117@gmail.com>
Date: Mon, 9 Nov 2020 10:24:35 -0800
Subject: [PATCH] CPython: Don't use ldconfig
---
Lib/ctypes/util.py | 77 ++--------------------------------------------
1 file changed, 2 insertions(+), 75 deletions(-)
diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py
index 0c2510e161..7fb98af308 100644
--- a/Lib/ctypes/util.py
+++ b/Lib/ctypes/util.py
@@ -100,53 +100,7 @@ def _is_elf(filename):
return thefile.read(4) == elf_header
def _findLib_gcc(name):
- # Run GCC's linker with the -t (aka --trace) option and examine the
- # library name it prints out. The GCC command will fail because we
- # haven't supplied a proper program with main(), but that does not
- # matter.
- expr = os.fsencode(r'[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name))
-
- c_compiler = shutil.which('gcc')
- if not c_compiler:
- c_compiler = shutil.which('cc')
- if not c_compiler:
- # No C compiler available, give up
- return None
-
- temp = tempfile.NamedTemporaryFile()
- try:
- args = [c_compiler, '-Wl,-t', '-o', temp.name, '-l' + name]
-
- env = dict(os.environ)
- env['LC_ALL'] = 'C'
- env['LANG'] = 'C'
- try:
- proc = subprocess.Popen(args,
- stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT,
- env=env)
- except OSError: # E.g. bad executable
- return None
- with proc:
- trace = proc.stdout.read()
- finally:
- try:
- temp.close()
- except FileNotFoundError:
- # Raised if the file was already removed, which is the normal
- # behaviour of GCC if linking fails
- pass
- res = re.findall(expr, trace)
- if not res:
- return None
-
- for file in res:
- # Check if the given file is an elf file: gcc can report
- # some files that are linker scripts and not actual
- # shared objects. See bpo-41976 for more details
- if not _is_elf(file):
- continue
- return os.fsdecode(file)
+ return None
if sys.platform == "sunos5":
@@ -268,34 +222,7 @@ def find_library(name, is64 = False):
else:
def _findSoname_ldconfig(name):
- import struct
- if struct.calcsize('l') == 4:
- machine = os.uname().machine + '-32'
- else:
- machine = os.uname().machine + '-64'
- mach_map = {
- 'x86_64-64': 'libc6,x86-64',
- 'ppc64-64': 'libc6,64bit',
- 'sparc64-64': 'libc6,64bit',
- 's390x-64': 'libc6,64bit',
- 'ia64-64': 'libc6,IA-64',
- }
- abi_type = mach_map.get(machine, 'libc6')
-
- # XXX assuming GLIBC's ldconfig (with option -p)
- regex = r'\s+(lib%s\.[^\s]+)\s+\(%s'
- regex = os.fsencode(regex % (re.escape(name), abi_type))
- try:
- with subprocess.Popen(['/sbin/ldconfig', '-p'],
- stdin=subprocess.DEVNULL,
- stderr=subprocess.DEVNULL,
- stdout=subprocess.PIPE,
- env={'LC_ALL': 'C', 'LANG': 'C'}) as p:
- res = re.search(regex, p.stdout.read())
- if res:
- return os.fsdecode(res.group(1))
- except OSError:
- pass
+ return None
def _findLib_ld(name):
# See issue #9998 for why this is needed
--
2.33.1

View file

@ -0,0 +1,12 @@
diff --git a/Lib/venv/__init__.py b/Lib/venv/__init__.py
index 4856594755..6769ab8026 100644
--- a/Lib/venv/__init__.py
+++ b/Lib/venv/__init__.py
@@ -522,6 +522,7 @@ def skip_file(f):
with open(dstfile, 'wb') as f:
f.write(new_data)
shutil.copymode(srcfile, dstfile)
+ os.chmod(dstfile, 0o644)
def upgrade_dependencies(self, context):
logger.debug(

View file

@ -0,0 +1,23 @@
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index c3682b4..16826c6 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -5880,15 +5880,13 @@ error:
#if defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) || defined(HAVE_DEV_PTMX)
#ifdef HAVE_PTY_H
#include <pty.h>
-#else
+#endif
#ifdef HAVE_LIBUTIL_H
#include <libutil.h>
-#else
+#endif
#ifdef HAVE_UTIL_H
#include <util.h>
-#endif /* HAVE_UTIL_H */
-#endif /* HAVE_LIBUTIL_H */
-#endif /* HAVE_PTY_H */
+#endif
#ifdef HAVE_STROPTS_H
#include <stropts.h>
#endif

View file

@ -0,0 +1,54 @@
From debccd4be0a8d619770f63622d9de1b451dd02ac Mon Sep 17 00:00:00 2001
From: Ben Wolsieffer <benwolsieffer@gmail.com>
Date: Fri, 25 Sep 2020 16:49:16 -0400
Subject: [PATCH] Fix finding headers when cross compiling
When cross-compiling third-party extensions, get_python_inc() may be called to
return the path to Python's headers. However, it uses the sys.prefix or
sys.exec_prefix of the build Python, which returns incorrect paths when
cross-compiling (paths pointing to build system headers).
To fix this, we use the INCLUDEPY and CONFINCLUDEPY conf variables, which can
be configured to point at host Python by setting _PYTHON_SYSCONFIGDATA_NAME.
The existing behavior is maintained on non-POSIX platforms or if a prefix is
manually specified.
---
Lib/distutils/sysconfig.py | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/Lib/distutils/sysconfig.py b/Lib/distutils/sysconfig.py
index 37feae5df7..6d4ad06696 100644
--- a/Lib/distutils/sysconfig.py
+++ b/Lib/distutils/sysconfig.py
@@ -95,8 +95,6 @@ def get_python_inc(plat_specific=0, prefix=None):
If 'prefix' is supplied, use it instead of sys.base_prefix or
sys.base_exec_prefix -- i.e., ignore 'plat_specific'.
"""
- if prefix is None:
- prefix = plat_specific and BASE_EXEC_PREFIX or BASE_PREFIX
if os.name == "posix":
if python_build:
# Assume the executable is in the build directory. The
@@ -109,9 +107,17 @@ def get_python_inc(plat_specific=0, prefix=None):
else:
incdir = os.path.join(get_config_var('srcdir'), 'Include')
return os.path.normpath(incdir)
- python_dir = 'python' + get_python_version() + build_flags
- return os.path.join(prefix, "include", python_dir)
+ if prefix is None:
+ if plat_specific:
+ return get_config_var('CONFINCLUDEPY')
+ else:
+ return get_config_var('INCLUDEPY')
+ else:
+ python_dir = 'python' + get_python_version() + build_flags
+ return os.path.join(prefix, "include", python_dir)
elif os.name == "nt":
+ if prefix is None:
+ prefix = plat_specific and BASE_EXEC_PREFIX or BASE_PREFIX
if python_build:
# Include both the include and PC dir to ensure we can find
# pyconfig.h
--
2.28.0

View file

@ -0,0 +1,37 @@
From e6b247c8e524dbe5fc03b3492f628d0d5348bc49 Mon Sep 17 00:00:00 2001
From: Victor Stinner <vstinner@redhat.com>
Date: Tue, 18 Dec 2018 14:47:21 +0100
Subject: [PATCH] bpo-35523: Remove ctypes callback workaround (GH-11211)
Remove ctypes callback workaround: no longer create a callback at startup.
Avoid SELinux alert on "import ctypes" and "import uuid".
---
Lib/ctypes/__init__.py | 5 -----
.../next/Library/2018-12-18-13-52-13.bpo-35523.SkoMno.rst | 2 ++
2 files changed, 2 insertions(+), 5 deletions(-)
create mode 100644 Misc/NEWS.d/next/Library/2018-12-18-13-52-13.bpo-35523.SkoMno.rst
diff --git a/Lib/ctypes/__init__.py b/Lib/ctypes/__init__.py
index 6146773988648..5f78beda5866e 100644
--- a/Lib/ctypes/__init__.py
+++ b/Lib/ctypes/__init__.py
@@ -266,11 +266,6 @@ def _reset_cache():
# _SimpleCData.c_char_p_from_param
POINTER(c_char).from_param = c_char_p.from_param
_pointer_type_cache[None] = c_void_p
- # XXX for whatever reasons, creating the first instance of a callback
- # function is needed for the unittests on Win64 to succeed. This MAY
- # be a compiler bug, since the problem occurs only when _ctypes is
- # compiled with the MS SDK compiler. Or an uninitialized variable?
- CFUNCTYPE(c_int)(lambda: None)
def create_unicode_buffer(init, size=None):
"""create_unicode_buffer(aString) -> character array
diff --git a/Misc/NEWS.d/next/Library/2018-12-18-13-52-13.bpo-35523.SkoMno.rst b/Misc/NEWS.d/next/Library/2018-12-18-13-52-13.bpo-35523.SkoMno.rst
new file mode 100644
index 0000000000000..94a9fd257383e
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-12-18-13-52-13.bpo-35523.SkoMno.rst
@@ -0,0 +1,2 @@
+Remove :mod:`ctypes` callback workaround: no longer create a callback at
+startup. Avoid SELinux alert on ``import ctypes`` and ``import uuid``.

View file

@ -0,0 +1,248 @@
--- a/Lib/_osx_support.py
+++ b/Lib/_osx_support.py
@@ -14,13 +14,13 @@ __all__ = [
# configuration variables that may contain universal build flags,
# like "-arch" or "-isdkroot", that may need customization for
# the user environment
-_UNIVERSAL_CONFIG_VARS = ('CFLAGS', 'LDFLAGS', 'CPPFLAGS', 'BASECFLAGS',
- 'BLDSHARED', 'LDSHARED', 'CC', 'CXX',
- 'PY_CFLAGS', 'PY_LDFLAGS', 'PY_CPPFLAGS',
- 'PY_CORE_CFLAGS', 'PY_CORE_LDFLAGS')
+_UNIVERSAL_CONFIG_VARS = ('CFLAGS', 'CXXFLAGS', 'LDFLAGS', 'CPPFLAGS',
+ 'BASECFLAGS', 'BLDSHARED', 'LDSHARED', 'LDCXXSHARED',
+ 'CC', 'CXX', 'PY_CFLAGS', 'PY_LDFLAGS',
+ 'PY_CPPFLAGS', 'PY_CORE_LDFLAGS', 'PY_CORE_CFLAGS')
# configuration variables that may contain compiler calls
-_COMPILER_CONFIG_VARS = ('BLDSHARED', 'LDSHARED', 'CC', 'CXX')
+_COMPILER_CONFIG_VARS = ('BLDSHARED', 'LDSHARED', 'LDCXXSHARED', 'CC', 'CXX')
# prefix added to original configuration variable names
_INITPRE = '_OSX_SUPPORT_INITIAL_'
--- a/Lib/distutils/cygwinccompiler.py
+++ b/Lib/distutils/cygwinccompiler.py
@@ -125,8 +125,10 @@ class CygwinCCompiler(UnixCCompiler):
# dllwrap 2.10.90 is buggy
if self.ld_version >= "2.10.90":
self.linker_dll = "gcc"
+ self.linker_dll_cxx = "g++"
else:
self.linker_dll = "dllwrap"
+ self.linker_dll_cxx = "dllwrap"
# ld_version >= "2.13" support -shared so use it instead of
# -mdll -static
@@ -140,9 +142,13 @@ class CygwinCCompiler(UnixCCompiler):
self.set_executables(compiler='gcc -mcygwin -O -Wall',
compiler_so='gcc -mcygwin -mdll -O -Wall',
compiler_cxx='g++ -mcygwin -O -Wall',
+ compiler_so_cxx='g++ -mcygwin -mdll -O -Wall',
linker_exe='gcc -mcygwin',
linker_so=('%s -mcygwin %s' %
- (self.linker_dll, shared_option)))
+ (self.linker_dll, shared_option)),
+ linker_exe_cxx='g++ -mcygwin',
+ linker_so_cxx=('%s -mcygwin %s' %
+ (self.linker_dll_cxx, shared_option)))
# cygwin and mingw32 need different sets of libraries
if self.gcc_version == "2.91.57":
@@ -166,8 +172,12 @@ class CygwinCCompiler(UnixCCompiler):
raise CompileError(msg)
else: # for other files use the C-compiler
try:
- self.spawn(self.compiler_so + cc_args + [src, '-o', obj] +
- extra_postargs)
+ if self.detect_language(src) == 'c++':
+ self.spawn(self.compiler_so_cxx + cc_args + [src, '-o', obj] +
+ extra_postargs)
+ else:
+ self.spawn(self.compiler_so + cc_args + [src, '-o', obj] +
+ extra_postargs)
except DistutilsExecError as msg:
raise CompileError(msg)
@@ -302,9 +312,14 @@ class Mingw32CCompiler(CygwinCCompiler):
self.set_executables(compiler='gcc -O -Wall',
compiler_so='gcc -mdll -O -Wall',
compiler_cxx='g++ -O -Wall',
+ compiler_so_cxx='g++ -mdll -O -Wall',
linker_exe='gcc',
linker_so='%s %s %s'
% (self.linker_dll, shared_option,
+ entry_point),
+ linker_exe_cxx='g++',
+ linker_so_cxx='%s %s %s'
+ % (self.linker_dll_cxx, shared_option,
entry_point))
# Maybe we should also append -mthreads, but then the finished
# dlls need another dll (mingwm10.dll see Mingw32 docs)
--- a/Lib/distutils/sysconfig.py
+++ b/Lib/distutils/sysconfig.py
@@ -170,9 +170,11 @@ def customize_compiler(compiler):
_osx_support.customize_compiler(_config_vars)
_config_vars['CUSTOMIZED_OSX_COMPILER'] = 'True'
- (cc, cxx, cflags, ccshared, ldshared, shlib_suffix, ar, ar_flags) = \
- get_config_vars('CC', 'CXX', 'CFLAGS',
- 'CCSHARED', 'LDSHARED', 'SHLIB_SUFFIX', 'AR', 'ARFLAGS')
+ (cc, cxx, cflags, ccshared, ldshared, ldcxxshared, shlib_suffix, ar, ar_flags) = \
+ get_config_vars('CC', 'CXX', 'CFLAGS', 'CCSHARED', 'LDSHARED', 'LDCXXSHARED',
+ 'SHLIB_SUFFIX', 'AR', 'ARFLAGS')
+
+ cxxflags = cflags
if 'CC' in os.environ:
newcc = os.environ['CC']
@@ -187,19 +189,27 @@ def customize_compiler(compiler):
cxx = os.environ['CXX']
if 'LDSHARED' in os.environ:
ldshared = os.environ['LDSHARED']
+ if 'LDCXXSHARED' in os.environ:
+ ldcxxshared = os.environ['LDCXXSHARED']
if 'CPP' in os.environ:
cpp = os.environ['CPP']
else:
cpp = cc + " -E" # not always
if 'LDFLAGS' in os.environ:
ldshared = ldshared + ' ' + os.environ['LDFLAGS']
+ ldcxxshared = ldcxxshared + ' ' + os.environ['LDFLAGS']
if 'CFLAGS' in os.environ:
- cflags = cflags + ' ' + os.environ['CFLAGS']
+ cflags = os.environ['CFLAGS']
ldshared = ldshared + ' ' + os.environ['CFLAGS']
+ if 'CXXFLAGS' in os.environ:
+ cxxflags = os.environ['CXXFLAGS']
+ ldcxxshared = ldcxxshared + ' ' + os.environ['CXXFLAGS']
if 'CPPFLAGS' in os.environ:
cpp = cpp + ' ' + os.environ['CPPFLAGS']
cflags = cflags + ' ' + os.environ['CPPFLAGS']
+ cxxflags = cxxflags + ' ' + os.environ['CPPFLAGS']
ldshared = ldshared + ' ' + os.environ['CPPFLAGS']
+ ldcxxshared = ldcxxshared + ' ' + os.environ['CPPFLAGS']
if 'AR' in os.environ:
ar = os.environ['AR']
if 'ARFLAGS' in os.environ:
@@ -208,13 +218,17 @@ def customize_compiler(compiler):
archiver = ar + ' ' + ar_flags
cc_cmd = cc + ' ' + cflags
+ cxx_cmd = cxx + ' ' + cxxflags
compiler.set_executables(
preprocessor=cpp,
compiler=cc_cmd,
compiler_so=cc_cmd + ' ' + ccshared,
- compiler_cxx=cxx,
+ compiler_cxx=cxx_cmd,
+ compiler_so_cxx=cxx_cmd + ' ' + ccshared,
linker_so=ldshared,
linker_exe=cc,
+ linker_so_cxx=ldcxxshared,
+ linker_exe_cxx=cxx,
archiver=archiver)
compiler.shared_lib_extension = shlib_suffix
--- a/Lib/distutils/unixccompiler.py
+++ b/Lib/distutils/unixccompiler.py
@@ -52,14 +52,17 @@ class UnixCCompiler(CCompiler):
# are pretty generic; they will probably have to be set by an outsider
# (eg. using information discovered by the sysconfig about building
# Python extensions).
- executables = {'preprocessor' : None,
- 'compiler' : ["cc"],
- 'compiler_so' : ["cc"],
- 'compiler_cxx' : ["cc"],
- 'linker_so' : ["cc", "-shared"],
- 'linker_exe' : ["cc"],
- 'archiver' : ["ar", "-cr"],
- 'ranlib' : None,
+ executables = {'preprocessor' : None,
+ 'compiler' : ["cc"],
+ 'compiler_so' : ["cc"],
+ 'compiler_cxx' : ["c++"],
+ 'compiler_so_cxx' : ["c++"],
+ 'linker_so' : ["cc", "-shared"],
+ 'linker_exe' : ["cc"],
+ 'linker_so_cxx' : ["c++", "-shared"],
+ 'linker_exe_cxx' : ["c++"],
+ 'archiver' : ["ar", "-cr"],
+ 'ranlib' : None,
}
if sys.platform[:6] == "darwin":
@@ -110,12 +113,19 @@ class UnixCCompiler(CCompiler):
def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
compiler_so = self.compiler_so
+ compiler_so_cxx = self.compiler_so_cxx
if sys.platform == 'darwin':
compiler_so = _osx_support.compiler_fixup(compiler_so,
cc_args + extra_postargs)
+ compiler_so_cxx = _osx_support.compiler_fixup(compiler_so_cxx,
+ cc_args + extra_postargs)
try:
- self.spawn(compiler_so + cc_args + [src, '-o', obj] +
- extra_postargs)
+ if self.detect_language(src) == 'c++':
+ self.spawn(compiler_so_cxx + cc_args + [src, '-o', obj] +
+ extra_postargs)
+ else:
+ self.spawn(compiler_so + cc_args + [src, '-o', obj] +
+ extra_postargs)
except DistutilsExecError as msg:
raise CompileError(msg)
@@ -173,30 +183,16 @@ class UnixCCompiler(CCompiler):
ld_args.extend(extra_postargs)
self.mkpath(os.path.dirname(output_filename))
try:
- if target_desc == CCompiler.EXECUTABLE:
- linker = self.linker_exe[:]
+ if target_lang == "c++":
+ if target_desc == CCompiler.EXECUTABLE:
+ linker = self.linker_exe_cxx[:]
+ else:
+ linker = self.linker_so_cxx[:]
else:
- linker = self.linker_so[:]
- if target_lang == "c++" and self.compiler_cxx:
- # skip over environment variable settings if /usr/bin/env
- # is used to set up the linker's environment.
- # This is needed on OSX. Note: this assumes that the
- # normal and C++ compiler have the same environment
- # settings.
- i = 0
- if os.path.basename(linker[0]) == "env":
- i = 1
- while '=' in linker[i]:
- i += 1
-
- if os.path.basename(linker[i]) == 'ld_so_aix':
- # AIX platforms prefix the compiler with the ld_so_aix
- # script, so we need to adjust our linker index
- offset = 1
+ if target_desc == CCompiler.EXECUTABLE:
+ linker = self.linker_exe[:]
else:
- offset = 0
-
- linker[i+offset] = self.compiler_cxx[i]
+ linker = self.linker_so[:]
if sys.platform == 'darwin':
linker = _osx_support.compiler_fixup(linker, ld_args)
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -584,10 +584,10 @@ sharedmods: $(BUILDPYTHON) pybuilddir.txt Modules/_math.o
*\ -s*|s*) quiet="-q";; \
*) quiet="";; \
esac; \
- echo "$(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \
+ echo "$(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' CFLAGS='$(PY_CFLAGS)' \
_TCLTK_INCLUDES='$(TCLTK_INCLUDES)' _TCLTK_LIBS='$(TCLTK_LIBS)' \
$(PYTHON_FOR_BUILD) $(srcdir)/setup.py $$quiet build"; \
- $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \
+ $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' CFLAGS='$(PY_CFLAGS)' \
_TCLTK_INCLUDES='$(TCLTK_INCLUDES)' _TCLTK_LIBS='$(TCLTK_LIBS)' \
$(PYTHON_FOR_BUILD) $(srcdir)/setup.py $$quiet build

View file

@ -0,0 +1,33 @@
From 1911995b1a1252d80bf2b9651840e185a1a6baf5 Mon Sep 17 00:00:00 2001
From: Hong Xu <hong@topbug.net>
Date: Thu, 25 Jul 2019 10:25:55 -0700
Subject: [PATCH] On all posix systems, not just Darwin, set LDSHARED (if not
set) according to CC
This patch is slightly different from https://bugs.python.org/issue24935
, except that we now handle LDSHARED according to CC on all posix
systems, not just Darwin or Linux.
---
Lib/distutils/sysconfig.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Lib/distutils/sysconfig.py b/Lib/distutils/sysconfig.py
index 37feae5df7..9fdce6896d 100644
--- a/Lib/distutils/sysconfig.py
+++ b/Lib/distutils/sysconfig.py
@@ -199,10 +199,10 @@ def customize_compiler(compiler):
if 'CC' in os.environ:
newcc = os.environ['CC']
- if (sys.platform == 'darwin'
+ if (os.name == 'posix'
and 'LDSHARED' not in os.environ
and ldshared.startswith(cc)):
- # On OS X, if CC is overridden, use that as the default
+ # On POSIX systems, if CC is overridden, use that as the default
# command for LDSHARED as well
ldshared = newcc + ldshared[len(cc):]
cc = newcc
--
2.25.1

View file

@ -0,0 +1,106 @@
From 66f492d2eda94bd64db833839a325caf6ba0fed5 Mon Sep 17 00:00:00 2001
From: Greg Roodt <greg@canva.com>
Date: Wed, 9 Dec 2020 17:59:24 +1100
Subject: [PATCH] Don't use ldconfig
---
Lib/ctypes/util.py | 77 ++--------------------------------------------
1 file changed, 2 insertions(+), 75 deletions(-)
diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py
index 0c2510e161..7fb98af308 100644
--- a/Lib/ctypes/util.py
+++ b/Lib/ctypes/util.py
@@ -100,53 +100,7 @@ elif os.name == "posix":
return thefile.read(4) == elf_header
def _findLib_gcc(name):
- # Run GCC's linker with the -t (aka --trace) option and examine the
- # library name it prints out. The GCC command will fail because we
- # haven't supplied a proper program with main(), but that does not
- # matter.
- expr = os.fsencode(r'[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name))
-
- c_compiler = shutil.which('gcc')
- if not c_compiler:
- c_compiler = shutil.which('cc')
- if not c_compiler:
- # No C compiler available, give up
- return None
-
- temp = tempfile.NamedTemporaryFile()
- try:
- args = [c_compiler, '-Wl,-t', '-o', temp.name, '-l' + name]
-
- env = dict(os.environ)
- env['LC_ALL'] = 'C'
- env['LANG'] = 'C'
- try:
- proc = subprocess.Popen(args,
- stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT,
- env=env)
- except OSError: # E.g. bad executable
- return None
- with proc:
- trace = proc.stdout.read()
- finally:
- try:
- temp.close()
- except FileNotFoundError:
- # Raised if the file was already removed, which is the normal
- # behaviour of GCC if linking fails
- pass
- res = re.findall(expr, trace)
- if not res:
- return None
-
- for file in res:
- # Check if the given file is an elf file: gcc can report
- # some files that are linker scripts and not actual
- # shared objects. See bpo-41976 for more details
- if not _is_elf(file):
- continue
- return os.fsdecode(file)
+ return None
if sys.platform == "sunos5":
@@ -268,34 +222,7 @@ elif os.name == "posix":
else:
def _findSoname_ldconfig(name):
- import struct
- if struct.calcsize('l') == 4:
- machine = os.uname().machine + '-32'
- else:
- machine = os.uname().machine + '-64'
- mach_map = {
- 'x86_64-64': 'libc6,x86-64',
- 'ppc64-64': 'libc6,64bit',
- 'sparc64-64': 'libc6,64bit',
- 's390x-64': 'libc6,64bit',
- 'ia64-64': 'libc6,IA-64',
- }
- abi_type = mach_map.get(machine, 'libc6')
-
- # XXX assuming GLIBC's ldconfig (with option -p)
- regex = r'\s+(lib%s\.[^\s]+)\s+\(%s'
- regex = os.fsencode(regex % (re.escape(name), abi_type))
- try:
- with subprocess.Popen(['/sbin/ldconfig', '-p'],
- stdin=subprocess.DEVNULL,
- stderr=subprocess.DEVNULL,
- stdout=subprocess.PIPE,
- env={'LC_ALL': 'C', 'LANG': 'C'}) as p:
- res = re.search(regex, p.stdout.read())
- if res:
- return os.fsdecode(res.group(1))
- except OSError:
- pass
+ return None
def _findLib_ld(name):
# See issue #9998 for why this is needed
--
2.24.3 (Apple Git-128)

View file

@ -0,0 +1,15 @@
diff --git a/setup.py b/setup.py
index 04eb6b2..2e1160d 100644
--- a/setup.py
+++ b/setup.py
@@ -1981,8 +1981,8 @@ class PyBuildExt(build_ext):
# Rather than complicate the code below, detecting and building
# AquaTk is a separate method. Only one Tkinter will be built on
# Darwin - either AquaTk, if it is found, or X11 based Tk.
- if (MACOS and self.detect_tkinter_darwin()):
- return True
+ # if (MACOS and self.detect_tkinter_darwin()):
+ # return True
# Assume we haven't found any of the libraries or include files
# The versions with dots are used on Unix, and the versions without

View file

@ -0,0 +1,106 @@
From 66f492d2eda94bd64db833839a325caf6ba0fed5 Mon Sep 17 00:00:00 2001
From: Greg Roodt <greg@canva.com>
Date: Wed, 9 Dec 2020 17:59:24 +1100
Subject: [PATCH] Don't use ldconfig
---
Lib/ctypes/util.py | 77 ++--------------------------------------------
1 file changed, 2 insertions(+), 75 deletions(-)
diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py
index 0c2510e161..7fb98af308 100644
--- a/Lib/ctypes/util.py
+++ b/Lib/ctypes/util.py
@@ -100,53 +100,7 @@ elif os.name == "posix":
return thefile.read(4) == elf_header
def _findLib_gcc(name):
- # Run GCC's linker with the -t (aka --trace) option and examine the
- # library name it prints out. The GCC command will fail because we
- # haven't supplied a proper program with main(), but that does not
- # matter.
- expr = os.fsencode(r'[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name))
-
- c_compiler = shutil.which('gcc')
- if not c_compiler:
- c_compiler = shutil.which('cc')
- if not c_compiler:
- # No C compiler available, give up
- return None
-
- temp = tempfile.NamedTemporaryFile()
- try:
- args = [c_compiler, '-Wl,-t', '-o', temp.name, '-l' + name]
-
- env = dict(os.environ)
- env['LC_ALL'] = 'C'
- env['LANG'] = 'C'
- try:
- proc = subprocess.Popen(args,
- stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT,
- env=env)
- except OSError: # E.g. bad executable
- return None
- with proc:
- trace = proc.stdout.read()
- finally:
- try:
- temp.close()
- except FileNotFoundError:
- # Raised if the file was already removed, which is the normal
- # behaviour of GCC if linking fails
- pass
- res = re.findall(expr, trace)
- if not res:
- return None
-
- for file in res:
- # Check if the given file is an elf file: gcc can report
- # some files that are linker scripts and not actual
- # shared objects. See bpo-41976 for more details
- if not _is_elf(file):
- continue
- return os.fsdecode(file)
+ return None
if sys.platform == "sunos5":
@@ -268,34 +222,7 @@ elif os.name == "posix":
else:
def _findSoname_ldconfig(name):
- import struct
- if struct.calcsize('l') == 4:
- machine = os.uname().machine + '-32'
- else:
- machine = os.uname().machine + '-64'
- mach_map = {
- 'x86_64-64': 'libc6,x86-64',
- 'ppc64-64': 'libc6,64bit',
- 'sparc64-64': 'libc6,64bit',
- 's390x-64': 'libc6,64bit',
- 'ia64-64': 'libc6,IA-64',
- }
- abi_type = mach_map.get(machine, 'libc6')
-
- # XXX assuming GLIBC's ldconfig (with option -p)
- regex = r'\s+(lib%s\.[^\s]+)\s+\(%s'
- regex = os.fsencode(regex % (re.escape(name), abi_type))
- try:
- with subprocess.Popen(['/sbin/ldconfig', '-p'],
- stdin=subprocess.DEVNULL,
- stderr=subprocess.DEVNULL,
- stdout=subprocess.PIPE,
- env={'LC_ALL': 'C', 'LANG': 'C'}) as p:
- res = re.search(regex, p.stdout.read())
- if res:
- return os.fsdecode(res.group(1))
- except OSError:
- pass
+ return None
def _findLib_ld(name):
# See issue #9998 for why this is needed
--
2.24.3 (Apple Git-128)

View file

@ -0,0 +1,618 @@
{ lib, stdenv, fetchurl, fetchpatch, fetchgit
# build dependencies
, autoconf-archive, autoreconfHook, nukeReferences, pkg-config
, python-setup-hook
# runtime dependencies
, bzip2, expat, libffi, libxcrypt, mpdecimal, ncurses, openssl, sqlite, xz, zlib
# platform-specific dependencies
, bash, configd, darwin, windows
# optional dependencies
, bluezSupport ? false, bluez, mimetypesSupport ? true, mailcap, tzdata
, withGdbm ? !stdenv.hostPlatform.isWindows, gdbm
, withReadline ? !stdenv.hostPlatform.isWindows, readline, x11Support ? false
, tcl, tk, tix, libX11, xorgproto
# splicing/cross
, pythonAttr ? "python${sourceVersion.major}${sourceVersion.minor}", self
, pkgsBuildBuild, pkgsBuildHost, pkgsBuildTarget, pkgsHostHost, pkgsTargetTarget
# build customization
, sourceVersion, hash, passthruFun, stripConfig ? false, stripIdlelib ? false
, stripTests ? false, stripTkinter ? false, rebuildBytecode ? true
, stripBytecode ? true, includeSiteCustomize ? true
, static ? stdenv.hostPlatform.isStatic, enableFramework ? false
, noldconfigPatch ? ./.
+ "/${sourceVersion.major}.${sourceVersion.minor}/no-ldconfig.patch"
, enableGIL ? true
# pgo (not reproducible) + -fno-semantic-interposition
# https://docs.python.org/3/using/configure.html#cmdoption-enable-optimizations
, enableOptimizations ? false
# improves performance, but remains reproducible
, enableNoSemanticInterposition ? true
# enabling LTO on 32bit arch causes downstream packages to fail when linking
# enabling LTO on *-darwin causes python3 to fail when linking.
, enableLTO ? stdenv.is64bit && stdenv.isLinux
# enable asserts to ensure the build remains reproducible
, reproducibleBuild ? false
# for the Python package set
, packageOverrides ? (self: super: { })
# tests
, testers
}@inputs:
# Note: this package is used for bootstrapping fetchurl, and thus
# cannot use fetchpatch! All mutable patches (generated by GitHub or
# cgit) that are needed here should be included directly in Nixpkgs as
# files.
assert x11Support -> tcl != null && tk != null && xorgproto != null && libX11
!= null;
assert bluezSupport -> bluez != null;
assert lib.assertMsg (enableFramework -> stdenv.isDarwin)
"Framework builds are only supported on Darwin.";
assert lib.assertMsg (reproducibleBuild -> stripBytecode)
"Deterministic builds require stripping bytecode.";
assert lib.assertMsg (reproducibleBuild -> (!enableOptimizations))
"Deterministic builds are not achieved when optimizations are enabled.";
assert lib.assertMsg (reproducibleBuild -> (!rebuildBytecode))
"Deterministic builds are not achieved when (default unoptimized) bytecode is created.";
let
inherit (lib)
concatMapStringsSep concatStringsSep enableFeature getDev getLib optionals
optionalString replaceStrings versionOlder;
buildPackages = pkgsBuildHost;
inherit (passthru) pythonOnBuildForHost;
tzdataSupport = tzdata != null && passthru.pythonAtLeast "3.9";
passthru = let
# When we override the interpreter we also need to override the spliced versions of the interpreter
inputs' =
lib.filterAttrs (n: v: !lib.isDerivation v && n != "passthruFun") inputs;
override = attr:
let python = attr.override (inputs' // { self = python; });
in python;
in passthruFun rec {
inherit self sourceVersion packageOverrides;
implementation = "cpython";
libPrefix = "python${pythonVersion}";
executable = libPrefix;
pythonVersion = with sourceVersion; "${major}.${minor}";
sitePackages = "lib/${libPrefix}/site-packages";
inherit hasDistutilsCxxPatch pythonAttr;
pythonOnBuildForBuild = override pkgsBuildBuild.${pythonAttr};
pythonOnBuildForHost = override pkgsBuildHost.${pythonAttr};
pythonOnBuildForTarget = override pkgsBuildTarget.${pythonAttr};
pythonOnHostForHost = override pkgsHostHost.${pythonAttr};
pythonOnTargetForTarget =
lib.optionalAttrs (lib.hasAttr pythonAttr pkgsTargetTarget)
(override pkgsTargetTarget.${pythonAttr});
};
version = with sourceVersion; "${major}.${minor}.${patch}${suffix}";
nativeBuildInputs = [ nukeReferences ] ++ optionals (!stdenv.isDarwin) [
autoconf-archive # needed for AX_CHECK_COMPILE_FLAG
autoreconfHook
pkg-config
] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
buildPackages.stdenv.cc
pythonOnBuildForHost
] ++ optionals (stdenv.cc.isClang
&& (!stdenv.hostPlatform.useAndroidPrebuilt or false)
&& (enableLTO || enableOptimizations)) [ stdenv.cc.cc.libllvm.out ];
buildInputs = lib.filter (p: p != null)
([ bzip2 expat libffi libxcrypt mpdecimal ncurses openssl sqlite xz zlib ]
++ optionals bluezSupport [ bluez ]
++ optionals enableFramework [ darwin.apple_sdk.frameworks.Cocoa ]
++ optionals stdenv.hostPlatform.isMinGW [
windows.dlfcn
windows.mingw_w64_pthreads
] ++ optionals stdenv.isDarwin [ configd ]
++ optionals tzdataSupport [ tzdata ] ++ optionals withGdbm [ gdbm ]
++ optionals withReadline [ readline ]
++ optionals x11Support [ libX11 tcl tk xorgproto ]);
hasDistutilsCxxPatch = !(stdenv.cc.isGNU or false);
pythonOnBuildForHostInterpreter =
if stdenv.hostPlatform == stdenv.buildPlatform then
"$out/bin/python"
else
pythonOnBuildForHost.interpreter;
src = fetchurl {
url = with sourceVersion;
"https://www.python.org/ftp/python/${major}.${minor}.${patch}/Python-${version}.tar.xz";
inherit hash;
};
# The CPython interpreter contains a _sysconfigdata_<platform specific suffix>
# module that is imported by the sysconfig and distutils.sysconfig modules.
# The sysconfigdata module is generated at build time and contains settings
# required for building Python extension modules, such as include paths and
# other compiler flags. By default, the sysconfigdata module is loaded from
# the currently running interpreter (ie. the build platform interpreter), but
# when cross-compiling we want to load it from the host platform interpreter.
# This can be done using the _PYTHON_SYSCONFIGDATA_NAME environment variable.
# The _PYTHON_HOST_PLATFORM variable also needs to be set to get the correct
# platform suffix on extension modules. The correct values for these variables
# are not documented, and must be derived from the configure script (see links
# below).
sysconfigdataHook = with stdenv.hostPlatform;
with passthru;
let
machdep = if isWindows then
"win32"
else
parsed.kernel.name; # win32 is added by Fedoras patch
# https://github.com/python/cpython/blob/e488e300f5c01289c10906c2e53a8e43d6de32d8/configure.ac#L428
# The configure script uses "arm" as the CPU name for all 32-bit ARM
# variants when cross-compiling, but native builds include the version
# suffix, so we do the same.
pythonHostPlatform = let
cpu = {
# According to PEP600, Python's name for the Power PC
# architecture is "ppc", not "powerpc". Without the Rosetta
# Stone below, the PEP600 requirement that "${ARCH} matches
# the return value from distutils.util.get_platform()" fails.
# https://peps.python.org/pep-0600/
powerpc = "ppc";
powerpcle = "ppcle";
powerpc64 = "ppc64";
powerpc64le = "ppc64le";
}.${parsed.cpu.name} or parsed.cpu.name;
in "${machdep}-${cpu}";
# https://github.com/python/cpython/blob/e488e300f5c01289c10906c2e53a8e43d6de32d8/configure.ac#L724
multiarchCpu = if isAarch32 then
if parsed.cpu.significantByte.name == "littleEndian" then
"arm"
else
"armeb"
else if isx86_32 then
"i386"
else
parsed.cpu.name;
pythonAbiName = let
# python's build doesn't match the nixpkgs abi in some cases.
# https://github.com/python/cpython/blob/e488e300f5c01289c10906c2e53a8e43d6de32d8/configure.ac#L724
nixpkgsPythonAbiMappings = {
"gnuabielfv2" = "gnu";
"muslabielfv2" = "musl";
};
pythonAbi =
nixpkgsPythonAbiMappings.${parsed.abi.name} or parsed.abi.name;
# Python <3.11 doesn't distinguish musl and glibc and always prefixes with "gnu"
in if versionOlder version "3.11" then
replaceStrings [ "musl" ] [ "gnu" ] pythonAbi
else
pythonAbi;
multiarch = if isDarwin then
"darwin"
else if isWindows then
""
else
"${multiarchCpu}-${machdep}-${pythonAbiName}";
abiFlags = optionalString isPy37 "m";
# https://github.com/python/cpython/blob/e488e300f5c01289c10906c2e53a8e43d6de32d8/configure.ac#L78
pythonSysconfigdataName =
"_sysconfigdata_${abiFlags}_${machdep}_${multiarch}";
in ''
sysconfigdataHook() {
if [ "$1" = '${placeholder "out"}' ]; then
export _PYTHON_HOST_PLATFORM='${pythonHostPlatform}'
export _PYTHON_SYSCONFIGDATA_NAME='${pythonSysconfigdataName}'
fi
}
addEnvHooks "$hostOffset" sysconfigdataHook
'';
execSuffix = stdenv.hostPlatform.extensions.executable;
in with passthru;
stdenv.mkDerivation (finalAttrs: {
pname = "python3";
inherit src version;
inherit nativeBuildInputs;
buildInputs = lib.optionals (!stdenv.hostPlatform.isWindows) [
bash # only required for patchShebangs
] ++ buildInputs;
prePatch = optionalString stdenv.isDarwin ''
substituteInPlace configure --replace-fail '`/usr/bin/arch`' '"i386"'
'' + optionalString (pythonOlder "3.9" && stdenv.isDarwin && x11Support) ''
# Broken on >= 3.9; replaced with ./3.9/darwin-tcl-tk.patch
substituteInPlace setup.py --replace-fail /Library/Frameworks /no-such-path
'';
patches = [
# Disable the use of ldconfig in ctypes.util.find_library (since
# ldconfig doesn't work on NixOS), and don't use
# ctypes.util.find_library during the loading of the uuid module
# (since it will do a futile invocation of gcc (!) to find
# libuuid, slowing down program startup a lot).
noldconfigPatch
# Make sure that the virtualenv activation scripts are
# owner-writable, so venvs can be recreated without permission
# errors.
] ++ optionals (pythonOlder "3.13") [ ./virtualenv-permissions.patch ]
++ optionals (pythonAtLeast "3.13") [ ./3.13/virtualenv-permissions.patch ]
++ optionals mimetypesSupport [
# Make the mimetypes module refer to the right file
./mimetypes.patch
] ++ optionals (pythonAtLeast "3.7" && pythonOlder "3.11") [
# Fix darwin build https://bugs.python.org/issue34027
./3.7/darwin-libutil.patch
] ++ optionals (pythonAtLeast "3.11") [ ./3.11/darwin-libutil.patch ]
++ optionals (pythonAtLeast "3.9" && pythonOlder "3.11" && stdenv.isDarwin)
[
# Stop checking for TCL/TK in global macOS locations
./3.9/darwin-tcl-tk.patch
] ++ optionals (hasDistutilsCxxPatch && pythonOlder "3.12") [
# Fix for http://bugs.python.org/issue1222585
# Upstream distutils is calling C compiler to compile C++ code, which
# only works for GCC and Apple Clang. This makes distutils to call C++
# compiler when needed.
(if pythonAtLeast "3.7" && pythonOlder "3.11" then
./3.7/python-3.x-distutils-C++.patch
else if pythonAtLeast "3.11" then
./3.11/python-3.x-distutils-C++.patch
else
fetchpatch {
url =
"https://bugs.python.org/file48016/python-3.x-distutils-C++.patch";
sha256 = "1h18lnpx539h5lfxyk379dxwr8m2raigcjixkf133l4xy3f4bzi2";
})
] ++ optionals (pythonAtLeast "3.7" && pythonOlder "3.12") [
# LDSHARED now uses $CC instead of gcc. Fixes cross-compilation of extension modules.
./3.8/0001-On-all-posix-systems-not-just-Darwin-set-LDSHARED-if.patch
# Use sysconfigdata to find headers. Fixes cross-compilation of extension modules.
./3.7/fix-finding-headers-when-cross-compiling.patch
] ++ optionals (pythonOlder "3.12") [
# https://github.com/python/cpython/issues/90656
./loongarch-support.patch
] ++ optionals (pythonAtLeast "3.11" && pythonOlder "3.13") [
# backport fix for https://github.com/python/cpython/issues/95855
./platform-triplet-detection.patch
] ++ optionals (stdenv.hostPlatform.isMinGW) (let
# https://src.fedoraproject.org/rpms/mingw-python3
mingw-patch = fetchgit {
name = "mingw-python-patches";
url = "https://src.fedoraproject.org/rpms/mingw-python3.git";
rev =
"45c45833ab9e5480ad0ae00778a05ebf35812ed4"; # for python 3.11.5 at the time of writing.
sha256 = "sha256-KIyNvO6MlYTrmSy9V/DbzXm5OsIuyT/BEpuo7Umm9DI=";
};
in [ "${mingw-patch}/*.patch" ]);
postPatch = optionalString (!stdenv.hostPlatform.isWindows) ''
substituteInPlace Lib/subprocess.py \
--replace-fail "'/bin/sh'" "'${bash}/bin/sh'"
'' + optionalString mimetypesSupport ''
substituteInPlace Lib/mimetypes.py \
--replace-fail "@mime-types@" "${mailcap}"
'' + optionalString (pythonOlder "3.13" && x11Support && (tix != null)) ''
substituteInPlace "Lib/tkinter/tix.py" --replace-fail \
"os.environ.get('TIX_LIBRARY')" \
"os.environ.get('TIX_LIBRARY') or '${tix}/lib'"
'';
env = {
CPPFLAGS =
concatStringsSep " " (map (p: "-I${getDev p}/include") buildInputs);
LDFLAGS = concatStringsSep " " (map (p: "-L${getLib p}/lib") buildInputs);
LIBS = "${optionalString (!stdenv.isDarwin) "-lcrypt"}";
NIX_LDFLAGS =
lib.optionalString (stdenv.cc.isGNU && !stdenv.hostPlatform.isStatic) ({
"glibc" = "-lgcc_s";
"musl" = "-lgcc_eh";
}."${stdenv.hostPlatform.libc}" or "");
# Determinism: We fix the hashes of str, bytes and datetime objects.
PYTHONHASHSEED = 0;
};
# https://docs.python.org/3/using/configure.html
configureFlags = [ "--without-ensurepip" "--with-system-expat" ]
++ optionals (!(stdenv.isDarwin && pythonAtLeast "3.12")) [
# ./Modules/_decimal/_decimal.c:4673:6: error: "No valid combination of CONFIG_64, CONFIG_32 and _PyHASH_BITS"
# https://hydra.nixos.org/build/248410479/nixlog/2/tail
"--with-system-libmpdec"
] ++ optionals (openssl != null) [ "--with-openssl=${openssl.dev}" ]
++ optionals tzdataSupport [ "--with-tzpath=${tzdata}/share/zoneinfo" ]
++ optionals (execSuffix != "") [ "--with-suffix=${execSuffix}" ]
++ optionals enableLTO [ "--with-lto" ]
++ optionals (!static && !enableFramework) [ "--enable-shared" ]
++ optionals enableFramework
[ "--enable-framework=${placeholder "out"}/Library/Frameworks" ]
++ optionals (pythonAtLeast "3.13") [ (enableFeature enableGIL "gil") ]
++ optionals enableOptimizations [ "--enable-optimizations" ]
++ optionals (sqlite != null) [ "--enable-loadable-sqlite-extensions" ]
++ optionals (libxcrypt != null) [
"CFLAGS=-I${libxcrypt}/include"
"LIBS=-L${libxcrypt}/lib"
] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
"ac_cv_buggy_getaddrinfo=no"
# Assume little-endian IEEE 754 floating point when cross compiling
"ac_cv_little_endian_double=yes"
"ac_cv_big_endian_double=no"
"ac_cv_mixed_endian_double=no"
"ac_cv_x87_double_rounding=yes"
"ac_cv_tanh_preserves_zero_sign=yes"
# Generally assume that things are present and work
"ac_cv_posix_semaphores_enabled=yes"
"ac_cv_broken_sem_getvalue=no"
"ac_cv_wchar_t_signed=yes"
"ac_cv_rshift_extends_sign=yes"
"ac_cv_broken_nice=no"
"ac_cv_broken_poll=no"
"ac_cv_working_tzset=yes"
"ac_cv_have_long_long_format=yes"
"ac_cv_have_size_t_format=yes"
"ac_cv_computed_gotos=yes"
# Both fail when building for windows, normally configure checks this by itself but on other platforms this is set to yes always.
"ac_cv_file__dev_ptmx=${
if stdenv.hostPlatform.isWindows then "no" else "yes"
}"
"ac_cv_file__dev_ptc=${
if stdenv.hostPlatform.isWindows then "no" else "yes"
}"
] ++ optionals
(stdenv.hostPlatform != stdenv.buildPlatform && pythonAtLeast "3.11")
[ "--with-build-python=${pythonOnBuildForHostInterpreter}" ]
++ optionals stdenv.hostPlatform.isLinux [
# Never even try to use lchmod on linux,
# don't rely on detecting glibc-isms.
"ac_cv_func_lchmod=no"
] ++ optionals static [ "LDFLAGS=-static" ];
preConfigure = optionalString (pythonOlder "3.12") ''
# Improve purity
for path in /usr /sw /opt /pkg; do
substituteInPlace ./setup.py --replace-warn $path /no-such-path
done
'' + optionalString stdenv.isDarwin ''
# Override the auto-detection in setup.py, which assumes a universal build
export PYTHON_DECIMAL_WITH_MACHINE=${
if stdenv.isAarch64 then "uint128" else "x64"
}
'' + optionalString (stdenv.isDarwin && x11Support && pythonAtLeast "3.11") ''
export TCLTK_LIBS="-L${tcl}/lib -L${tk}/lib -l${tcl.libPrefix} -l${tk.libPrefix}"
export TCLTK_CFLAGS="-I${tcl}/include -I${tk}/include"
'' + optionalString stdenv.hostPlatform.isMusl ''
export NIX_CFLAGS_COMPILE+=" -DTHREAD_STACK_SIZE=0x100000"
'' +
# enableNoSemanticInterposition essentially sets that CFLAG -fno-semantic-interposition
# which changes how symbols are looked up. This essentially means we can't override
# libpython symbols via LD_PRELOAD anymore. This is common enough as every build
# that uses --enable-optimizations has the same "issue".
#
# The Fedora wiki has a good article about their journey towards enabling this flag:
# https://fedoraproject.org/wiki/Changes/PythonNoSemanticInterpositionSpeedup
optionalString enableNoSemanticInterposition ''
export CFLAGS_NODIST="-fno-semantic-interposition"
'';
setupHook = python-setup-hook sitePackages;
postInstall = let
# References *not* to nuke from (sys)config files
keep-references = concatMapStringsSep " " (val: "-e ${val}")
([ (placeholder "out") libxcrypt ] ++ optionals tzdataSupport [ tzdata ]);
in lib.optionalString enableFramework ''
for dir in include lib share; do
ln -s $out/Library/Frameworks/Python.framework/Versions/Current/$dir $out/$dir
done
'' + ''
# needed for some packages, especially packages that backport functionality
# to 2.x from 3.x
for item in $out/lib/${libPrefix}/test/*; do
if [[ "$item" != */test_support.py*
&& "$item" != */test/support
&& "$item" != */test/libregrtest
&& "$item" != */test/regrtest.py* ]]; then
rm -rf "$item"
else
echo $item
fi
done
touch $out/lib/${libPrefix}/test/__init__.py
# Determinism: Windows installers were not deterministic.
# We're also not interested in building Windows installers.
find "$out" -name 'wininst*.exe' | xargs -r rm -f
# Use Python3 as default python
ln -s "$out/bin/idle3" "$out/bin/idle"
ln -s "$out/bin/pydoc3" "$out/bin/pydoc"
ln -s "$out/bin/python3${execSuffix}" "$out/bin/python${execSuffix}"
ln -s "$out/bin/python3-config" "$out/bin/python-config"
ln -s "$out/lib/pkgconfig/python3.pc" "$out/lib/pkgconfig/python.pc"
ln -sL "$out/share/man/man1/python3.1.gz" "$out/share/man/man1/python.1.gz"
# Get rid of retained dependencies on -dev packages, and remove
# some $TMPDIR references to improve binary reproducibility.
# Note that the .pyc file of _sysconfigdata.py should be regenerated!
for i in $out/lib/${libPrefix}/_sysconfigdata*.py $out/lib/${libPrefix}/config-${sourceVersion.major}${sourceVersion.minor}*/Makefile; do
sed -i $i -e "s|$TMPDIR|/no-such-path|g"
done
# Further get rid of references. https://github.com/NixOS/nixpkgs/issues/51668
find $out/lib/python*/config-* -type f -print -exec nuke-refs ${keep-references} '{}' +
find $out/lib -name '_sysconfigdata*.py*' -print -exec nuke-refs ${keep-references} '{}' +
# Make the sysconfigdata module accessible on PYTHONPATH
# This allows build Python to import host Python's sysconfigdata
mkdir -p "$out/${sitePackages}"
ln -s "$out/lib/${libPrefix}/"_sysconfigdata*.py "$out/${sitePackages}/"
'' + optionalString stripConfig ''
rm -R $out/bin/python*-config $out/lib/python*/config-*
'' + optionalString stripIdlelib ''
# Strip IDLE (and turtledemo, which uses it)
rm -R $out/bin/idle* $out/lib/python*/{idlelib,turtledemo}
'' + optionalString stripTkinter ''
rm -R $out/lib/python*/tkinter
'' + optionalString stripTests ''
# Strip tests
rm -R $out/lib/python*/test $out/lib/python*/**/test{,s}
'' + optionalString includeSiteCustomize ''
# Include a sitecustomize.py file
cp ${../sitecustomize.py} $out/${sitePackages}/sitecustomize.py
'' + optionalString stripBytecode ''
# Determinism: deterministic bytecode
# First we delete all old bytecode.
find $out -type d -name __pycache__ -print0 | xargs -0 -I {} rm -rf "{}"
'' + optionalString rebuildBytecode ''
# Python 3.7 implements PEP 552, introducing support for deterministic bytecode.
# compileall uses the therein introduced checked-hash method by default when
# `SOURCE_DATE_EPOCH` is set.
# We exclude lib2to3 because that's Python 2 code which fails
# We build 3 levels of optimized bytecode. Note the default level, without optimizations,
# is not reproducible yet. https://bugs.python.org/issue29708
# Not creating bytecode will result in a large performance loss however, so we do build it.
find $out -name "*.py" | ${pythonOnBuildForHostInterpreter} -m compileall -q -f -x "lib2to3" -i -
find $out -name "*.py" | ${pythonOnBuildForHostInterpreter} -O -m compileall -q -f -x "lib2to3" -i -
find $out -name "*.py" | ${pythonOnBuildForHostInterpreter} -OO -m compileall -q -f -x "lib2to3" -i -
'' + ''
# *strip* shebang from libpython gdb script - it should be dual-syntax and
# interpretable by whatever python the gdb in question is using, which may
# not even match the major version of this python. doing this after the
# bytecode compilations for the same reason - we don't want bytecode generated.
mkdir -p $out/share/gdb
sed '/^#!/d' Tools/gdb/libpython.py > $out/share/gdb/libpython.py
# Disable system-wide pip installation. See https://peps.python.org/pep-0668/.
cat <<'EXTERNALLY_MANAGED' > $out/lib/${libPrefix}/EXTERNALLY-MANAGED
[externally-managed]
Error=This command has been disabled as it tries to modify the immutable
`/nix/store` filesystem.
To use Python with Nix and nixpkgs, have a look at the online documentation:
<https://nixos.org/manual/nixpkgs/stable/#python>.
EXTERNALLY_MANAGED
'' + optionalString stdenv.hostPlatform.isWindows ''
# Shebang files that link against the build python. Shebang dont work on windows
rm $out/bin/2to3*
rm $out/bin/idle*
rm $out/bin/pydoc*
echo linking DLLs for pythons compiled librairies
linkDLLsInfolder $out/lib/python*/lib-dynload/
'';
preFixup = lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) ''
# Ensure patch-shebangs uses shebangs of host interpreter.
export PATH=${lib.makeBinPath [ "$out" ]}:$PATH
'';
# Add CPython specific setup-hook that configures distutils.sysconfig to
# always load sysconfigdata from host Python.
postFixup = lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
cat << "EOF" >> "$out/nix-support/setup-hook"
${sysconfigdataHook}
EOF
'';
# Enforce that we don't have references to the OpenSSL -dev package, which we
# explicitly specify in our configure flags above.
disallowedReferences =
lib.optionals (openssl != null && !static && !enableFramework)
[ openssl.dev ]
++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
# Ensure we don't have references to build-time packages.
# These typically end up in shebangs.
pythonOnBuildForHost
buildPackages.bash
];
separateDebugInfo = true;
passthru = passthru // {
doc = stdenv.mkDerivation {
inherit src;
name = "python${pythonVersion}-${version}-doc";
patches = optionals (pythonAtLeast "3.9" && pythonOlder "3.10") [
# https://github.com/python/cpython/issues/98366
(fetchpatch {
url =
"https://github.com/python/cpython/commit/5612471501b05518287ed61c1abcb9ed38c03942.patch";
hash = "sha256-p41hJwAiyRgyVjCVQokMSpSFg/VDDrqkCSxsodVb6vY=";
})
];
dontConfigure = true;
dontBuild = true;
sphinxRoot = "Doc";
postInstallSphinx = ''
mv $out/share/doc/* $out/share/doc/python${pythonVersion}-${version}
'';
nativeBuildInputs = with pkgsBuildBuild.python3.pkgs; [
sphinxHook
python-docs-theme
];
};
tests = passthru.tests // {
pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;
};
};
enableParallelBuilding = true;
meta = with lib; {
homepage = "https://www.python.org";
changelog = let
majorMinor = versions.majorMinor version;
dashedVersion = replaceStrings [ "." "a" ] [ "-" "-alpha-" ] version;
in if sourceVersion.suffix == "" then
"https://docs.python.org/release/${version}/whatsnew/changelog.html"
else
"https://docs.python.org/${majorMinor}/whatsnew/changelog.html#python-${dashedVersion}";
description = "A high-level dynamically-typed programming language";
longDescription = ''
Python is a remarkably powerful dynamic programming language that
is used in a wide variety of application domains. Some of its key
distinguishing features include: clear, readable syntax; strong
introspection capabilities; intuitive object orientation; natural
expression of procedural code; full modularity, supporting
hierarchical packages; exception-based error handling; and very
high level dynamic data types.
'';
license = licenses.psfl;
pkgConfigModules = [ "python3" ];
platforms = platforms.linux ++ platforms.darwin ++ platforms.windows;
maintainers = with maintainers; [ fridh ];
mainProgram = executable;
};
})

View file

@ -0,0 +1,19 @@
# This file was generated and will be overwritten by ./generate.sh
{ stdenv, fetchurl, lib }:
stdenv.mkDerivation {
pname = "python27-docs-html";
version = "2.7.18";
src = fetchurl {
url =
"http://www.python.org/ftp/python/doc/2.7.18/python-2.7.18-docs-html.tar.bz2";
sha256 = "03igxwpqc2lvzspnj78zz1prnmfwwj00jbvh1wsxvb0wayd5wi10";
};
installPhase = ''
mkdir -p $out/share/doc/python27
cp -R ./ $out/share/doc/python27/html
'';
meta = { maintainers = [ ]; };
}

View file

@ -0,0 +1,19 @@
# This file was generated and will be overwritten by ./generate.sh
{ stdenv, fetchurl, lib }:
stdenv.mkDerivation {
pname = "python27-docs-pdf-a4";
version = "2.7.18";
src = fetchurl {
url =
"http://www.python.org/ftp/python/doc/2.7.18/python-2.7.18-docs-pdf-a4.tar.bz2";
sha256 = "0rxb2fpxwivjpk5wi2pl1fqibr4khf9s0yq6a49k9b4awi9nkb6v";
};
installPhase = ''
mkdir -p $out/share/doc/python27
cp -R ./ $out/share/doc/python27/pdf-a4
'';
meta = { maintainers = [ ]; };
}

View file

@ -0,0 +1,19 @@
# This file was generated and will be overwritten by ./generate.sh
{ stdenv, fetchurl, lib }:
stdenv.mkDerivation {
pname = "python27-docs-pdf-letter";
version = "2.7.18";
src = fetchurl {
url =
"http://www.python.org/ftp/python/doc/2.7.18/python-2.7.18-docs-pdf-letter.tar.bz2";
sha256 = "07hbqvrdlq01cb95r1574bxqqhiqbkj4f92wzlq4d6dq1l272nan";
};
installPhase = ''
mkdir -p $out/share/doc/python27
cp -R ./ $out/share/doc/python27/pdf-letter
'';
meta = { maintainers = [ ]; };
}

View file

@ -0,0 +1,19 @@
# This file was generated and will be overwritten by ./generate.sh
{ stdenv, fetchurl, lib }:
stdenv.mkDerivation {
pname = "python27-docs-text";
version = "2.7.18";
src = fetchurl {
url =
"http://www.python.org/ftp/python/doc/2.7.18/python-2.7.18-docs-text.tar.bz2";
sha256 = "1wj7mxs52kp5lmn5mvv574sygkfnk00kbz9ya9c03yfq5dd5nvy8";
};
installPhase = ''
mkdir -p $out/share/doc/python27
cp -R ./ $out/share/doc/python27/text
'';
meta = { maintainers = [ ]; };
}

View file

@ -0,0 +1,19 @@
# This file was generated and will be overwritten by ./generate.sh
{ stdenv, fetchurl, lib }:
stdenv.mkDerivation {
pname = "python310-docs-html";
version = "3.10.7";
src = fetchurl {
url =
"http://www.python.org/ftp/python/doc/3.10.7/python-3.10.7-docs-html.tar.bz2";
sha256 = "0j86z1vmaghzj5i4frvzyfb9qwsmm09g4f4ssx5w27cm30b8k0v1";
};
installPhase = ''
mkdir -p $out/share/doc/python310
cp -R ./ $out/share/doc/python310/html
'';
meta = { maintainers = [ ]; };
}

View file

@ -0,0 +1,19 @@
# This file was generated and will be overwritten by ./generate.sh
{ stdenv, fetchurl, lib }:
stdenv.mkDerivation {
pname = "python310-docs-pdf-a4";
version = "3.10.7";
src = fetchurl {
url =
"http://www.python.org/ftp/python/doc/3.10.7/python-3.10.7-docs-pdf-a4.tar.bz2";
sha256 = "1gvi457dsj3ywwvxysp7idkk9ndngnby1dnfh1q8f5gv3kg4093r";
};
installPhase = ''
mkdir -p $out/share/doc/python310
cp -R ./ $out/share/doc/python310/pdf-a4
'';
meta = { maintainers = [ ]; };
}

View file

@ -0,0 +1,19 @@
# This file was generated and will be overwritten by ./generate.sh
{ stdenv, fetchurl, lib }:
stdenv.mkDerivation {
pname = "python310-docs-pdf-letter";
version = "3.10.7";
src = fetchurl {
url =
"http://www.python.org/ftp/python/doc/3.10.7/python-3.10.7-docs-pdf-letter.tar.bz2";
sha256 = "0hzq5n6absqsh21jp6j5iaim9a1wq69d8lc2assldzb2zg4i75hr";
};
installPhase = ''
mkdir -p $out/share/doc/python310
cp -R ./ $out/share/doc/python310/pdf-letter
'';
meta = { maintainers = [ ]; };
}

View file

@ -0,0 +1,19 @@
# This file was generated and will be overwritten by ./generate.sh
{ stdenv, fetchurl, lib }:
stdenv.mkDerivation {
pname = "python310-docs-texinfo";
version = "3.10.7";
src = fetchurl {
url =
"http://www.python.org/ftp/python/doc/3.10.7/python-3.10.7-docs-texinfo.tar.bz2";
sha256 = "0p0fifi84ijz4ng6krw7c1x965jhgysprkijblmlnax7x9rmqrdf";
};
installPhase = ''
mkdir -p $out/share/info
cp ./python.info $out/share/info
'';
meta = { maintainers = [ ]; };
}

View file

@ -0,0 +1,19 @@
# This file was generated and will be overwritten by ./generate.sh
{ stdenv, fetchurl, lib }:
stdenv.mkDerivation {
pname = "python310-docs-text";
version = "3.10.7";
src = fetchurl {
url =
"http://www.python.org/ftp/python/doc/3.10.7/python-3.10.7-docs-text.tar.bz2";
sha256 = "1zbmm2fvdjnl214y41yffyqw3ywfai5r5npc00n1wkfxsdp7gcc3";
};
installPhase = ''
mkdir -p $out/share/doc/python310
cp -R ./ $out/share/doc/python310/text
'';
meta = { maintainers = [ ]; };
}

View file

@ -0,0 +1,30 @@
{ stdenv, fetchurl, lib }:
let
pythonDocs = {
html = {
recurseForDerivations = true;
python27 = import ./2.7-html.nix { inherit stdenv fetchurl lib; };
python310 = import ./3.10-html.nix { inherit stdenv fetchurl lib; };
};
pdf_a4 = {
recurseForDerivations = true;
python27 = import ./2.7-pdf-a4.nix { inherit stdenv fetchurl lib; };
python310 = import ./3.10-pdf-a4.nix { inherit stdenv fetchurl lib; };
};
pdf_letter = {
recurseForDerivations = true;
python27 = import ./2.7-pdf-letter.nix { inherit stdenv fetchurl lib; };
python310 = import ./3.10-pdf-letter.nix { inherit stdenv fetchurl lib; };
};
text = {
recurseForDerivations = true;
python27 = import ./2.7-text.nix { inherit stdenv fetchurl lib; };
python310 = import ./3.10-text.nix { inherit stdenv fetchurl lib; };
};
texinfo = {
recurseForDerivations = true;
python310 = import ./3.10-texinfo.nix { inherit stdenv fetchurl lib; };
};
};
in pythonDocs

View file

@ -0,0 +1,71 @@
#!/usr/bin/env bash
cd -- "$(dirname -- "${BASH_SOURCE[0]}")"
TYPES="html pdf-a4 pdf-letter text texinfo"
URL=http://www.python.org/ftp/python/doc/VERSION/python-VERSION-docs-TYPE.tar.bz2
VERSIONS=$(for major in 2 3; do curl https://docs.python.org/$major/archives/ 2>/dev/null | perl -l -n -e'/<a href="python-([23].[0-9]+.[0-9]+)-docs-html.tar.bz2/ && print $1' | tail -n 1; done)
echo "Generating expressions for:
${VERSIONS}
"
cat >default.nix <<EOF
{ stdenv, fetchurl, lib }:
let
pythonDocs = {
EOF
for type in $TYPES; do
cat >>default.nix <<EOF
${type/-/_} = {
recurseForDerivations = true;
EOF
for version in $VERSIONS; do
major=$(echo -n ${version}| cut -d. -f1)
minor=$(echo -n ${version}| cut -d. -f2)
if [ "${type}" = "texinfo" ]; then
if [ "${major}" = "2" ]; then
# Python 2 doesn't have pregenerated texinfos available
continue
fi
template=template-info.nix
else
template=template.nix
fi
outfile=${major}.${minor}-${type}.nix
hash=
if [ -e ${outfile} ]; then
currentversion=$(grep "url =" ${outfile} |cut -d/ -f7)
if [ ${version} = ${currentversion} ]; then
hash=$(grep sha256 ${outfile} | cut -d'"' -f2)
fi
fi
echo "Generating ${outfile}"
url=$(echo -n $URL |sed -e "s,VERSION,${version},g" -e "s,TYPE,${type},")
sha=$(nix-prefetch-url ${url} ${hash})
sed -e "s,VERSION,${version}," \
-e "s,MAJOR,${major}," \
-e "s,MINOR,${minor}," \
-e "s,TYPE,${type}," \
-e "s,URL,${url}," \
-e "s,SHA,${sha}," < ${template} > ${outfile}
attrname=python${major}${minor}
cat >>default.nix <<EOF
${attrname} = import ./${major}.${minor}-${type}.nix {
inherit stdenv fetchurl lib;
};
EOF
echo "done."
echo
done
echo " };" >> default.nix
done
echo "}; in pythonDocs" >> default.nix

View file

@ -0,0 +1,18 @@
# This file was generated and will be overwritten by ./generate.sh
{ stdenv, fetchurl, lib }:
stdenv.mkDerivation {
pname = "pythonMAJORMINOR-docs-TYPE";
version = "VERSION";
src = fetchurl {
url = "URL";
sha256 = "SHA";
};
installPhase = ''
mkdir -p $out/share/info
cp ./python.info $out/share/info
'';
meta = { maintainers = [ ]; };
}

View file

@ -0,0 +1,18 @@
# This file was generated and will be overwritten by ./generate.sh
{ stdenv, fetchurl, lib }:
stdenv.mkDerivation {
pname = "pythonMAJORMINOR-docs-TYPE";
version = "VERSION";
src = fetchurl {
url = "URL";
sha256 = "SHA";
};
installPhase = ''
mkdir -p $out/share/doc/pythonMAJORMINOR
cp -R ./ $out/share/doc/pythonMAJORMINOR/TYPE
'';
meta = { maintainers = [ ]; };
}

View file

@ -0,0 +1,50 @@
diff --git a/configure b/configure
index 8133d47f61..334c98e208 100755
--- a/configure
+++ b/configure
@@ -6215,6 +6215,20 @@ cat > conftest.c <<EOF
# else
# error unknown platform triplet
# endif
+# elif defined(__loongarch__)
+# if defined(__loongarch_lp64)
+# if defined(__loongarch_soft_float)
+ loongarch64-linux-gnusf
+# elif defined(__loongarch_single_float)
+ loongarch64-linux-gnuf32
+# elif defined(__loongarch_double_float)
+ loongarch64-linux-gnu
+# else
+# error unknown platform triplet
+# endif
+# else
+# error unknown platform triplet
+# endif
# else
# error unknown platform triplet
# endif
diff --git a/configure.ac b/configure.ac
index 3f20d8980d..acde94a181 100644
--- a/configure.ac
+++ b/configure.ac
@@ -959,6 +959,20 @@ cat > conftest.c <<EOF
hppa-linux-gnu
# elif defined(__ia64__)
ia64-linux-gnu
+# elif defined(__loongarch__)
+# if defined(__loongarch_lp64)
+# if defined(__loongarch_soft_float)
+ loongarch64-linux-gnusf
+# elif defined(__loongarch_single_float)
+ loongarch64-linux-gnuf32
+# elif defined(__loongarch_double_float)
+ loongarch64-linux-gnu
+# else
+# error unknown platform triplet
+# endif
+# else
+# error unknown platform triplet
+# endif
# elif defined(__m68k__) && !defined(__mcoldfire__)
m68k-linux-gnu
# elif defined(__mips_hard_float) && defined(__mips_isa_rev) && (__mips_isa_rev >=6) && defined(_MIPSEL)

View file

@ -0,0 +1,23 @@
diff --git i/Lib/mimetypes.py w/Lib/mimetypes.py
index f3343c8..ab5b886 100644
--- i/Lib/mimetypes.py
+++ w/Lib/mimetypes.py
@@ -40,16 +40,8 @@
]
knownfiles = [
- "/etc/mime.types",
- "/etc/httpd/mime.types", # Mac OS X
- "/etc/httpd/conf/mime.types", # Apache
- "/etc/apache/mime.types", # Apache 1
- "/etc/apache2/mime.types", # Apache 2
- "/usr/local/etc/httpd/conf/mime.types",
- "/usr/local/lib/netscape/mime.types",
- "/usr/local/etc/httpd/conf/mime.types", # Apache 1.2
- "/usr/local/etc/mime.types", # Apache 1.3
- ]
+ "@mime-types@/etc/mime.types",
+]
inited = False
_db = None

View file

@ -0,0 +1,295 @@
diff --git a/configure.ac b/configure.ac
index ba768aea93..621ac166bd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -936,125 +936,192 @@ cat > conftest.c <<EOF
#if defined(__ANDROID__)
# Android is not a multiarch system.
#elif defined(__linux__)
+# include <features.h>
+# if defined(__UCLIBC__)
+# error uclibc not supported
+# elif defined(__dietlibc__)
+# error dietlibc not supported
+# elif defined(__GLIBC__)
+# define LIBC gnu
+# define LIBC_X32 gnux32
+# if defined(__ARM_PCS_VFP)
+# define LIBC_ARM gnueabihf
+# else
+# define LIBC_ARM gnueabi
+# endif
+# if defined(__loongarch__)
+# if defined(__loongarch_soft_float)
+# define LIBC_LA gnusf
+# elif defined(__loongarch_single_float)
+# define LIBC_LA gnuf32
+# elif defined(__loongarch_double_float)
+# define LIBC_LA gnu
+# else
+# error unknown loongarch floating-point base abi
+# endif
+# endif
+# if defined(_MIPS_SIM)
+# if defined(__mips_hard_float)
+# if _MIPS_SIM == _ABIO32
+# define LIBC_MIPS gnu
+# elif _MIPS_SIM == _ABIN32
+# define LIBC_MIPS gnuabin32
+# elif _MIPS_SIM == _ABI64
+# define LIBC_MIPS gnuabi64
+# else
+# error unknown mips sim value
+# endif
+# else
+# if _MIPS_SIM == _ABIO32
+# define LIBC_MIPS gnusf
+# elif _MIPS_SIM == _ABIN32
+# define LIBC_MIPS gnuabin32sf
+# elif _MIPS_SIM == _ABI64
+# define LIBC_MIPS gnuabi64sf
+# else
+# error unknown mips sim value
+# endif
+# endif
+# endif
+# if defined(__SPE__)
+# define LIBC_PPC gnuspe
+# else
+# define LIBC_PPC gnu
+# endif
+# else
+# include <stdarg.h>
+# ifdef __DEFINED_va_list
+# define LIBC musl
+# define LIBC_X32 muslx32
+# if defined(__ARM_PCS_VFP)
+# define LIBC_ARM musleabihf
+# else
+# define LIBC_ARM musleabi
+# endif
+# if defined(__loongarch__)
+# if defined(__loongarch_soft_float)
+# define LIBC_LA muslsf
+# elif defined(__loongarch_single_float)
+# define LIBC_LA muslf32
+# elif defined(__loongarch_double_float)
+# define LIBC_LA musl
+# else
+# error unknown loongarch floating-point base abi
+# endif
+# endif
+# if defined(_MIPS_SIM)
+# if defined(__mips_hard_float)
+# if _MIPS_SIM == _ABIO32
+# define LIBC_MIPS musl
+# elif _MIPS_SIM == _ABIN32
+# define LIBC_MIPS musln32
+# elif _MIPS_SIM == _ABI64
+# define LIBC_MIPS musl
+# else
+# error unknown mips sim value
+# endif
+# else
+# if _MIPS_SIM == _ABIO32
+# define LIBC_MIPS muslsf
+# elif _MIPS_SIM == _ABIN32
+# define LIBC_MIPS musln32sf
+# elif _MIPS_SIM == _ABI64
+# define LIBC_MIPS muslsf
+# else
+# error unknown mips sim value
+# endif
+# endif
+# endif
+# if defined(_SOFT_FLOAT) || defined(__NO_FPRS__)
+# define LIBC_PPC muslsf
+# else
+# define LIBC_PPC musl
+# endif
+# else
+# error unknown libc
+# endif
+# endif
# if defined(__x86_64__) && defined(__LP64__)
- x86_64-linux-gnu
+ x86_64-linux-LIBC
# elif defined(__x86_64__) && defined(__ILP32__)
- x86_64-linux-gnux32
+ x86_64-linux-LIBC_X32
# elif defined(__i386__)
- i386-linux-gnu
+ i386-linux-LIBC
# elif defined(__aarch64__) && defined(__AARCH64EL__)
# if defined(__ILP32__)
- aarch64_ilp32-linux-gnu
+ aarch64_ilp32-linux-LIBC
# else
- aarch64-linux-gnu
+ aarch64-linux-LIBC
# endif
# elif defined(__aarch64__) && defined(__AARCH64EB__)
# if defined(__ILP32__)
- aarch64_be_ilp32-linux-gnu
+ aarch64_be_ilp32-linux-LIBC
# else
- aarch64_be-linux-gnu
+ aarch64_be-linux-LIBC
# endif
# elif defined(__alpha__)
- alpha-linux-gnu
-# elif defined(__ARM_EABI__) && defined(__ARM_PCS_VFP)
+ alpha-linux-LIBC
+# elif defined(__ARM_EABI__)
# if defined(__ARMEL__)
- arm-linux-gnueabihf
+ arm-linux-LIBC_ARM
# else
- armeb-linux-gnueabihf
-# endif
-# elif defined(__ARM_EABI__) && !defined(__ARM_PCS_VFP)
-# if defined(__ARMEL__)
- arm-linux-gnueabi
-# else
- armeb-linux-gnueabi
+ armeb-linux-LIBC_ARM
# endif
# elif defined(__hppa__)
- hppa-linux-gnu
+ hppa-linux-LIBC
# elif defined(__ia64__)
- ia64-linux-gnu
-# elif defined(__loongarch__)
-# if defined(__loongarch_lp64)
-# if defined(__loongarch_soft_float)
- loongarch64-linux-gnusf
-# elif defined(__loongarch_single_float)
- loongarch64-linux-gnuf32
-# elif defined(__loongarch_double_float)
- loongarch64-linux-gnu
+ ia64-linux-LIBC
+# elif defined(__loongarch__) && defined(__loongarch_lp64)
+ loongarch64-linux-LIBC_LA
+# elif defined(__m68k__) && !defined(__mcoldfire__)
+ m68k-linux-LIBC
+# elif defined(__mips__)
+# if defined(__mips_isa_rev) && (__mips_isa_rev >=6)
+# if defined(_MIPSEL) && defined(__mips64)
+ mipsisa64r6el-linux-LIBC_MIPS
+# elif defined(_MIPSEL)
+ mipsisa32r6el-linux-LIBC_MIPS
+# elif defined(__mips64)
+ mipsisa64r6-linux-LIBC_MIPS
# else
-# error unknown platform triplet
+ mipsisa32r6-linux-LIBC_MIPS
# endif
# else
-# error unknown platform triplet
-# endif
-# elif defined(__m68k__) && !defined(__mcoldfire__)
- m68k-linux-gnu
-# elif defined(__mips_hard_float) && defined(__mips_isa_rev) && (__mips_isa_rev >=6) && defined(_MIPSEL)
-# if _MIPS_SIM == _ABIO32
- mipsisa32r6el-linux-gnu
-# elif _MIPS_SIM == _ABIN32
- mipsisa64r6el-linux-gnuabin32
-# elif _MIPS_SIM == _ABI64
- mipsisa64r6el-linux-gnuabi64
-# else
-# error unknown platform triplet
-# endif
-# elif defined(__mips_hard_float) && defined(__mips_isa_rev) && (__mips_isa_rev >=6)
-# if _MIPS_SIM == _ABIO32
- mipsisa32r6-linux-gnu
-# elif _MIPS_SIM == _ABIN32
- mipsisa64r6-linux-gnuabin32
-# elif _MIPS_SIM == _ABI64
- mipsisa64r6-linux-gnuabi64
-# else
-# error unknown platform triplet
-# endif
-# elif defined(__mips_hard_float) && defined(_MIPSEL)
-# if _MIPS_SIM == _ABIO32
- mipsel-linux-gnu
-# elif _MIPS_SIM == _ABIN32
- mips64el-linux-gnuabin32
-# elif _MIPS_SIM == _ABI64
- mips64el-linux-gnuabi64
-# else
-# error unknown platform triplet
-# endif
-# elif defined(__mips_hard_float)
-# if _MIPS_SIM == _ABIO32
- mips-linux-gnu
-# elif _MIPS_SIM == _ABIN32
- mips64-linux-gnuabin32
-# elif _MIPS_SIM == _ABI64
- mips64-linux-gnuabi64
-# else
-# error unknown platform triplet
+# if defined(_MIPSEL) && defined(__mips64)
+ mips64el-linux-LIBC_MIPS
+# elif defined(_MIPSEL)
+ mipsel-linux-LIBC_MIPS
+# elif defined(__mips64)
+ mips64-linux-LIBC_MIPS
+# else
+ mips-linux-LIBC_MIPS
+# endif
# endif
# elif defined(__or1k__)
- or1k-linux-gnu
-# elif defined(__powerpc__) && defined(__SPE__)
- powerpc-linux-gnuspe
+ or1k-linux-LIBC
# elif defined(__powerpc64__)
# if defined(__LITTLE_ENDIAN__)
- powerpc64le-linux-gnu
+ powerpc64le-linux-LIBC
# else
- powerpc64-linux-gnu
+ powerpc64-linux-LIBC
# endif
# elif defined(__powerpc__)
- powerpc-linux-gnu
+ powerpc-linux-LIBC_PPC
# elif defined(__s390x__)
- s390x-linux-gnu
+ s390x-linux-LIBC
# elif defined(__s390__)
- s390-linux-gnu
+ s390-linux-LIBC
# elif defined(__sh__) && defined(__LITTLE_ENDIAN__)
- sh4-linux-gnu
+ sh4-linux-LIBC
# elif defined(__sparc__) && defined(__arch64__)
- sparc64-linux-gnu
+ sparc64-linux-LIBC
# elif defined(__sparc__)
- sparc-linux-gnu
+ sparc-linux-LIBC
# elif defined(__riscv)
# if __riscv_xlen == 32
- riscv32-linux-gnu
+ riscv32-linux-LIBC
# elif __riscv_xlen == 64
- riscv64-linux-gnu
+ riscv64-linux-LIBC
# else
# error unknown platform triplet
# endif
@@ -1102,12 +1169,7 @@ cat > conftest.c <<EOF
EOF
if $CPP $CPPFLAGS conftest.c >conftest.out 2>/dev/null; then
- PLATFORM_TRIPLET=`grep -v '^#' conftest.out | grep -v '^ *$' | tr -d ' '`
- case "$build_os" in
- linux-musl*)
- PLATFORM_TRIPLET=`echo "$PLATFORM_TRIPLET" | sed 's/linux-gnu/linux-musl/'`
- ;;
- esac
+ PLATFORM_TRIPLET=`grep -v '^#' conftest.out | grep -v '^ *$' | grep -v typedef | tr -d ' '`
AC_MSG_RESULT([$PLATFORM_TRIPLET])
else
AC_MSG_RESULT([none])

View file

@ -0,0 +1,13 @@
diff --git a/Lib/venv/__init__.py b/Lib/venv/__init__.py
index caa7285..ad666ac 100644
--- a/Lib/venv/__init__.py
+++ b/Lib/venv/__init__.py
@@ -379,7 +379,7 @@ class EnvBuilder:
if data is not None:
with open(dstfile, 'wb') as f:
f.write(data)
- shutil.copymode(srcfile, dstfile)
+ os.chmod(dstfile, 0o644)
def create(env_dir, system_site_packages=False, clear=False,

View file

@ -0,0 +1,48 @@
{ __splicedPackages, callPackage, config, darwin, db, lib, libffiBoot
, makeScopeWithSplicing', pythonPackagesExtensions, stdenv }@args:
let
sources = {
python311 = {
sourceVersion = {
major = "3";
minor = "11";
patch = "9";
suffix = "";
};
hash = "sha256-mx6JZSP8UQaREmyGRAbZNgo9Hphqy9pZzaV7Wr2kW4c=";
};
};
in {
# Minimal versions of Python (built without optional dependencies)
python3Minimal = (callPackage ./cpython ({
self = __splicedPackages.python3Minimal;
inherit passthruFun;
pythonAttr = "python3Minimal";
# strip down that python version as much as possible
openssl = null;
readline = null;
ncurses = null;
gdbm = null;
configd = null;
sqlite = null;
tzdata = null;
libX11 = null;
xorgproto = null;
libffi = libffiBoot; # without test suite
stripConfig = true;
stripIdlelib = true;
stripTests = true;
stripTkinter = true;
rebuildBytecode = false;
stripBytecode = true;
includeSiteCustomize = false;
enableOptimizations = false;
enableLTO = false;
mimetypesSupport = false;
} // sources.python311)).overrideAttrs (old: {
# TODO(@Artturin): Add this to the main cpython expr
strictDeps = true;
pname = "python3-minimal";
});
}

View file

@ -0,0 +1,59 @@
{ ... }:
res: pkgs: super:
with pkgs; {
pythonInterpreters = callPackage ./. { };
inherit (pythonInterpreters)
python27 python39 python310 python311 python312 python313 python3Minimal
pypy27 pypy310 pypy39 rustpython;
# List of extensions with overrides to apply to all Python package sets.
pythonPackagesExtensions = [ ];
# Python package sets.
python27Packages = python27.pkgs // { __attrsFailEvaluation = true; };
python39Packages = python39.pkgs // { __attrsFailEvaluation = true; };
python310Packages = python310.pkgs // { __attrsFailEvaluation = true; };
python311Packages = recurseIntoAttrs python311.pkgs // {
pythonPackages = python311.pkgs // { __attrsFailEvaluation = true; };
};
python312Packages = recurseIntoAttrs python312.pkgs // {
pythonPackages = python312.pkgs // { __attrsFailEvaluation = true; };
};
python313Packages = python313.pkgs // { __attrsFailEvaluation = true; };
pypyPackages = pypy.pkgs // { __attrsFailEvaluation = true; };
pypy2Packages = pypy2.pkgs // { __attrsFailEvaluation = true; };
pypy27Packages = pypy27.pkgs // { __attrsFailEvaluation = true; };
pypy3Packages = pypy3.pkgs // { __attrsFailEvaluation = true; };
pypy39Packages = pypy39.pkgs // { __attrsFailEvaluation = true; };
pypy310Packages = pypy310.pkgs // { __attrsFailEvaluation = true; };
# Python interpreters. All standard library modules are included except for tkinter, which is
# available as `pythonPackages.tkinter` and can be used as any other Python package.
# When switching these sets, please update docs at ../../doc/languages-frameworks/python.md
python2 = python27;
python3 = python311;
# pythonPackages further below, but assigned here because they need to be in sync
python2Packages = dontRecurseIntoAttrs python27Packages;
python3Packages = dontRecurseIntoAttrs python311Packages;
# Should eventually be moved inside Python interpreters.
python-setup-hook = buildPackages.callPackage ./setup-hook.nix { };
update-python-libraries = callPackage ./update-python-libraries { };
docutils = with python3Packages;
toPythonApplication (docutils.overridePythonAttrs (attrs: rec {
version = "0.20.1";
src = attrs.src.override {
inherit version;
hash = "sha256-8IpOJ2w6FYOobc4+NKuj/gTQK7ot1R7RYQYkToqSPjs=";
};
}));
actdiag = with python3.pkgs; toPythonApplication actdiag;
blockdiag = with python3Packages; toPythonApplication blockdiag;
nwdiag = with python3Packages; toPythonApplication nwdiag;
buildcatrust = with python3.pkgs; toPythonApplication buildcatrust;
seqdiag = with python3Packages; toPythonApplication seqdiag;
}

View file

@ -0,0 +1,103 @@
{ lib, stdenv, callPackage, pythonPackagesExtensions, config
, makeScopeWithSplicing', ... }:
{ implementation, libPrefix, executable, sourceVersion, pythonVersion
, packageOverrides, sitePackages, hasDistutilsCxxPatch, pythonOnBuildForBuild
, pythonOnBuildForHost, pythonOnBuildForTarget, pythonOnHostForHost
, pythonOnTargetForTarget, pythonAttr ? null, self # is pythonOnHostForTarget
}:
let
pythonPackages = let
ensurePythonModules = items:
let
exceptions = [ stdenv ];
providesSetupHook = lib.attrByPath [ "provides" "setupHook" ] false;
valid = value:
pythonPackages.hasPythonModule value || providesSetupHook value
|| lib.elem value exceptions;
func = name: value:
if lib.isDerivation value then
lib.extendDerivation (valid value || throw
"${name} should use `buildPythonPackage` or `toPythonModule` if it is to be part of the Python packages set.")
{ } value
else
value;
in lib.mapAttrs func items;
in ensurePythonModules (callPackage
# Function that when called
# - imports python-packages.nix
# - adds spliced package sets to the package set
# - applies overrides from `packageOverrides` and `pythonPackagesOverlays`.
({ pkgs, stdenv, python, overrides }:
let
pythonPackagesFun = import ./python-packages-base.nix {
inherit stdenv pkgs lib;
python = self;
};
otherSplices = {
selfBuildBuild = pythonOnBuildForBuild.pkgs;
selfBuildHost = pythonOnBuildForHost.pkgs;
selfBuildTarget = pythonOnBuildForTarget.pkgs;
selfHostHost = pythonOnHostForHost.pkgs;
selfTargetTarget =
pythonOnTargetForTarget.pkgs or { }; # There is no Python TargetTarget.
};
hooks = import ./hooks/default.nix;
keep = self: hooks self { };
optionalExtensions = cond: as: lib.optionals cond as;
pythonExtension = import ../../../top-level/python-packages.nix;
python2Extension = import ../../../top-level/python2-packages.nix;
extensions = lib.composeManyExtensions ([ hooks pythonExtension ]
++ (optionalExtensions (!self.isPy3k) [ python2Extension ])
++ pythonPackagesExtensions ++ [ overrides ]);
aliases = self: super:
lib.optionalAttrs config.allowAliases
(import ../../../top-level/python-aliases.nix lib self super);
in makeScopeWithSplicing' {
inherit otherSplices keep;
f = lib.extends (lib.composeExtensions aliases extensions)
pythonPackagesFun;
}) {
overrides = packageOverrides;
python = self;
});
pythonOnBuildForHost_overridden = pythonOnBuildForHost.override {
inherit packageOverrides;
self = pythonOnBuildForHost_overridden;
};
in rec {
isPy27 = pythonVersion == "2.7";
isPy37 = pythonVersion == "3.7";
isPy38 = pythonVersion == "3.8";
isPy39 = pythonVersion == "3.9";
isPy310 = pythonVersion == "3.10";
isPy311 = pythonVersion == "3.11";
isPy312 = pythonVersion == "3.12";
isPy2 = lib.strings.substring 0 1 pythonVersion == "2";
isPy3 = lib.strings.substring 0 1 pythonVersion == "3";
isPy3k = isPy3;
isPyPy = lib.hasInfix "pypy" interpreter;
buildEnv = callPackage ./wrapper.nix {
python = self;
inherit (pythonPackages) requiredPythonModules;
};
withPackages =
import ./with-packages.nix { inherit buildEnv pythonPackages; };
pkgs = pythonPackages;
interpreter = "${self}/bin/${executable}";
inherit executable implementation libPrefix pythonVersion sitePackages;
inherit sourceVersion;
pythonAtLeast = lib.versionAtLeast pythonVersion;
pythonOlder = lib.versionOlder pythonVersion;
inherit hasDistutilsCxxPatch;
# Remove after 24.11 is released.
pythonForBuild = lib.warnIf (lib.isInOldestRelease 2311)
"`pythonForBuild` (from `python*`) has been renamed to `pythonOnBuildForHost`"
pythonOnBuildForHost_overridden;
pythonOnBuildForHost = pythonOnBuildForHost_overridden;
tests = callPackage ./tests.nix { python = self; };
inherit pythonAttr;
}

View file

@ -0,0 +1,13 @@
{ runCommand }:
sitePackages:
let hook = ./setup-hook.sh;
in runCommand "python-setup-hook.sh" {
strictDeps = true;
env = { inherit sitePackages; };
} ''
cp ${hook} hook.sh
substituteAllInPlace hook.sh
mv hook.sh $out
''

View file

@ -0,0 +1,26 @@
addPythonPath() {
addToSearchPathWithCustomDelimiter : PYTHONPATH $1/@sitePackages@
}
toPythonPath() {
local paths="$1"
local result=
for i in $paths; do
p="$i/@sitePackages@"
result="${result}${result:+:}$p"
done
echo $result
}
if [ -z "${dontAddPythonPath:-}" ]; then
addEnvHooks "$hostOffset" addPythonPath
fi
# Determinism: The interpreter is patched to write null timestamps when compiling python files.
# This way python doesn't try to update them when we freeze timestamps in nix store.
export DETERMINISTIC_BUILD=1;
# Determinism: We fix the hashes of str, bytes and datetime objects.
export PYTHONHASHSEED=0;
# Determinism. Whenever Python is included, it should not check user site-packages.
# This option is only relevant when the sandbox is disabled.
export PYTHONNOUSERSITE=1;

View file

@ -0,0 +1,28 @@
{ lib, stdenv, fetchurl }:
stdenv.mkDerivation rec {
pname = "which";
version = "2.21";
src = fetchurl {
url = "mirror://gnu/which/which-${version}.tar.gz";
hash = "sha256-9KJFuUEks3fYtJZGv0IfkVXTaqdhS26/g3BdP/x26q0=";
};
strictDeps = true;
enableParallelBuilding = true;
env.NIX_CFLAGS_COMPILE = toString (
# Enable 64-bit file API. Otherwise `which` fails to find tools
# on filesystems with 64-bit inodes (like `btrfs`) when running
# binaries from 32-bit systems (like `i686-linux`).
lib.optional stdenv.hostPlatform.is32bit "-D_FILE_OFFSET_BITS=64");
meta = {
homepage = "https://www.gnu.org/software/which/";
description = "Shows the full path of (shell) commands";
license = lib.licenses.gpl3Plus;
mainProgram = "which";
platforms = lib.platforms.all;
};
}