Commit 7e960dc9 authored by Thomas Petazzoni's avatar Thomas Petazzoni Committed by Peter Korsgaard
Browse files

python: bump to 2.7.6



Even though jumping from 2.7.3 to 2.7.6 looks like a minor version
bump, it is in fact a fairly significant one, because a good number of
changes to help cross-compilation have been merged into Python
upstream. Therefore, most of our patches are affected by this change.

In detail, this commit:

 * Renames all the patches to follow the naming convention of patches
   in Buildroot: the patch file names should not have any version
   number.

 * The patches numbered above 100, that add configuration options to
   disable certain modules of the Python standard library, are only
   renamed and slightly adapted, they didn't change that much.

 * The patches numbered below 100 are almost entirely rewritten: many
   of the cross-compilation problems that used to exist in Python
   2.7.3 no longer exist, and the number of remaining problems is
   smaller, and can be fixed with smaller patches.

Signed-off-by: default avatarThomas Petazzoni <thomas.petazzoni@free-electrons.com>
Signed-off-by: default avatarPeter Korsgaard <peter@korsgaard.com>
parent 577e52ac
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
setup.py: do not add invalid header locations

This piece of code incorrectly adds /usr/include to
self.compiler.include_dirs, and results in the following invalid
compilation line:

/home/thomas/projets/buildroot/output/host/usr/bin/arm-none-linux-gnueabi-gcc -fPIC \
  -fno-strict-aliasing -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 \
  -pipe -Os -DNDEBUG -g -O3 -Wall -Wstrict-prototypes \
  -I/usr/include -I. -IInclude -I./Include \
  -I/home/thomas/projets/buildroot/output/host/usr/arm-buildroot-linux-gnueabi/sysroot/usr/include \
  -I/home/thomas/projets/buildroot/output/build/python-2.7.6/Include \
  -I/home/thomas/projets/buildroot/output/build/python-2.7.6 \
  -c /home/thomas/projets/buildroot/output/build/python-2.7.6/Modules/mathmodule.c \
  -o build/temp.linux2-arm-2.7/home/thomas/projets/buildroot/output/build/python-2.7.6/Modules/mathmodule.o
cc1: warning: include location "/usr/include" is unsafe for cross-compilation [-Wpoison-system-directories]
[...]

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Index: b/setup.py
===================================================================
--- a/setup.py
+++ b/setup.py
@@ -478,7 +478,7 @@
                     for directory in reversed(options.dirs):
                         add_dir_to_list(dir_list, directory)
 
-        if os.path.normpath(sys.prefix) != '/usr' \
+        if False and os.path.normpath(sys.prefix) != '/usr' \
                 and not sysconfig.get_config_var('PYTHONFRAMEWORK'):
             # OSX note: Don't add LIBDIR and INCLUDEDIR to building a framework
             # (PYTHONFRAMEWORK is set) to avoid # linking problems when
+36 −0
Original line number Diff line number Diff line
Fix get_python_inc() for cross-compilation

When we are cross compiling, doing os.path.dirname(sys.executable) to
get the build directory is incorrect, because we're executing the host
Python to build things for the target. Instead, we should use the
project_base variable.

This fixes cross-compilation, which was adding incorrect header paths
pointing to the location where the host Python was built:

/home/thomas/projets/buildroot/output/host/usr/bin/arm-none-linux-gnueabi-gcc -fPIC -fno-strict-aliasing \
  -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -pipe -Os -DNDEBUG -g -O3 -Wall -Wstrict-prototypes \
  -I/usr/include -I. -IInclude -I./Include -I/home/thomas/projets/buildroot/output/host/usr/arm-buildroot-linux-gnueabi/sysroot/usr/include \
  -I/home/thomas/projets/buildroot/output/host/usr/bin/Include -I/home/thomas/projets/buildroot/output/host/usr/bin \
  -c /home/thomas/projets/buildroot/output/build/python-2.7.6/Modules/_struct.c \
  -o build/temp.linux2-arm-2.7/home/thomas/projets/buildroot/output/build/python-2.7.6/Modules/_struct.o

This patch allows to fix the
/home/thomas/projets/buildroot/output/host/usr/bin/Include and
/home/thomas/projets/buildroot/output/host/usr/bin paths that are
incorrectly added to the header paths.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Index: b/Lib/distutils/sysconfig.py
===================================================================
--- a/Lib/distutils/sysconfig.py
+++ b/Lib/distutils/sysconfig.py
@@ -79,7 +79,7 @@
 
     if os.name == "posix":
         if python_build:
-            buildir = os.path.dirname(sys.executable)
+            buildir = project_base
             if plat_specific:
                 # python.h is located in the buildir
                 inc_dir = buildir
+23 −0
Original line number Diff line number Diff line
distutils: fix build_ext check to find whether we're building Python or not

The build_ext logic uses
sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")) to
determine whether we're building a third-party Python extension, or a
built-in Python extension. However, this check is wrong in
cross-compilation mode, and instead, the sysconfig.python_build
variable should be used.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Index: b/Lib/distutils/command/build_ext.py
===================================================================
--- a/Lib/distutils/command/build_ext.py
+++ b/Lib/distutils/command/build_ext.py
@@ -235,7 +235,7 @@
         # Python's library directory must be appended to library_dirs
         # See Issues: #1600860, #4366
         if (sysconfig.get_config_var('Py_ENABLE_SHARED')):
-            if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")):
+            if not sysconfig.python_build:
                 # building third party extensions
                 self.library_dirs.append(sysconfig.get_config_var('LIBDIR'))
             else:
+76 −0
Original line number Diff line number Diff line
Change the install location of _sysconfigdata.py

The _sysconfigdata.py module contains definitions that are needed when
building Python modules. In cross-compilation mode, when building
Python extensions for the target, we need to use the _sysconfigdata.py
of the target Python while executing the host Python.

However until now, the _sysconfigdata.py module was installed in
build/lib.<arch>-<version> directory, together with a number of
architecture-specific shared objects, which cannot be used with the
host Python.

To solve this problem, this patch moves _sysconfigdata.py to a
separate location, build/sysconfigdata.<arch>-<version>/, and only
this directory gets added to the PYTHONPATH of the host Python
interpreter when building Python modules for the target.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>

Index: b/Makefile.pre.in
===================================================================
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -449,6 +449,9 @@
 # sys.path fixup -- see Modules/getpath.c.
 pybuilddir.txt: $(BUILDPYTHON)
 		$(RUNSHARED) $(PYTHON_FOR_BUILD) -S -m sysconfig --generate-posix-vars
+		echo `cat pybuilddir.txt`/sysconfigdata > pysysconfigdatadir.txt
+		mkdir -p `cat pysysconfigdatadir.txt`
+		cp `cat pybuilddir.txt`/_sysconfigdata.py `cat pysysconfigdatadir.txt`
 
 # Build the shared modules
 # Under GNU make, MAKEFLAGS are sorted and normalized; the 's' for
@@ -965,7 +968,7 @@
 		else	true; \
 		fi; \
 	done
-	@for i in $(srcdir)/Lib/*.py `cat pybuilddir.txt`/_sysconfigdata.py $(srcdir)/Lib/*.doc $(srcdir)/Lib/*.egg-info ; \
+	@for i in $(srcdir)/Lib/*.py $(srcdir)/Lib/*.doc $(srcdir)/Lib/*.egg-info ; \
 	do \
 		if test -x $$i; then \
 			$(INSTALL_SCRIPT) $$i $(DESTDIR)$(LIBDEST); \
@@ -975,6 +978,11 @@
 			echo $(INSTALL_DATA) $$i $(LIBDEST); \
 		fi; \
 	done
+	$(INSTALL_DATA) `cat pysysconfigdatadir.txt`/_sysconfigdata.py \
+		$(DESTDIR)$(LIBDEST)
+	mkdir -p $(DESTDIR)$(LIBDEST)/sysconfigdata
+	$(INSTALL_DATA) `cat pysysconfigdatadir.txt`/_sysconfigdata.py \
+		$(DESTDIR)$(LIBDEST)/sysconfigdata
 	@for d in $(LIBSUBDIRS); \
 	do \
 		a=$(srcdir)/Lib/$$d; \
@@ -1299,7 +1307,7 @@
 		Modules/Setup Modules/Setup.local Modules/Setup.config \
 		Modules/ld_so_aix Modules/python.exp Misc/python.pc
 	-rm -f python*-gdb.py
-	-rm -f pybuilddir.txt
+	-rm -f pybuilddir.txt pysysconfigdatadir.txt
 	find $(srcdir)/[a-zA-Z]* '(' -name '*.fdc' -o -name '*~' \
 				     -o -name '[@,#]*' -o -name '*.old' \
 				     -o -name '*.orig' -o -name '*.rej' \
Index: b/configure.ac
===================================================================
--- a/configure.ac
+++ b/configure.ac
@@ -30,7 +30,7 @@
 	    AC_MSG_ERROR([python$PACKAGE_VERSION interpreter not found])
 	fi
         AC_MSG_RESULT($interp)
-	PYTHON_FOR_BUILD='_PYTHON_PROJECT_BASE=$(abs_builddir) _PYTHON_HOST_PLATFORM=$(_PYTHON_HOST_PLATFORM) PYTHONPATH=$(shell test -f pybuilddir.txt && echo $(abs_builddir)/`cat pybuilddir.txt`:)$(srcdir)/Lib:$(srcdir)/Lib/plat-$(MACHDEP) '$interp
+	PYTHON_FOR_BUILD='_PYTHON_PROJECT_BASE=$(abs_builddir) _PYTHON_HOST_PLATFORM=$(_PYTHON_HOST_PLATFORM) PYTHONPATH=$(shell test -f pysysconfigdatadir.txt && echo $(abs_builddir)/`cat pysysconfigdatadir.txt`:)$(srcdir)/Lib:$(srcdir)/Lib/plat-$(MACHDEP) '$interp
     fi
 elif test "$cross_compiling" = maybe; then
     AC_MSG_ERROR([Cross compiling required --host=HOST-TUPLE and --build=ARCH])
+59 −0
Original line number Diff line number Diff line
Index: b/Makefile.pre.in
===================================================================
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -1013,24 +1013,32 @@
 		$(INSTALL_DATA) $(srcdir)/Modules/xxmodule.c \
 			$(DESTDIR)$(LIBDEST)/distutils/tests ; \
 	fi
+ifeq (@PYC_BUILD@,yes)
 	PYTHONPATH=$(DESTDIR)$(LIBDEST)  $(RUNSHARED) \
 		$(PYTHON_FOR_BUILD) -Wi -tt $(DESTDIR)$(LIBDEST)/compileall.py \
 		-d $(LIBDEST) -f \
 		-x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
 		$(DESTDIR)$(LIBDEST)
+endif
+ifeq (@PYO_BUILD@,yes)
 	PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
 		$(PYTHON_FOR_BUILD) -Wi -tt -O $(DESTDIR)$(LIBDEST)/compileall.py \
 		-d $(LIBDEST) -f \
 		-x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
 		$(DESTDIR)$(LIBDEST)
+endif
+ifeq (@PYC_BUILD@,yes)
 	-PYTHONPATH=$(DESTDIR)$(LIBDEST)  $(RUNSHARED) \
 		$(PYTHON_FOR_BUILD) -Wi -t $(DESTDIR)$(LIBDEST)/compileall.py \
 		-d $(LIBDEST)/site-packages -f \
 		-x badsyntax $(DESTDIR)$(LIBDEST)/site-packages
+endif
+ifeq (@PYO_BUILD@,yes)
 	-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
 		$(PYTHON_FOR_BUILD) -Wi -t -O $(DESTDIR)$(LIBDEST)/compileall.py \
 		-d $(LIBDEST)/site-packages -f \
 		-x badsyntax $(DESTDIR)$(LIBDEST)/site-packages
+endif
 	-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
 		$(PYTHON_FOR_BUILD) -m lib2to3.pgen2.driver $(DESTDIR)$(LIBDEST)/lib2to3/Grammar.txt
 	-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
Index: b/configure.ac
===================================================================
--- a/configure.ac
+++ b/configure.ac
@@ -733,6 +733,17 @@
     ;;
 esac
 
+AC_SUBST(PYC_BUILD)
+
+AC_ARG_ENABLE(pyc-build,
+	AS_HELP_STRING([--disable-pyc-build], [disable build of pyc files]),
+	[ PYC_BUILD="${enableval}" ], [ PYC_BUILD=yes ])
+
+AC_SUBST(PYO_BUILD)
+
+AC_ARG_ENABLE(pyo-build,
+	AS_HELP_STRING([--disable-pyo-build], [disable build of pyo files]),
+	[ PYO_BUILD="${enableval}" ], [ PYO_BUILD=yes ])
 
 AC_SUBST(LIBRARY)
 AC_MSG_CHECKING(LIBRARY)
Loading