コード例 #1
0
    def build_extensions(self):
        def compiler_ok_with_extra_std():
            """Test if default compiler is okay with specifying c++ version
            when invoked in C mode. GCC is okay with this, while clang is not.
            """
            try:
                if platform.system() == 'Windows':
                    return False
                # TODO(lidiz) Remove the generated a.out for success tests.
                cc_test = subprocess.Popen(
                    ['cc', '-x', 'c', '-std=c++11', '-'],
                    stdin=subprocess.PIPE,
                    stdout=subprocess.PIPE,
                    stderr=subprocess.PIPE)
                _, cc_err = cc_test.communicate(input=b'int main(){return 0;}')
                return not 'invalid argument' in str(cc_err)
            except:
                sys.stderr.write(traceback.format_exc() + '\n')
                return False

        # This special conditioning is here due to difference of compiler
        #   behavior in gcc and clang. The clang doesn't take --stdc++11
        #   flags but gcc does. Since the setuptools of Python only support
        #   all C or all C++ compilation, the mix of C and C++ will crash.
        #   *By default*, macOS and FreBSD use clang and Linux use gcc
        #
        #   If we are not using a permissive compiler that's OK with being
        #   passed wrong std flags, swap out compile function by adding a filter
        #   for it.
        if not compiler_ok_with_extra_std():
            old_compile = self.compiler._compile

            def new_compile(obj, src, ext, cc_args, extra_postargs, pp_opts):
                if src[-2:] == '.c':
                    extra_postargs = [
                        arg for arg in extra_postargs if not '-std=c++' in arg
                    ]
                return old_compile(obj, src, ext, cc_args, extra_postargs,
                                   pp_opts)

            self.compiler._compile = new_compile

        compiler = self.compiler.compiler_type
        if compiler in BuildExt.C_OPTIONS:
            for extension in self.extensions:
                extension.extra_compile_args += list(
                    BuildExt.C_OPTIONS[compiler])
        if compiler in BuildExt.LINK_OPTIONS:
            for extension in self.extensions:
                extension.extra_link_args += list(
                    BuildExt.LINK_OPTIONS[compiler])
        if not check_and_update_cythonization(self.extensions):
            self.extensions = try_cythonize(self.extensions)
        try:
            build_ext.build_ext.build_extensions(self)
        except Exception as error:
            formatted_exception = traceback.format_exc()
            support.diagnose_build_ext_error(self, error, formatted_exception)
            raise CommandError(
                "Failed `build_ext` step:\n{}".format(formatted_exception))
コード例 #2
0
ファイル: commands.py プロジェクト: zhangqibupt/grpc
    def build_extensions(self):
        if "darwin" in sys.platform:
            config = os.environ.get('CONFIG', 'opt')
            target_path = os.path.abspath(
                os.path.join(
                    os.path.dirname(os.path.realpath(__file__)), '..', '..',
                    '..', 'libs', config))
            targets = [
                os.path.join(target_path, 'libboringssl.a'),
                os.path.join(target_path, 'libares.a'),
                os.path.join(target_path, 'libgpr.a'),
                os.path.join(target_path, 'libgrpc.a')
            ]
            # Running make separately for Mac means we lose all
            # Extension.define_macros configured in setup.py. Re-add the macro
            # for gRPC Core's fork handlers.
            # TODO(ericgribkoff) Decide what to do about the other missing core
            #   macros, including GRPC_ENABLE_FORK_SUPPORT, which defaults to 1
            #   on Linux but remains unset on Mac.
            extra_defines = [
                'EXTRA_DEFINES="GRPC_POSIX_FORK_ALLOW_PTHREAD_ATFORK=1"'
            ]
            # Ensure the BoringSSL are built instead of using system provided
            #   libraries. It prevents dependency issues while distributing to
            #   Mac users who use MacPorts to manage their libraries. #17002
            mod_env = dict(os.environ)
            mod_env['REQUIRE_CUSTOM_LIBRARIES_opt'] = '1'
            make_process = subprocess.Popen(
                ['make'] + extra_defines + targets,
                env=mod_env,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE)
            make_out, make_err = make_process.communicate()
            if make_out and make_process.returncode != 0:
                sys.stdout.write(str(make_out) + '\n')
            if make_err:
                sys.stderr.write(str(make_err) + '\n')
            if make_process.returncode != 0:
                raise Exception("make command failed!")

        compiler = self.compiler.compiler_type
        if compiler in BuildExt.C_OPTIONS:
            for extension in self.extensions:
                extension.extra_compile_args += list(
                    BuildExt.C_OPTIONS[compiler])
        if compiler in BuildExt.LINK_OPTIONS:
            for extension in self.extensions:
                extension.extra_link_args += list(
                    BuildExt.LINK_OPTIONS[compiler])
        if not check_and_update_cythonization(self.extensions):
            self.extensions = try_cythonize(self.extensions)
        try:
            build_ext.build_ext.build_extensions(self)
        except Exception as error:
            formatted_exception = traceback.format_exc()
            support.diagnose_build_ext_error(self, error, formatted_exception)
            raise CommandError(
                "Failed `build_ext` step:\n{}".format(formatted_exception))
コード例 #3
0
    def build_extensions(self):
        def compiler_ok_with_extra_std():
            """Test if default compiler is okay with specifying c++ version
            when invoked in C mode. GCC is okay with this, while clang is not.
            """
            cc = self.compiler.compiler[0]
            cc_test = subprocess.Popen([cc, '-x', 'c', '-std=c++11', '-'],
                                       stdin=subprocess.PIPE,
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.PIPE)
            _, cc_err = cc_test.communicate(input=b'int main(){return 0;}')
            # We don't check .returncode because we're looking for the failure; missing
            # compiler is also a failure, but hopefully this uses the same one that real
            # compilations will later use, which will provide a user-visible error.
            return not 'invalid argument' in str(cc_err)

        # This special conditioning is here due to difference of compiler
        #   behavior in gcc and clang. The clang doesn't take --stdc++11
        #   flags but gcc does. Since the setuptools of Python only support
        #   all C or all C++ compilation, the mix of C and C++ will crash.
        #   *By default*, macOS and FreBSD use clang and Linux use gcc
        #
        #   If we are not using a permissive compiler that's OK with being
        #   passed wrong std flags, swap out compile function by adding a filter
        #   for it.
        if not compiler_ok_with_extra_std():
            old_compile = self.compiler._compile

            def new_compile(obj, src, ext, cc_args, extra_postargs, pp_opts):
                if src[-2:] == '.c':
                    extra_postargs = [
                        arg for arg in extra_postargs if not '-std=c++' in arg
                    ]
                return old_compile(obj, src, ext, cc_args, extra_postargs,
                                   pp_opts)

            self.compiler._compile = new_compile

        compiler = self.compiler.compiler_type
        if compiler in BuildExt.C_OPTIONS:
            for extension in self.extensions:
                extension.extra_compile_args += list(
                    BuildExt.C_OPTIONS[compiler])
        if compiler in BuildExt.LINK_OPTIONS:
            for extension in self.extensions:
                extension.extra_link_args += list(
                    BuildExt.LINK_OPTIONS[compiler])
        if not check_and_update_cythonization(self.extensions):
            self.extensions = try_cythonize(self.extensions)
        try:
            build_ext.build_ext.build_extensions(self)
        except Exception as error:
            formatted_exception = traceback.format_exc()
            support.diagnose_build_ext_error(self, error, formatted_exception)
            raise CommandError(
                "Failed `build_ext` step:\n{}".format(formatted_exception))
