| 1124 | |
| 1125 | |
| 1126 | class CythonRecipe(PythonRecipe): |
| 1127 | pre_build_ext = False |
| 1128 | cythonize = True |
| 1129 | cython_args = [] |
| 1130 | call_hostpython_via_targetpython = False |
| 1131 | |
| 1132 | def build_arch(self, arch): |
| 1133 | '''Build any cython components, then install the Python module by |
| 1134 | calling pip install with the target Python dir. |
| 1135 | ''' |
| 1136 | Recipe.build_arch(self, arch) |
| 1137 | self.build_cython_components(arch) |
| 1138 | self.install_python_package(arch) |
| 1139 | |
| 1140 | def build_cython_components(self, arch): |
| 1141 | info('Cythonizing anything necessary in {}'.format(self.name)) |
| 1142 | |
| 1143 | env = self.get_recipe_env(arch) |
| 1144 | |
| 1145 | with current_directory(self.get_build_dir(arch.arch)): |
| 1146 | hostpython = sh.Command(self.ctx.hostpython) |
| 1147 | shprint(hostpython, '-c', 'import sys; print(sys.path)', _env=env) |
| 1148 | debug('cwd is {}'.format(realpath(curdir))) |
| 1149 | info('Trying first build of {} to get cython files: this is ' |
| 1150 | 'expected to fail'.format(self.name)) |
| 1151 | |
| 1152 | manually_cythonise = False |
| 1153 | try: |
| 1154 | shprint(hostpython, 'setup.py', 'build_ext', '-v', _env=env, |
| 1155 | *self.setup_extra_args) |
| 1156 | except sh.ErrorReturnCode_1: |
| 1157 | print() |
| 1158 | info('{} first build failed (as expected)'.format(self.name)) |
| 1159 | manually_cythonise = True |
| 1160 | |
| 1161 | if manually_cythonise: |
| 1162 | self.cythonize_build(env=env) |
| 1163 | shprint(hostpython, 'setup.py', 'build_ext', '-v', _env=env, |
| 1164 | _tail=20, _critical=True, *self.setup_extra_args) |
| 1165 | else: |
| 1166 | info('First build appeared to complete correctly, skipping manual' |
| 1167 | 'cythonising.') |
| 1168 | |
| 1169 | if not self.ctx.with_debug_symbols: |
| 1170 | self.strip_object_files(arch, env) |
| 1171 | |
| 1172 | def strip_object_files(self, arch, env, build_dir=None): |
| 1173 | if build_dir is None: |
| 1174 | build_dir = self.get_build_dir(arch.arch) |
| 1175 | with current_directory(build_dir): |
| 1176 | info('Stripping object files') |
| 1177 | shprint(sh.find, '.', '-iname', '*.so', '-exec', |
| 1178 | '/usr/bin/echo', '{}', ';', _env=env) |
| 1179 | shprint(sh.find, '.', '-iname', '*.so', '-exec', |
| 1180 | env['STRIP'].split(' ')[0], '--strip-unneeded', |
| 1181 | # '/usr/bin/strip', '--strip-unneeded', |
| 1182 | '{}', ';', _env=env) |
| 1183 |
no outgoing calls
no test coverage detected