From da2b49f7a78d48bbc95404f965bec70e789ee00a Mon Sep 17 00:00:00 2001 From: mattip Date: Fri, 18 Oct 2024 07:43:10 +0300 Subject: [PATCH] when building, cd into tmpdir to shorten builddir name on windows --- src/cffi/verifier.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/cffi/verifier.py b/src/cffi/verifier.py index e392a2b7..e494d1c8 100644 --- a/src/cffi/verifier.py +++ b/src/cffi/verifier.py @@ -197,8 +197,20 @@ def _write_source(self, file=None): def _compile_module(self): # compile this C source + # Note: compilation will create artifacts in tmpdir + sourcefilename + # This can exceed the windows MAXPATH quite easily. To make it shorter, + # cd into tmpdir and make the sourcefilename relative to tmdir tmpdir = os.path.dirname(self.sourcefilename) - outputfilename = ffiplatform.compile(tmpdir, self.get_extension()) + olddir = os.getcwd() + os.chdir(tmpdir) + self.sourcefilename_orig = self.sourcefilename + try: + self.sourcefilename = os.path.relpath(self.sourcefilename) + output_rel_filename = ffiplatform.compile(tmpdir, self.get_extension()) + outputfilename = os.path.join(tmpdir, output_rel_filename) + finally: + os.chdir(olddir) + self.sourcefilename = self.sourcefilename_orig try: same = ffiplatform.samefile(outputfilename, self.modulefilename) except OSError: