Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1 | require python.inc |
| 2 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 3 | DEPENDS = "python-native libffi bzip2 gdbm openssl \ |
| 4 | readline sqlite3 zlib virtual/crypt" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 5 | |
| 6 | PR = "${INC_PR}" |
| 7 | |
| 8 | DISTRO_SRC_URI ?= "file://sitecustomize.py" |
| 9 | DISTRO_SRC_URI_linuxstdbase = "" |
| 10 | SRC_URI += "\ |
| 11 | file://01-use-proper-tools-for-cross-build.patch \ |
| 12 | file://03-fix-tkinter-detection.patch \ |
| 13 | file://06-avoid_usr_lib_termcap_path_in_linking.patch \ |
| 14 | ${DISTRO_SRC_URI} \ |
| 15 | file://multilib.patch \ |
| 16 | file://cgi_py.patch \ |
| 17 | file://setup_py_skip_cross_import_check.patch \ |
| 18 | file://add-md5module-support.patch \ |
| 19 | file://host_include_contamination.patch \ |
| 20 | file://fix_for_using_different_libdir.patch \ |
| 21 | file://setuptweaks.patch \ |
| 22 | file://check-if-target-is-64b-not-host.patch \ |
| 23 | file://search_db_h_in_inc_dirs_and_avoid_warning.patch \ |
| 24 | file://avoid_warning_about_tkinter.patch \ |
| 25 | file://avoid_warning_for_sunos_specific_module.patch \ |
| 26 | file://python-2.7.3-remove-bsdb-rpath.patch \ |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 27 | file://run-ptest \ |
| 28 | file://parallel-makeinst-create-bindir.patch \ |
| 29 | file://use_sysroot_ncurses_instead_of_host.patch \ |
| 30 | file://add-CROSSPYTHONPATH-for-PYTHON_FOR_BUILD.patch \ |
| 31 | file://pass-missing-libraries-to-Extension-for-mul.patch \ |
| 32 | file://support_SOURCE_DATE_EPOCH_in_py_compile_2.7.patch \ |
Brad Bishop | 6f8dcde | 2018-10-16 10:47:12 +0800 | [diff] [blame] | 33 | file://float-endian.patch \ |
| 34 | file://0001-closes-bpo-34540-Convert-shutil._call_external_zip-t.patch \ |
| 35 | file://0001-2.7-bpo-34623-Use-XML_SetHashSalt-in-_elementtree-GH.patch \ |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 36 | " |
| 37 | |
| 38 | S = "${WORKDIR}/Python-${PV}" |
| 39 | |
Brad Bishop | 6f8dcde | 2018-10-16 10:47:12 +0800 | [diff] [blame] | 40 | inherit autotools multilib_header python-dir pythonnative ptest |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 41 | |
| 42 | CONFIGUREOPTS += " --with-system-ffi " |
| 43 | |
| 44 | EXTRA_OECONF += "ac_cv_file__dev_ptmx=yes ac_cv_file__dev_ptc=no" |
| 45 | |
| 46 | PACKAGECONFIG ??= "bdb" |
| 47 | PACKAGECONFIG[bdb] = ",,db" |
| 48 | |
| 49 | do_configure_append() { |
| 50 | rm -f ${S}/Makefile.orig |
| 51 | autoreconf -Wcross --verbose --install --force --exclude=autopoint ../Python-${PV}/Modules/_ctypes/libffi |
| 52 | } |
| 53 | |
| 54 | do_compile() { |
| 55 | # regenerate platform specific files, because they depend on system headers |
| 56 | cd ${S}/Lib/plat-linux2 |
| 57 | include=${STAGING_INCDIR} ${STAGING_BINDIR_NATIVE}/python-native/python \ |
| 58 | ${S}/Tools/scripts/h2py.py -i '(u_long)' \ |
| 59 | ${STAGING_INCDIR}/dlfcn.h \ |
| 60 | ${STAGING_INCDIR}/linux/cdrom.h \ |
| 61 | ${STAGING_INCDIR}/netinet/in.h \ |
| 62 | ${STAGING_INCDIR}/sys/types.h |
| 63 | sed -e 's,${STAGING_DIR_HOST},,g' -i *.py |
| 64 | cd - |
| 65 | |
| 66 | # remove any bogus LD_LIBRARY_PATH |
| 67 | sed -i -e s,RUNSHARED=.*,RUNSHARED=, Makefile |
| 68 | |
| 69 | if [ ! -f Makefile.orig ]; then |
| 70 | install -m 0644 Makefile Makefile.orig |
| 71 | fi |
| 72 | sed -i -e 's#^LDFLAGS=.*#LDFLAGS=${LDFLAGS} -L. -L${STAGING_LIBDIR}#g' \ |
| 73 | -e 's,libdir=${libdir},libdir=${STAGING_LIBDIR},g' \ |
| 74 | -e 's,libexecdir=${libexecdir},libexecdir=${STAGING_DIR_HOST}${libexecdir},g' \ |
| 75 | -e 's,^LIBDIR=.*,LIBDIR=${STAGING_LIBDIR},g' \ |
| 76 | -e 's,includedir=${includedir},includedir=${STAGING_INCDIR},g' \ |
| 77 | -e 's,^INCLUDEDIR=.*,INCLUDE=${STAGING_INCDIR},g' \ |
| 78 | -e 's,^CONFINCLUDEDIR=.*,CONFINCLUDE=${STAGING_INCDIR},g' \ |
| 79 | Makefile |
| 80 | # save copy of it now, because if we do it in do_install and |
| 81 | # then call do_install twice we get Makefile.orig == Makefile.sysroot |
| 82 | install -m 0644 Makefile Makefile.sysroot |
| 83 | |
| 84 | export CROSS_COMPILE="${TARGET_PREFIX}" |
| 85 | export PYTHONBUILDDIR="${B}" |
| 86 | |
| 87 | oe_runmake HOSTPGEN=${STAGING_BINDIR_NATIVE}/python-native/pgen \ |
| 88 | HOSTPYTHON=${STAGING_BINDIR_NATIVE}/python-native/python \ |
| 89 | STAGING_LIBDIR=${STAGING_LIBDIR} \ |
| 90 | STAGING_INCDIR=${STAGING_INCDIR} \ |
| 91 | STAGING_BASELIBDIR=${STAGING_BASELIBDIR} \ |
| 92 | OPT="${CFLAGS}" |
| 93 | } |
| 94 | |
| 95 | do_install() { |
| 96 | # make install needs the original Makefile, or otherwise the inclues would |
| 97 | # go to ${D}${STAGING...}/... |
| 98 | install -m 0644 Makefile.orig Makefile |
| 99 | |
| 100 | export CROSS_COMPILE="${TARGET_PREFIX}" |
| 101 | export PYTHONBUILDDIR="${B}" |
| 102 | |
| 103 | # After swizzling the makefile, we need to run the build again. |
| 104 | # install can race with the build so we have to run this first, then install |
| 105 | oe_runmake HOSTPGEN=${STAGING_BINDIR_NATIVE}/python-native/pgen \ |
| 106 | HOSTPYTHON=${STAGING_BINDIR_NATIVE}/python-native/python \ |
| 107 | CROSSPYTHONPATH=${STAGING_LIBDIR_NATIVE}/python${PYTHON_MAJMIN}/lib-dynload/ \ |
| 108 | STAGING_LIBDIR=${STAGING_LIBDIR} \ |
| 109 | STAGING_INCDIR=${STAGING_INCDIR} \ |
| 110 | STAGING_BASELIBDIR=${STAGING_BASELIBDIR} \ |
| 111 | DESTDIR=${D} LIBDIR=${libdir} |
| 112 | |
| 113 | oe_runmake HOSTPGEN=${STAGING_BINDIR_NATIVE}/python-native/pgen \ |
| 114 | HOSTPYTHON=${STAGING_BINDIR_NATIVE}/python-native/python \ |
| 115 | CROSSPYTHONPATH=${STAGING_LIBDIR_NATIVE}/python${PYTHON_MAJMIN}/lib-dynload/ \ |
| 116 | STAGING_LIBDIR=${STAGING_LIBDIR} \ |
| 117 | STAGING_INCDIR=${STAGING_INCDIR} \ |
| 118 | STAGING_BASELIBDIR=${STAGING_BASELIBDIR} \ |
| 119 | DESTDIR=${D} LIBDIR=${libdir} install |
| 120 | |
| 121 | install -m 0644 Makefile.sysroot ${D}/${libdir}/python${PYTHON_MAJMIN}/config/Makefile |
| 122 | |
| 123 | if [ -e ${WORKDIR}/sitecustomize.py ]; then |
| 124 | install -m 0644 ${WORKDIR}/sitecustomize.py ${D}/${libdir}/python${PYTHON_MAJMIN} |
| 125 | fi |
| 126 | |
| 127 | oe_multilib_header python${PYTHON_MAJMIN}/pyconfig.h |
| 128 | |
| 129 | if [ -z "${@bb.utils.filter('PACKAGECONFIG', 'bdb', d)}" ]; then |
| 130 | rm -rf ${D}/${libdir}/python${PYTHON_MAJMIN}/bsddb |
| 131 | fi |
| 132 | } |
| 133 | |
| 134 | do_install_append_class-nativesdk () { |
Brad Bishop | d5ae7d9 | 2018-06-14 09:52:03 -0700 | [diff] [blame] | 135 | create_wrapper ${D}${bindir}/python2.7 PYTHONHOME='${prefix}' TERMINFO_DIRS='${sysconfdir}/terminfo:/etc/terminfo:/usr/share/terminfo:/usr/share/misc/terminfo:/lib/terminfo' PYTHONNOUSERSITE='1' |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | SSTATE_SCAN_FILES += "Makefile" |
| 139 | PACKAGE_PREPROCESS_FUNCS += "py_package_preprocess" |
| 140 | |
| 141 | py_package_preprocess () { |
| 142 | # copy back the old Makefile to fix target package |
| 143 | install -m 0644 ${B}/Makefile.orig ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/config/Makefile |
| 144 | |
| 145 | # Remove references to buildmachine paths in target Makefile and _sysconfigdata |
| 146 | sed -i -e 's:--sysroot=${STAGING_DIR_TARGET}::g' -e s:'--with-libtool-sysroot=${STAGING_DIR_TARGET}'::g \ |
| 147 | -e 's|${DEBUG_PREFIX_MAP}||g' \ |
| 148 | -e 's:${HOSTTOOLS_DIR}/::g' \ |
| 149 | -e 's:${RECIPE_SYSROOT_NATIVE}::g' \ |
| 150 | -e 's:${RECIPE_SYSROOT}::g' \ |
| 151 | -e 's:${BASE_WORKDIR}/${MULTIMACH_TARGET_SYS}::g' \ |
| 152 | ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/config/Makefile \ |
| 153 | ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/_sysconfigdata.py |
| 154 | (cd ${PKGD}; python -m py_compile ./${libdir}/python${PYTHON_MAJMIN}/_sysconfigdata.py) |
| 155 | } |
| 156 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 157 | PACKAGES_remove = "${PN}" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 158 | |
| 159 | # manual dependency additions |
| 160 | RPROVIDES_${PN}-core = "${PN}" |
| 161 | RRECOMMENDS_${PN}-core_append_class-nativesdk = " nativesdk-python-modules" |
| 162 | RRECOMMENDS_${PN}-crypt = "openssl" |
| 163 | |
| 164 | # package libpython2 |
| 165 | PACKAGES =+ "lib${BPN}2" |
| 166 | FILES_lib${BPN}2 = "${libdir}/libpython*.so.*" |
| 167 | |
| 168 | # catch all the rest (unsorted) |
| 169 | PACKAGES += "${PN}-misc" |
| 170 | FILES_${PN}-misc = "${libdir}/python${PYTHON_MAJMIN}" |
| 171 | RDEPENDS_${PN}-modules += "${PN}-misc" |
| 172 | |
| 173 | # ptest |
Brad Bishop | 6f8dcde | 2018-10-16 10:47:12 +0800 | [diff] [blame] | 174 | RDEPENDS_${PN}-ptest = "${PN}-modules ${PN}-tests unzip" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 175 | |
| 176 | # catch manpage |
| 177 | PACKAGES += "${PN}-man" |
| 178 | FILES_${PN}-man = "${datadir}/man" |
| 179 | |
| 180 | # Nasty but if bdb isn't enabled the package won't be generated |
| 181 | RDEPENDS_${PN}-modules_remove = "${@bb.utils.contains('PACKAGECONFIG', 'bdb', '', '${PN}-bsddb', d)}" |
| 182 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 183 | RDEPENDS_${PN}-dev = "" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 184 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 185 | BBCLASSEXTEND = "nativesdk" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 186 | |
| 187 | # We want bytecode precompiled .py files (.pyc's) by default |
| 188 | # but the user may set it on their own conf |
| 189 | |
| 190 | INCLUDE_PYCS ?= "1" |
| 191 | |
| 192 | python(){ |
Andrew Geissler | 9f6e941 | 2018-09-19 09:22:28 -0700 | [diff] [blame] | 193 | import collections, json |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 194 | |
| 195 | filename = os.path.join(d.getVar('THISDIR'), 'python', 'python2-manifest.json') |
| 196 | # This python changes the datastore based on the contents of a file, so mark |
| 197 | # that dependency. |
| 198 | bb.parse.mark_dependency(d, filename) |
| 199 | |
| 200 | with open(filename) as manifest_file: |
Brad Bishop | a5c52ff | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 201 | manifest_str = manifest_file.read() |
| 202 | json_start = manifest_str.find('# EOC') + 6 |
| 203 | manifest_file.seek(json_start) |
| 204 | manifest_str = manifest_file.read() |
| 205 | python_manifest = json.loads(manifest_str, object_pairs_hook=collections.OrderedDict) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 206 | |
| 207 | include_pycs = d.getVar('INCLUDE_PYCS') |
| 208 | |
| 209 | packages = d.getVar('PACKAGES').split() |
| 210 | pn = d.getVar('PN') |
| 211 | |
| 212 | newpackages=[] |
| 213 | |
| 214 | for key in python_manifest: |
| 215 | pypackage= pn + '-' + key |
| 216 | |
| 217 | if pypackage not in packages: |
| 218 | # We need to prepend, otherwise python-misc gets everything |
| 219 | # so we use a new variable |
| 220 | newpackages.append(pypackage) |
| 221 | |
| 222 | # "Build" python's manifest FILES, RDEPENDS and SUMMARY |
| 223 | d.setVar('FILES_' + pypackage, '') |
| 224 | for value in python_manifest[key]['files']: |
| 225 | d.appendVar('FILES_' + pypackage, ' ' + value) |
| 226 | if include_pycs == '1': |
| 227 | if value.endswith('.py'): |
| 228 | d.appendVar('FILES_' + pypackage, ' ' + value + 'c') |
| 229 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 230 | for value in python_manifest[key]['rdepends']: |
| 231 | # Make it work with or without $PN |
| 232 | if '${PN}' in value: |
| 233 | value=value.split('-')[1] |
| 234 | d.appendVar('RDEPENDS_' + pypackage, ' ' + pn + '-' + value) |
| 235 | d.setVar('SUMMARY_' + pypackage, python_manifest[key]['summary']) |
| 236 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 237 | # Prepending so to avoid python-misc getting everything |
| 238 | packages = newpackages + packages |
| 239 | d.setVar('PACKAGES', ' '.join(packages)) |
| 240 | d.setVar('ALLOW_EMPTY_${PN}-modules', '1') |
| 241 | } |
| 242 | |
| 243 | # Files needed to create a new manifest |
| 244 | SRC_URI += "file://create_manifest2.py file://get_module_deps2.py file://python2-manifest.json" |
| 245 | |
| 246 | do_create_manifest() { |
| 247 | # This task should be run with every new release of Python. |
| 248 | # We must ensure that PACKAGECONFIG enables everything when creating |
| 249 | # a new manifest, this is to base our new manifest on a complete |
| 250 | # native python build, containing all dependencies, otherwise the task |
| 251 | # wont be able to find the required files. |
| 252 | # e.g. BerkeleyDB is an optional build dependency so it may or may not |
| 253 | # be present, we must ensure it is. |
| 254 | |
| 255 | cd ${WORKDIR} |
| 256 | # This needs to be executed by python-native and NOT by HOST's python |
| 257 | nativepython create_manifest2.py |
| 258 | cp python2-manifest.json.new ${THISDIR}/python/python2-manifest.json |
| 259 | } |
| 260 | |
| 261 | # bitbake python -c create_manifest |
| 262 | addtask do_create_manifest |
| 263 | |
| 264 | # Make sure we have native python ready when we create a new manifest |
| 265 | do_create_manifest[depends] += "python:do_prepare_recipe_sysroot" |
| 266 | do_create_manifest[depends] += "python:do_patch" |