| @@ -1,121 +1,134 @@ | | | @@ -1,121 +1,134 @@ |
1 | $NetBSD: patch-setup.py,v 1.4 2022/01/14 10:32:28 tnn Exp $ | | 1 | $NetBSD: patch-setup.py,v 1.5 2022/04/03 10:54:52 riastradh Exp $ |
2 | | | 2 | |
3 | Disable certain modules, so they can be built as separate packages. | | 3 | Disable certain modules, so they can be built as separate packages. |
4 | Do not look for ncursesw. | | 4 | Do not look for ncursesw. |
5 | Assume panel_library is correct; this is a fix for ncurses' gnupanel | | 5 | Assume panel_library is correct; this is a fix for ncurses' gnupanel |
6 | which will get transformed to panel in buildlink. | | 6 | which will get transformed to panel in buildlink. |
7 | Don't search for modules in PREFIX. Fixes build failure when py-setuptools | | 7 | Don't search for modules in PREFIX. Fixes build failure when py-setuptools |
8 | are installed. | | 8 | are installed. |
| | | 9 | Enable cross-build by setting sys._home and sys.path to build directory |
9 | | | 10 | |
10 | --- setup.py.orig 2021-12-06 18:23:39.000000000 +0000 | | 11 | --- setup.py.orig 2022-03-23 20:12:04.000000000 +0000 |
11 | +++ setup.py | | 12 | +++ setup.py |
12 | @@ -13,6 +13,7 @@ import warnings | | 13 | @@ -1,5 +1,11 @@ |
| | | 14 | # Autodetecting setup.py script for building the Python extensions |
| | | 15 | |
| | | 16 | +import sys |
| | | 17 | +sys._home = __file__[:-len('/setup.py')] |
| | | 18 | +sys.path.append(__file__[:-len('/setup.py')] + '/Lib') |
| | | 19 | +with open('pybuilddir.txt') as pybuilddir: |
| | | 20 | + sys.path.append(__file__[:-len('/setup.py')] + '/' + next(pybuilddir)) |
| | | 21 | + |
| | | 22 | import argparse |
| | | 23 | import importlib._bootstrap |
| | | 24 | import importlib.machinery |
| | | 25 | @@ -13,6 +19,7 @@ import warnings |
13 | from glob import glob, escape | | 26 | from glob import glob, escape |
14 | import _osx_support | | 27 | import _osx_support |
15 | | | 28 | |
16 | +sys.path = [p for p in sys.path if not re.compile('^' + sys.base_prefix + '/').match(p)] | | 29 | +sys.path = [p for p in sys.path if not re.compile('^' + sys.base_prefix + '/').match(p)] |
17 | | | 30 | |
18 | try: | | 31 | try: |
19 | import subprocess | | 32 | import subprocess |
20 | @@ -45,6 +46,7 @@ with warnings.catch_warnings(): | | 33 | @@ -45,6 +52,7 @@ with warnings.catch_warnings(): |
21 | DeprecationWarning | | 34 | DeprecationWarning |
22 | ) | | 35 | ) |
23 | | | 36 | |
24 | + from distutils import text_file | | 37 | + from distutils import text_file |
25 | from distutils.command.build_ext import build_ext | | 38 | from distutils.command.build_ext import build_ext |
26 | from distutils.command.build_scripts import build_scripts | | 39 | from distutils.command.build_scripts import build_scripts |
27 | from distutils.command.install import install | | 40 | from distutils.command.install import install |
28 | @@ -58,7 +60,7 @@ with warnings.catch_warnings(): | | 41 | @@ -58,7 +66,7 @@ with warnings.catch_warnings(): |
29 | TEST_EXTENSIONS = (sysconfig.get_config_var('TEST_MODULES') == 'yes') | | 42 | TEST_EXTENSIONS = (sysconfig.get_config_var('TEST_MODULES') == 'yes') |
30 | | | 43 | |
31 | # This global variable is used to hold the list of modules to be disabled. | | 44 | # This global variable is used to hold the list of modules to be disabled. |
32 | -DISABLED_MODULE_LIST = [] | | 45 | -DISABLED_MODULE_LIST = [] |
33 | +DISABLED_MODULE_LIST = ["_curses", "_curses_panel", "_elementtree", "_gdbm", "pyexpat", "readline", "_sqlite3", "_tkinter", "xxlimited"] | | 46 | +DISABLED_MODULE_LIST = ["_curses", "_curses_panel", "_elementtree", "_gdbm", "pyexpat", "readline", "_sqlite3", "_tkinter", "xxlimited"] |
34 | | | 47 | |
35 | # --list-module-names option used by Tools/scripts/generate_module_names.py | | 48 | # --list-module-names option used by Tools/scripts/generate_module_names.py |
36 | LIST_MODULE_NAMES = False | | 49 | LIST_MODULE_NAMES = False |
37 | @@ -249,6 +251,16 @@ def grep_headers_for(function, headers): | | 50 | @@ -249,6 +257,16 @@ def grep_headers_for(function, headers): |
38 | return False | | 51 | return False |
39 | | | 52 | |
40 | | | 53 | |
41 | +def grep_headers_for(function, headers): | | 54 | +def grep_headers_for(function, headers): |
42 | + for header in headers: | | 55 | + for header in headers: |
43 | + try: | | 56 | + try: |
44 | + with open(header, 'r') as f: | | 57 | + with open(header, 'r') as f: |
45 | + if function in f.read(): | | 58 | + if function in f.read(): |
46 | + return True | | 59 | + return True |
47 | + except UnicodeDecodeError: | | 60 | + except UnicodeDecodeError: |
48 | + pass | | 61 | + pass |
49 | + return False | | 62 | + return False |
50 | + | | 63 | + |
51 | def find_file(filename, std_dirs, paths): | | 64 | def find_file(filename, std_dirs, paths): |
52 | """Searches for the directory where a given file is located, | | 65 | """Searches for the directory where a given file is located, |
53 | and returns a possibly-empty list of additional directories, or None | | 66 | and returns a possibly-empty list of additional directories, or None |
54 | @@ -821,15 +833,15 @@ class PyBuildExt(build_ext): | | 67 | @@ -823,15 +841,15 @@ class PyBuildExt(build_ext): |
55 | add_dir_to_list(dir_list, directory) | | 68 | add_dir_to_list(dir_list, directory) |
56 | | | 69 | |
57 | def configure_compiler(self): | | 70 | def configure_compiler(self): |
58 | - # Ensure that /usr/local is always used, but the local build | | 71 | - # Ensure that /usr/local is always used, but the local build |
59 | - # directories (i.e. '.' and 'Include') must be first. See issue | | 72 | - # directories (i.e. '.' and 'Include') must be first. See issue |
60 | - # 10520. | | 73 | - # 10520. |
61 | - if not CROSS_COMPILING: | | 74 | - if not CROSS_COMPILING: |
62 | - add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib') | | 75 | - add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib') |
63 | - add_dir_to_list(self.compiler.include_dirs, '/usr/local/include') | | 76 | - add_dir_to_list(self.compiler.include_dirs, '/usr/local/include') |
64 | - # only change this for cross builds for 3.3, issues on Mageia | | 77 | - # only change this for cross builds for 3.3, issues on Mageia |
65 | - if CROSS_COMPILING: | | 78 | - if CROSS_COMPILING: |
66 | - self.add_cross_compiling_paths() | | 79 | - self.add_cross_compiling_paths() |
67 | + # Add the buildlink directories for pkgsrc | | 80 | + # Add the buildlink directories for pkgsrc |
68 | + if os.environ.get('BUILDLINK_DIR'): | | 81 | + if os.environ.get('BUILDLINK_DIR'): |
69 | + dir = os.environ['BUILDLINK_DIR'] | | 82 | + dir = os.environ['BUILDLINK_DIR'] |
70 | + libdir = dir + '/lib' | | 83 | + libdir = dir + '/lib' |
71 | + incdir = dir + '/include' | | 84 | + incdir = dir + '/include' |
72 | + if libdir not in self.compiler.library_dirs: | | 85 | + if libdir not in self.compiler.library_dirs: |
73 | + self.compiler.library_dirs.insert(0, libdir) | | 86 | + self.compiler.library_dirs.insert(0, libdir) |
74 | + if incdir not in self.compiler.include_dirs: | | 87 | + if incdir not in self.compiler.include_dirs: |
75 | + self.compiler.include_dirs.insert(0, incdir) | | 88 | + self.compiler.include_dirs.insert(0, incdir) |
76 | self.add_multiarch_paths() | | 89 | self.add_multiarch_paths() |
77 | self.add_ldflags_cppflags() | | 90 | self.add_ldflags_cppflags() |
78 | | | 91 | |
79 | @@ -877,6 +889,9 @@ class PyBuildExt(build_ext): | | 92 | @@ -879,6 +897,9 @@ class PyBuildExt(build_ext): |
80 | self.lib_dirs += ['/usr/lib/hpux64', '/usr/lib/hpux32'] | | 93 | self.lib_dirs += ['/usr/lib/hpux64', '/usr/lib/hpux32'] |
81 | | | 94 | |
82 | if MACOS: | | 95 | if MACOS: |
83 | + self.inc_dirs.append(macosx_sdk_root() + '/usr/include') | | 96 | + self.inc_dirs.append(macosx_sdk_root() + '/usr/include') |
84 | + self.lib_dirs.append(macosx_sdk_root() + '/usr/lib') | | 97 | + self.lib_dirs.append(macosx_sdk_root() + '/usr/lib') |
85 | + | | 98 | + |
86 | # This should work on any unixy platform ;-) | | 99 | # This should work on any unixy platform ;-) |
87 | # If the user has bothered specifying additional -I and -L flags | | 100 | # If the user has bothered specifying additional -I and -L flags |
88 | # in OPT and LDFLAGS we might as well use them here. | | 101 | # in OPT and LDFLAGS we might as well use them here. |
89 | @@ -1104,8 +1119,6 @@ class PyBuildExt(build_ext): | | 102 | @@ -1106,8 +1127,6 @@ class PyBuildExt(build_ext): |
90 | # use the same library for the readline and curses modules. | | 103 | # use the same library for the readline and curses modules. |
91 | if 'curses' in readline_termcap_library: | | 104 | if 'curses' in readline_termcap_library: |
92 | curses_library = readline_termcap_library | | 105 | curses_library = readline_termcap_library |
93 | - elif self.compiler.find_library_file(self.lib_dirs, 'ncursesw'): | | 106 | - elif self.compiler.find_library_file(self.lib_dirs, 'ncursesw'): |
94 | - curses_library = 'ncursesw' | | 107 | - curses_library = 'ncursesw' |
95 | # Issue 36210: OSS provided ncurses does not link on AIX | | 108 | # Issue 36210: OSS provided ncurses does not link on AIX |
96 | # Use IBM supplied 'curses' for successful build of _curses | | 109 | # Use IBM supplied 'curses' for successful build of _curses |
97 | elif AIX and self.compiler.find_library_file(self.lib_dirs, 'curses'): | | 110 | elif AIX and self.compiler.find_library_file(self.lib_dirs, 'curses'): |
98 | @@ -1209,8 +1222,7 @@ class PyBuildExt(build_ext): | | 111 | @@ -1211,8 +1230,7 @@ class PyBuildExt(build_ext): |
99 | # If the curses module is enabled, check for the panel module | | 112 | # If the curses module is enabled, check for the panel module |
100 | # _curses_panel needs some form of ncurses | | 113 | # _curses_panel needs some form of ncurses |
101 | skip_curses_panel = True if AIX else False | | 114 | skip_curses_panel = True if AIX else False |
102 | - if (curses_enabled and not skip_curses_panel and | | 115 | - if (curses_enabled and not skip_curses_panel and |
103 | - self.compiler.find_library_file(self.lib_dirs, panel_library)): | | 116 | - self.compiler.find_library_file(self.lib_dirs, panel_library)): |
104 | + if curses_enabled and not skip_curses_panel: | | 117 | + if curses_enabled and not skip_curses_panel: |
105 | self.add(Extension('_curses_panel', ['_curses_panel.c'], | | 118 | self.add(Extension('_curses_panel', ['_curses_panel.c'], |
106 | include_dirs=curses_includes, | | 119 | include_dirs=curses_includes, |
107 | define_macros=curses_defines, | | 120 | define_macros=curses_defines, |
108 | @@ -1455,6 +1467,31 @@ class PyBuildExt(build_ext): | | 121 | @@ -1457,6 +1475,31 @@ class PyBuildExt(build_ext): |
109 | dbm_order = ['gdbm'] | | 122 | dbm_order = ['gdbm'] |
110 | # The standard Unix dbm module: | | 123 | # The standard Unix dbm module: |
111 | if not CYGWIN: | | 124 | if not CYGWIN: |
112 | + # Top half based on find_file | | 125 | + # Top half based on find_file |
113 | + def find_ndbm_h(dirs): | | 126 | + def find_ndbm_h(dirs): |
114 | + ret = None | | 127 | + ret = None |
115 | + if MACOS: | | 128 | + if MACOS: |
116 | + sysroot = macosx_sdk_root() | | 129 | + sysroot = macosx_sdk_root() |
117 | + for dir in dirs: | | 130 | + for dir in dirs: |
118 | + f = os.path.join(dir, 'ndbm.h') | | 131 | + f = os.path.join(dir, 'ndbm.h') |
119 | + if MACOS and is_macosx_sdk_path(dir): | | 132 | + if MACOS and is_macosx_sdk_path(dir): |
120 | + f = os.path.join(sysroot, dir[1:], 'ndbm.h') | | 133 | + f = os.path.join(sysroot, dir[1:], 'ndbm.h') |
121 | + if not os.path.exists(f): | | 134 | + if not os.path.exists(f): |
| @@ -127,43 +140,43 @@ Don't search for modules in PREFIX. Fixe | | | @@ -127,43 +140,43 @@ Don't search for modules in PREFIX. Fixe |
127 | + line = input.readline() | | 140 | + line = input.readline() |
128 | + if not line: | | 141 | + if not line: |
129 | + break | | 142 | + break |
130 | + if re.search('This file is part of GDBM', line): | | 143 | + if re.search('This file is part of GDBM', line): |
131 | + ret = None | | 144 | + ret = None |
132 | + break | | 145 | + break |
133 | + input.close() | | 146 | + input.close() |
134 | + break | | 147 | + break |
135 | + return ret | | 148 | + return ret |
136 | + | | 149 | + |
137 | config_args = [arg.strip("'") | | 150 | config_args = [arg.strip("'") |
138 | for arg in sysconfig.get_config_var("CONFIG_ARGS").split()] | | 151 | for arg in sysconfig.get_config_var("CONFIG_ARGS").split()] |
139 | dbm_args = [arg for arg in config_args | | 152 | dbm_args = [arg for arg in config_args |
140 | @@ -1466,7 +1503,7 @@ class PyBuildExt(build_ext): | | 153 | @@ -1468,7 +1511,7 @@ class PyBuildExt(build_ext): |
141 | dbmext = None | | 154 | dbmext = None |
142 | for cand in dbm_order: | | 155 | for cand in dbm_order: |
143 | if cand == "ndbm": | | 156 | if cand == "ndbm": |
144 | - if find_file("ndbm.h", self.inc_dirs, []) is not None: | | 157 | - if find_file("ndbm.h", self.inc_dirs, []) is not None: |
145 | + if find_ndbm_h(self.inc_dirs) is not None: | | 158 | + if find_ndbm_h(self.inc_dirs) is not None: |
146 | # Some systems have -lndbm, others have -lgdbm_compat, | | 159 | # Some systems have -lndbm, others have -lgdbm_compat, |
147 | # others don't have either | | 160 | # others don't have either |
148 | if self.compiler.find_library_file(self.lib_dirs, | | 161 | if self.compiler.find_library_file(self.lib_dirs, |
149 | @@ -2326,10 +2363,7 @@ class PyBuildExt(build_ext): | | 162 | @@ -2328,10 +2371,7 @@ class PyBuildExt(build_ext): |
150 | sources = ['_decimal/_decimal.c'] | | 163 | sources = ['_decimal/_decimal.c'] |
151 | depends = ['_decimal/docstrings.h'] | | 164 | depends = ['_decimal/docstrings.h'] |
152 | else: | | 165 | else: |
153 | - include_dirs = [os.path.abspath(os.path.join(self.srcdir, | | 166 | - include_dirs = [os.path.abspath(os.path.join(self.srcdir, |
154 | - 'Modules', | | 167 | - 'Modules', |
155 | - '_decimal', | | 168 | - '_decimal', |
156 | - 'libmpdec'))] | | 169 | - 'libmpdec'))] |
157 | + include_dirs = ['Modules/_decimal/libmpdec'] | | 170 | + include_dirs = ['Modules/_decimal/libmpdec'] |
158 | libraries = ['m'] | | 171 | libraries = ['m'] |
159 | sources = [ | | 172 | sources = [ |
160 | '_decimal/_decimal.c', | | 173 | '_decimal/_decimal.c', |
161 | @@ -2745,7 +2779,7 @@ def main(): | | 174 | @@ -2747,7 +2787,7 @@ def main(): |
162 | # If you change the scripts installed here, you also need to | | 175 | # If you change the scripts installed here, you also need to |
163 | # check the PyBuildScripts command above, and change the links | | 176 | # check the PyBuildScripts command above, and change the links |
164 | # created by the bininstall target in Makefile.pre.in | | 177 | # created by the bininstall target in Makefile.pre.in |
165 | - scripts = ["Tools/scripts/pydoc3", "Tools/scripts/idle3", | | 178 | - scripts = ["Tools/scripts/pydoc3", "Tools/scripts/idle3", |
166 | + scripts = ["Tools/scripts/pydoc3", | | 179 | + scripts = ["Tools/scripts/pydoc3", |
167 | "Tools/scripts/2to3"] | | 180 | "Tools/scripts/2to3"] |
168 | ) | | 181 | ) |
169 | | | 182 | |