コード例 #4
0
ファイル: commands.py プロジェクト: Falco20019/grpc
    def build_extensions(self):

        def compiler_ok_with_extra_std():
            """Test if default compiler is okay with specifying c++ version
            when invoked in C mode. GCC is okay with this, while clang is not.
            """
            cc_test = subprocess.Popen(
                ['cc', '-x', 'c', '-std=c++11', '-'],
                stdin=subprocess.PIPE,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE)
            _, cc_err = cc_test.communicate(input=b'int main(){return 0;}')
            return not 'invalid argument' in str(cc_err)

        # This special conditioning is here due to difference of compiler
        #   behavior in gcc and clang. The clang doesn't take --stdc++11
        #   flags but gcc does. Since the setuptools of Python only support
        #   all C or all C++ compilation, the mix of C and C++ will crash.
        #   *By default*, macOS and FreBSD use clang and Linux use gcc
        #
        #   If we are not using a permissive compiler that's OK with being
        #   passed wrong std flags, swap out compile function by adding a filter
        #   for it.
        if not compiler_ok_with_extra_std():
            old_compile = self.compiler._compile

            def new_compile(obj, src, ext, cc_args, extra_postargs, pp_opts):
                if src[-2:] == '.c':
                    extra_postargs = [
                        arg for arg in extra_postargs if not '-std=c++' in arg
                    ]
                return old_compile(obj, src, ext, cc_args, extra_postargs,
                                   pp_opts)

            self.compiler._compile = new_compile

        compiler = self.compiler.compiler_type
        if compiler in BuildExt.C_OPTIONS:
            for extension in self.extensions:
                extension.extra_compile_args += list(
                    BuildExt.C_OPTIONS[compiler])
        if compiler in BuildExt.LINK_OPTIONS:
            for extension in self.extensions:
                extension.extra_link_args += list(
                    BuildExt.LINK_OPTIONS[compiler])
        if not check_and_update_cythonization(self.extensions):
            self.extensions = try_cythonize(self.extensions)
        try:
            build_ext.build_ext.build_extensions(self)
        except Exception as error:
            formatted_exception = traceback.format_exc()
            support.diagnose_build_ext_error(self, error, formatted_exception)
            raise CommandError(
                "Failed `build_ext` step:\n{}".format(formatted_exception))
コード例 #5
0
ファイル: commands.py プロジェクト: alexinblock/grpc
    def build_extensions(self):
        if "darwin" in sys.platform:
            config = os.environ.get('CONFIG', 'opt')
            target_path = os.path.abspath(
                os.path.join(
                    os.path.dirname(os.path.realpath(__file__)), '..', '..',
                    '..', 'libs', config))
            targets = [
                os.path.join(target_path, 'libboringssl.a'),
                os.path.join(target_path, 'libares.a'),
                os.path.join(target_path, 'libgpr.a'),
                os.path.join(target_path, 'libgrpc.a')
            ]
            # Running make separately for Mac means we lose all
            # Extension.define_macros configured in setup.py. Re-add the macro
            # for gRPC Core's fork handlers.
            # TODO(ericgribkoff) Decide what to do about the other missing core
            #   macros, including GRPC_ENABLE_FORK_SUPPORT, which defaults to 1
            #   on Linux but remains unset on Mac.
            extra_defines = [
                'EXTRA_DEFINES="GRPC_POSIX_FORK_ALLOW_PTHREAD_ATFORK=1"'
            ]
            make_process = subprocess.Popen(
                ['make'] + extra_defines + targets,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE)
            make_out, make_err = make_process.communicate()
            if make_out and make_process.returncode != 0:
                sys.stdout.write(str(make_out) + '\n')
            if make_err:
                sys.stderr.write(str(make_err) + '\n')
            if make_process.returncode != 0:
                raise Exception("make command failed!")

        compiler = self.compiler.compiler_type
        if compiler in BuildExt.C_OPTIONS:
            for extension in self.extensions:
                extension.extra_compile_args += list(
                    BuildExt.C_OPTIONS[compiler])
        if compiler in BuildExt.LINK_OPTIONS:
            for extension in self.extensions:
                extension.extra_link_args += list(
                    BuildExt.LINK_OPTIONS[compiler])
        if not check_and_update_cythonization(self.extensions):
            self.extensions = try_cythonize(self.extensions)
        try:
            build_ext.build_ext.build_extensions(self)
        except Exception as error:
            formatted_exception = traceback.format_exc()
            support.diagnose_build_ext_error(self, error, formatted_exception)
            raise CommandError(
                "Failed `build_ext` step:\n{}".format(formatted_exception))
