OLD | NEW |
1 #! /usr/bin/env python | 1 #! /usr/bin/env python |
2 # | 2 # |
3 # See README for usage instructions. | 3 # See README for usage instructions. |
4 import glob | 4 import glob |
5 import os | 5 import os |
6 import subprocess | 6 import subprocess |
7 import sys | 7 import sys |
8 | 8 |
9 # We must use setuptools, not distutils, because we need to use the | 9 # We must use setuptools, not distutils, because we need to use the |
10 # namespace_packages option for the "google" package. | 10 # namespace_packages option for the "google" package. |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 try: | 142 try: |
143 open('google/protobuf/%s__init__.py' % path, 'a').close() | 143 open('google/protobuf/%s__init__.py' % path, 'a').close() |
144 except EnvironmentError: | 144 except EnvironmentError: |
145 pass | 145 pass |
146 # _build_py is an old-style class, so super() doesn't work. | 146 # _build_py is an old-style class, so super() doesn't work. |
147 _build_py.run(self) | 147 _build_py.run(self) |
148 | 148 |
149 class test_conformance(_build_py): | 149 class test_conformance(_build_py): |
150 target = 'test_python' | 150 target = 'test_python' |
151 def run(self): | 151 def run(self): |
| 152 if sys.version_info >= (2, 7): |
| 153 # Python 2.6 dodges these extra failures. |
| 154 os.environ["CONFORMANCE_PYTHON_EXTRA_FAILURES"] = ( |
| 155 "--failure_list failure_list_python-post26.txt") |
152 cmd = 'cd ../conformance && make %s' % (test_conformance.target) | 156 cmd = 'cd ../conformance && make %s' % (test_conformance.target) |
153 status = subprocess.check_call(cmd, shell=True) | 157 status = subprocess.check_call(cmd, shell=True) |
154 | 158 |
155 | 159 |
| 160 def get_option_from_sys_argv(option_str): |
| 161 if option_str in sys.argv: |
| 162 sys.argv.remove(option_str) |
| 163 return True |
| 164 return False |
| 165 |
| 166 |
156 if __name__ == '__main__': | 167 if __name__ == '__main__': |
157 ext_module_list = [] | 168 ext_module_list = [] |
158 cpp_impl = '--cpp_implementation' | |
159 warnings_as_errors = '--warnings_as_errors' | 169 warnings_as_errors = '--warnings_as_errors' |
160 if cpp_impl in sys.argv: | 170 if get_option_from_sys_argv('--cpp_implementation'): |
161 sys.argv.remove(cpp_impl) | 171 # Link libprotobuf.a and libprotobuf-lite.a statically with the |
162 extra_compile_args = ['-Wno-write-strings', '-Wno-invalid-offsetof'] | 172 # extension. Note that those libraries have to be compiled with |
| 173 # -fPIC for this to work. |
| 174 compile_static_ext = get_option_from_sys_argv('--compile_static_extension') |
| 175 extra_compile_args = ['-Wno-write-strings', |
| 176 '-Wno-invalid-offsetof', |
| 177 '-Wno-sign-compare'] |
| 178 libraries = ['protobuf'] |
| 179 extra_objects = None |
| 180 if compile_static_ext: |
| 181 libraries = None |
| 182 extra_objects = ['../src/.libs/libprotobuf.a', |
| 183 '../src/.libs/libprotobuf-lite.a'] |
163 test_conformance.target = 'test_python_cpp' | 184 test_conformance.target = 'test_python_cpp' |
164 | 185 |
165 if "clang" in os.popen('$CC --version').read(): | 186 if "clang" in os.popen('$CC --version 2> /dev/null').read(): |
166 extra_compile_args.append('-Wno-shorten-64-to-32') | 187 extra_compile_args.append('-Wno-shorten-64-to-32') |
167 | 188 |
168 if warnings_as_errors in sys.argv: | 189 if warnings_as_errors in sys.argv: |
169 extra_compile_args.append('-Werror') | 190 extra_compile_args.append('-Werror') |
170 sys.argv.remove(warnings_as_errors) | 191 sys.argv.remove(warnings_as_errors) |
171 | 192 |
172 # C++ implementation extension | 193 # C++ implementation extension |
173 ext_module_list.append( | 194 ext_module_list.extend([ |
174 Extension( | 195 Extension( |
175 "google.protobuf.pyext._message", | 196 "google.protobuf.pyext._message", |
176 glob.glob('google/protobuf/pyext/*.cc'), | 197 glob.glob('google/protobuf/pyext/*.cc'), |
177 include_dirs=[".", "../src"], | 198 include_dirs=[".", "../src"], |
178 libraries=['protobuf'], | 199 libraries=libraries, |
| 200 extra_objects=extra_objects, |
179 library_dirs=['../src/.libs'], | 201 library_dirs=['../src/.libs'], |
180 extra_compile_args=extra_compile_args, | 202 extra_compile_args=extra_compile_args, |
181 ) | 203 ), |
182 ) | 204 Extension( |
| 205 "google.protobuf.internal._api_implementation", |
| 206 glob.glob('google/protobuf/internal/api_implementation.cc'), |
| 207 extra_compile_args=['-DPYTHON_PROTO2_CPP_IMPL_V2'], |
| 208 ), |
| 209 ]) |
183 os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'] = 'cpp' | 210 os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'] = 'cpp' |
184 | 211 |
185 # Keep this list of dependencies in sync with tox.ini. | 212 # Keep this list of dependencies in sync with tox.ini. |
186 install_requires = ['six>=1.9', 'setuptools'] | 213 install_requires = ['six>=1.9', 'setuptools'] |
187 if sys.version_info <= (2,7): | 214 if sys.version_info <= (2,7): |
188 install_requires.append('ordereddict') | 215 install_requires.append('ordereddict') |
189 install_requires.append('unittest2') | 216 install_requires.append('unittest2') |
190 | 217 |
191 setup( | 218 setup( |
192 name='protobuf', | 219 name='protobuf', |
(...skipping 21 matching lines...) Expand all Loading... |
214 ), | 241 ), |
215 test_suite='google.protobuf.internal', | 242 test_suite='google.protobuf.internal', |
216 cmdclass={ | 243 cmdclass={ |
217 'clean': clean, | 244 'clean': clean, |
218 'build_py': build_py, | 245 'build_py': build_py, |
219 'test_conformance': test_conformance, | 246 'test_conformance': test_conformance, |
220 }, | 247 }, |
221 install_requires=install_requires, | 248 install_requires=install_requires, |
222 ext_modules=ext_module_list, | 249 ext_modules=ext_module_list, |
223 ) | 250 ) |
OLD | NEW |