From 89be7a031df4f410769b7ff8491664d7f1f73f5c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 30 Dec 2018 15:22:05 +0530 Subject: [PATCH] Fix #1278 --- setup.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index f4691303e..cd8cac9bf 100755 --- a/setup.py +++ b/setup.py @@ -393,14 +393,22 @@ def compile_c_extension(kenv, module, incremental, compilation_database, all_key todo[original_src] = cmd if todo: parallel_run(todo) - dest = os.path.join(base, module + '.so') + dest = os.path.join(base, module + '.temp.so') if not incremental or newer(dest, *objects): # Old versions of clang don't like -pthread being passed to the linker # Don't treat linker warnings as errors (linker generates spurious # warnings on some old systems) unsafe = {'-pthread', '-Werror', '-pedantic-errors'} linker_cflags = list(filter(lambda x: x not in unsafe, kenv.cflags)) - run_tool([kenv.cc] + linker_cflags + kenv.ldflags + objects + kenv.ldpaths + ['-o', dest], desc='Linking {} ...'.format(emphasis(module))) + try: + run_tool([kenv.cc] + linker_cflags + kenv.ldflags + objects + kenv.ldpaths + ['-o', dest], desc='Linking {} ...'.format(emphasis(module))) + except Exception: + try: + os.remove(dest) + except EnvironmentError: + pass + else: + os.rename(dest, dest[:-len('.temp.so')] + '.so') def find_c_files():