コード例 #6
0
ファイル: commands.py プロジェクト: srv4wang/grpc
 def build_extensions(self):
   compiler = self.compiler.compiler_type
   if compiler in BuildExt.C_OPTIONS:
     for extension in self.extensions:
       extension.extra_compile_args += list(BuildExt.C_OPTIONS[compiler])
   if compiler in BuildExt.LINK_OPTIONS:
     for extension in self.extensions:
       extension.extra_link_args += list(BuildExt.LINK_OPTIONS[compiler])
   try:
     build_ext.build_ext.build_extensions(self)
   except Exception as error:
     formatted_exception = traceback.format_exc()
     support.diagnose_build_ext_error(self, error, formatted_exception)
     raise CommandError(
         "Failed `build_ext` step:\n{}".format(formatted_exception))
コード例 #7
0
ファイル: commands.py プロジェクト: nimrodp/grpc
 def build_extensions(self):
   compiler = self.compiler.compiler_type
   if compiler in BuildExt.C_OPTIONS:
     for extension in self.extensions:
       extension.extra_compile_args += list(BuildExt.C_OPTIONS[compiler])
   if compiler in BuildExt.LINK_OPTIONS:
     for extension in self.extensions:
       extension.extra_link_args += list(BuildExt.LINK_OPTIONS[compiler])
   try:
     build_ext.build_ext.build_extensions(self)
   except KeyboardInterrupt:
     raise
   except Exception as error:
     support.diagnose_build_ext_error(self, error, traceback.format_exc())
     raise CommandError("Failed `build_ext` step.")
コード例 #8
0
ファイル: commands.py プロジェクト: zengchunyun/grpc
    def build_extensions(self):
        if "darwin" in sys.platform:
            config = os.environ.get('CONFIG', 'opt')
            target_path = os.path.abspath(
                os.path.join(
                    os.path.dirname(os.path.realpath(__file__)), '..', '..',
                    '..', 'libs', config))
            targets = [
                os.path.join(target_path, 'libboringssl.a'),
                os.path.join(target_path, 'libares.a'),
                os.path.join(target_path, 'libgpr.a'),
                os.path.join(target_path, 'libgrpc.a')
            ]
            make_process = subprocess.Popen(
                ['make'] + targets,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE)
            make_out, make_err = make_process.communicate()
            if make_out and make_process.returncode != 0:
                sys.stdout.write(make_out + '\n')
            if make_err:
                sys.stderr.write(make_err + '\n')
            if make_process.returncode != 0:
                raise Exception("make command failed!")

        compiler = self.compiler.compiler_type
        if compiler in BuildExt.C_OPTIONS:
            for extension in self.extensions:
                extension.extra_compile_args += list(
                    BuildExt.C_OPTIONS[compiler])
        if compiler in BuildExt.LINK_OPTIONS:
            for extension in self.extensions:
                extension.extra_link_args += list(
                    BuildExt.LINK_OPTIONS[compiler])
        if not check_and_update_cythonization(self.extensions):
            self.extensions = try_cythonize(self.extensions)
        try:
            build_ext.build_ext.build_extensions(self)
        except Exception as error:
            formatted_exception = traceback.format_exc()
            support.diagnose_build_ext_error(self, error, formatted_exception)
            raise CommandError(
                "Failed `build_ext` step:\n{}".format(formatted_exception))
