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