Tamir Duberstein | 9d9d0b7 | 2015-04-11 20:23:45 -0700 | [diff] [blame] | 1 | #! /usr/bin/env python |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 2 | # |
| 3 | # See README for usage instructions. |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 4 | |
| 5 | # pylint:disable=missing-module-docstring |
| 6 | # pylint:disable=g-bad-import-order |
Paul Yang | 704037f | 2018-11-28 16:45:16 -0800 | [diff] [blame] | 7 | from distutils import util |
Misha Seltzer | 223e891 | 2020-05-14 21:09:09 -0400 | [diff] [blame] | 8 | import fnmatch |
Tamir Duberstein | 5018c43 | 2015-05-08 08:48:40 -0400 | [diff] [blame] | 9 | import glob |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 10 | import os |
Paul Yang | 704037f | 2018-11-28 16:45:16 -0800 | [diff] [blame] | 11 | import pkg_resources |
| 12 | import re |
kenton@google.com | a6de64a | 2009-04-18 02:28:15 +0000 | [diff] [blame] | 13 | import subprocess |
Tamir Duberstein | 5018c43 | 2015-05-08 08:48:40 -0400 | [diff] [blame] | 14 | import sys |
Paul Yang | 704037f | 2018-11-28 16:45:16 -0800 | [diff] [blame] | 15 | import sysconfig |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 16 | |
| 17 | # pylint:disable=g-importing-member |
| 18 | # pylint:disable=g-multiple-import |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 19 | |
liujisi@google.com | 9ced30c | 2012-08-01 06:22:19 +0000 | [diff] [blame] | 20 | # We must use setuptools, not distutils, because we need to use the |
| 21 | # namespace_packages option for the "google" package. |
Dan O'Reilly | 3bdfb4b | 2015-08-20 13:51:26 -0400 | [diff] [blame] | 22 | from setuptools import setup, Extension, find_packages |
liujisi@google.com | 9ced30c | 2012-08-01 06:22:19 +0000 | [diff] [blame] | 23 | |
Sandy Zhang | 215dd13 | 2021-09-10 20:04:52 +0000 | [diff] [blame] | 24 | from distutils.command.build_ext import build_ext as _build_ext |
Benjamin Peterson | 188c44b | 2018-09-10 13:35:38 -0700 | [diff] [blame] | 25 | from distutils.command.build_py import build_py as _build_py |
Tamir Duberstein | 21a7cf9 | 2015-04-11 18:24:24 -0700 | [diff] [blame] | 26 | from distutils.command.clean import clean as _clean |
Tamir Duberstein | 21a7cf9 | 2015-04-11 18:24:24 -0700 | [diff] [blame] | 27 | from distutils.spawn import find_executable |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 28 | |
| 29 | # Find the Protocol Compiler. |
liujisi@google.com | e34f1f6 | 2012-12-05 01:25:12 +0000 | [diff] [blame] | 30 | if 'PROTOC' in os.environ and os.path.exists(os.environ['PROTOC']): |
| 31 | protoc = os.environ['PROTOC'] |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 32 | elif os.path.exists('../src/protoc'): |
| 33 | protoc = '../src/protoc' |
| 34 | elif os.path.exists('../src/protoc.exe'): |
| 35 | protoc = '../src/protoc.exe' |
| 36 | elif os.path.exists('../vsprojects/Debug/protoc.exe'): |
| 37 | protoc = '../vsprojects/Debug/protoc.exe' |
| 38 | elif os.path.exists('../vsprojects/Release/protoc.exe'): |
| 39 | protoc = '../vsprojects/Release/protoc.exe' |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 40 | else: |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 41 | protoc = find_executable('protoc') |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 42 | |
Tamir Duberstein | 21a7cf9 | 2015-04-11 18:24:24 -0700 | [diff] [blame] | 43 | |
Jisi Liu | 4573e11 | 2015-03-04 16:45:13 -0800 | [diff] [blame] | 44 | def GetVersion(): |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 45 | """Reads and returns the version from google/protobuf/__init__.py. |
Jisi Liu | 4573e11 | 2015-03-04 16:45:13 -0800 | [diff] [blame] | 46 | |
Tamir Duberstein | 21a7cf9 | 2015-04-11 18:24:24 -0700 | [diff] [blame] | 47 | Do not import google.protobuf.__init__ directly, because an installed |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 48 | protobuf library may be loaded instead. |
| 49 | |
| 50 | Returns: |
| 51 | The version. |
| 52 | """ |
Jisi Liu | 4573e11 | 2015-03-04 16:45:13 -0800 | [diff] [blame] | 53 | |
Joshua Haberman | b99994d | 2020-03-31 16:25:37 -0700 | [diff] [blame] | 54 | with open(os.path.join('google', 'protobuf', '__init__.py')) as version_file: |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 55 | exec(version_file.read(), globals()) # pylint:disable=exec-used |
| 56 | return __version__ # pylint:disable=undefined-variable |
Jisi Liu | 4573e11 | 2015-03-04 16:45:13 -0800 | [diff] [blame] | 57 | |
| 58 | |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 59 | def GenProto(source, require=True): |
| 60 | """Generates a _pb2.py from the given .proto file. |
| 61 | |
| 62 | Does nothing if the output already exists and is newer than the input. |
| 63 | |
| 64 | Args: |
| 65 | source: the .proto file path. |
| 66 | require: if True, exit immediately when a path is not found. |
| 67 | """ |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 68 | |
Feng Xiao | 8e14268 | 2015-05-26 00:11:09 -0700 | [diff] [blame] | 69 | if not require and not os.path.exists(source): |
| 70 | return |
| 71 | |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 72 | output = source.replace('.proto', '_pb2.py').replace('../src/', '') |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 73 | |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 74 | if (not os.path.exists(output) or |
| 75 | (os.path.exists(source) and |
| 76 | os.path.getmtime(source) > os.path.getmtime(output))): |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 77 | print('Generating %s...' % output) |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 78 | |
liujisi@google.com | 9ced30c | 2012-08-01 06:22:19 +0000 | [diff] [blame] | 79 | if not os.path.exists(source): |
| 80 | sys.stderr.write("Can't find required file: %s\n" % source) |
| 81 | sys.exit(-1) |
| 82 | |
Tamir Duberstein | 21a7cf9 | 2015-04-11 18:24:24 -0700 | [diff] [blame] | 83 | if protoc is None: |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 84 | sys.stderr.write( |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 85 | 'protoc is not installed nor found in ../src. Please compile it ' |
| 86 | 'or install the binary package.\n') |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 87 | sys.exit(-1) |
| 88 | |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 89 | protoc_command = [protoc, '-I../src', '-I.', '--python_out=.', source] |
kenton@google.com | a6de64a | 2009-04-18 02:28:15 +0000 | [diff] [blame] | 90 | if subprocess.call(protoc_command) != 0: |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 91 | sys.exit(-1) |
| 92 | |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 93 | |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 94 | def GenerateUnittestProtos(): |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 95 | """Generates protobuf code for unittests.""" |
| 96 | GenProto('../src/google/protobuf/any_test.proto', False) |
| 97 | GenProto('../src/google/protobuf/map_proto2_unittest.proto', False) |
| 98 | GenProto('../src/google/protobuf/map_unittest.proto', False) |
| 99 | GenProto('../src/google/protobuf/test_messages_proto3.proto', False) |
| 100 | GenProto('../src/google/protobuf/test_messages_proto2.proto', False) |
| 101 | GenProto('../src/google/protobuf/unittest_arena.proto', False) |
| 102 | GenProto('../src/google/protobuf/unittest.proto', False) |
| 103 | GenProto('../src/google/protobuf/unittest_custom_options.proto', False) |
| 104 | GenProto('../src/google/protobuf/unittest_import.proto', False) |
| 105 | GenProto('../src/google/protobuf/unittest_import_public.proto', False) |
| 106 | GenProto('../src/google/protobuf/unittest_mset.proto', False) |
| 107 | GenProto('../src/google/protobuf/unittest_mset_wire_format.proto', False) |
| 108 | GenProto('../src/google/protobuf/unittest_no_generic_services.proto', False) |
| 109 | GenProto('../src/google/protobuf/unittest_proto3_arena.proto', False) |
| 110 | GenProto('../src/google/protobuf/util/json_format.proto', False) |
| 111 | GenProto('../src/google/protobuf/util/json_format_proto3.proto', False) |
| 112 | GenProto('google/protobuf/internal/any_test.proto', False) |
| 113 | GenProto('google/protobuf/internal/descriptor_pool_test1.proto', False) |
| 114 | GenProto('google/protobuf/internal/descriptor_pool_test2.proto', False) |
| 115 | GenProto('google/protobuf/internal/factory_test1.proto', False) |
| 116 | GenProto('google/protobuf/internal/factory_test2.proto', False) |
| 117 | GenProto('google/protobuf/internal/file_options_test.proto', False) |
Adam Cozzette | a336ba0 | 2022-03-18 21:25:56 +0000 | [diff] [blame] | 118 | GenProto('google/protobuf/internal/import_test_package/import_public.proto', |
| 119 | False) |
| 120 | GenProto( |
| 121 | 'google/protobuf/internal/import_test_package/import_public_nested.proto', |
| 122 | False) |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 123 | GenProto('google/protobuf/internal/import_test_package/inner.proto', False) |
| 124 | GenProto('google/protobuf/internal/import_test_package/outer.proto', False) |
| 125 | GenProto('google/protobuf/internal/missing_enum_values.proto', False) |
| 126 | GenProto('google/protobuf/internal/message_set_extensions.proto', False) |
| 127 | GenProto('google/protobuf/internal/more_extensions.proto', False) |
| 128 | GenProto('google/protobuf/internal/more_extensions_dynamic.proto', False) |
| 129 | GenProto('google/protobuf/internal/more_messages.proto', False) |
| 130 | GenProto('google/protobuf/internal/no_package.proto', False) |
| 131 | GenProto('google/protobuf/internal/packed_field_test.proto', False) |
| 132 | GenProto('google/protobuf/internal/test_bad_identifiers.proto', False) |
| 133 | GenProto('google/protobuf/internal/test_proto3_optional.proto', False) |
| 134 | GenProto('google/protobuf/pyext/python.proto', False) |
liujisi@google.com | 9ced30c | 2012-08-01 06:22:19 +0000 | [diff] [blame] | 135 | |
Tamir Duberstein | 21a7cf9 | 2015-04-11 18:24:24 -0700 | [diff] [blame] | 136 | |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 137 | class CleanCmd(_clean): |
| 138 | """Custom clean command for building the protobuf extension.""" |
| 139 | |
liujisi@google.com | 9ced30c | 2012-08-01 06:22:19 +0000 | [diff] [blame] | 140 | def run(self): |
| 141 | # Delete generated files in the code tree. |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 142 | for (dirpath, unused_dirnames, filenames) in os.walk('.'): |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 143 | for filename in filenames: |
| 144 | filepath = os.path.join(dirpath, filename) |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 145 | if (filepath.endswith('_pb2.py') or filepath.endswith('.pyc') or |
| 146 | filepath.endswith('.so') or filepath.endswith('.o')): |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 147 | os.remove(filepath) |
liujisi@google.com | 9ced30c | 2012-08-01 06:22:19 +0000 | [diff] [blame] | 148 | # _clean is an old-style class, so super() doesn't work. |
| 149 | _clean.run(self) |
| 150 | |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 151 | |
| 152 | class BuildPyCmd(_build_py): |
| 153 | """Custom build_py command for building the protobuf runtime.""" |
| 154 | |
liujisi@google.com | 9ced30c | 2012-08-01 06:22:19 +0000 | [diff] [blame] | 155 | def run(self): |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 156 | # Generate necessary .proto file if it doesn't exist. |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 157 | GenProto('../src/google/protobuf/descriptor.proto') |
| 158 | GenProto('../src/google/protobuf/compiler/plugin.proto') |
| 159 | GenProto('../src/google/protobuf/any.proto') |
| 160 | GenProto('../src/google/protobuf/api.proto') |
| 161 | GenProto('../src/google/protobuf/duration.proto') |
| 162 | GenProto('../src/google/protobuf/empty.proto') |
| 163 | GenProto('../src/google/protobuf/field_mask.proto') |
| 164 | GenProto('../src/google/protobuf/source_context.proto') |
| 165 | GenProto('../src/google/protobuf/struct.proto') |
| 166 | GenProto('../src/google/protobuf/timestamp.proto') |
| 167 | GenProto('../src/google/protobuf/type.proto') |
| 168 | GenProto('../src/google/protobuf/wrappers.proto') |
jieluo@google.com | bde4a32 | 2014-08-12 21:10:30 +0000 | [diff] [blame] | 169 | GenerateUnittestProtos() |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 170 | |
liujisi@google.com | 9ced30c | 2012-08-01 06:22:19 +0000 | [diff] [blame] | 171 | # _build_py is an old-style class, so super() doesn't work. |
| 172 | _build_py.run(self) |
jieluo@google.com | bde4a32 | 2014-08-12 21:10:30 +0000 | [diff] [blame] | 173 | |
Misha Seltzer | 223e891 | 2020-05-14 21:09:09 -0400 | [diff] [blame] | 174 | def find_package_modules(self, package, package_dir): |
| 175 | exclude = ( |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 176 | '*test*', |
| 177 | 'google/protobuf/internal/*_pb2.py', |
| 178 | 'google/protobuf/internal/_parameterized.py', |
| 179 | 'google/protobuf/pyext/python_pb2.py', |
Misha Seltzer | 223e891 | 2020-05-14 21:09:09 -0400 | [diff] [blame] | 180 | ) |
| 181 | modules = _build_py.find_package_modules(self, package, package_dir) |
| 182 | return [(pkg, mod, fil) for (pkg, mod, fil) in modules |
| 183 | if not any(fnmatch.fnmatchcase(fil, pat=pat) for pat in exclude)] |
| 184 | |
| 185 | |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 186 | class BuildExtCmd(_build_ext): |
| 187 | """Command class for building the protobuf Python extension.""" |
Sandy Zhang | 215dd13 | 2021-09-10 20:04:52 +0000 | [diff] [blame] | 188 | |
| 189 | def get_ext_filename(self, ext_name): |
| 190 | # since python3.5, python extensions' shared libraries use a suffix that |
| 191 | # corresponds to the value of sysconfig.get_config_var('EXT_SUFFIX') and |
| 192 | # contains info about the architecture the library targets. E.g. on x64 |
| 193 | # linux the suffix is ".cpython-XYZ-x86_64-linux-gnu.so" When |
| 194 | # crosscompiling python wheels, we need to be able to override this |
| 195 | # suffix so that the resulting file name matches the target architecture |
| 196 | # and we end up with a well-formed wheel. |
| 197 | filename = _build_ext.get_ext_filename(self, ext_name) |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 198 | orig_ext_suffix = sysconfig.get_config_var('EXT_SUFFIX') |
| 199 | new_ext_suffix = os.getenv('PROTOCOL_BUFFERS_OVERRIDE_EXT_SUFFIX') |
Sandy Zhang | 215dd13 | 2021-09-10 20:04:52 +0000 | [diff] [blame] | 200 | if new_ext_suffix and filename.endswith(orig_ext_suffix): |
| 201 | filename = filename[:-len(orig_ext_suffix)] + new_ext_suffix |
| 202 | return filename |
| 203 | |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 204 | |
| 205 | class TestConformanceCmd(_build_py): |
Josh Haberman | 325392d | 2015-08-17 12:30:49 -0700 | [diff] [blame] | 206 | target = 'test_python' |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 207 | |
Josh Haberman | 325392d | 2015-08-17 12:30:49 -0700 | [diff] [blame] | 208 | def run(self): |
Yuchen Xie | 595231d | 2018-06-26 06:20:53 +0800 | [diff] [blame] | 209 | # Python 2.6 dodges these extra failures. |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 210 | os.environ['CONFORMANCE_PYTHON_EXTRA_FAILURES'] = ( |
| 211 | '--failure_list failure_list_python-post26.txt') |
| 212 | cmd = 'cd ../conformance && make %s' % (TestConformanceCmd.target) |
| 213 | subprocess.check_call(cmd, shell=True) |
Josh Haberman | 325392d | 2015-08-17 12:30:49 -0700 | [diff] [blame] | 214 | |
liujisi@google.com | 9b7f6c5 | 2010-12-08 03:45:27 +0000 | [diff] [blame] | 215 | |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 216 | def GetOptionFromArgv(option_str): |
Manjunath Kudlur | cf828de | 2016-03-25 10:58:46 -0700 | [diff] [blame] | 217 | if option_str in sys.argv: |
| 218 | sys.argv.remove(option_str) |
| 219 | return True |
| 220 | return False |
| 221 | |
| 222 | |
liujisi@google.com | 9ced30c | 2012-08-01 06:22:19 +0000 | [diff] [blame] | 223 | if __name__ == '__main__': |
jieluo@google.com | 1eba9d9 | 2014-08-25 20:17:53 +0000 | [diff] [blame] | 224 | ext_module_list = [] |
Josh Haberman | 00700b7 | 2015-10-06 14:13:09 -0700 | [diff] [blame] | 225 | warnings_as_errors = '--warnings_as_errors' |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 226 | if GetOptionFromArgv('--cpp_implementation'): |
Manjunath Kudlur | cf828de | 2016-03-25 10:58:46 -0700 | [diff] [blame] | 227 | # Link libprotobuf.a and libprotobuf-lite.a statically with the |
| 228 | # extension. Note that those libraries have to be compiled with |
| 229 | # -fPIC for this to work. |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 230 | compile_static_ext = GetOptionFromArgv('--compile_static_extension') |
Manjunath Kudlur | cf828de | 2016-03-25 10:58:46 -0700 | [diff] [blame] | 231 | libraries = ['protobuf'] |
| 232 | extra_objects = None |
| 233 | if compile_static_ext: |
| 234 | libraries = None |
| 235 | extra_objects = ['../src/.libs/libprotobuf.a', |
| 236 | '../src/.libs/libprotobuf-lite.a'] |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 237 | TestConformanceCmd.target = 'test_python_cpp' |
Josh Haberman | d8814ed | 2015-10-07 11:46:23 -0700 | [diff] [blame] | 238 | |
Paul Yang | c931743 | 2018-04-02 15:55:28 -0700 | [diff] [blame] | 239 | extra_compile_args = [] |
| 240 | |
Adam Cozzette | a035bd0 | 2022-01-25 08:24:12 -0800 | [diff] [blame] | 241 | message_extra_link_args = None |
| 242 | api_implementation_link_args = None |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 243 | if 'darwin' in sys.platform: |
Adam Cozzette | a035bd0 | 2022-01-25 08:24:12 -0800 | [diff] [blame] | 244 | if sys.version_info[0] == 2: |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 245 | message_init_symbol = 'init_message' |
| 246 | api_implementation_init_symbol = 'init_api_implementation' |
Adam Cozzette | a035bd0 | 2022-01-25 08:24:12 -0800 | [diff] [blame] | 247 | else: |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 248 | message_init_symbol = 'PyInit__message' |
| 249 | api_implementation_init_symbol = 'PyInit__api_implementation' |
| 250 | message_extra_link_args = [ |
| 251 | '-Wl,-exported_symbol,_%s' % message_init_symbol |
| 252 | ] |
| 253 | api_implementation_link_args = [ |
| 254 | '-Wl,-exported_symbol,_%s' % api_implementation_init_symbol |
| 255 | ] |
Adam Cozzette | a035bd0 | 2022-01-25 08:24:12 -0800 | [diff] [blame] | 256 | |
Paul Yang | c931743 | 2018-04-02 15:55:28 -0700 | [diff] [blame] | 257 | if sys.platform != 'win32': |
Adam Cozzette | 3afc828 | 2021-10-08 16:45:26 -0700 | [diff] [blame] | 258 | extra_compile_args.append('-Wno-write-strings') |
| 259 | extra_compile_args.append('-Wno-invalid-offsetof') |
| 260 | extra_compile_args.append('-Wno-sign-compare') |
| 261 | extra_compile_args.append('-Wno-unused-variable') |
| 262 | extra_compile_args.append('-std=c++11') |
Paul Yang | c931743 | 2018-04-02 15:55:28 -0700 | [diff] [blame] | 263 | |
Feng Xiao | acd5b05 | 2018-08-09 21:21:01 -0700 | [diff] [blame] | 264 | if sys.platform == 'darwin': |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 265 | extra_compile_args.append('-Wno-shorten-64-to-32') |
| 266 | extra_compile_args.append('-Wno-deprecated-register') |
Feng Xiao | acd5b05 | 2018-08-09 21:21:01 -0700 | [diff] [blame] | 267 | |
Paul Yang | 704037f | 2018-11-28 16:45:16 -0800 | [diff] [blame] | 268 | # https://developer.apple.com/documentation/xcode_release_notes/xcode_10_release_notes |
| 269 | # C++ projects must now migrate to libc++ and are recommended to set a |
| 270 | # deployment target of macOS 10.9 or later, or iOS 7 or later. |
| 271 | if sys.platform == 'darwin': |
Thomas BACCELLI | 26c0fbc | 2020-12-06 15:40:04 +0100 | [diff] [blame] | 272 | mac_target = str(sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')) |
Paul Yang | 704037f | 2018-11-28 16:45:16 -0800 | [diff] [blame] | 273 | if mac_target and (pkg_resources.parse_version(mac_target) < |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 274 | pkg_resources.parse_version('10.9.0')): |
Paul Yang | 704037f | 2018-11-28 16:45:16 -0800 | [diff] [blame] | 275 | os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.9' |
| 276 | os.environ['_PYTHON_HOST_PLATFORM'] = re.sub( |
| 277 | r'macosx-[0-9]+\.[0-9]+-(.+)', r'macosx-10.9-\1', |
| 278 | util.get_platform()) |
| 279 | |
Paul Yang | c931743 | 2018-04-02 15:55:28 -0700 | [diff] [blame] | 280 | # https://github.com/Theano/Theano/issues/4926 |
| 281 | if sys.platform == 'win32': |
| 282 | extra_compile_args.append('-D_hypot=hypot') |
| 283 | |
| 284 | # https://github.com/tpaviot/pythonocc-core/issues/48 |
| 285 | if sys.platform == 'win32' and '64 bit' in sys.version: |
| 286 | extra_compile_args.append('-DMS_WIN64') |
| 287 | |
| 288 | # MSVS default is dymanic |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 289 | if sys.platform == 'win32': |
Paul Yang | c931743 | 2018-04-02 15:55:28 -0700 | [diff] [blame] | 290 | extra_compile_args.append('/MT') |
| 291 | |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 292 | if 'clang' in os.popen('$CC --version 2> /dev/null').read(): |
Josh Haberman | d8814ed | 2015-10-07 11:46:23 -0700 | [diff] [blame] | 293 | extra_compile_args.append('-Wno-shorten-64-to-32') |
Josh Haberman | 00700b7 | 2015-10-06 14:13:09 -0700 | [diff] [blame] | 294 | |
| 295 | if warnings_as_errors in sys.argv: |
| 296 | extra_compile_args.append('-Werror') |
| 297 | sys.argv.remove(warnings_as_errors) |
| 298 | |
jieluo@google.com | 1eba9d9 | 2014-08-25 20:17:53 +0000 | [diff] [blame] | 299 | # C++ implementation extension |
Manjunath Kudlur | cf828de | 2016-03-25 10:58:46 -0700 | [diff] [blame] | 300 | ext_module_list.extend([ |
Tamir Duberstein | 21a7cf9 | 2015-04-11 18:24:24 -0700 | [diff] [blame] | 301 | Extension( |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 302 | 'google.protobuf.pyext._message', |
Tamir Duberstein | 5018c43 | 2015-05-08 08:48:40 -0400 | [diff] [blame] | 303 | glob.glob('google/protobuf/pyext/*.cc'), |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 304 | include_dirs=['.', '../src'], |
Manjunath Kudlur | cf828de | 2016-03-25 10:58:46 -0700 | [diff] [blame] | 305 | libraries=libraries, |
| 306 | extra_objects=extra_objects, |
Adam Cozzette | a035bd0 | 2022-01-25 08:24:12 -0800 | [diff] [blame] | 307 | extra_link_args=message_extra_link_args, |
Tamir Duberstein | 21a7cf9 | 2015-04-11 18:24:24 -0700 | [diff] [blame] | 308 | library_dirs=['../src/.libs'], |
Josh Haberman | 00700b7 | 2015-10-06 14:13:09 -0700 | [diff] [blame] | 309 | extra_compile_args=extra_compile_args, |
Manjunath Kudlur | cf828de | 2016-03-25 10:58:46 -0700 | [diff] [blame] | 310 | ), |
| 311 | Extension( |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 312 | 'google.protobuf.internal._api_implementation', |
Manjunath Kudlur | cf828de | 2016-03-25 10:58:46 -0700 | [diff] [blame] | 313 | glob.glob('google/protobuf/internal/api_implementation.cc'), |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 314 | extra_compile_args=(extra_compile_args + |
| 315 | ['-DPYTHON_PROTO2_CPP_IMPL_V2']), |
Adam Cozzette | a035bd0 | 2022-01-25 08:24:12 -0800 | [diff] [blame] | 316 | extra_link_args=api_implementation_link_args, |
Manjunath Kudlur | cf828de | 2016-03-25 10:58:46 -0700 | [diff] [blame] | 317 | ), |
| 318 | ]) |
Jisi Liu | ada6556 | 2015-02-25 16:39:11 -0800 | [diff] [blame] | 319 | os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'] = 'cpp' |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 320 | |
Dan O'Reilly | 3791c80 | 2015-08-20 20:49:45 -0400 | [diff] [blame] | 321 | # Keep this list of dependencies in sync with tox.ini. |
Joshua Haberman | a33aa73 | 2021-09-09 13:20:34 -0700 | [diff] [blame] | 322 | install_requires = [] |
Dan O'Reilly | 2621c8a | 2015-08-14 22:54:53 -0400 | [diff] [blame] | 323 | |
Tamir Duberstein | 21a7cf9 | 2015-04-11 18:24:24 -0700 | [diff] [blame] | 324 | setup( |
| 325 | name='protobuf', |
| 326 | version=GetVersion(), |
| 327 | description='Protocol Buffers', |
Feng Xiao | afe98de | 2018-08-22 11:55:30 -0700 | [diff] [blame] | 328 | download_url='https://github.com/protocolbuffers/protobuf/releases', |
Tamir Duberstein | 21a7cf9 | 2015-04-11 18:24:24 -0700 | [diff] [blame] | 329 | long_description="Protocol Buffers are Google's data interchange format", |
| 330 | url='https://developers.google.com/protocol-buffers/', |
| 331 | maintainer='protobuf@googlegroups.com', |
| 332 | maintainer_email='protobuf@googlegroups.com', |
Maximilian | 82372d8 | 2022-01-27 01:23:14 +0100 | [diff] [blame] | 333 | license='BSD-3-Clause', |
Tamir Duberstein | 21a7cf9 | 2015-04-11 18:24:24 -0700 | [diff] [blame] | 334 | classifiers=[ |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 335 | 'Programming Language :: Python', |
| 336 | 'Programming Language :: Python :: 3', |
| 337 | 'Programming Language :: Python :: 3.7', |
| 338 | 'Programming Language :: Python :: 3.8', |
| 339 | 'Programming Language :: Python :: 3.9', |
| 340 | 'Programming Language :: Python :: 3.10', |
Adam Cozzette | 3afc828 | 2021-10-08 16:45:26 -0700 | [diff] [blame] | 341 | ], |
Craig Citro | 0e7c0c2 | 2016-03-04 20:40:24 -0800 | [diff] [blame] | 342 | namespace_packages=['google'], |
Tamir Duberstein | 21a7cf9 | 2015-04-11 18:24:24 -0700 | [diff] [blame] | 343 | packages=find_packages( |
| 344 | exclude=[ |
| 345 | 'import_test_package', |
David L. Jones | ff06e23 | 2020-08-31 10:40:57 -0700 | [diff] [blame] | 346 | 'protobuf_distutils', |
Adam Cozzette | 3afc828 | 2021-10-08 16:45:26 -0700 | [diff] [blame] | 347 | ],), |
Tamir Duberstein | 21a7cf9 | 2015-04-11 18:24:24 -0700 | [diff] [blame] | 348 | test_suite='google.protobuf.internal', |
| 349 | cmdclass={ |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 350 | 'clean': CleanCmd, |
| 351 | 'build_py': BuildPyCmd, |
| 352 | 'build_ext': BuildExtCmd, |
| 353 | 'test_conformance': TestConformanceCmd, |
Tamir Duberstein | 21a7cf9 | 2015-04-11 18:24:24 -0700 | [diff] [blame] | 354 | }, |
Dan O'Reilly | 2621c8a | 2015-08-14 22:54:53 -0400 | [diff] [blame] | 355 | install_requires=install_requires, |
Tamir Duberstein | 21a7cf9 | 2015-04-11 18:24:24 -0700 | [diff] [blame] | 356 | ext_modules=ext_module_list, |
David L. Jones | 1ba1d73 | 2022-02-17 09:53:51 -0800 | [diff] [blame] | 357 | python_requires='>=3.7', |
Tamir Duberstein | 21a7cf9 | 2015-04-11 18:24:24 -0700 | [diff] [blame] | 358 | ) |