コード例 #9
0
ファイル: commands.py プロジェクト: CCNITSilchar/grpc
    def build_extensions(self):
        if "darwin" in sys.platform:
            config = os.environ.get('CONFIG', 'opt')
            target_path = os.path.abspath(
                os.path.join(
                    os.path.dirname(os.path.realpath(__file__)), '..', '..',
                    '..', 'libs', config))
            targets = [
                os.path.join(target_path, 'libboringssl.a'),
                os.path.join(target_path, 'libares.a'),
                os.path.join(target_path, 'libgpr.a'),
                os.path.join(target_path, 'libgrpc.a')
            ]
            make_process = subprocess.Popen(
                ['make'] + targets,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE)
            make_out, make_err = make_process.communicate()
            if make_out and make_process.returncode != 0:
                sys.stdout.write(str(make_out) + '\n')
            if make_err:
                sys.stderr.write(str(make_err) + '\n')
            if make_process.returncode != 0:
                raise Exception("make command failed!")

        compiler = self.compiler.compiler_type
        if compiler in BuildExt.C_OPTIONS:
            for extension in self.extensions:
                extension.extra_compile_args += list(
                    BuildExt.C_OPTIONS[compiler])
        if compiler in BuildExt.LINK_OPTIONS:
            for extension in self.extensions:
                extension.extra_link_args += list(
                    BuildExt.LINK_OPTIONS[compiler])
        if not check_and_update_cythonization(self.extensions):
            self.extensions = try_cythonize(self.extensions)
        try:
            build_ext.build_ext.build_extensions(self)
        except Exception as error:
            formatted_exception = traceback.format_exc()
            support.diagnose_build_ext_error(self, error, formatted_exception)
            raise CommandError(
                "Failed `build_ext` step:\n{}".format(formatted_exception))
コード例 #10
0
    def build_extensions(self):
        # This special conditioning is here due to difference of compiler
        #   behavior in gcc and clang. The clang doesn't take --stdc++11
        #   flags but gcc does. Since the setuptools of Python only support
        #   all C or all C++ compilation, the mix of C and C++ will crash.
        #   *By default*, the macOS use clang and Linux use gcc, that's why
        #   the special condition here is checking platform.
        if "darwin" in sys.platform:
            config = os.environ.get('CONFIG', 'opt')
            target_path = os.path.abspath(
                os.path.join(
                    os.path.dirname(os.path.realpath(__file__)), '..', '..',
                    '..', 'libs', config))
            targets = [
                os.path.join(target_path, 'libboringssl.a'),
                os.path.join(target_path, 'libares.a'),
                os.path.join(target_path, 'libgpr.a'),
                os.path.join(target_path, 'libgrpc.a')
            ]
            # Running make separately for Mac means we lose all
            # Extension.define_macros configured in setup.py. Re-add the macro
            # for gRPC Core's fork handlers.
            # TODO(ericgribkoff) Decide what to do about the other missing core
            #   macros, including GRPC_ENABLE_FORK_SUPPORT, which defaults to 1
            #   on Linux but remains unset on Mac.
            extra_defines = [
                'EXTRA_DEFINES="GRPC_POSIX_FORK_ALLOW_PTHREAD_ATFORK=1"'
            ]
            # Ensure the BoringSSL are built instead of using system provided
            #   libraries. It prevents dependency issues while distributing to
            #   Mac users who use MacPorts to manage their libraries. #17002
            mod_env = dict(os.environ)
            mod_env['REQUIRE_CUSTOM_LIBRARIES_opt'] = '1'
            make_process = subprocess.Popen(
                ['make'] + extra_defines + targets,
                env=mod_env,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE)
            make_out, make_err = make_process.communicate()
            if make_out and make_process.returncode != 0:
                sys.stdout.write(str(make_out) + '\n')
            if make_err:
                sys.stderr.write(str(make_err) + '\n')
            if make_process.returncode != 0:
                raise Exception("make command failed!")

        compiler = self.compiler.compiler_type
        if compiler in BuildExt.C_OPTIONS:
            for extension in self.extensions:
                extension.extra_compile_args += list(
                    BuildExt.C_OPTIONS[compiler])
        if compiler in BuildExt.LINK_OPTIONS:
            for extension in self.extensions:
                extension.extra_link_args += list(
                    BuildExt.LINK_OPTIONS[compiler])
        if not check_and_update_cythonization(self.extensions):
            self.extensions = try_cythonize(self.extensions)
        try:
            build_ext.build_ext.build_extensions(self)
        except Exception as error:
            formatted_exception = traceback.format_exc()
            support.diagnose_build_ext_error(self, error, formatted_exception)
            raise CommandError(
                "Failed `build_ext` step:\n{}".format(formatted_exception))